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" |
Gerd Hoffmann | a861c45 | 2009-09-25 21:42:40 +0200 | [diff] [blame] | 4 | #include "sysemu.h" |
Gerd Hoffmann | 7282a03 | 2009-07-31 12:25:35 +0200 | [diff] [blame] | 5 | |
| 6 | QemuOptsList qemu_drive_opts = { |
| 7 | .name = "drive", |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 8 | .head = QTAILQ_HEAD_INITIALIZER(qemu_drive_opts.head), |
Gerd Hoffmann | 7282a03 | 2009-07-31 12:25:35 +0200 | [diff] [blame] | 9 | .desc = { |
| 10 | { |
| 11 | .name = "bus", |
| 12 | .type = QEMU_OPT_NUMBER, |
| 13 | .help = "bus number", |
| 14 | },{ |
| 15 | .name = "unit", |
| 16 | .type = QEMU_OPT_NUMBER, |
| 17 | .help = "unit number (i.e. lun for scsi)", |
| 18 | },{ |
| 19 | .name = "if", |
| 20 | .type = QEMU_OPT_STRING, |
| 21 | .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)", |
| 22 | },{ |
| 23 | .name = "index", |
| 24 | .type = QEMU_OPT_NUMBER, |
| 25 | },{ |
| 26 | .name = "cyls", |
| 27 | .type = QEMU_OPT_NUMBER, |
| 28 | .help = "number of cylinders (ide disk geometry)", |
| 29 | },{ |
| 30 | .name = "heads", |
| 31 | .type = QEMU_OPT_NUMBER, |
| 32 | .help = "number of heads (ide disk geometry)", |
| 33 | },{ |
| 34 | .name = "secs", |
| 35 | .type = QEMU_OPT_NUMBER, |
| 36 | .help = "number of sectors (ide disk geometry)", |
| 37 | },{ |
| 38 | .name = "trans", |
| 39 | .type = QEMU_OPT_STRING, |
| 40 | .help = "chs translation (auto, lba. none)", |
| 41 | },{ |
| 42 | .name = "media", |
| 43 | .type = QEMU_OPT_STRING, |
| 44 | .help = "media type (disk, cdrom)", |
| 45 | },{ |
| 46 | .name = "snapshot", |
| 47 | .type = QEMU_OPT_BOOL, |
| 48 | },{ |
| 49 | .name = "file", |
| 50 | .type = QEMU_OPT_STRING, |
| 51 | .help = "disk image", |
| 52 | },{ |
| 53 | .name = "cache", |
| 54 | .type = QEMU_OPT_STRING, |
| 55 | .help = "host cache usage (none, writeback, writethrough)", |
| 56 | },{ |
Christoph Hellwig | 5c6c3a6 | 2009-08-20 16:58:35 +0200 | [diff] [blame] | 57 | .name = "aio", |
| 58 | .type = QEMU_OPT_STRING, |
| 59 | .help = "host AIO implementation (threads, native)", |
| 60 | },{ |
Gerd Hoffmann | 7282a03 | 2009-07-31 12:25:35 +0200 | [diff] [blame] | 61 | .name = "format", |
| 62 | .type = QEMU_OPT_STRING, |
| 63 | .help = "disk format (raw, qcow2, ...)", |
| 64 | },{ |
| 65 | .name = "serial", |
| 66 | .type = QEMU_OPT_STRING, |
| 67 | },{ |
| 68 | .name = "werror", |
| 69 | .type = QEMU_OPT_STRING, |
| 70 | },{ |
| 71 | .name = "addr", |
| 72 | .type = QEMU_OPT_STRING, |
| 73 | .help = "pci address (virtio only)", |
Naphtali Sprei | 59f2689 | 2009-10-26 16:25:16 +0200 | [diff] [blame] | 74 | },{ |
| 75 | .name = "readonly", |
| 76 | .type = QEMU_OPT_BOOL, |
Gerd Hoffmann | 7282a03 | 2009-07-31 12:25:35 +0200 | [diff] [blame] | 77 | }, |
| 78 | { /* end if list */ } |
| 79 | }, |
| 80 | }; |
| 81 | |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 82 | QemuOptsList qemu_chardev_opts = { |
| 83 | .name = "chardev", |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 84 | .head = QTAILQ_HEAD_INITIALIZER(qemu_chardev_opts.head), |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 85 | .desc = { |
Gerd Hoffmann | 7d31544 | 2009-09-10 10:58:36 +0200 | [diff] [blame] | 86 | { |
| 87 | .name = "backend", |
| 88 | .type = QEMU_OPT_STRING, |
| 89 | },{ |
| 90 | .name = "path", |
| 91 | .type = QEMU_OPT_STRING, |
Gerd Hoffmann | aeb2c47 | 2009-09-10 10:58:42 +0200 | [diff] [blame] | 92 | },{ |
| 93 | .name = "host", |
| 94 | .type = QEMU_OPT_STRING, |
| 95 | },{ |
| 96 | .name = "port", |
| 97 | .type = QEMU_OPT_STRING, |
| 98 | },{ |
Gerd Hoffmann | 7e1b35b | 2009-09-10 10:58:51 +0200 | [diff] [blame] | 99 | .name = "localaddr", |
| 100 | .type = QEMU_OPT_STRING, |
| 101 | },{ |
| 102 | .name = "localport", |
| 103 | .type = QEMU_OPT_STRING, |
| 104 | },{ |
Gerd Hoffmann | aeb2c47 | 2009-09-10 10:58:42 +0200 | [diff] [blame] | 105 | .name = "to", |
| 106 | .type = QEMU_OPT_NUMBER, |
| 107 | },{ |
| 108 | .name = "ipv4", |
| 109 | .type = QEMU_OPT_BOOL, |
| 110 | },{ |
| 111 | .name = "ipv6", |
| 112 | .type = QEMU_OPT_BOOL, |
| 113 | },{ |
| 114 | .name = "wait", |
| 115 | .type = QEMU_OPT_BOOL, |
| 116 | },{ |
| 117 | .name = "server", |
| 118 | .type = QEMU_OPT_BOOL, |
| 119 | },{ |
| 120 | .name = "delay", |
| 121 | .type = QEMU_OPT_BOOL, |
| 122 | },{ |
| 123 | .name = "telnet", |
| 124 | .type = QEMU_OPT_BOOL, |
Gerd Hoffmann | 6ea314d | 2009-09-10 10:58:49 +0200 | [diff] [blame] | 125 | },{ |
| 126 | .name = "width", |
| 127 | .type = QEMU_OPT_NUMBER, |
| 128 | },{ |
| 129 | .name = "height", |
| 130 | .type = QEMU_OPT_NUMBER, |
| 131 | },{ |
| 132 | .name = "cols", |
| 133 | .type = QEMU_OPT_NUMBER, |
| 134 | },{ |
| 135 | .name = "rows", |
| 136 | .type = QEMU_OPT_NUMBER, |
Gerd Hoffmann | c845f40 | 2009-09-10 10:58:52 +0200 | [diff] [blame] | 137 | },{ |
| 138 | .name = "mux", |
| 139 | .type = QEMU_OPT_BOOL, |
Kusanagi Kouichi | 5989020 | 2009-10-16 22:31:38 +0900 | [diff] [blame] | 140 | },{ |
| 141 | .name = "signal", |
| 142 | .type = QEMU_OPT_BOOL, |
Gerd Hoffmann | 7d31544 | 2009-09-10 10:58:36 +0200 | [diff] [blame] | 143 | }, |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 144 | { /* end if list */ } |
| 145 | }, |
| 146 | }; |
| 147 | |
Gerd Hoffmann | f31d07d | 2009-07-31 12:25:37 +0200 | [diff] [blame] | 148 | QemuOptsList qemu_device_opts = { |
| 149 | .name = "device", |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 150 | .head = QTAILQ_HEAD_INITIALIZER(qemu_device_opts.head), |
Gerd Hoffmann | f31d07d | 2009-07-31 12:25:37 +0200 | [diff] [blame] | 151 | .desc = { |
| 152 | /* |
| 153 | * no elements => accept any |
| 154 | * sanity checking will happen later |
| 155 | * when setting device properties |
| 156 | */ |
| 157 | { /* end if list */ } |
| 158 | }, |
| 159 | }; |
| 160 | |
Mark McLoughlin | a1ea458 | 2009-10-08 19:58:26 +0100 | [diff] [blame] | 161 | QemuOptsList qemu_netdev_opts = { |
| 162 | .name = "netdev", |
| 163 | .head = QTAILQ_HEAD_INITIALIZER(qemu_netdev_opts.head), |
| 164 | .desc = { |
| 165 | /* |
| 166 | * no elements => accept any params |
| 167 | * validation will happen later |
| 168 | */ |
| 169 | { /* end of list */ } |
| 170 | }, |
| 171 | }; |
| 172 | |
Mark McLoughlin | 8119b33 | 2009-10-06 12:17:05 +0100 | [diff] [blame] | 173 | QemuOptsList qemu_net_opts = { |
| 174 | .name = "net", |
| 175 | .head = QTAILQ_HEAD_INITIALIZER(qemu_net_opts.head), |
| 176 | .desc = { |
| 177 | /* |
| 178 | * no elements => accept any params |
| 179 | * validation will happen later |
| 180 | */ |
| 181 | { /* end of list */ } |
| 182 | }, |
| 183 | }; |
| 184 | |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 185 | QemuOptsList qemu_rtc_opts = { |
| 186 | .name = "rtc", |
| 187 | .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head), |
| 188 | .desc = { |
| 189 | { |
| 190 | .name = "base", |
| 191 | .type = QEMU_OPT_STRING, |
Jan Kiszka | 6875204 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 192 | },{ |
| 193 | .name = "clock", |
| 194 | .type = QEMU_OPT_STRING, |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 195 | #ifdef TARGET_I386 |
| 196 | },{ |
| 197 | .name = "driftfix", |
| 198 | .type = QEMU_OPT_STRING, |
| 199 | #endif |
| 200 | }, |
| 201 | { /* end if list */ } |
| 202 | }, |
| 203 | }; |
| 204 | |
Gerd Hoffmann | d058fe0 | 2009-07-31 12:25:36 +0200 | [diff] [blame] | 205 | static QemuOptsList *lists[] = { |
| 206 | &qemu_drive_opts, |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 207 | &qemu_chardev_opts, |
Gerd Hoffmann | f31d07d | 2009-07-31 12:25:37 +0200 | [diff] [blame] | 208 | &qemu_device_opts, |
Mark McLoughlin | a1ea458 | 2009-10-08 19:58:26 +0100 | [diff] [blame] | 209 | &qemu_netdev_opts, |
Mark McLoughlin | 8119b33 | 2009-10-06 12:17:05 +0100 | [diff] [blame] | 210 | &qemu_net_opts, |
Jan Kiszka | 5fdfbf7 | 2009-10-06 12:16:50 +0100 | [diff] [blame] | 211 | &qemu_rtc_opts, |
Gerd Hoffmann | d058fe0 | 2009-07-31 12:25:36 +0200 | [diff] [blame] | 212 | NULL, |
| 213 | }; |
| 214 | |
Gerd Hoffmann | ddc9785 | 2009-10-14 10:39:25 +0200 | [diff] [blame^] | 215 | static QemuOptsList *find_list(const char *group) |
Gerd Hoffmann | d058fe0 | 2009-07-31 12:25:36 +0200 | [diff] [blame] | 216 | { |
Gerd Hoffmann | ddc9785 | 2009-10-14 10:39:25 +0200 | [diff] [blame^] | 217 | int i; |
Gerd Hoffmann | d058fe0 | 2009-07-31 12:25:36 +0200 | [diff] [blame] | 218 | |
| 219 | for (i = 0; lists[i] != NULL; i++) { |
| 220 | if (strcmp(lists[i]->name, group) == 0) |
| 221 | break; |
| 222 | } |
| 223 | if (lists[i] == NULL) { |
Gerd Hoffmann | a861c45 | 2009-09-25 21:42:40 +0200 | [diff] [blame] | 224 | qemu_error("there is no option group \"%s\"\n", group); |
Gerd Hoffmann | ddc9785 | 2009-10-14 10:39:25 +0200 | [diff] [blame^] | 225 | } |
| 226 | return lists[i]; |
| 227 | } |
| 228 | |
| 229 | int qemu_set_option(const char *str) |
| 230 | { |
| 231 | char group[64], id[64], arg[64]; |
| 232 | QemuOptsList *list; |
| 233 | QemuOpts *opts; |
| 234 | int rc, offset; |
| 235 | |
| 236 | rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset); |
| 237 | if (rc < 3 || str[offset] != '=') { |
| 238 | qemu_error("can't parse: \"%s\"\n", str); |
Gerd Hoffmann | d058fe0 | 2009-07-31 12:25:36 +0200 | [diff] [blame] | 239 | return -1; |
| 240 | } |
| 241 | |
Gerd Hoffmann | ddc9785 | 2009-10-14 10:39:25 +0200 | [diff] [blame^] | 242 | list = find_list(group); |
| 243 | if (list == NULL) { |
| 244 | return -1; |
| 245 | } |
| 246 | |
| 247 | opts = qemu_opts_find(list, id); |
Gerd Hoffmann | d058fe0 | 2009-07-31 12:25:36 +0200 | [diff] [blame] | 248 | if (!opts) { |
Gerd Hoffmann | a861c45 | 2009-09-25 21:42:40 +0200 | [diff] [blame] | 249 | qemu_error("there is no %s \"%s\" defined\n", |
Gerd Hoffmann | ddc9785 | 2009-10-14 10:39:25 +0200 | [diff] [blame^] | 250 | list->name, id); |
Gerd Hoffmann | d058fe0 | 2009-07-31 12:25:36 +0200 | [diff] [blame] | 251 | return -1; |
| 252 | } |
| 253 | |
Mark McLoughlin | 3df04ac | 2009-09-23 11:24:05 +0100 | [diff] [blame] | 254 | if (qemu_opt_set(opts, arg, str+offset+1) == -1) { |
Gerd Hoffmann | d058fe0 | 2009-07-31 12:25:36 +0200 | [diff] [blame] | 255 | return -1; |
| 256 | } |
| 257 | return 0; |
| 258 | } |
| 259 | |