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)", |
| 74 | }, |
| 75 | { /* end if list */ } |
| 76 | }, |
| 77 | }; |
| 78 | |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 79 | QemuOptsList qemu_chardev_opts = { |
| 80 | .name = "chardev", |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 81 | .head = QTAILQ_HEAD_INITIALIZER(qemu_chardev_opts.head), |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 82 | .desc = { |
Gerd Hoffmann | 7d31544 | 2009-09-10 10:58:36 +0200 | [diff] [blame] | 83 | { |
| 84 | .name = "backend", |
| 85 | .type = QEMU_OPT_STRING, |
| 86 | },{ |
| 87 | .name = "path", |
| 88 | .type = QEMU_OPT_STRING, |
Gerd Hoffmann | aeb2c47 | 2009-09-10 10:58:42 +0200 | [diff] [blame] | 89 | },{ |
| 90 | .name = "host", |
| 91 | .type = QEMU_OPT_STRING, |
| 92 | },{ |
| 93 | .name = "port", |
| 94 | .type = QEMU_OPT_STRING, |
| 95 | },{ |
Gerd Hoffmann | 7e1b35b | 2009-09-10 10:58:51 +0200 | [diff] [blame] | 96 | .name = "localaddr", |
| 97 | .type = QEMU_OPT_STRING, |
| 98 | },{ |
| 99 | .name = "localport", |
| 100 | .type = QEMU_OPT_STRING, |
| 101 | },{ |
Gerd Hoffmann | aeb2c47 | 2009-09-10 10:58:42 +0200 | [diff] [blame] | 102 | .name = "to", |
| 103 | .type = QEMU_OPT_NUMBER, |
| 104 | },{ |
| 105 | .name = "ipv4", |
| 106 | .type = QEMU_OPT_BOOL, |
| 107 | },{ |
| 108 | .name = "ipv6", |
| 109 | .type = QEMU_OPT_BOOL, |
| 110 | },{ |
| 111 | .name = "wait", |
| 112 | .type = QEMU_OPT_BOOL, |
| 113 | },{ |
| 114 | .name = "server", |
| 115 | .type = QEMU_OPT_BOOL, |
| 116 | },{ |
| 117 | .name = "delay", |
| 118 | .type = QEMU_OPT_BOOL, |
| 119 | },{ |
| 120 | .name = "telnet", |
| 121 | .type = QEMU_OPT_BOOL, |
Gerd Hoffmann | 6ea314d | 2009-09-10 10:58:49 +0200 | [diff] [blame] | 122 | },{ |
| 123 | .name = "width", |
| 124 | .type = QEMU_OPT_NUMBER, |
| 125 | },{ |
| 126 | .name = "height", |
| 127 | .type = QEMU_OPT_NUMBER, |
| 128 | },{ |
| 129 | .name = "cols", |
| 130 | .type = QEMU_OPT_NUMBER, |
| 131 | },{ |
| 132 | .name = "rows", |
| 133 | .type = QEMU_OPT_NUMBER, |
Gerd Hoffmann | c845f40 | 2009-09-10 10:58:52 +0200 | [diff] [blame] | 134 | },{ |
| 135 | .name = "mux", |
| 136 | .type = QEMU_OPT_BOOL, |
Gerd Hoffmann | 7d31544 | 2009-09-10 10:58:36 +0200 | [diff] [blame] | 137 | }, |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 138 | { /* end if list */ } |
| 139 | }, |
| 140 | }; |
| 141 | |
Gerd Hoffmann | f31d07d | 2009-07-31 12:25:37 +0200 | [diff] [blame] | 142 | QemuOptsList qemu_device_opts = { |
| 143 | .name = "device", |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 144 | .head = QTAILQ_HEAD_INITIALIZER(qemu_device_opts.head), |
Gerd Hoffmann | f31d07d | 2009-07-31 12:25:37 +0200 | [diff] [blame] | 145 | .desc = { |
| 146 | /* |
| 147 | * no elements => accept any |
| 148 | * sanity checking will happen later |
| 149 | * when setting device properties |
| 150 | */ |
| 151 | { /* end if list */ } |
| 152 | }, |
| 153 | }; |
| 154 | |
Mark McLoughlin | a1ea458 | 2009-10-08 19:58:26 +0100 | [diff] [blame^] | 155 | QemuOptsList qemu_netdev_opts = { |
| 156 | .name = "netdev", |
| 157 | .head = QTAILQ_HEAD_INITIALIZER(qemu_netdev_opts.head), |
| 158 | .desc = { |
| 159 | /* |
| 160 | * no elements => accept any params |
| 161 | * validation will happen later |
| 162 | */ |
| 163 | { /* end of list */ } |
| 164 | }, |
| 165 | }; |
| 166 | |
Mark McLoughlin | 8119b33 | 2009-10-06 12:17:05 +0100 | [diff] [blame] | 167 | QemuOptsList qemu_net_opts = { |
| 168 | .name = "net", |
| 169 | .head = QTAILQ_HEAD_INITIALIZER(qemu_net_opts.head), |
| 170 | .desc = { |
| 171 | /* |
| 172 | * no elements => accept any params |
| 173 | * validation will happen later |
| 174 | */ |
| 175 | { /* end of list */ } |
| 176 | }, |
| 177 | }; |
| 178 | |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 179 | QemuOptsList qemu_rtc_opts = { |
| 180 | .name = "rtc", |
| 181 | .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head), |
| 182 | .desc = { |
| 183 | { |
| 184 | .name = "base", |
| 185 | .type = QEMU_OPT_STRING, |
Jan Kiszka | 6875204 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 186 | },{ |
| 187 | .name = "clock", |
| 188 | .type = QEMU_OPT_STRING, |
Jan Kiszka | 1ed2fc1 | 2009-09-15 13:36:04 +0200 | [diff] [blame] | 189 | #ifdef TARGET_I386 |
| 190 | },{ |
| 191 | .name = "driftfix", |
| 192 | .type = QEMU_OPT_STRING, |
| 193 | #endif |
| 194 | }, |
| 195 | { /* end if list */ } |
| 196 | }, |
| 197 | }; |
| 198 | |
Gerd Hoffmann | d058fe0 | 2009-07-31 12:25:36 +0200 | [diff] [blame] | 199 | static QemuOptsList *lists[] = { |
| 200 | &qemu_drive_opts, |
Gerd Hoffmann | 191bc01 | 2009-09-10 10:58:35 +0200 | [diff] [blame] | 201 | &qemu_chardev_opts, |
Gerd Hoffmann | f31d07d | 2009-07-31 12:25:37 +0200 | [diff] [blame] | 202 | &qemu_device_opts, |
Mark McLoughlin | a1ea458 | 2009-10-08 19:58:26 +0100 | [diff] [blame^] | 203 | &qemu_netdev_opts, |
Mark McLoughlin | 8119b33 | 2009-10-06 12:17:05 +0100 | [diff] [blame] | 204 | &qemu_net_opts, |
Jan Kiszka | 5fdfbf7 | 2009-10-06 12:16:50 +0100 | [diff] [blame] | 205 | &qemu_rtc_opts, |
Gerd Hoffmann | d058fe0 | 2009-07-31 12:25:36 +0200 | [diff] [blame] | 206 | NULL, |
| 207 | }; |
| 208 | |
| 209 | int qemu_set_option(const char *str) |
| 210 | { |
| 211 | char group[64], id[64], arg[64]; |
| 212 | QemuOpts *opts; |
| 213 | int i, rc, offset; |
| 214 | |
| 215 | rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset); |
| 216 | if (rc < 3 || str[offset] != '=') { |
Gerd Hoffmann | a861c45 | 2009-09-25 21:42:40 +0200 | [diff] [blame] | 217 | qemu_error("can't parse: \"%s\"\n", str); |
Gerd Hoffmann | d058fe0 | 2009-07-31 12:25:36 +0200 | [diff] [blame] | 218 | return -1; |
| 219 | } |
| 220 | |
| 221 | for (i = 0; lists[i] != NULL; i++) { |
| 222 | if (strcmp(lists[i]->name, group) == 0) |
| 223 | break; |
| 224 | } |
| 225 | if (lists[i] == NULL) { |
Gerd Hoffmann | a861c45 | 2009-09-25 21:42:40 +0200 | [diff] [blame] | 226 | qemu_error("there is no option group \"%s\"\n", group); |
Gerd Hoffmann | d058fe0 | 2009-07-31 12:25:36 +0200 | [diff] [blame] | 227 | return -1; |
| 228 | } |
| 229 | |
| 230 | opts = qemu_opts_find(lists[i], id); |
| 231 | if (!opts) { |
Gerd Hoffmann | a861c45 | 2009-09-25 21:42:40 +0200 | [diff] [blame] | 232 | qemu_error("there is no %s \"%s\" defined\n", |
Gerd Hoffmann | d058fe0 | 2009-07-31 12:25:36 +0200 | [diff] [blame] | 233 | lists[i]->name, id); |
| 234 | return -1; |
| 235 | } |
| 236 | |
Mark McLoughlin | 3df04ac | 2009-09-23 11:24:05 +0100 | [diff] [blame] | 237 | if (qemu_opt_set(opts, arg, str+offset+1) == -1) { |
Gerd Hoffmann | d058fe0 | 2009-07-31 12:25:36 +0200 | [diff] [blame] | 238 | return -1; |
| 239 | } |
| 240 | return 0; |
| 241 | } |
| 242 | |