1 #include "qemu-common.h"
2 #include "qemu-error.h"
3 #include "qemu-option.h"
4 #include "qemu-config.h"
8 static QemuOptsList qemu_drive_opts
= {
10 .head
= QTAILQ_HEAD_INITIALIZER(qemu_drive_opts
.head
),
14 .type
= QEMU_OPT_NUMBER
,
18 .type
= QEMU_OPT_NUMBER
,
19 .help
= "unit number (i.e. lun for scsi)",
22 .type
= QEMU_OPT_STRING
,
23 .help
= "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)",
26 .type
= QEMU_OPT_NUMBER
,
27 .help
= "index number",
30 .type
= QEMU_OPT_NUMBER
,
31 .help
= "number of cylinders (ide disk geometry)",
34 .type
= QEMU_OPT_NUMBER
,
35 .help
= "number of heads (ide disk geometry)",
38 .type
= QEMU_OPT_NUMBER
,
39 .help
= "number of sectors (ide disk geometry)",
42 .type
= QEMU_OPT_STRING
,
43 .help
= "chs translation (auto, lba. none)",
46 .type
= QEMU_OPT_STRING
,
47 .help
= "media type (disk, cdrom)",
50 .type
= QEMU_OPT_BOOL
,
51 .help
= "enable/disable snapshot mode",
54 .type
= QEMU_OPT_STRING
,
58 .type
= QEMU_OPT_STRING
,
59 .help
= "host cache usage (none, writeback, writethrough, "
60 "directsync, unsafe)",
63 .type
= QEMU_OPT_STRING
,
64 .help
= "host AIO implementation (threads, native)",
67 .type
= QEMU_OPT_STRING
,
68 .help
= "disk format (raw, qcow2, ...)",
71 .type
= QEMU_OPT_STRING
,
72 .help
= "disk serial number",
75 .type
= QEMU_OPT_STRING
,
76 .help
= "read error action",
79 .type
= QEMU_OPT_STRING
,
80 .help
= "write error action",
83 .type
= QEMU_OPT_STRING
,
84 .help
= "pci address (virtio only)",
87 .type
= QEMU_OPT_BOOL
,
88 .help
= "open drive file as read-only",
91 .type
= QEMU_OPT_NUMBER
,
92 .help
= "limit total I/O operations per second",
95 .type
= QEMU_OPT_NUMBER
,
96 .help
= "limit read operations per second",
99 .type
= QEMU_OPT_NUMBER
,
100 .help
= "limit write operations per second",
103 .type
= QEMU_OPT_NUMBER
,
104 .help
= "limit total bytes per second",
107 .type
= QEMU_OPT_NUMBER
,
108 .help
= "limit read bytes per second",
111 .type
= QEMU_OPT_NUMBER
,
112 .help
= "limit write bytes per second",
114 .name
= "copy-on-read",
115 .type
= QEMU_OPT_BOOL
,
116 .help
= "copy read data from backing file into image file",
118 { /* end of list */ }
122 static QemuOptsList qemu_iscsi_opts
= {
124 .head
= QTAILQ_HEAD_INITIALIZER(qemu_iscsi_opts
.head
),
128 .type
= QEMU_OPT_STRING
,
129 .help
= "username for CHAP authentication to target",
132 .type
= QEMU_OPT_STRING
,
133 .help
= "password for CHAP authentication to target",
135 .name
= "header-digest",
136 .type
= QEMU_OPT_STRING
,
137 .help
= "HeaderDigest setting. "
138 "{CRC32C|CRC32C-NONE|NONE-CRC32C|NONE}",
140 .name
= "initiator-name",
141 .type
= QEMU_OPT_STRING
,
142 .help
= "Initiator iqn name to use when connecting",
144 { /* end of list */ }
148 static QemuOptsList qemu_chardev_opts
= {
150 .implied_opt_name
= "backend",
151 .head
= QTAILQ_HEAD_INITIALIZER(qemu_chardev_opts
.head
),
155 .type
= QEMU_OPT_STRING
,
158 .type
= QEMU_OPT_STRING
,
161 .type
= QEMU_OPT_STRING
,
164 .type
= QEMU_OPT_STRING
,
167 .type
= QEMU_OPT_STRING
,
170 .type
= QEMU_OPT_STRING
,
173 .type
= QEMU_OPT_NUMBER
,
176 .type
= QEMU_OPT_BOOL
,
179 .type
= QEMU_OPT_BOOL
,
182 .type
= QEMU_OPT_BOOL
,
185 .type
= QEMU_OPT_BOOL
,
188 .type
= QEMU_OPT_BOOL
,
191 .type
= QEMU_OPT_BOOL
,
194 .type
= QEMU_OPT_NUMBER
,
197 .type
= QEMU_OPT_NUMBER
,
200 .type
= QEMU_OPT_NUMBER
,
203 .type
= QEMU_OPT_NUMBER
,
206 .type
= QEMU_OPT_BOOL
,
209 .type
= QEMU_OPT_BOOL
,
212 .type
= QEMU_OPT_STRING
,
215 .type
= QEMU_OPT_NUMBER
,
217 { /* end of list */ }
221 QemuOptsList qemu_fsdev_opts
= {
223 .implied_opt_name
= "fsdriver",
224 .head
= QTAILQ_HEAD_INITIALIZER(qemu_fsdev_opts
.head
),
228 .type
= QEMU_OPT_STRING
,
231 .type
= QEMU_OPT_STRING
,
233 .name
= "security_model",
234 .type
= QEMU_OPT_STRING
,
237 .type
= QEMU_OPT_STRING
,
240 .type
= QEMU_OPT_BOOL
,
244 .type
= QEMU_OPT_STRING
,
247 .type
= QEMU_OPT_NUMBER
,
254 QemuOptsList qemu_virtfs_opts
= {
256 .implied_opt_name
= "fsdriver",
257 .head
= QTAILQ_HEAD_INITIALIZER(qemu_virtfs_opts
.head
),
261 .type
= QEMU_OPT_STRING
,
264 .type
= QEMU_OPT_STRING
,
267 .type
= QEMU_OPT_STRING
,
269 .name
= "security_model",
270 .type
= QEMU_OPT_STRING
,
273 .type
= QEMU_OPT_STRING
,
276 .type
= QEMU_OPT_BOOL
,
279 .type
= QEMU_OPT_STRING
,
282 .type
= QEMU_OPT_NUMBER
,
289 static QemuOptsList qemu_device_opts
= {
291 .implied_opt_name
= "driver",
292 .head
= QTAILQ_HEAD_INITIALIZER(qemu_device_opts
.head
),
295 * no elements => accept any
296 * sanity checking will happen later
297 * when setting device properties
299 { /* end of list */ }
303 static QemuOptsList qemu_netdev_opts
= {
305 .implied_opt_name
= "type",
306 .head
= QTAILQ_HEAD_INITIALIZER(qemu_netdev_opts
.head
),
309 * no elements => accept any params
310 * validation will happen later
312 { /* end of list */ }
316 static QemuOptsList qemu_net_opts
= {
318 .implied_opt_name
= "type",
319 .head
= QTAILQ_HEAD_INITIALIZER(qemu_net_opts
.head
),
322 * no elements => accept any params
323 * validation will happen later
325 { /* end of list */ }
329 static QemuOptsList qemu_rtc_opts
= {
331 .head
= QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts
.head
),
335 .type
= QEMU_OPT_STRING
,
338 .type
= QEMU_OPT_STRING
,
341 .type
= QEMU_OPT_STRING
,
343 { /* end of list */ }
347 static QemuOptsList qemu_global_opts
= {
349 .head
= QTAILQ_HEAD_INITIALIZER(qemu_global_opts
.head
),
353 .type
= QEMU_OPT_STRING
,
356 .type
= QEMU_OPT_STRING
,
359 .type
= QEMU_OPT_STRING
,
361 { /* end of list */ }
365 static QemuOptsList qemu_mon_opts
= {
367 .implied_opt_name
= "chardev",
368 .head
= QTAILQ_HEAD_INITIALIZER(qemu_mon_opts
.head
),
372 .type
= QEMU_OPT_STRING
,
375 .type
= QEMU_OPT_STRING
,
378 .type
= QEMU_OPT_BOOL
,
381 .type
= QEMU_OPT_BOOL
,
383 { /* end of list */ }
387 static QemuOptsList qemu_trace_opts
= {
389 .implied_opt_name
= "trace",
390 .head
= QTAILQ_HEAD_INITIALIZER(qemu_trace_opts
.head
),
394 .type
= QEMU_OPT_STRING
,
397 .type
= QEMU_OPT_STRING
,
399 { /* end of list */ }
403 static QemuOptsList qemu_cpudef_opts
= {
405 .head
= QTAILQ_HEAD_INITIALIZER(qemu_cpudef_opts
.head
),
409 .type
= QEMU_OPT_STRING
,
412 .type
= QEMU_OPT_NUMBER
,
415 .type
= QEMU_OPT_STRING
,
418 .type
= QEMU_OPT_NUMBER
,
421 .type
= QEMU_OPT_NUMBER
,
424 .type
= QEMU_OPT_NUMBER
,
426 .name
= "feature_edx", /* cpuid 0000_0001.edx */
427 .type
= QEMU_OPT_STRING
,
429 .name
= "feature_ecx", /* cpuid 0000_0001.ecx */
430 .type
= QEMU_OPT_STRING
,
432 .name
= "extfeature_edx", /* cpuid 8000_0001.edx */
433 .type
= QEMU_OPT_STRING
,
435 .name
= "extfeature_ecx", /* cpuid 8000_0001.ecx */
436 .type
= QEMU_OPT_STRING
,
439 .type
= QEMU_OPT_NUMBER
,
442 .type
= QEMU_OPT_STRING
,
444 .name
= "vendor_override",
445 .type
= QEMU_OPT_NUMBER
,
447 { /* end of list */ }
451 QemuOptsList qemu_spice_opts
= {
453 .head
= QTAILQ_HEAD_INITIALIZER(qemu_spice_opts
.head
),
457 .type
= QEMU_OPT_NUMBER
,
460 .type
= QEMU_OPT_NUMBER
,
463 .type
= QEMU_OPT_STRING
,
466 .type
= QEMU_OPT_BOOL
,
469 .type
= QEMU_OPT_BOOL
,
472 .type
= QEMU_OPT_STRING
,
474 .name
= "disable-ticketing",
475 .type
= QEMU_OPT_BOOL
,
477 .name
= "disable-copy-paste",
478 .type
= QEMU_OPT_BOOL
,
481 .type
= QEMU_OPT_BOOL
,
484 .type
= QEMU_OPT_STRING
,
486 .name
= "x509-key-file",
487 .type
= QEMU_OPT_STRING
,
489 .name
= "x509-key-password",
490 .type
= QEMU_OPT_STRING
,
492 .name
= "x509-cert-file",
493 .type
= QEMU_OPT_STRING
,
495 .name
= "x509-cacert-file",
496 .type
= QEMU_OPT_STRING
,
498 .name
= "x509-dh-key-file",
499 .type
= QEMU_OPT_STRING
,
501 .name
= "tls-ciphers",
502 .type
= QEMU_OPT_STRING
,
504 .name
= "tls-channel",
505 .type
= QEMU_OPT_STRING
,
507 .name
= "plaintext-channel",
508 .type
= QEMU_OPT_STRING
,
510 .name
= "image-compression",
511 .type
= QEMU_OPT_STRING
,
513 .name
= "jpeg-wan-compression",
514 .type
= QEMU_OPT_STRING
,
516 .name
= "zlib-glz-wan-compression",
517 .type
= QEMU_OPT_STRING
,
519 .name
= "streaming-video",
520 .type
= QEMU_OPT_STRING
,
522 .name
= "agent-mouse",
523 .type
= QEMU_OPT_BOOL
,
525 .name
= "playback-compression",
526 .type
= QEMU_OPT_BOOL
,
528 { /* end of list */ }
532 QemuOptsList qemu_option_rom_opts
= {
533 .name
= "option-rom",
534 .implied_opt_name
= "romfile",
535 .head
= QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts
.head
),
539 .type
= QEMU_OPT_NUMBER
,
542 .type
= QEMU_OPT_STRING
,
544 { /* end of list */ }
548 static QemuOptsList qemu_machine_opts
= {
550 .implied_opt_name
= "type",
552 .head
= QTAILQ_HEAD_INITIALIZER(qemu_machine_opts
.head
),
556 .type
= QEMU_OPT_STRING
,
557 .help
= "emulated machine"
560 .type
= QEMU_OPT_STRING
,
561 .help
= "accelerator list",
563 .name
= "kernel_irqchip",
564 .type
= QEMU_OPT_BOOL
,
565 .help
= "use KVM in-kernel irqchip",
567 .name
= "kvm_shadow_mem",
568 .type
= QEMU_OPT_SIZE
,
569 .help
= "KVM shadow MMU size",
572 .type
= QEMU_OPT_STRING
,
573 .help
= "Linux kernel image file",
576 .type
= QEMU_OPT_STRING
,
577 .help
= "Linux initial ramdisk file",
580 .type
= QEMU_OPT_STRING
,
581 .help
= "Linux kernel command line",
584 .type
= QEMU_OPT_STRING
,
585 .help
= "Linux kernel device tree file",
588 .type
= QEMU_OPT_STRING
,
589 .help
= "Dump current dtb to a file and quit",
591 { /* End of list */ }
595 QemuOptsList qemu_boot_opts
= {
597 .head
= QTAILQ_HEAD_INITIALIZER(qemu_boot_opts
.head
),
599 /* the three names below are not used now */
602 .type
= QEMU_OPT_STRING
,
605 .type
= QEMU_OPT_STRING
,
608 .type
= QEMU_OPT_STRING
,
609 /* following are really used */
612 .type
= QEMU_OPT_STRING
,
614 .name
= "splash-time",
615 .type
= QEMU_OPT_STRING
,
621 static QemuOptsList
*vm_config_groups
[32] = {
632 &qemu_option_rom_opts
,
639 static QemuOptsList
*find_list(QemuOptsList
**lists
, const char *group
,
644 for (i
= 0; lists
[i
] != NULL
; i
++) {
645 if (strcmp(lists
[i
]->name
, group
) == 0)
648 if (lists
[i
] == NULL
) {
649 error_set(errp
, QERR_INVALID_OPTION_GROUP
, group
);
654 QemuOptsList
*qemu_find_opts(const char *group
)
657 Error
*local_err
= NULL
;
659 ret
= find_list(vm_config_groups
, group
, &local_err
);
660 if (error_is_set(&local_err
)) {
661 error_report("%s\n", error_get_pretty(local_err
));
662 error_free(local_err
);
668 QemuOptsList
*qemu_find_opts_err(const char *group
, Error
**errp
)
670 return find_list(vm_config_groups
, group
, errp
);
673 void qemu_add_opts(QemuOptsList
*list
)
677 entries
= ARRAY_SIZE(vm_config_groups
);
678 entries
--; /* keep list NULL terminated */
679 for (i
= 0; i
< entries
; i
++) {
680 if (vm_config_groups
[i
] == NULL
) {
681 vm_config_groups
[i
] = list
;
685 fprintf(stderr
, "ran out of space in vm_config_groups");
689 int qemu_set_option(const char *str
)
691 char group
[64], id
[64], arg
[64];
696 rc
= sscanf(str
, "%63[^.].%63[^.].%63[^=]%n", group
, id
, arg
, &offset
);
697 if (rc
< 3 || str
[offset
] != '=') {
698 error_report("can't parse: \"%s\"", str
);
702 list
= qemu_find_opts(group
);
707 opts
= qemu_opts_find(list
, id
);
709 error_report("there is no %s \"%s\" defined",
714 if (qemu_opt_set(opts
, arg
, str
+offset
+1) == -1) {
720 int qemu_global_option(const char *str
)
722 char driver
[64], property
[64];
726 rc
= sscanf(str
, "%63[^.].%63[^=]%n", driver
, property
, &offset
);
727 if (rc
< 2 || str
[offset
] != '=') {
728 error_report("can't parse: \"%s\"", str
);
732 opts
= qemu_opts_create(&qemu_global_opts
, NULL
, 0, NULL
);
733 qemu_opt_set(opts
, "driver", driver
);
734 qemu_opt_set(opts
, "property", property
);
735 qemu_opt_set(opts
, "value", str
+offset
+1);
739 struct ConfigWriteData
{
744 static int config_write_opt(const char *name
, const char *value
, void *opaque
)
746 struct ConfigWriteData
*data
= opaque
;
748 fprintf(data
->fp
, " %s = \"%s\"\n", name
, value
);
752 static int config_write_opts(QemuOpts
*opts
, void *opaque
)
754 struct ConfigWriteData
*data
= opaque
;
755 const char *id
= qemu_opts_id(opts
);
758 fprintf(data
->fp
, "[%s \"%s\"]\n", data
->list
->name
, id
);
760 fprintf(data
->fp
, "[%s]\n", data
->list
->name
);
762 qemu_opt_foreach(opts
, config_write_opt
, data
, 0);
763 fprintf(data
->fp
, "\n");
767 void qemu_config_write(FILE *fp
)
769 struct ConfigWriteData data
= { .fp
= fp
};
770 QemuOptsList
**lists
= vm_config_groups
;
773 fprintf(fp
, "# qemu config file\n\n");
774 for (i
= 0; lists
[i
] != NULL
; i
++) {
775 data
.list
= lists
[i
];
776 qemu_opts_foreach(data
.list
, config_write_opts
, &data
, 0);
780 int qemu_config_parse(FILE *fp
, QemuOptsList
**lists
, const char *fname
)
782 char line
[1024], group
[64], id
[64], arg
[64], value
[1024];
784 QemuOptsList
*list
= NULL
;
785 Error
*local_err
= NULL
;
786 QemuOpts
*opts
= NULL
;
787 int res
= -1, lno
= 0;
790 while (fgets(line
, sizeof(line
), fp
) != NULL
) {
791 loc_set_file(fname
, ++lno
);
792 if (line
[0] == '\n') {
793 /* skip empty lines */
796 if (line
[0] == '#') {
800 if (sscanf(line
, "[%63s \"%63[^\"]\"]", group
, id
) == 2) {
802 list
= find_list(lists
, group
, &local_err
);
803 if (error_is_set(&local_err
)) {
804 error_report("%s\n", error_get_pretty(local_err
));
805 error_free(local_err
);
808 opts
= qemu_opts_create(list
, id
, 1, NULL
);
811 if (sscanf(line
, "[%63[^]]]", group
) == 1) {
812 /* group without id */
813 list
= find_list(lists
, group
, &local_err
);
814 if (error_is_set(&local_err
)) {
815 error_report("%s\n", error_get_pretty(local_err
));
816 error_free(local_err
);
819 opts
= qemu_opts_create(list
, NULL
, 0, NULL
);
822 if (sscanf(line
, " %63s = \"%1023[^\"]\"", arg
, value
) == 2) {
825 error_report("no group defined");
828 if (qemu_opt_set(opts
, arg
, value
) != 0) {
833 error_report("parse error");
837 error_report("error reading file");
846 int qemu_read_config_file(const char *filename
)
848 FILE *f
= fopen(filename
, "r");
855 ret
= qemu_config_parse(f
, vm_config_groups
, filename
);