usb: Halt ep queue en cancel pending packets on a packet error
[qemu/agraf.git] / qemu-config.c
blobc05ffbc444ed50abaf69b343efb3d790b9757fa7
1 #include "qemu-common.h"
2 #include "qemu-error.h"
3 #include "qemu-option.h"
4 #include "qemu-config.h"
5 #include "hw/qdev.h"
6 #include "error.h"
8 static QemuOptsList qemu_drive_opts = {
9 .name = "drive",
10 .head = QTAILQ_HEAD_INITIALIZER(qemu_drive_opts.head),
11 .desc = {
13 .name = "bus",
14 .type = QEMU_OPT_NUMBER,
15 .help = "bus number",
16 },{
17 .name = "unit",
18 .type = QEMU_OPT_NUMBER,
19 .help = "unit number (i.e. lun for scsi)",
20 },{
21 .name = "if",
22 .type = QEMU_OPT_STRING,
23 .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)",
24 },{
25 .name = "index",
26 .type = QEMU_OPT_NUMBER,
27 .help = "index number",
28 },{
29 .name = "cyls",
30 .type = QEMU_OPT_NUMBER,
31 .help = "number of cylinders (ide disk geometry)",
32 },{
33 .name = "heads",
34 .type = QEMU_OPT_NUMBER,
35 .help = "number of heads (ide disk geometry)",
36 },{
37 .name = "secs",
38 .type = QEMU_OPT_NUMBER,
39 .help = "number of sectors (ide disk geometry)",
40 },{
41 .name = "trans",
42 .type = QEMU_OPT_STRING,
43 .help = "chs translation (auto, lba. none)",
44 },{
45 .name = "media",
46 .type = QEMU_OPT_STRING,
47 .help = "media type (disk, cdrom)",
48 },{
49 .name = "snapshot",
50 .type = QEMU_OPT_BOOL,
51 .help = "enable/disable snapshot mode",
52 },{
53 .name = "file",
54 .type = QEMU_OPT_STRING,
55 .help = "disk image",
56 },{
57 .name = "cache",
58 .type = QEMU_OPT_STRING,
59 .help = "host cache usage (none, writeback, writethrough, "
60 "directsync, unsafe)",
61 },{
62 .name = "aio",
63 .type = QEMU_OPT_STRING,
64 .help = "host AIO implementation (threads, native)",
65 },{
66 .name = "format",
67 .type = QEMU_OPT_STRING,
68 .help = "disk format (raw, qcow2, ...)",
69 },{
70 .name = "serial",
71 .type = QEMU_OPT_STRING,
72 .help = "disk serial number",
73 },{
74 .name = "rerror",
75 .type = QEMU_OPT_STRING,
76 .help = "read error action",
77 },{
78 .name = "werror",
79 .type = QEMU_OPT_STRING,
80 .help = "write error action",
81 },{
82 .name = "addr",
83 .type = QEMU_OPT_STRING,
84 .help = "pci address (virtio only)",
85 },{
86 .name = "readonly",
87 .type = QEMU_OPT_BOOL,
88 .help = "open drive file as read-only",
89 },{
90 .name = "iops",
91 .type = QEMU_OPT_NUMBER,
92 .help = "limit total I/O operations per second",
93 },{
94 .name = "iops_rd",
95 .type = QEMU_OPT_NUMBER,
96 .help = "limit read operations per second",
97 },{
98 .name = "iops_wr",
99 .type = QEMU_OPT_NUMBER,
100 .help = "limit write operations per second",
102 .name = "bps",
103 .type = QEMU_OPT_NUMBER,
104 .help = "limit total bytes per second",
106 .name = "bps_rd",
107 .type = QEMU_OPT_NUMBER,
108 .help = "limit read bytes per second",
110 .name = "bps_wr",
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 = {
123 .name = "iscsi",
124 .head = QTAILQ_HEAD_INITIALIZER(qemu_iscsi_opts.head),
125 .desc = {
127 .name = "user",
128 .type = QEMU_OPT_STRING,
129 .help = "username for CHAP authentication to target",
131 .name = "password",
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 = {
149 .name = "chardev",
150 .implied_opt_name = "backend",
151 .head = QTAILQ_HEAD_INITIALIZER(qemu_chardev_opts.head),
152 .desc = {
154 .name = "backend",
155 .type = QEMU_OPT_STRING,
157 .name = "path",
158 .type = QEMU_OPT_STRING,
160 .name = "host",
161 .type = QEMU_OPT_STRING,
163 .name = "port",
164 .type = QEMU_OPT_STRING,
166 .name = "localaddr",
167 .type = QEMU_OPT_STRING,
169 .name = "localport",
170 .type = QEMU_OPT_STRING,
172 .name = "to",
173 .type = QEMU_OPT_NUMBER,
175 .name = "ipv4",
176 .type = QEMU_OPT_BOOL,
178 .name = "ipv6",
179 .type = QEMU_OPT_BOOL,
181 .name = "wait",
182 .type = QEMU_OPT_BOOL,
184 .name = "server",
185 .type = QEMU_OPT_BOOL,
187 .name = "delay",
188 .type = QEMU_OPT_BOOL,
190 .name = "telnet",
191 .type = QEMU_OPT_BOOL,
193 .name = "width",
194 .type = QEMU_OPT_NUMBER,
196 .name = "height",
197 .type = QEMU_OPT_NUMBER,
199 .name = "cols",
200 .type = QEMU_OPT_NUMBER,
202 .name = "rows",
203 .type = QEMU_OPT_NUMBER,
205 .name = "mux",
206 .type = QEMU_OPT_BOOL,
208 .name = "signal",
209 .type = QEMU_OPT_BOOL,
211 .name = "name",
212 .type = QEMU_OPT_STRING,
214 .name = "debug",
215 .type = QEMU_OPT_NUMBER,
217 { /* end of list */ }
221 QemuOptsList qemu_fsdev_opts = {
222 .name = "fsdev",
223 .implied_opt_name = "fsdriver",
224 .head = QTAILQ_HEAD_INITIALIZER(qemu_fsdev_opts.head),
225 .desc = {
227 .name = "fsdriver",
228 .type = QEMU_OPT_STRING,
229 }, {
230 .name = "path",
231 .type = QEMU_OPT_STRING,
232 }, {
233 .name = "security_model",
234 .type = QEMU_OPT_STRING,
235 }, {
236 .name = "writeout",
237 .type = QEMU_OPT_STRING,
238 }, {
239 .name = "readonly",
240 .type = QEMU_OPT_BOOL,
242 }, {
243 .name = "socket",
244 .type = QEMU_OPT_STRING,
245 }, {
246 .name = "sock_fd",
247 .type = QEMU_OPT_NUMBER,
250 { /*End of list */ }
254 QemuOptsList qemu_virtfs_opts = {
255 .name = "virtfs",
256 .implied_opt_name = "fsdriver",
257 .head = QTAILQ_HEAD_INITIALIZER(qemu_virtfs_opts.head),
258 .desc = {
260 .name = "fsdriver",
261 .type = QEMU_OPT_STRING,
262 }, {
263 .name = "path",
264 .type = QEMU_OPT_STRING,
265 }, {
266 .name = "mount_tag",
267 .type = QEMU_OPT_STRING,
268 }, {
269 .name = "security_model",
270 .type = QEMU_OPT_STRING,
271 }, {
272 .name = "writeout",
273 .type = QEMU_OPT_STRING,
274 }, {
275 .name = "readonly",
276 .type = QEMU_OPT_BOOL,
277 }, {
278 .name = "socket",
279 .type = QEMU_OPT_STRING,
280 }, {
281 .name = "sock_fd",
282 .type = QEMU_OPT_NUMBER,
285 { /*End of list */ }
289 static QemuOptsList qemu_device_opts = {
290 .name = "device",
291 .implied_opt_name = "driver",
292 .head = QTAILQ_HEAD_INITIALIZER(qemu_device_opts.head),
293 .desc = {
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 = {
304 .name = "netdev",
305 .implied_opt_name = "type",
306 .head = QTAILQ_HEAD_INITIALIZER(qemu_netdev_opts.head),
307 .desc = {
309 * no elements => accept any params
310 * validation will happen later
312 { /* end of list */ }
316 static QemuOptsList qemu_net_opts = {
317 .name = "net",
318 .implied_opt_name = "type",
319 .head = QTAILQ_HEAD_INITIALIZER(qemu_net_opts.head),
320 .desc = {
322 * no elements => accept any params
323 * validation will happen later
325 { /* end of list */ }
329 static QemuOptsList qemu_rtc_opts = {
330 .name = "rtc",
331 .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head),
332 .desc = {
334 .name = "base",
335 .type = QEMU_OPT_STRING,
337 .name = "clock",
338 .type = QEMU_OPT_STRING,
340 .name = "driftfix",
341 .type = QEMU_OPT_STRING,
343 { /* end of list */ }
347 static QemuOptsList qemu_global_opts = {
348 .name = "global",
349 .head = QTAILQ_HEAD_INITIALIZER(qemu_global_opts.head),
350 .desc = {
352 .name = "driver",
353 .type = QEMU_OPT_STRING,
355 .name = "property",
356 .type = QEMU_OPT_STRING,
358 .name = "value",
359 .type = QEMU_OPT_STRING,
361 { /* end of list */ }
365 QemuOptsList qemu_sandbox_opts = {
366 .name = "sandbox",
367 .implied_opt_name = "enable",
368 .head = QTAILQ_HEAD_INITIALIZER(qemu_sandbox_opts.head),
369 .desc = {
371 .name = "enable",
372 .type = QEMU_OPT_BOOL,
374 { /* end of list */ }
378 static QemuOptsList qemu_mon_opts = {
379 .name = "mon",
380 .implied_opt_name = "chardev",
381 .head = QTAILQ_HEAD_INITIALIZER(qemu_mon_opts.head),
382 .desc = {
384 .name = "mode",
385 .type = QEMU_OPT_STRING,
387 .name = "chardev",
388 .type = QEMU_OPT_STRING,
390 .name = "default",
391 .type = QEMU_OPT_BOOL,
393 .name = "pretty",
394 .type = QEMU_OPT_BOOL,
396 { /* end of list */ }
400 static QemuOptsList qemu_trace_opts = {
401 .name = "trace",
402 .implied_opt_name = "trace",
403 .head = QTAILQ_HEAD_INITIALIZER(qemu_trace_opts.head),
404 .desc = {
406 .name = "events",
407 .type = QEMU_OPT_STRING,
409 .name = "file",
410 .type = QEMU_OPT_STRING,
412 { /* end of list */ }
416 static QemuOptsList qemu_cpudef_opts = {
417 .name = "cpudef",
418 .head = QTAILQ_HEAD_INITIALIZER(qemu_cpudef_opts.head),
419 .desc = {
421 .name = "name",
422 .type = QEMU_OPT_STRING,
424 .name = "level",
425 .type = QEMU_OPT_NUMBER,
427 .name = "vendor",
428 .type = QEMU_OPT_STRING,
430 .name = "family",
431 .type = QEMU_OPT_NUMBER,
433 .name = "model",
434 .type = QEMU_OPT_NUMBER,
436 .name = "stepping",
437 .type = QEMU_OPT_NUMBER,
439 .name = "feature_edx", /* cpuid 0000_0001.edx */
440 .type = QEMU_OPT_STRING,
442 .name = "feature_ecx", /* cpuid 0000_0001.ecx */
443 .type = QEMU_OPT_STRING,
445 .name = "extfeature_edx", /* cpuid 8000_0001.edx */
446 .type = QEMU_OPT_STRING,
448 .name = "extfeature_ecx", /* cpuid 8000_0001.ecx */
449 .type = QEMU_OPT_STRING,
451 .name = "xlevel",
452 .type = QEMU_OPT_NUMBER,
454 .name = "model_id",
455 .type = QEMU_OPT_STRING,
457 .name = "vendor_override",
458 .type = QEMU_OPT_NUMBER,
460 { /* end of list */ }
464 QemuOptsList qemu_spice_opts = {
465 .name = "spice",
466 .head = QTAILQ_HEAD_INITIALIZER(qemu_spice_opts.head),
467 .desc = {
469 .name = "port",
470 .type = QEMU_OPT_NUMBER,
472 .name = "tls-port",
473 .type = QEMU_OPT_NUMBER,
475 .name = "addr",
476 .type = QEMU_OPT_STRING,
478 .name = "ipv4",
479 .type = QEMU_OPT_BOOL,
481 .name = "ipv6",
482 .type = QEMU_OPT_BOOL,
484 .name = "password",
485 .type = QEMU_OPT_STRING,
487 .name = "disable-ticketing",
488 .type = QEMU_OPT_BOOL,
490 .name = "disable-copy-paste",
491 .type = QEMU_OPT_BOOL,
493 .name = "sasl",
494 .type = QEMU_OPT_BOOL,
496 .name = "x509-dir",
497 .type = QEMU_OPT_STRING,
499 .name = "x509-key-file",
500 .type = QEMU_OPT_STRING,
502 .name = "x509-key-password",
503 .type = QEMU_OPT_STRING,
505 .name = "x509-cert-file",
506 .type = QEMU_OPT_STRING,
508 .name = "x509-cacert-file",
509 .type = QEMU_OPT_STRING,
511 .name = "x509-dh-key-file",
512 .type = QEMU_OPT_STRING,
514 .name = "tls-ciphers",
515 .type = QEMU_OPT_STRING,
517 .name = "tls-channel",
518 .type = QEMU_OPT_STRING,
520 .name = "plaintext-channel",
521 .type = QEMU_OPT_STRING,
523 .name = "image-compression",
524 .type = QEMU_OPT_STRING,
526 .name = "jpeg-wan-compression",
527 .type = QEMU_OPT_STRING,
529 .name = "zlib-glz-wan-compression",
530 .type = QEMU_OPT_STRING,
532 .name = "streaming-video",
533 .type = QEMU_OPT_STRING,
535 .name = "agent-mouse",
536 .type = QEMU_OPT_BOOL,
538 .name = "playback-compression",
539 .type = QEMU_OPT_BOOL,
541 { /* end of list */ }
545 QemuOptsList qemu_option_rom_opts = {
546 .name = "option-rom",
547 .implied_opt_name = "romfile",
548 .head = QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts.head),
549 .desc = {
551 .name = "bootindex",
552 .type = QEMU_OPT_NUMBER,
553 }, {
554 .name = "romfile",
555 .type = QEMU_OPT_STRING,
557 { /* end of list */ }
561 static QemuOptsList qemu_machine_opts = {
562 .name = "machine",
563 .implied_opt_name = "type",
564 .merge_lists = true,
565 .head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head),
566 .desc = {
568 .name = "type",
569 .type = QEMU_OPT_STRING,
570 .help = "emulated machine"
571 }, {
572 .name = "accel",
573 .type = QEMU_OPT_STRING,
574 .help = "accelerator list",
575 }, {
576 .name = "kernel_irqchip",
577 .type = QEMU_OPT_BOOL,
578 .help = "use KVM in-kernel irqchip",
579 }, {
580 .name = "kvm_shadow_mem",
581 .type = QEMU_OPT_SIZE,
582 .help = "KVM shadow MMU size",
583 }, {
584 .name = "kernel",
585 .type = QEMU_OPT_STRING,
586 .help = "Linux kernel image file",
587 }, {
588 .name = "initrd",
589 .type = QEMU_OPT_STRING,
590 .help = "Linux initial ramdisk file",
591 }, {
592 .name = "append",
593 .type = QEMU_OPT_STRING,
594 .help = "Linux kernel command line",
595 }, {
596 .name = "dtb",
597 .type = QEMU_OPT_STRING,
598 .help = "Linux kernel device tree file",
599 }, {
600 .name = "dumpdtb",
601 .type = QEMU_OPT_STRING,
602 .help = "Dump current dtb to a file and quit",
603 }, {
604 .name = "phandle_start",
605 .type = QEMU_OPT_STRING,
606 .help = "The first phandle ID we may generate dynamically",
607 }, {
608 .name = "dt_compatible",
609 .type = QEMU_OPT_STRING,
610 .help = "Overrides the \"compatible\" property of the dt root node",
611 }, {
612 .name = "dump-guest-core",
613 .type = QEMU_OPT_BOOL,
614 .help = "Include guest memory in a core dump",
616 { /* End of list */ }
620 QemuOptsList qemu_boot_opts = {
621 .name = "boot-opts",
622 .head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head),
623 .desc = {
624 /* the three names below are not used now */
626 .name = "order",
627 .type = QEMU_OPT_STRING,
628 }, {
629 .name = "once",
630 .type = QEMU_OPT_STRING,
631 }, {
632 .name = "menu",
633 .type = QEMU_OPT_STRING,
634 /* following are really used */
635 }, {
636 .name = "splash",
637 .type = QEMU_OPT_STRING,
638 }, {
639 .name = "splash-time",
640 .type = QEMU_OPT_STRING,
642 { /*End of list */ }
646 static QemuOptsList *vm_config_groups[32] = {
647 &qemu_drive_opts,
648 &qemu_chardev_opts,
649 &qemu_device_opts,
650 &qemu_netdev_opts,
651 &qemu_net_opts,
652 &qemu_rtc_opts,
653 &qemu_global_opts,
654 &qemu_mon_opts,
655 &qemu_cpudef_opts,
656 &qemu_trace_opts,
657 &qemu_option_rom_opts,
658 &qemu_machine_opts,
659 &qemu_boot_opts,
660 &qemu_iscsi_opts,
661 &qemu_sandbox_opts,
662 NULL,
665 static QemuOptsList *find_list(QemuOptsList **lists, const char *group,
666 Error **errp)
668 int i;
670 for (i = 0; lists[i] != NULL; i++) {
671 if (strcmp(lists[i]->name, group) == 0)
672 break;
674 if (lists[i] == NULL) {
675 error_set(errp, QERR_INVALID_OPTION_GROUP, group);
677 return lists[i];
680 QemuOptsList *qemu_find_opts(const char *group)
682 QemuOptsList *ret;
683 Error *local_err = NULL;
685 ret = find_list(vm_config_groups, group, &local_err);
686 if (error_is_set(&local_err)) {
687 error_report("%s\n", error_get_pretty(local_err));
688 error_free(local_err);
691 return ret;
694 QemuOptsList *qemu_find_opts_err(const char *group, Error **errp)
696 return find_list(vm_config_groups, group, errp);
699 void qemu_add_opts(QemuOptsList *list)
701 int entries, i;
703 entries = ARRAY_SIZE(vm_config_groups);
704 entries--; /* keep list NULL terminated */
705 for (i = 0; i < entries; i++) {
706 if (vm_config_groups[i] == NULL) {
707 vm_config_groups[i] = list;
708 return;
711 fprintf(stderr, "ran out of space in vm_config_groups");
712 abort();
715 int qemu_set_option(const char *str)
717 char group[64], id[64], arg[64];
718 QemuOptsList *list;
719 QemuOpts *opts;
720 int rc, offset;
722 rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset);
723 if (rc < 3 || str[offset] != '=') {
724 error_report("can't parse: \"%s\"", str);
725 return -1;
728 list = qemu_find_opts(group);
729 if (list == NULL) {
730 return -1;
733 opts = qemu_opts_find(list, id);
734 if (!opts) {
735 error_report("there is no %s \"%s\" defined",
736 list->name, id);
737 return -1;
740 if (qemu_opt_set(opts, arg, str+offset+1) == -1) {
741 return -1;
743 return 0;
746 int qemu_global_option(const char *str)
748 char driver[64], property[64];
749 QemuOpts *opts;
750 int rc, offset;
752 rc = sscanf(str, "%63[^.].%63[^=]%n", driver, property, &offset);
753 if (rc < 2 || str[offset] != '=') {
754 error_report("can't parse: \"%s\"", str);
755 return -1;
758 opts = qemu_opts_create(&qemu_global_opts, NULL, 0, NULL);
759 qemu_opt_set(opts, "driver", driver);
760 qemu_opt_set(opts, "property", property);
761 qemu_opt_set(opts, "value", str+offset+1);
762 return 0;
765 struct ConfigWriteData {
766 QemuOptsList *list;
767 FILE *fp;
770 static int config_write_opt(const char *name, const char *value, void *opaque)
772 struct ConfigWriteData *data = opaque;
774 fprintf(data->fp, " %s = \"%s\"\n", name, value);
775 return 0;
778 static int config_write_opts(QemuOpts *opts, void *opaque)
780 struct ConfigWriteData *data = opaque;
781 const char *id = qemu_opts_id(opts);
783 if (id) {
784 fprintf(data->fp, "[%s \"%s\"]\n", data->list->name, id);
785 } else {
786 fprintf(data->fp, "[%s]\n", data->list->name);
788 qemu_opt_foreach(opts, config_write_opt, data, 0);
789 fprintf(data->fp, "\n");
790 return 0;
793 void qemu_config_write(FILE *fp)
795 struct ConfigWriteData data = { .fp = fp };
796 QemuOptsList **lists = vm_config_groups;
797 int i;
799 fprintf(fp, "# qemu config file\n\n");
800 for (i = 0; lists[i] != NULL; i++) {
801 data.list = lists[i];
802 qemu_opts_foreach(data.list, config_write_opts, &data, 0);
806 int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname)
808 char line[1024], group[64], id[64], arg[64], value[1024];
809 Location loc;
810 QemuOptsList *list = NULL;
811 Error *local_err = NULL;
812 QemuOpts *opts = NULL;
813 int res = -1, lno = 0;
815 loc_push_none(&loc);
816 while (fgets(line, sizeof(line), fp) != NULL) {
817 loc_set_file(fname, ++lno);
818 if (line[0] == '\n') {
819 /* skip empty lines */
820 continue;
822 if (line[0] == '#') {
823 /* comment */
824 continue;
826 if (sscanf(line, "[%63s \"%63[^\"]\"]", group, id) == 2) {
827 /* group with id */
828 list = find_list(lists, group, &local_err);
829 if (error_is_set(&local_err)) {
830 error_report("%s\n", error_get_pretty(local_err));
831 error_free(local_err);
832 goto out;
834 opts = qemu_opts_create(list, id, 1, NULL);
835 continue;
837 if (sscanf(line, "[%63[^]]]", group) == 1) {
838 /* group without id */
839 list = find_list(lists, group, &local_err);
840 if (error_is_set(&local_err)) {
841 error_report("%s\n", error_get_pretty(local_err));
842 error_free(local_err);
843 goto out;
845 opts = qemu_opts_create(list, NULL, 0, NULL);
846 continue;
848 if (sscanf(line, " %63s = \"%1023[^\"]\"", arg, value) == 2) {
849 /* arg = value */
850 if (opts == NULL) {
851 error_report("no group defined");
852 goto out;
854 if (qemu_opt_set(opts, arg, value) != 0) {
855 goto out;
857 continue;
859 error_report("parse error");
860 goto out;
862 if (ferror(fp)) {
863 error_report("error reading file");
864 goto out;
866 res = 0;
867 out:
868 loc_pop(&loc);
869 return res;
872 int qemu_read_config_file(const char *filename)
874 FILE *f = fopen(filename, "r");
875 int ret;
877 if (f == NULL) {
878 return -errno;
881 ret = qemu_config_parse(f, vm_config_groups, filename);
882 fclose(f);
884 if (ret == 0) {
885 return 0;
886 } else {
887 return -EINVAL;