]> git.proxmox.com Git - qemu.git/blame - qemu-config.c
hw/9pfs: Add validation to {un}marshal code
[qemu.git] / qemu-config.c
CommitLineData
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 7static 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 121static 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
194QemuOptsList 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
VJJ
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,
74db920c 214 },
2c74c2cb 215
74db920c
GS
216 { /*End of list */ }
217 },
218};
74db920c 219
3d54abc7
GS
220QemuOptsList qemu_virtfs_opts = {
221 .name = "virtfs",
fbcbf101 222 .implied_opt_name = "fsdriver",
3d54abc7
GS
223 .head = QTAILQ_HEAD_INITIALIZER(qemu_virtfs_opts.head),
224 .desc = {
225 {
fbcbf101 226 .name = "fsdriver",
3d54abc7
GS
227 .type = QEMU_OPT_STRING,
228 }, {
229 .name = "path",
230 .type = QEMU_OPT_STRING,
231 }, {
232 .name = "mount_tag",
233 .type = QEMU_OPT_STRING,
9ce56db6
VJJ
234 }, {
235 .name = "security_model",
236 .type = QEMU_OPT_STRING,
d3ab98e6
AK
237 }, {
238 .name = "writeout",
239 .type = QEMU_OPT_STRING,
2c74c2cb
MK
240 }, {
241 .name = "readonly",
242 .type = QEMU_OPT_BOOL,
3d54abc7
GS
243 },
244
245 { /*End of list */ }
246 },
247};
3d54abc7 248
3329f07b 249static QemuOptsList qemu_device_opts = {
f31d07d1 250 .name = "device",
8212c64f 251 .implied_opt_name = "driver",
72cf2d4f 252 .head = QTAILQ_HEAD_INITIALIZER(qemu_device_opts.head),
f31d07d1
GH
253 .desc = {
254 /*
255 * no elements => accept any
256 * sanity checking will happen later
257 * when setting device properties
258 */
26056e0c 259 { /* end of list */ }
f31d07d1
GH
260 },
261};
262
3329f07b 263static QemuOptsList qemu_netdev_opts = {
a1ea458f 264 .name = "netdev",
8212c64f 265 .implied_opt_name = "type",
a1ea458f
MM
266 .head = QTAILQ_HEAD_INITIALIZER(qemu_netdev_opts.head),
267 .desc = {
268 /*
269 * no elements => accept any params
270 * validation will happen later
271 */
272 { /* end of list */ }
273 },
274};
275
3329f07b 276static QemuOptsList qemu_net_opts = {
8119b33d 277 .name = "net",
8212c64f 278 .implied_opt_name = "type",
8119b33d
MM
279 .head = QTAILQ_HEAD_INITIALIZER(qemu_net_opts.head),
280 .desc = {
281 /*
282 * no elements => accept any params
283 * validation will happen later
284 */
285 { /* end of list */ }
286 },
287};
288
3329f07b 289static QemuOptsList qemu_rtc_opts = {
1ed2fc1f
JK
290 .name = "rtc",
291 .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head),
292 .desc = {
293 {
294 .name = "base",
295 .type = QEMU_OPT_STRING,
6875204c
JK
296 },{
297 .name = "clock",
298 .type = QEMU_OPT_STRING,
1ed2fc1f
JK
299 },{
300 .name = "driftfix",
301 .type = QEMU_OPT_STRING,
1ed2fc1f 302 },
26056e0c 303 { /* end of list */ }
1ed2fc1f
JK
304 },
305};
306
3329f07b 307static QemuOptsList qemu_global_opts = {
d0fef6fb
GH
308 .name = "global",
309 .head = QTAILQ_HEAD_INITIALIZER(qemu_global_opts.head),
310 .desc = {
311 {
312 .name = "driver",
313 .type = QEMU_OPT_STRING,
314 },{
315 .name = "property",
316 .type = QEMU_OPT_STRING,
317 },{
318 .name = "value",
319 .type = QEMU_OPT_STRING,
320 },
26056e0c 321 { /* end of list */ }
d0fef6fb
GH
322 },
323};
324
3329f07b 325static QemuOptsList qemu_mon_opts = {
88589343 326 .name = "mon",
8212c64f 327 .implied_opt_name = "chardev",
88589343
GH
328 .head = QTAILQ_HEAD_INITIALIZER(qemu_mon_opts.head),
329 .desc = {
330 {
331 .name = "mode",
332 .type = QEMU_OPT_STRING,
333 },{
334 .name = "chardev",
335 .type = QEMU_OPT_STRING,
336 },{
337 .name = "default",
338 .type = QEMU_OPT_BOOL,
39eaab9a
DB
339 },{
340 .name = "pretty",
341 .type = QEMU_OPT_BOOL,
88589343 342 },
26056e0c 343 { /* end of list */ }
88589343
GH
344 },
345};
346
ab6540d5
PS
347static QemuOptsList qemu_trace_opts = {
348 .name = "trace",
349 .implied_opt_name = "trace",
350 .head = QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head),
351 .desc = {
352 {
23d15e86
L
353 .name = "events",
354 .type = QEMU_OPT_STRING,
355 },{
ab6540d5
PS
356 .name = "file",
357 .type = QEMU_OPT_STRING,
358 },
44bd6907 359 { /* end of list */ }
ab6540d5
PS
360 },
361};
ab6540d5 362
3329f07b 363static QemuOptsList qemu_cpudef_opts = {
b5ec5ce0 364 .name = "cpudef",
365 .head = QTAILQ_HEAD_INITIALIZER(qemu_cpudef_opts.head),
366 .desc = {
367 {
368 .name = "name",
369 .type = QEMU_OPT_STRING,
370 },{
371 .name = "level",
372 .type = QEMU_OPT_NUMBER,
373 },{
374 .name = "vendor",
375 .type = QEMU_OPT_STRING,
376 },{
377 .name = "family",
378 .type = QEMU_OPT_NUMBER,
379 },{
380 .name = "model",
381 .type = QEMU_OPT_NUMBER,
382 },{
383 .name = "stepping",
384 .type = QEMU_OPT_NUMBER,
385 },{
386 .name = "feature_edx", /* cpuid 0000_0001.edx */
387 .type = QEMU_OPT_STRING,
388 },{
389 .name = "feature_ecx", /* cpuid 0000_0001.ecx */
390 .type = QEMU_OPT_STRING,
391 },{
392 .name = "extfeature_edx", /* cpuid 8000_0001.edx */
393 .type = QEMU_OPT_STRING,
394 },{
395 .name = "extfeature_ecx", /* cpuid 8000_0001.ecx */
396 .type = QEMU_OPT_STRING,
397 },{
398 .name = "xlevel",
399 .type = QEMU_OPT_NUMBER,
400 },{
401 .name = "model_id",
402 .type = QEMU_OPT_STRING,
403 },{
404 .name = "vendor_override",
405 .type = QEMU_OPT_NUMBER,
406 },
407 { /* end of list */ }
408 },
409};
410
29b0040b
GH
411QemuOptsList qemu_spice_opts = {
412 .name = "spice",
413 .head = QTAILQ_HEAD_INITIALIZER(qemu_spice_opts.head),
414 .desc = {
415 {
416 .name = "port",
417 .type = QEMU_OPT_NUMBER,
c448e855
GH
418 },{
419 .name = "tls-port",
420 .type = QEMU_OPT_NUMBER,
333b0eeb
GH
421 },{
422 .name = "addr",
423 .type = QEMU_OPT_STRING,
424 },{
425 .name = "ipv4",
426 .type = QEMU_OPT_BOOL,
427 },{
428 .name = "ipv6",
429 .type = QEMU_OPT_BOOL,
29b0040b
GH
430 },{
431 .name = "password",
432 .type = QEMU_OPT_STRING,
433 },{
434 .name = "disable-ticketing",
435 .type = QEMU_OPT_BOOL,
d4970b07
HG
436 },{
437 .name = "disable-copy-paste",
438 .type = QEMU_OPT_BOOL,
48b3ed0a
MAL
439 },{
440 .name = "sasl",
441 .type = QEMU_OPT_BOOL,
c448e855
GH
442 },{
443 .name = "x509-dir",
444 .type = QEMU_OPT_STRING,
445 },{
446 .name = "x509-key-file",
447 .type = QEMU_OPT_STRING,
448 },{
449 .name = "x509-key-password",
450 .type = QEMU_OPT_STRING,
451 },{
452 .name = "x509-cert-file",
453 .type = QEMU_OPT_STRING,
454 },{
455 .name = "x509-cacert-file",
456 .type = QEMU_OPT_STRING,
457 },{
458 .name = "x509-dh-key-file",
459 .type = QEMU_OPT_STRING,
460 },{
461 .name = "tls-ciphers",
462 .type = QEMU_OPT_STRING,
17b6dea0
GH
463 },{
464 .name = "tls-channel",
465 .type = QEMU_OPT_STRING,
466 },{
467 .name = "plaintext-channel",
468 .type = QEMU_OPT_STRING,
9f04e09e
YH
469 },{
470 .name = "image-compression",
471 .type = QEMU_OPT_STRING,
472 },{
473 .name = "jpeg-wan-compression",
474 .type = QEMU_OPT_STRING,
475 },{
476 .name = "zlib-glz-wan-compression",
477 .type = QEMU_OPT_STRING,
84a23f25
GH
478 },{
479 .name = "streaming-video",
480 .type = QEMU_OPT_STRING,
481 },{
482 .name = "agent-mouse",
483 .type = QEMU_OPT_BOOL,
484 },{
485 .name = "playback-compression",
486 .type = QEMU_OPT_BOOL,
29b0040b 487 },
44bd6907 488 { /* end of list */ }
29b0040b
GH
489 },
490};
491
2e55e842
GN
492QemuOptsList qemu_option_rom_opts = {
493 .name = "option-rom",
494 .implied_opt_name = "romfile",
495 .head = QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts.head),
496 .desc = {
497 {
498 .name = "bootindex",
499 .type = QEMU_OPT_NUMBER,
500 }, {
501 .name = "romfile",
502 .type = QEMU_OPT_STRING,
503 },
44bd6907 504 { /* end of list */ }
2e55e842
GN
505 },
506};
507
303d4e86
AP
508static QemuOptsList qemu_machine_opts = {
509 .name = "machine",
9052ea6b 510 .implied_opt_name = "type",
303d4e86
AP
511 .head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head),
512 .desc = {
513 {
9052ea6b
JK
514 .name = "type",
515 .type = QEMU_OPT_STRING,
516 .help = "emulated machine"
517 }, {
303d4e86
AP
518 .name = "accel",
519 .type = QEMU_OPT_STRING,
520 .help = "accelerator list",
521 },
522 { /* End of list */ }
523 },
524};
525
3d3b8303 526QemuOptsList qemu_boot_opts = {
527 .name = "boot-opts",
528 .head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head),
529 .desc = {
530 /* the three names below are not used now */
531 {
532 .name = "order",
533 .type = QEMU_OPT_STRING,
534 }, {
535 .name = "once",
536 .type = QEMU_OPT_STRING,
537 }, {
538 .name = "menu",
539 .type = QEMU_OPT_STRING,
540 /* following are really used */
541 }, {
542 .name = "splash",
543 .type = QEMU_OPT_STRING,
544 }, {
545 .name = "splash-time",
546 .type = QEMU_OPT_STRING,
547 },
548 { /*End of list */ }
549 },
550};
551
dfe795e7 552static QemuOptsList *vm_config_groups[32] = {
d058fe03 553 &qemu_drive_opts,
191bc01b 554 &qemu_chardev_opts,
f31d07d1 555 &qemu_device_opts,
a1ea458f 556 &qemu_netdev_opts,
8119b33d 557 &qemu_net_opts,
5fdfbf7e 558 &qemu_rtc_opts,
d0fef6fb 559 &qemu_global_opts,
88589343 560 &qemu_mon_opts,
b5ec5ce0 561 &qemu_cpudef_opts,
ab6540d5 562 &qemu_trace_opts,
2e55e842 563 &qemu_option_rom_opts,
303d4e86 564 &qemu_machine_opts,
3d3b8303 565 &qemu_boot_opts,
d058fe03
GH
566 NULL,
567};
568
490b648e 569static QemuOptsList *find_list(QemuOptsList **lists, const char *group)
ddc97855
GH
570{
571 int i;
572
573 for (i = 0; lists[i] != NULL; i++) {
574 if (strcmp(lists[i]->name, group) == 0)
575 break;
576 }
577 if (lists[i] == NULL) {
1ecda02b 578 error_report("there is no option group \"%s\"", group);
ddc97855
GH
579 }
580 return lists[i];
581}
582
490b648e
KW
583QemuOptsList *qemu_find_opts(const char *group)
584{
585 return find_list(vm_config_groups, group);
586}
587
dfe795e7
GH
588void qemu_add_opts(QemuOptsList *list)
589{
590 int entries, i;
591
592 entries = ARRAY_SIZE(vm_config_groups);
593 entries--; /* keep list NULL terminated */
594 for (i = 0; i < entries; i++) {
595 if (vm_config_groups[i] == NULL) {
596 vm_config_groups[i] = list;
597 return;
598 }
599 }
600 fprintf(stderr, "ran out of space in vm_config_groups");
601 abort();
602}
603
d058fe03
GH
604int qemu_set_option(const char *str)
605{
606 char group[64], id[64], arg[64];
ddc97855 607 QemuOptsList *list;
d058fe03 608 QemuOpts *opts;
ddc97855 609 int rc, offset;
d058fe03
GH
610
611 rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset);
612 if (rc < 3 || str[offset] != '=') {
1ecda02b 613 error_report("can't parse: \"%s\"", str);
d058fe03
GH
614 return -1;
615 }
616
304329ee 617 list = qemu_find_opts(group);
ddc97855 618 if (list == NULL) {
d058fe03
GH
619 return -1;
620 }
621
ddc97855 622 opts = qemu_opts_find(list, id);
d058fe03 623 if (!opts) {
1ecda02b
MA
624 error_report("there is no %s \"%s\" defined",
625 list->name, id);
d058fe03
GH
626 return -1;
627 }
628
3df04ac3 629 if (qemu_opt_set(opts, arg, str+offset+1) == -1) {
d058fe03
GH
630 return -1;
631 }
632 return 0;
633}
634
d0fef6fb
GH
635int qemu_global_option(const char *str)
636{
637 char driver[64], property[64];
638 QemuOpts *opts;
639 int rc, offset;
640
641 rc = sscanf(str, "%63[^.].%63[^=]%n", driver, property, &offset);
642 if (rc < 2 || str[offset] != '=') {
1ecda02b 643 error_report("can't parse: \"%s\"", str);
d0fef6fb
GH
644 return -1;
645 }
646
647 opts = qemu_opts_create(&qemu_global_opts, NULL, 0);
648 qemu_opt_set(opts, "driver", driver);
649 qemu_opt_set(opts, "property", property);
650 qemu_opt_set(opts, "value", str+offset+1);
651 return 0;
652}
653
9d993394
GH
654struct ConfigWriteData {
655 QemuOptsList *list;
656 FILE *fp;
657};
658
659static int config_write_opt(const char *name, const char *value, void *opaque)
660{
661 struct ConfigWriteData *data = opaque;
662
663 fprintf(data->fp, " %s = \"%s\"\n", name, value);
664 return 0;
665}
666
667static int config_write_opts(QemuOpts *opts, void *opaque)
668{
669 struct ConfigWriteData *data = opaque;
670 const char *id = qemu_opts_id(opts);
671
672 if (id) {
673 fprintf(data->fp, "[%s \"%s\"]\n", data->list->name, id);
674 } else {
675 fprintf(data->fp, "[%s]\n", data->list->name);
676 }
677 qemu_opt_foreach(opts, config_write_opt, data, 0);
678 fprintf(data->fp, "\n");
679 return 0;
680}
681
682void qemu_config_write(FILE *fp)
683{
684 struct ConfigWriteData data = { .fp = fp };
490b648e 685 QemuOptsList **lists = vm_config_groups;
9d993394
GH
686 int i;
687
688 fprintf(fp, "# qemu config file\n\n");
689 for (i = 0; lists[i] != NULL; i++) {
690 data.list = lists[i];
691 qemu_opts_foreach(data.list, config_write_opts, &data, 0);
692 }
693}
42262ba8 694
490b648e 695int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname)
42262ba8
GH
696{
697 char line[1024], group[64], id[64], arg[64], value[1024];
cf5a65aa 698 Location loc;
42262ba8
GH
699 QemuOptsList *list = NULL;
700 QemuOpts *opts = NULL;
cf5a65aa 701 int res = -1, lno = 0;
42262ba8 702
cf5a65aa 703 loc_push_none(&loc);
42262ba8 704 while (fgets(line, sizeof(line), fp) != NULL) {
cf5a65aa 705 loc_set_file(fname, ++lno);
42262ba8
GH
706 if (line[0] == '\n') {
707 /* skip empty lines */
708 continue;
709 }
710 if (line[0] == '#') {
711 /* comment */
712 continue;
713 }
714 if (sscanf(line, "[%63s \"%63[^\"]\"]", group, id) == 2) {
715 /* group with id */
490b648e 716 list = find_list(lists, group);
42262ba8 717 if (list == NULL)
cf5a65aa 718 goto out;
42262ba8
GH
719 opts = qemu_opts_create(list, id, 1);
720 continue;
721 }
722 if (sscanf(line, "[%63[^]]]", group) == 1) {
723 /* group without id */
490b648e 724 list = find_list(lists, group);
42262ba8 725 if (list == NULL)
cf5a65aa 726 goto out;
42262ba8
GH
727 opts = qemu_opts_create(list, NULL, 0);
728 continue;
729 }
730 if (sscanf(line, " %63s = \"%1023[^\"]\"", arg, value) == 2) {
731 /* arg = value */
732 if (opts == NULL) {
cf5a65aa
MA
733 error_report("no group defined");
734 goto out;
42262ba8
GH
735 }
736 if (qemu_opt_set(opts, arg, value) != 0) {
cf5a65aa 737 goto out;
42262ba8
GH
738 }
739 continue;
740 }
cf5a65aa
MA
741 error_report("parse error");
742 goto out;
42262ba8 743 }
ef82516d
MA
744 if (ferror(fp)) {
745 error_report("error reading file");
746 goto out;
747 }
cf5a65aa
MA
748 res = 0;
749out:
750 loc_pop(&loc);
751 return res;
42262ba8 752}
dcfb0939
KW
753
754int qemu_read_config_file(const char *filename)
755{
756 FILE *f = fopen(filename, "r");
019e78ba
KW
757 int ret;
758
dcfb0939
KW
759 if (f == NULL) {
760 return -errno;
761 }
762
019e78ba 763 ret = qemu_config_parse(f, vm_config_groups, filename);
dcfb0939
KW
764 fclose(f);
765
019e78ba
KW
766 if (ret == 0) {
767 return 0;
768 } else {
769 return -EINVAL;
770 }
dcfb0939 771}