Gerd Hoffmann | 7282a03 | 2009-07-31 12:25:35 +0200 | [diff] [blame] | 1 | #include "qemu-common.h" |
| 2 | #include "qemu-option.h" |
| 3 | #include "qemu-config.h" |
| 4 | |
| 5 | QemuOptsList qemu_drive_opts = { |
| 6 | .name = "drive", |
| 7 | .head = TAILQ_HEAD_INITIALIZER(qemu_drive_opts.head), |
| 8 | .desc = { |
| 9 | { |
| 10 | .name = "bus", |
| 11 | .type = QEMU_OPT_NUMBER, |
| 12 | .help = "bus number", |
| 13 | },{ |
| 14 | .name = "unit", |
| 15 | .type = QEMU_OPT_NUMBER, |
| 16 | .help = "unit number (i.e. lun for scsi)", |
| 17 | },{ |
| 18 | .name = "if", |
| 19 | .type = QEMU_OPT_STRING, |
| 20 | .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)", |
| 21 | },{ |
| 22 | .name = "index", |
| 23 | .type = QEMU_OPT_NUMBER, |
| 24 | },{ |
| 25 | .name = "cyls", |
| 26 | .type = QEMU_OPT_NUMBER, |
| 27 | .help = "number of cylinders (ide disk geometry)", |
| 28 | },{ |
| 29 | .name = "heads", |
| 30 | .type = QEMU_OPT_NUMBER, |
| 31 | .help = "number of heads (ide disk geometry)", |
| 32 | },{ |
| 33 | .name = "secs", |
| 34 | .type = QEMU_OPT_NUMBER, |
| 35 | .help = "number of sectors (ide disk geometry)", |
| 36 | },{ |
| 37 | .name = "trans", |
| 38 | .type = QEMU_OPT_STRING, |
| 39 | .help = "chs translation (auto, lba. none)", |
| 40 | },{ |
| 41 | .name = "media", |
| 42 | .type = QEMU_OPT_STRING, |
| 43 | .help = "media type (disk, cdrom)", |
| 44 | },{ |
| 45 | .name = "snapshot", |
| 46 | .type = QEMU_OPT_BOOL, |
| 47 | },{ |
| 48 | .name = "file", |
| 49 | .type = QEMU_OPT_STRING, |
| 50 | .help = "disk image", |
| 51 | },{ |
| 52 | .name = "cache", |
| 53 | .type = QEMU_OPT_STRING, |
| 54 | .help = "host cache usage (none, writeback, writethrough)", |
| 55 | },{ |
Christoph Hellwig | 5c6c3a6 | 2009-08-20 16:58:35 +0200 | [diff] [blame] | 56 | .name = "aio", |
| 57 | .type = QEMU_OPT_STRING, |
| 58 | .help = "host AIO implementation (threads, native)", |
| 59 | },{ |
Gerd Hoffmann | 7282a03 | 2009-07-31 12:25:35 +0200 | [diff] [blame] | 60 | .name = "format", |
| 61 | .type = QEMU_OPT_STRING, |
| 62 | .help = "disk format (raw, qcow2, ...)", |
| 63 | },{ |
| 64 | .name = "serial", |
| 65 | .type = QEMU_OPT_STRING, |
| 66 | },{ |
| 67 | .name = "werror", |
| 68 | .type = QEMU_OPT_STRING, |
| 69 | },{ |
| 70 | .name = "addr", |
| 71 | .type = QEMU_OPT_STRING, |
| 72 | .help = "pci address (virtio only)", |
| 73 | }, |
| 74 | { /* end if list */ } |
| 75 | }, |
| 76 | }; |
| 77 | |
Gerd Hoffmann | f31d07d | 2009-07-31 12:25:37 +0200 | [diff] [blame] | 78 | QemuOptsList qemu_device_opts = { |
| 79 | .name = "device", |
| 80 | .head = TAILQ_HEAD_INITIALIZER(qemu_device_opts.head), |
| 81 | .desc = { |
| 82 | /* |
| 83 | * no elements => accept any |
| 84 | * sanity checking will happen later |
| 85 | * when setting device properties |
| 86 | */ |
| 87 | { /* end if list */ } |
| 88 | }, |
| 89 | }; |
| 90 | |
Gerd Hoffmann | d058fe0 | 2009-07-31 12:25:36 +0200 | [diff] [blame] | 91 | static QemuOptsList *lists[] = { |
| 92 | &qemu_drive_opts, |
Gerd Hoffmann | f31d07d | 2009-07-31 12:25:37 +0200 | [diff] [blame] | 93 | &qemu_device_opts, |
Gerd Hoffmann | d058fe0 | 2009-07-31 12:25:36 +0200 | [diff] [blame] | 94 | NULL, |
| 95 | }; |
| 96 | |
| 97 | int qemu_set_option(const char *str) |
| 98 | { |
| 99 | char group[64], id[64], arg[64]; |
| 100 | QemuOpts *opts; |
| 101 | int i, rc, offset; |
| 102 | |
| 103 | rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset); |
| 104 | if (rc < 3 || str[offset] != '=') { |
| 105 | fprintf(stderr, "can't parse: \"%s\"\n", str); |
| 106 | return -1; |
| 107 | } |
| 108 | |
| 109 | for (i = 0; lists[i] != NULL; i++) { |
| 110 | if (strcmp(lists[i]->name, group) == 0) |
| 111 | break; |
| 112 | } |
| 113 | if (lists[i] == NULL) { |
| 114 | fprintf(stderr, "there is no option group \"%s\"\n", group); |
| 115 | return -1; |
| 116 | } |
| 117 | |
| 118 | opts = qemu_opts_find(lists[i], id); |
| 119 | if (!opts) { |
| 120 | fprintf(stderr, "there is no %s \"%s\" defined\n", |
| 121 | lists[i]->name, id); |
| 122 | return -1; |
| 123 | } |
| 124 | |
| 125 | if (-1 == qemu_opt_set(opts, arg, str+offset+1)) { |
| 126 | fprintf(stderr, "failed to set \"%s\" for %s \"%s\"\n", |
| 127 | arg, lists[i]->name, id); |
| 128 | return -1; |
| 129 | } |
| 130 | return 0; |
| 131 | } |
| 132 | |