]>
Commit | Line | Data |
---|---|---|
7282a033 GH |
1 | #include "qemu-common.h" |
2 | #include "qemu-option.h" | |
3 | #include "qemu-config.h" | |
4 | ||
5 | QemuOptsList qemu_drive_opts = { | |
6 | .name = "drive", | |
7 | .head = TAILQ_HEAD_INITIALIZER(qemu_drive_opts.head), | |
8 | .desc = { | |
9 | { | |
10 | .name = "bus", | |
11 | .type = QEMU_OPT_NUMBER, | |
12 | .help = "bus number", | |
13 | },{ | |
14 | .name = "unit", | |
15 | .type = QEMU_OPT_NUMBER, | |
16 | .help = "unit number (i.e. lun for scsi)", | |
17 | },{ | |
18 | .name = "if", | |
19 | .type = QEMU_OPT_STRING, | |
20 | .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)", | |
21 | },{ | |
22 | .name = "index", | |
23 | .type = QEMU_OPT_NUMBER, | |
24 | },{ | |
25 | .name = "cyls", | |
26 | .type = QEMU_OPT_NUMBER, | |
27 | .help = "number of cylinders (ide disk geometry)", | |
28 | },{ | |
29 | .name = "heads", | |
30 | .type = QEMU_OPT_NUMBER, | |
31 | .help = "number of heads (ide disk geometry)", | |
32 | },{ | |
33 | .name = "secs", | |
34 | .type = QEMU_OPT_NUMBER, | |
35 | .help = "number of sectors (ide disk geometry)", | |
36 | },{ | |
37 | .name = "trans", | |
38 | .type = QEMU_OPT_STRING, | |
39 | .help = "chs translation (auto, lba. none)", | |
40 | },{ | |
41 | .name = "media", | |
42 | .type = QEMU_OPT_STRING, | |
43 | .help = "media type (disk, cdrom)", | |
44 | },{ | |
45 | .name = "snapshot", | |
46 | .type = QEMU_OPT_BOOL, | |
47 | },{ | |
48 | .name = "file", | |
49 | .type = QEMU_OPT_STRING, | |
50 | .help = "disk image", | |
51 | },{ | |
52 | .name = "cache", | |
53 | .type = QEMU_OPT_STRING, | |
54 | .help = "host cache usage (none, writeback, writethrough)", | |
5c6c3a6c CH |
55 | },{ |
56 | .name = "aio", | |
57 | .type = QEMU_OPT_STRING, | |
58 | .help = "host AIO implementation (threads, native)", | |
7282a033 GH |
59 | },{ |
60 | .name = "format", | |
61 | .type = QEMU_OPT_STRING, | |
62 | .help = "disk format (raw, qcow2, ...)", | |
63 | },{ | |
64 | .name = "serial", | |
65 | .type = QEMU_OPT_STRING, | |
66 | },{ | |
67 | .name = "werror", | |
68 | .type = QEMU_OPT_STRING, | |
69 | },{ | |
70 | .name = "addr", | |
71 | .type = QEMU_OPT_STRING, | |
72 | .help = "pci address (virtio only)", | |
73 | }, | |
74 | { /* end if list */ } | |
75 | }, | |
76 | }; | |
77 | ||
191bc01b GH |
78 | QemuOptsList qemu_chardev_opts = { |
79 | .name = "chardev", | |
80 | .head = TAILQ_HEAD_INITIALIZER(qemu_chardev_opts.head), | |
81 | .desc = { | |
7d31544f GH |
82 | { |
83 | .name = "backend", | |
84 | .type = QEMU_OPT_STRING, | |
85 | },{ | |
86 | .name = "path", | |
87 | .type = QEMU_OPT_STRING, | |
aeb2c47a GH |
88 | },{ |
89 | .name = "host", | |
90 | .type = QEMU_OPT_STRING, | |
91 | },{ | |
92 | .name = "port", | |
93 | .type = QEMU_OPT_STRING, | |
94 | },{ | |
95 | .name = "to", | |
96 | .type = QEMU_OPT_NUMBER, | |
97 | },{ | |
98 | .name = "ipv4", | |
99 | .type = QEMU_OPT_BOOL, | |
100 | },{ | |
101 | .name = "ipv6", | |
102 | .type = QEMU_OPT_BOOL, | |
103 | },{ | |
104 | .name = "wait", | |
105 | .type = QEMU_OPT_BOOL, | |
106 | },{ | |
107 | .name = "server", | |
108 | .type = QEMU_OPT_BOOL, | |
109 | },{ | |
110 | .name = "delay", | |
111 | .type = QEMU_OPT_BOOL, | |
112 | },{ | |
113 | .name = "telnet", | |
114 | .type = QEMU_OPT_BOOL, | |
7d31544f | 115 | }, |
191bc01b GH |
116 | { /* end if list */ } |
117 | }, | |
118 | }; | |
119 | ||
f31d07d1 GH |
120 | QemuOptsList qemu_device_opts = { |
121 | .name = "device", | |
122 | .head = TAILQ_HEAD_INITIALIZER(qemu_device_opts.head), | |
123 | .desc = { | |
124 | /* | |
125 | * no elements => accept any | |
126 | * sanity checking will happen later | |
127 | * when setting device properties | |
128 | */ | |
129 | { /* end if list */ } | |
130 | }, | |
131 | }; | |
132 | ||
d058fe03 GH |
133 | static QemuOptsList *lists[] = { |
134 | &qemu_drive_opts, | |
191bc01b | 135 | &qemu_chardev_opts, |
f31d07d1 | 136 | &qemu_device_opts, |
d058fe03 GH |
137 | NULL, |
138 | }; | |
139 | ||
140 | int qemu_set_option(const char *str) | |
141 | { | |
142 | char group[64], id[64], arg[64]; | |
143 | QemuOpts *opts; | |
144 | int i, rc, offset; | |
145 | ||
146 | rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset); | |
147 | if (rc < 3 || str[offset] != '=') { | |
148 | fprintf(stderr, "can't parse: \"%s\"\n", str); | |
149 | return -1; | |
150 | } | |
151 | ||
152 | for (i = 0; lists[i] != NULL; i++) { | |
153 | if (strcmp(lists[i]->name, group) == 0) | |
154 | break; | |
155 | } | |
156 | if (lists[i] == NULL) { | |
157 | fprintf(stderr, "there is no option group \"%s\"\n", group); | |
158 | return -1; | |
159 | } | |
160 | ||
161 | opts = qemu_opts_find(lists[i], id); | |
162 | if (!opts) { | |
163 | fprintf(stderr, "there is no %s \"%s\" defined\n", | |
164 | lists[i]->name, id); | |
165 | return -1; | |
166 | } | |
167 | ||
168 | if (-1 == qemu_opt_set(opts, arg, str+offset+1)) { | |
169 | fprintf(stderr, "failed to set \"%s\" for %s \"%s\"\n", | |
170 | arg, lists[i]->name, id); | |
171 | return -1; | |
172 | } | |
173 | return 0; | |
174 | } | |
175 |