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