]>
Commit | Line | Data |
---|---|---|
7282a033 | 1 | #include "qemu-common.h" |
2f792016 | 2 | #include "qemu-error.h" |
7282a033 GH |
3 | #include "qemu-option.h" |
4 | #include "qemu-config.h" | |
d0fef6fb | 5 | #include "hw/qdev.h" |
7282a033 | 6 | |
3329f07b | 7 | static QemuOptsList qemu_drive_opts = { |
7282a033 | 8 | .name = "drive", |
72cf2d4f | 9 | .head = QTAILQ_HEAD_INITIALIZER(qemu_drive_opts.head), |
7282a033 GH |
10 | .desc = { |
11 | { | |
12 | .name = "bus", | |
13 | .type = QEMU_OPT_NUMBER, | |
14 | .help = "bus number", | |
15 | },{ | |
16 | .name = "unit", | |
17 | .type = QEMU_OPT_NUMBER, | |
18 | .help = "unit number (i.e. lun for scsi)", | |
19 | },{ | |
20 | .name = "if", | |
21 | .type = QEMU_OPT_STRING, | |
22 | .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)", | |
23 | },{ | |
24 | .name = "index", | |
25 | .type = QEMU_OPT_NUMBER, | |
69d7e218 | 26 | .help = "index number", |
7282a033 GH |
27 | },{ |
28 | .name = "cyls", | |
29 | .type = QEMU_OPT_NUMBER, | |
30 | .help = "number of cylinders (ide disk geometry)", | |
31 | },{ | |
32 | .name = "heads", | |
33 | .type = QEMU_OPT_NUMBER, | |
34 | .help = "number of heads (ide disk geometry)", | |
35 | },{ | |
36 | .name = "secs", | |
37 | .type = QEMU_OPT_NUMBER, | |
38 | .help = "number of sectors (ide disk geometry)", | |
39 | },{ | |
40 | .name = "trans", | |
41 | .type = QEMU_OPT_STRING, | |
42 | .help = "chs translation (auto, lba. none)", | |
43 | },{ | |
44 | .name = "media", | |
45 | .type = QEMU_OPT_STRING, | |
46 | .help = "media type (disk, cdrom)", | |
47 | },{ | |
48 | .name = "snapshot", | |
49 | .type = QEMU_OPT_BOOL, | |
69d7e218 | 50 | .help = "enable/disable snapshot mode", |
7282a033 GH |
51 | },{ |
52 | .name = "file", | |
53 | .type = QEMU_OPT_STRING, | |
54 | .help = "disk image", | |
55 | },{ | |
56 | .name = "cache", | |
57 | .type = QEMU_OPT_STRING, | |
92196b2f SH |
58 | .help = "host cache usage (none, writeback, writethrough, " |
59 | "directsync, unsafe)", | |
5c6c3a6c CH |
60 | },{ |
61 | .name = "aio", | |
62 | .type = QEMU_OPT_STRING, | |
63 | .help = "host AIO implementation (threads, native)", | |
7282a033 GH |
64 | },{ |
65 | .name = "format", | |
66 | .type = QEMU_OPT_STRING, | |
67 | .help = "disk format (raw, qcow2, ...)", | |
68 | },{ | |
69 | .name = "serial", | |
70 | .type = QEMU_OPT_STRING, | |
69d7e218 | 71 | .help = "disk serial number", |
e9b2e818 KW |
72 | },{ |
73 | .name = "rerror", | |
74 | .type = QEMU_OPT_STRING, | |
69d7e218 | 75 | .help = "read error action", |
7282a033 GH |
76 | },{ |
77 | .name = "werror", | |
78 | .type = QEMU_OPT_STRING, | |
69d7e218 | 79 | .help = "write error action", |
7282a033 GH |
80 | },{ |
81 | .name = "addr", | |
82 | .type = QEMU_OPT_STRING, | |
83 | .help = "pci address (virtio only)", | |
59f2689d NS |
84 | },{ |
85 | .name = "readonly", | |
86 | .type = QEMU_OPT_BOOL, | |
69d7e218 | 87 | .help = "open drive file as read-only", |
0563e191 ZYW |
88 | },{ |
89 | .name = "iops", | |
90 | .type = QEMU_OPT_NUMBER, | |
91 | .help = "limit total I/O operations per second", | |
92 | },{ | |
93 | .name = "iops_rd", | |
94 | .type = QEMU_OPT_NUMBER, | |
95 | .help = "limit read operations per second", | |
96 | },{ | |
97 | .name = "iops_wr", | |
98 | .type = QEMU_OPT_NUMBER, | |
99 | .help = "limit write operations per second", | |
100 | },{ | |
101 | .name = "bps", | |
102 | .type = QEMU_OPT_NUMBER, | |
103 | .help = "limit total bytes per second", | |
104 | },{ | |
105 | .name = "bps_rd", | |
106 | .type = QEMU_OPT_NUMBER, | |
107 | .help = "limit read bytes per second", | |
108 | },{ | |
109 | .name = "bps_wr", | |
110 | .type = QEMU_OPT_NUMBER, | |
111 | .help = "limit write bytes per second", | |
fb0490f6 SH |
112 | },{ |
113 | .name = "copy-on-read", | |
114 | .type = QEMU_OPT_BOOL, | |
115 | .help = "copy read data from backing file into image file", | |
7282a033 | 116 | }, |
26056e0c | 117 | { /* end of list */ } |
7282a033 GH |
118 | }, |
119 | }; | |
120 | ||
3329f07b | 121 | static QemuOptsList qemu_chardev_opts = { |
191bc01b | 122 | .name = "chardev", |
8212c64f | 123 | .implied_opt_name = "backend", |
72cf2d4f | 124 | .head = QTAILQ_HEAD_INITIALIZER(qemu_chardev_opts.head), |
191bc01b | 125 | .desc = { |
7d31544f GH |
126 | { |
127 | .name = "backend", | |
128 | .type = QEMU_OPT_STRING, | |
129 | },{ | |
130 | .name = "path", | |
131 | .type = QEMU_OPT_STRING, | |
aeb2c47a GH |
132 | },{ |
133 | .name = "host", | |
134 | .type = QEMU_OPT_STRING, | |
135 | },{ | |
136 | .name = "port", | |
137 | .type = QEMU_OPT_STRING, | |
7e1b35b4 GH |
138 | },{ |
139 | .name = "localaddr", | |
140 | .type = QEMU_OPT_STRING, | |
141 | },{ | |
142 | .name = "localport", | |
143 | .type = QEMU_OPT_STRING, | |
aeb2c47a GH |
144 | },{ |
145 | .name = "to", | |
146 | .type = QEMU_OPT_NUMBER, | |
147 | },{ | |
148 | .name = "ipv4", | |
149 | .type = QEMU_OPT_BOOL, | |
150 | },{ | |
151 | .name = "ipv6", | |
152 | .type = QEMU_OPT_BOOL, | |
153 | },{ | |
154 | .name = "wait", | |
155 | .type = QEMU_OPT_BOOL, | |
156 | },{ | |
157 | .name = "server", | |
158 | .type = QEMU_OPT_BOOL, | |
159 | },{ | |
160 | .name = "delay", | |
161 | .type = QEMU_OPT_BOOL, | |
162 | },{ | |
163 | .name = "telnet", | |
164 | .type = QEMU_OPT_BOOL, | |
6ea314d9 GH |
165 | },{ |
166 | .name = "width", | |
167 | .type = QEMU_OPT_NUMBER, | |
168 | },{ | |
169 | .name = "height", | |
170 | .type = QEMU_OPT_NUMBER, | |
171 | },{ | |
172 | .name = "cols", | |
173 | .type = QEMU_OPT_NUMBER, | |
174 | },{ | |
175 | .name = "rows", | |
176 | .type = QEMU_OPT_NUMBER, | |
c845f401 GH |
177 | },{ |
178 | .name = "mux", | |
179 | .type = QEMU_OPT_BOOL, | |
5989020b KK |
180 | },{ |
181 | .name = "signal", | |
182 | .type = QEMU_OPT_BOOL, | |
cbcc6336 AL |
183 | },{ |
184 | .name = "name", | |
185 | .type = QEMU_OPT_STRING, | |
186 | },{ | |
187 | .name = "debug", | |
188 | .type = QEMU_OPT_NUMBER, | |
7d31544f | 189 | }, |
26056e0c | 190 | { /* end of list */ } |
191bc01b GH |
191 | }, |
192 | }; | |
193 | ||
74db920c GS |
194 | QemuOptsList qemu_fsdev_opts = { |
195 | .name = "fsdev", | |
fbcbf101 | 196 | .implied_opt_name = "fsdriver", |
74db920c GS |
197 | .head = QTAILQ_HEAD_INITIALIZER(qemu_fsdev_opts.head), |
198 | .desc = { | |
199 | { | |
fbcbf101 | 200 | .name = "fsdriver", |
74db920c GS |
201 | .type = QEMU_OPT_STRING, |
202 | }, { | |
203 | .name = "path", | |
204 | .type = QEMU_OPT_STRING, | |
9ce56db6 VJ |
205 | }, { |
206 | .name = "security_model", | |
207 | .type = QEMU_OPT_STRING, | |
d3ab98e6 AK |
208 | }, { |
209 | .name = "writeout", | |
210 | .type = QEMU_OPT_STRING, | |
2c74c2cb MK |
211 | }, { |
212 | .name = "readonly", | |
213 | .type = QEMU_OPT_BOOL, | |
4c793dda MK |
214 | }, { |
215 | .name = "sock_fd", | |
216 | .type = QEMU_OPT_NUMBER, | |
74db920c | 217 | }, |
2c74c2cb | 218 | |
74db920c GS |
219 | { /*End of list */ } |
220 | }, | |
221 | }; | |
74db920c | 222 | |
3d54abc7 GS |
223 | QemuOptsList qemu_virtfs_opts = { |
224 | .name = "virtfs", | |
fbcbf101 | 225 | .implied_opt_name = "fsdriver", |
3d54abc7 GS |
226 | .head = QTAILQ_HEAD_INITIALIZER(qemu_virtfs_opts.head), |
227 | .desc = { | |
228 | { | |
fbcbf101 | 229 | .name = "fsdriver", |
3d54abc7 GS |
230 | .type = QEMU_OPT_STRING, |
231 | }, { | |
232 | .name = "path", | |
233 | .type = QEMU_OPT_STRING, | |
234 | }, { | |
235 | .name = "mount_tag", | |
236 | .type = QEMU_OPT_STRING, | |
9ce56db6 VJ |
237 | }, { |
238 | .name = "security_model", | |
239 | .type = QEMU_OPT_STRING, | |
d3ab98e6 AK |
240 | }, { |
241 | .name = "writeout", | |
242 | .type = QEMU_OPT_STRING, | |
2c74c2cb MK |
243 | }, { |
244 | .name = "readonly", | |
245 | .type = QEMU_OPT_BOOL, | |
4c793dda MK |
246 | }, { |
247 | .name = "sock_fd", | |
248 | .type = QEMU_OPT_NUMBER, | |
3d54abc7 GS |
249 | }, |
250 | ||
251 | { /*End of list */ } | |
252 | }, | |
253 | }; | |
3d54abc7 | 254 | |
3329f07b | 255 | static QemuOptsList qemu_device_opts = { |
f31d07d1 | 256 | .name = "device", |
8212c64f | 257 | .implied_opt_name = "driver", |
72cf2d4f | 258 | .head = QTAILQ_HEAD_INITIALIZER(qemu_device_opts.head), |
f31d07d1 GH |
259 | .desc = { |
260 | /* | |
261 | * no elements => accept any | |
262 | * sanity checking will happen later | |
263 | * when setting device properties | |
264 | */ | |
26056e0c | 265 | { /* end of list */ } |
f31d07d1 GH |
266 | }, |
267 | }; | |
268 | ||
3329f07b | 269 | static QemuOptsList qemu_netdev_opts = { |
a1ea458f | 270 | .name = "netdev", |
8212c64f | 271 | .implied_opt_name = "type", |
a1ea458f MM |
272 | .head = QTAILQ_HEAD_INITIALIZER(qemu_netdev_opts.head), |
273 | .desc = { | |
274 | /* | |
275 | * no elements => accept any params | |
276 | * validation will happen later | |
277 | */ | |
278 | { /* end of list */ } | |
279 | }, | |
280 | }; | |
281 | ||
3329f07b | 282 | static QemuOptsList qemu_net_opts = { |
8119b33d | 283 | .name = "net", |
8212c64f | 284 | .implied_opt_name = "type", |
8119b33d MM |
285 | .head = QTAILQ_HEAD_INITIALIZER(qemu_net_opts.head), |
286 | .desc = { | |
287 | /* | |
288 | * no elements => accept any params | |
289 | * validation will happen later | |
290 | */ | |
291 | { /* end of list */ } | |
292 | }, | |
293 | }; | |
294 | ||
3329f07b | 295 | static QemuOptsList qemu_rtc_opts = { |
1ed2fc1f JK |
296 | .name = "rtc", |
297 | .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head), | |
298 | .desc = { | |
299 | { | |
300 | .name = "base", | |
301 | .type = QEMU_OPT_STRING, | |
6875204c JK |
302 | },{ |
303 | .name = "clock", | |
304 | .type = QEMU_OPT_STRING, | |
1ed2fc1f JK |
305 | },{ |
306 | .name = "driftfix", | |
307 | .type = QEMU_OPT_STRING, | |
1ed2fc1f | 308 | }, |
26056e0c | 309 | { /* end of list */ } |
1ed2fc1f JK |
310 | }, |
311 | }; | |
312 | ||
3329f07b | 313 | static QemuOptsList qemu_global_opts = { |
d0fef6fb GH |
314 | .name = "global", |
315 | .head = QTAILQ_HEAD_INITIALIZER(qemu_global_opts.head), | |
316 | .desc = { | |
317 | { | |
318 | .name = "driver", | |
319 | .type = QEMU_OPT_STRING, | |
320 | },{ | |
321 | .name = "property", | |
322 | .type = QEMU_OPT_STRING, | |
323 | },{ | |
324 | .name = "value", | |
325 | .type = QEMU_OPT_STRING, | |
326 | }, | |
26056e0c | 327 | { /* end of list */ } |
d0fef6fb GH |
328 | }, |
329 | }; | |
330 | ||
3329f07b | 331 | static QemuOptsList qemu_mon_opts = { |
88589343 | 332 | .name = "mon", |
8212c64f | 333 | .implied_opt_name = "chardev", |
88589343 GH |
334 | .head = QTAILQ_HEAD_INITIALIZER(qemu_mon_opts.head), |
335 | .desc = { | |
336 | { | |
337 | .name = "mode", | |
338 | .type = QEMU_OPT_STRING, | |
339 | },{ | |
340 | .name = "chardev", | |
341 | .type = QEMU_OPT_STRING, | |
342 | },{ | |
343 | .name = "default", | |
344 | .type = QEMU_OPT_BOOL, | |
39eaab9a DB |
345 | },{ |
346 | .name = "pretty", | |
347 | .type = QEMU_OPT_BOOL, | |
88589343 | 348 | }, |
26056e0c | 349 | { /* end of list */ } |
88589343 GH |
350 | }, |
351 | }; | |
352 | ||
ab6540d5 PS |
353 | static QemuOptsList qemu_trace_opts = { |
354 | .name = "trace", | |
355 | .implied_opt_name = "trace", | |
356 | .head = QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head), | |
357 | .desc = { | |
358 | { | |
23d15e86 LV |
359 | .name = "events", |
360 | .type = QEMU_OPT_STRING, | |
361 | },{ | |
ab6540d5 PS |
362 | .name = "file", |
363 | .type = QEMU_OPT_STRING, | |
364 | }, | |
44bd6907 | 365 | { /* end of list */ } |
ab6540d5 PS |
366 | }, |
367 | }; | |
ab6540d5 | 368 | |
3329f07b | 369 | static QemuOptsList qemu_cpudef_opts = { |
b5ec5ce0 | 370 | .name = "cpudef", |
371 | .head = QTAILQ_HEAD_INITIALIZER(qemu_cpudef_opts.head), | |
372 | .desc = { | |
373 | { | |
374 | .name = "name", | |
375 | .type = QEMU_OPT_STRING, | |
376 | },{ | |
377 | .name = "level", | |
378 | .type = QEMU_OPT_NUMBER, | |
379 | },{ | |
380 | .name = "vendor", | |
381 | .type = QEMU_OPT_STRING, | |
382 | },{ | |
383 | .name = "family", | |
384 | .type = QEMU_OPT_NUMBER, | |
385 | },{ | |
386 | .name = "model", | |
387 | .type = QEMU_OPT_NUMBER, | |
388 | },{ | |
389 | .name = "stepping", | |
390 | .type = QEMU_OPT_NUMBER, | |
391 | },{ | |
392 | .name = "feature_edx", /* cpuid 0000_0001.edx */ | |
393 | .type = QEMU_OPT_STRING, | |
394 | },{ | |
395 | .name = "feature_ecx", /* cpuid 0000_0001.ecx */ | |
396 | .type = QEMU_OPT_STRING, | |
397 | },{ | |
398 | .name = "extfeature_edx", /* cpuid 8000_0001.edx */ | |
399 | .type = QEMU_OPT_STRING, | |
400 | },{ | |
401 | .name = "extfeature_ecx", /* cpuid 8000_0001.ecx */ | |
402 | .type = QEMU_OPT_STRING, | |
403 | },{ | |
404 | .name = "xlevel", | |
405 | .type = QEMU_OPT_NUMBER, | |
406 | },{ | |
407 | .name = "model_id", | |
408 | .type = QEMU_OPT_STRING, | |
409 | },{ | |
410 | .name = "vendor_override", | |
411 | .type = QEMU_OPT_NUMBER, | |
412 | }, | |
413 | { /* end of list */ } | |
414 | }, | |
415 | }; | |
416 | ||
29b0040b GH |
417 | QemuOptsList qemu_spice_opts = { |
418 | .name = "spice", | |
419 | .head = QTAILQ_HEAD_INITIALIZER(qemu_spice_opts.head), | |
420 | .desc = { | |
421 | { | |
422 | .name = "port", | |
423 | .type = QEMU_OPT_NUMBER, | |
c448e855 GH |
424 | },{ |
425 | .name = "tls-port", | |
426 | .type = QEMU_OPT_NUMBER, | |
333b0eeb GH |
427 | },{ |
428 | .name = "addr", | |
429 | .type = QEMU_OPT_STRING, | |
430 | },{ | |
431 | .name = "ipv4", | |
432 | .type = QEMU_OPT_BOOL, | |
433 | },{ | |
434 | .name = "ipv6", | |
435 | .type = QEMU_OPT_BOOL, | |
29b0040b GH |
436 | },{ |
437 | .name = "password", | |
438 | .type = QEMU_OPT_STRING, | |
439 | },{ | |
440 | .name = "disable-ticketing", | |
441 | .type = QEMU_OPT_BOOL, | |
d4970b07 HG |
442 | },{ |
443 | .name = "disable-copy-paste", | |
444 | .type = QEMU_OPT_BOOL, | |
48b3ed0a MAL |
445 | },{ |
446 | .name = "sasl", | |
447 | .type = QEMU_OPT_BOOL, | |
c448e855 GH |
448 | },{ |
449 | .name = "x509-dir", | |
450 | .type = QEMU_OPT_STRING, | |
451 | },{ | |
452 | .name = "x509-key-file", | |
453 | .type = QEMU_OPT_STRING, | |
454 | },{ | |
455 | .name = "x509-key-password", | |
456 | .type = QEMU_OPT_STRING, | |
457 | },{ | |
458 | .name = "x509-cert-file", | |
459 | .type = QEMU_OPT_STRING, | |
460 | },{ | |
461 | .name = "x509-cacert-file", | |
462 | .type = QEMU_OPT_STRING, | |
463 | },{ | |
464 | .name = "x509-dh-key-file", | |
465 | .type = QEMU_OPT_STRING, | |
466 | },{ | |
467 | .name = "tls-ciphers", | |
468 | .type = QEMU_OPT_STRING, | |
17b6dea0 GH |
469 | },{ |
470 | .name = "tls-channel", | |
471 | .type = QEMU_OPT_STRING, | |
472 | },{ | |
473 | .name = "plaintext-channel", | |
474 | .type = QEMU_OPT_STRING, | |
9f04e09e YH |
475 | },{ |
476 | .name = "image-compression", | |
477 | .type = QEMU_OPT_STRING, | |
478 | },{ | |
479 | .name = "jpeg-wan-compression", | |
480 | .type = QEMU_OPT_STRING, | |
481 | },{ | |
482 | .name = "zlib-glz-wan-compression", | |
483 | .type = QEMU_OPT_STRING, | |
84a23f25 GH |
484 | },{ |
485 | .name = "streaming-video", | |
486 | .type = QEMU_OPT_STRING, | |
487 | },{ | |
488 | .name = "agent-mouse", | |
489 | .type = QEMU_OPT_BOOL, | |
490 | },{ | |
491 | .name = "playback-compression", | |
492 | .type = QEMU_OPT_BOOL, | |
29b0040b | 493 | }, |
44bd6907 | 494 | { /* end of list */ } |
29b0040b GH |
495 | }, |
496 | }; | |
497 | ||
2e55e842 GN |
498 | QemuOptsList qemu_option_rom_opts = { |
499 | .name = "option-rom", | |
500 | .implied_opt_name = "romfile", | |
501 | .head = QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts.head), | |
502 | .desc = { | |
503 | { | |
504 | .name = "bootindex", | |
505 | .type = QEMU_OPT_NUMBER, | |
506 | }, { | |
507 | .name = "romfile", | |
508 | .type = QEMU_OPT_STRING, | |
509 | }, | |
44bd6907 | 510 | { /* end of list */ } |
2e55e842 GN |
511 | }, |
512 | }; | |
513 | ||
303d4e86 AP |
514 | static QemuOptsList qemu_machine_opts = { |
515 | .name = "machine", | |
9052ea6b | 516 | .implied_opt_name = "type", |
303d4e86 AP |
517 | .head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head), |
518 | .desc = { | |
519 | { | |
9052ea6b JK |
520 | .name = "type", |
521 | .type = QEMU_OPT_STRING, | |
522 | .help = "emulated machine" | |
523 | }, { | |
303d4e86 AP |
524 | .name = "accel", |
525 | .type = QEMU_OPT_STRING, | |
526 | .help = "accelerator list", | |
527 | }, | |
528 | { /* End of list */ } | |
529 | }, | |
530 | }; | |
531 | ||
3d3b8303 WX |
532 | QemuOptsList qemu_boot_opts = { |
533 | .name = "boot-opts", | |
534 | .head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head), | |
535 | .desc = { | |
536 | /* the three names below are not used now */ | |
537 | { | |
538 | .name = "order", | |
539 | .type = QEMU_OPT_STRING, | |
540 | }, { | |
541 | .name = "once", | |
542 | .type = QEMU_OPT_STRING, | |
543 | }, { | |
544 | .name = "menu", | |
545 | .type = QEMU_OPT_STRING, | |
546 | /* following are really used */ | |
547 | }, { | |
548 | .name = "splash", | |
549 | .type = QEMU_OPT_STRING, | |
550 | }, { | |
551 | .name = "splash-time", | |
552 | .type = QEMU_OPT_STRING, | |
553 | }, | |
554 | { /*End of list */ } | |
555 | }, | |
556 | }; | |
557 | ||
dfe795e7 | 558 | static QemuOptsList *vm_config_groups[32] = { |
d058fe03 | 559 | &qemu_drive_opts, |
191bc01b | 560 | &qemu_chardev_opts, |
f31d07d1 | 561 | &qemu_device_opts, |
a1ea458f | 562 | &qemu_netdev_opts, |
8119b33d | 563 | &qemu_net_opts, |
5fdfbf7e | 564 | &qemu_rtc_opts, |
d0fef6fb | 565 | &qemu_global_opts, |
88589343 | 566 | &qemu_mon_opts, |
b5ec5ce0 | 567 | &qemu_cpudef_opts, |
ab6540d5 | 568 | &qemu_trace_opts, |
2e55e842 | 569 | &qemu_option_rom_opts, |
303d4e86 | 570 | &qemu_machine_opts, |
3d3b8303 | 571 | &qemu_boot_opts, |
d058fe03 GH |
572 | NULL, |
573 | }; | |
574 | ||
490b648e | 575 | static QemuOptsList *find_list(QemuOptsList **lists, const char *group) |
ddc97855 GH |
576 | { |
577 | int i; | |
578 | ||
579 | for (i = 0; lists[i] != NULL; i++) { | |
580 | if (strcmp(lists[i]->name, group) == 0) | |
581 | break; | |
582 | } | |
583 | if (lists[i] == NULL) { | |
1ecda02b | 584 | error_report("there is no option group \"%s\"", group); |
ddc97855 GH |
585 | } |
586 | return lists[i]; | |
587 | } | |
588 | ||
490b648e KW |
589 | QemuOptsList *qemu_find_opts(const char *group) |
590 | { | |
591 | return find_list(vm_config_groups, group); | |
592 | } | |
593 | ||
dfe795e7 GH |
594 | void qemu_add_opts(QemuOptsList *list) |
595 | { | |
596 | int entries, i; | |
597 | ||
598 | entries = ARRAY_SIZE(vm_config_groups); | |
599 | entries--; /* keep list NULL terminated */ | |
600 | for (i = 0; i < entries; i++) { | |
601 | if (vm_config_groups[i] == NULL) { | |
602 | vm_config_groups[i] = list; | |
603 | return; | |
604 | } | |
605 | } | |
606 | fprintf(stderr, "ran out of space in vm_config_groups"); | |
607 | abort(); | |
608 | } | |
609 | ||
d058fe03 GH |
610 | int qemu_set_option(const char *str) |
611 | { | |
612 | char group[64], id[64], arg[64]; | |
ddc97855 | 613 | QemuOptsList *list; |
d058fe03 | 614 | QemuOpts *opts; |
ddc97855 | 615 | int rc, offset; |
d058fe03 GH |
616 | |
617 | rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset); | |
618 | if (rc < 3 || str[offset] != '=') { | |
1ecda02b | 619 | error_report("can't parse: \"%s\"", str); |
d058fe03 GH |
620 | return -1; |
621 | } | |
622 | ||
304329ee | 623 | list = qemu_find_opts(group); |
ddc97855 | 624 | if (list == NULL) { |
d058fe03 GH |
625 | return -1; |
626 | } | |
627 | ||
ddc97855 | 628 | opts = qemu_opts_find(list, id); |
d058fe03 | 629 | if (!opts) { |
1ecda02b MA |
630 | error_report("there is no %s \"%s\" defined", |
631 | list->name, id); | |
d058fe03 GH |
632 | return -1; |
633 | } | |
634 | ||
3df04ac3 | 635 | if (qemu_opt_set(opts, arg, str+offset+1) == -1) { |
d058fe03 GH |
636 | return -1; |
637 | } | |
638 | return 0; | |
639 | } | |
640 | ||
d0fef6fb GH |
641 | int qemu_global_option(const char *str) |
642 | { | |
643 | char driver[64], property[64]; | |
644 | QemuOpts *opts; | |
645 | int rc, offset; | |
646 | ||
647 | rc = sscanf(str, "%63[^.].%63[^=]%n", driver, property, &offset); | |
648 | if (rc < 2 || str[offset] != '=') { | |
1ecda02b | 649 | error_report("can't parse: \"%s\"", str); |
d0fef6fb GH |
650 | return -1; |
651 | } | |
652 | ||
653 | opts = qemu_opts_create(&qemu_global_opts, NULL, 0); | |
654 | qemu_opt_set(opts, "driver", driver); | |
655 | qemu_opt_set(opts, "property", property); | |
656 | qemu_opt_set(opts, "value", str+offset+1); | |
657 | return 0; | |
658 | } | |
659 | ||
9d993394 GH |
660 | struct ConfigWriteData { |
661 | QemuOptsList *list; | |
662 | FILE *fp; | |
663 | }; | |
664 | ||
665 | static int config_write_opt(const char *name, const char *value, void *opaque) | |
666 | { | |
667 | struct ConfigWriteData *data = opaque; | |
668 | ||
669 | fprintf(data->fp, " %s = \"%s\"\n", name, value); | |
670 | return 0; | |
671 | } | |
672 | ||
673 | static int config_write_opts(QemuOpts *opts, void *opaque) | |
674 | { | |
675 | struct ConfigWriteData *data = opaque; | |
676 | const char *id = qemu_opts_id(opts); | |
677 | ||
678 | if (id) { | |
679 | fprintf(data->fp, "[%s \"%s\"]\n", data->list->name, id); | |
680 | } else { | |
681 | fprintf(data->fp, "[%s]\n", data->list->name); | |
682 | } | |
683 | qemu_opt_foreach(opts, config_write_opt, data, 0); | |
684 | fprintf(data->fp, "\n"); | |
685 | return 0; | |
686 | } | |
687 | ||
688 | void qemu_config_write(FILE *fp) | |
689 | { | |
690 | struct ConfigWriteData data = { .fp = fp }; | |
490b648e | 691 | QemuOptsList **lists = vm_config_groups; |
9d993394 GH |
692 | int i; |
693 | ||
694 | fprintf(fp, "# qemu config file\n\n"); | |
695 | for (i = 0; lists[i] != NULL; i++) { | |
696 | data.list = lists[i]; | |
697 | qemu_opts_foreach(data.list, config_write_opts, &data, 0); | |
698 | } | |
699 | } | |
42262ba8 | 700 | |
490b648e | 701 | int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname) |
42262ba8 GH |
702 | { |
703 | char line[1024], group[64], id[64], arg[64], value[1024]; | |
cf5a65aa | 704 | Location loc; |
42262ba8 GH |
705 | QemuOptsList *list = NULL; |
706 | QemuOpts *opts = NULL; | |
cf5a65aa | 707 | int res = -1, lno = 0; |
42262ba8 | 708 | |
cf5a65aa | 709 | loc_push_none(&loc); |
42262ba8 | 710 | while (fgets(line, sizeof(line), fp) != NULL) { |
cf5a65aa | 711 | loc_set_file(fname, ++lno); |
42262ba8 GH |
712 | if (line[0] == '\n') { |
713 | /* skip empty lines */ | |
714 | continue; | |
715 | } | |
716 | if (line[0] == '#') { | |
717 | /* comment */ | |
718 | continue; | |
719 | } | |
720 | if (sscanf(line, "[%63s \"%63[^\"]\"]", group, id) == 2) { | |
721 | /* group with id */ | |
490b648e | 722 | list = find_list(lists, group); |
42262ba8 | 723 | if (list == NULL) |
cf5a65aa | 724 | goto out; |
42262ba8 GH |
725 | opts = qemu_opts_create(list, id, 1); |
726 | continue; | |
727 | } | |
728 | if (sscanf(line, "[%63[^]]]", group) == 1) { | |
729 | /* group without id */ | |
490b648e | 730 | list = find_list(lists, group); |
42262ba8 | 731 | if (list == NULL) |
cf5a65aa | 732 | goto out; |
42262ba8 GH |
733 | opts = qemu_opts_create(list, NULL, 0); |
734 | continue; | |
735 | } | |
736 | if (sscanf(line, " %63s = \"%1023[^\"]\"", arg, value) == 2) { | |
737 | /* arg = value */ | |
738 | if (opts == NULL) { | |
cf5a65aa MA |
739 | error_report("no group defined"); |
740 | goto out; | |
42262ba8 GH |
741 | } |
742 | if (qemu_opt_set(opts, arg, value) != 0) { | |
cf5a65aa | 743 | goto out; |
42262ba8 GH |
744 | } |
745 | continue; | |
746 | } | |
cf5a65aa MA |
747 | error_report("parse error"); |
748 | goto out; | |
42262ba8 | 749 | } |
ef82516d MA |
750 | if (ferror(fp)) { |
751 | error_report("error reading file"); | |
752 | goto out; | |
753 | } | |
cf5a65aa MA |
754 | res = 0; |
755 | out: | |
756 | loc_pop(&loc); | |
757 | return res; | |
42262ba8 | 758 | } |
dcfb0939 KW |
759 | |
760 | int qemu_read_config_file(const char *filename) | |
761 | { | |
762 | FILE *f = fopen(filename, "r"); | |
019e78ba KW |
763 | int ret; |
764 | ||
dcfb0939 KW |
765 | if (f == NULL) { |
766 | return -errno; | |
767 | } | |
768 | ||
019e78ba | 769 | ret = qemu_config_parse(f, vm_config_groups, filename); |
dcfb0939 KW |
770 | fclose(f); |
771 | ||
019e78ba KW |
772 | if (ret == 0) { |
773 | return 0; | |
774 | } else { | |
775 | return -EINVAL; | |
776 | } | |
dcfb0939 | 777 | } |