root / qemu-config.c @ 77047bb7
History | View | Annotate | Download (10.6 kB)
1 | 7282a033 | Gerd Hoffmann | #include "qemu-common.h" |
---|---|---|---|
2 | 7282a033 | Gerd Hoffmann | #include "qemu-option.h" |
3 | 7282a033 | Gerd Hoffmann | #include "qemu-config.h" |
4 | a861c453 | Gerd Hoffmann | #include "sysemu.h" |
5 | d0fef6fb | Gerd Hoffmann | #include "hw/qdev.h" |
6 | 7282a033 | Gerd Hoffmann | |
7 | 7282a033 | Gerd Hoffmann | QemuOptsList qemu_drive_opts = { |
8 | 7282a033 | Gerd Hoffmann | .name = "drive",
|
9 | 72cf2d4f | Blue Swirl | .head = QTAILQ_HEAD_INITIALIZER(qemu_drive_opts.head), |
10 | 7282a033 | Gerd Hoffmann | .desc = { |
11 | 7282a033 | Gerd Hoffmann | { |
12 | 7282a033 | Gerd Hoffmann | .name = "bus",
|
13 | 7282a033 | Gerd Hoffmann | .type = QEMU_OPT_NUMBER, |
14 | 7282a033 | Gerd Hoffmann | .help = "bus number",
|
15 | 7282a033 | Gerd Hoffmann | },{ |
16 | 7282a033 | Gerd Hoffmann | .name = "unit",
|
17 | 7282a033 | Gerd Hoffmann | .type = QEMU_OPT_NUMBER, |
18 | 7282a033 | Gerd Hoffmann | .help = "unit number (i.e. lun for scsi)",
|
19 | 7282a033 | Gerd Hoffmann | },{ |
20 | 7282a033 | Gerd Hoffmann | .name = "if",
|
21 | 7282a033 | Gerd Hoffmann | .type = QEMU_OPT_STRING, |
22 | 7282a033 | Gerd Hoffmann | .help = "interface (ide, scsi, sd, mtd, floppy, pflash, virtio)",
|
23 | 7282a033 | Gerd Hoffmann | },{ |
24 | 7282a033 | Gerd Hoffmann | .name = "index",
|
25 | 7282a033 | Gerd Hoffmann | .type = QEMU_OPT_NUMBER, |
26 | 7282a033 | Gerd Hoffmann | },{ |
27 | 7282a033 | Gerd Hoffmann | .name = "cyls",
|
28 | 7282a033 | Gerd Hoffmann | .type = QEMU_OPT_NUMBER, |
29 | 7282a033 | Gerd Hoffmann | .help = "number of cylinders (ide disk geometry)",
|
30 | 7282a033 | Gerd Hoffmann | },{ |
31 | 7282a033 | Gerd Hoffmann | .name = "heads",
|
32 | 7282a033 | Gerd Hoffmann | .type = QEMU_OPT_NUMBER, |
33 | 7282a033 | Gerd Hoffmann | .help = "number of heads (ide disk geometry)",
|
34 | 7282a033 | Gerd Hoffmann | },{ |
35 | 7282a033 | Gerd Hoffmann | .name = "secs",
|
36 | 7282a033 | Gerd Hoffmann | .type = QEMU_OPT_NUMBER, |
37 | 7282a033 | Gerd Hoffmann | .help = "number of sectors (ide disk geometry)",
|
38 | 7282a033 | Gerd Hoffmann | },{ |
39 | 7282a033 | Gerd Hoffmann | .name = "trans",
|
40 | 7282a033 | Gerd Hoffmann | .type = QEMU_OPT_STRING, |
41 | 7282a033 | Gerd Hoffmann | .help = "chs translation (auto, lba. none)",
|
42 | 7282a033 | Gerd Hoffmann | },{ |
43 | 7282a033 | Gerd Hoffmann | .name = "media",
|
44 | 7282a033 | Gerd Hoffmann | .type = QEMU_OPT_STRING, |
45 | 7282a033 | Gerd Hoffmann | .help = "media type (disk, cdrom)",
|
46 | 7282a033 | Gerd Hoffmann | },{ |
47 | 7282a033 | Gerd Hoffmann | .name = "snapshot",
|
48 | 7282a033 | Gerd Hoffmann | .type = QEMU_OPT_BOOL, |
49 | 7282a033 | Gerd Hoffmann | },{ |
50 | 7282a033 | Gerd Hoffmann | .name = "file",
|
51 | 7282a033 | Gerd Hoffmann | .type = QEMU_OPT_STRING, |
52 | 7282a033 | Gerd Hoffmann | .help = "disk image",
|
53 | 7282a033 | Gerd Hoffmann | },{ |
54 | 7282a033 | Gerd Hoffmann | .name = "cache",
|
55 | 7282a033 | Gerd Hoffmann | .type = QEMU_OPT_STRING, |
56 | 7282a033 | Gerd Hoffmann | .help = "host cache usage (none, writeback, writethrough)",
|
57 | 7282a033 | Gerd Hoffmann | },{ |
58 | 5c6c3a6c | Christoph Hellwig | .name = "aio",
|
59 | 5c6c3a6c | Christoph Hellwig | .type = QEMU_OPT_STRING, |
60 | 5c6c3a6c | Christoph Hellwig | .help = "host AIO implementation (threads, native)",
|
61 | 5c6c3a6c | Christoph Hellwig | },{ |
62 | 7282a033 | Gerd Hoffmann | .name = "format",
|
63 | 7282a033 | Gerd Hoffmann | .type = QEMU_OPT_STRING, |
64 | 7282a033 | Gerd Hoffmann | .help = "disk format (raw, qcow2, ...)",
|
65 | 7282a033 | Gerd Hoffmann | },{ |
66 | 7282a033 | Gerd Hoffmann | .name = "serial",
|
67 | 7282a033 | Gerd Hoffmann | .type = QEMU_OPT_STRING, |
68 | 7282a033 | Gerd Hoffmann | },{ |
69 | e9b2e818 | Kevin Wolf | .name = "rerror",
|
70 | e9b2e818 | Kevin Wolf | .type = QEMU_OPT_STRING, |
71 | e9b2e818 | Kevin Wolf | },{ |
72 | 7282a033 | Gerd Hoffmann | .name = "werror",
|
73 | 7282a033 | Gerd Hoffmann | .type = QEMU_OPT_STRING, |
74 | 7282a033 | Gerd Hoffmann | },{ |
75 | 7282a033 | Gerd Hoffmann | .name = "addr",
|
76 | 7282a033 | Gerd Hoffmann | .type = QEMU_OPT_STRING, |
77 | 7282a033 | Gerd Hoffmann | .help = "pci address (virtio only)",
|
78 | 59f2689d | Naphtali Sprei | },{ |
79 | 59f2689d | Naphtali Sprei | .name = "readonly",
|
80 | 59f2689d | Naphtali Sprei | .type = QEMU_OPT_BOOL, |
81 | 7282a033 | Gerd Hoffmann | }, |
82 | 7282a033 | Gerd Hoffmann | { /* end if list */ }
|
83 | 7282a033 | Gerd Hoffmann | }, |
84 | 7282a033 | Gerd Hoffmann | }; |
85 | 7282a033 | Gerd Hoffmann | |
86 | 191bc01b | Gerd Hoffmann | QemuOptsList qemu_chardev_opts = { |
87 | 191bc01b | Gerd Hoffmann | .name = "chardev",
|
88 | 72cf2d4f | Blue Swirl | .head = QTAILQ_HEAD_INITIALIZER(qemu_chardev_opts.head), |
89 | 191bc01b | Gerd Hoffmann | .desc = { |
90 | 7d31544f | Gerd Hoffmann | { |
91 | 7d31544f | Gerd Hoffmann | .name = "backend",
|
92 | 7d31544f | Gerd Hoffmann | .type = QEMU_OPT_STRING, |
93 | 7d31544f | Gerd Hoffmann | },{ |
94 | 7d31544f | Gerd Hoffmann | .name = "path",
|
95 | 7d31544f | Gerd Hoffmann | .type = QEMU_OPT_STRING, |
96 | aeb2c47a | Gerd Hoffmann | },{ |
97 | aeb2c47a | Gerd Hoffmann | .name = "host",
|
98 | aeb2c47a | Gerd Hoffmann | .type = QEMU_OPT_STRING, |
99 | aeb2c47a | Gerd Hoffmann | },{ |
100 | aeb2c47a | Gerd Hoffmann | .name = "port",
|
101 | aeb2c47a | Gerd Hoffmann | .type = QEMU_OPT_STRING, |
102 | aeb2c47a | Gerd Hoffmann | },{ |
103 | 7e1b35b4 | Gerd Hoffmann | .name = "localaddr",
|
104 | 7e1b35b4 | Gerd Hoffmann | .type = QEMU_OPT_STRING, |
105 | 7e1b35b4 | Gerd Hoffmann | },{ |
106 | 7e1b35b4 | Gerd Hoffmann | .name = "localport",
|
107 | 7e1b35b4 | Gerd Hoffmann | .type = QEMU_OPT_STRING, |
108 | 7e1b35b4 | Gerd Hoffmann | },{ |
109 | aeb2c47a | Gerd Hoffmann | .name = "to",
|
110 | aeb2c47a | Gerd Hoffmann | .type = QEMU_OPT_NUMBER, |
111 | aeb2c47a | Gerd Hoffmann | },{ |
112 | aeb2c47a | Gerd Hoffmann | .name = "ipv4",
|
113 | aeb2c47a | Gerd Hoffmann | .type = QEMU_OPT_BOOL, |
114 | aeb2c47a | Gerd Hoffmann | },{ |
115 | aeb2c47a | Gerd Hoffmann | .name = "ipv6",
|
116 | aeb2c47a | Gerd Hoffmann | .type = QEMU_OPT_BOOL, |
117 | aeb2c47a | Gerd Hoffmann | },{ |
118 | aeb2c47a | Gerd Hoffmann | .name = "wait",
|
119 | aeb2c47a | Gerd Hoffmann | .type = QEMU_OPT_BOOL, |
120 | aeb2c47a | Gerd Hoffmann | },{ |
121 | aeb2c47a | Gerd Hoffmann | .name = "server",
|
122 | aeb2c47a | Gerd Hoffmann | .type = QEMU_OPT_BOOL, |
123 | aeb2c47a | Gerd Hoffmann | },{ |
124 | aeb2c47a | Gerd Hoffmann | .name = "delay",
|
125 | aeb2c47a | Gerd Hoffmann | .type = QEMU_OPT_BOOL, |
126 | aeb2c47a | Gerd Hoffmann | },{ |
127 | aeb2c47a | Gerd Hoffmann | .name = "telnet",
|
128 | aeb2c47a | Gerd Hoffmann | .type = QEMU_OPT_BOOL, |
129 | 6ea314d9 | Gerd Hoffmann | },{ |
130 | 6ea314d9 | Gerd Hoffmann | .name = "width",
|
131 | 6ea314d9 | Gerd Hoffmann | .type = QEMU_OPT_NUMBER, |
132 | 6ea314d9 | Gerd Hoffmann | },{ |
133 | 6ea314d9 | Gerd Hoffmann | .name = "height",
|
134 | 6ea314d9 | Gerd Hoffmann | .type = QEMU_OPT_NUMBER, |
135 | 6ea314d9 | Gerd Hoffmann | },{ |
136 | 6ea314d9 | Gerd Hoffmann | .name = "cols",
|
137 | 6ea314d9 | Gerd Hoffmann | .type = QEMU_OPT_NUMBER, |
138 | 6ea314d9 | Gerd Hoffmann | },{ |
139 | 6ea314d9 | Gerd Hoffmann | .name = "rows",
|
140 | 6ea314d9 | Gerd Hoffmann | .type = QEMU_OPT_NUMBER, |
141 | c845f401 | Gerd Hoffmann | },{ |
142 | c845f401 | Gerd Hoffmann | .name = "mux",
|
143 | c845f401 | Gerd Hoffmann | .type = QEMU_OPT_BOOL, |
144 | 5989020b | Kusanagi Kouichi | },{ |
145 | 5989020b | Kusanagi Kouichi | .name = "signal",
|
146 | 5989020b | Kusanagi Kouichi | .type = QEMU_OPT_BOOL, |
147 | 7d31544f | Gerd Hoffmann | }, |
148 | 191bc01b | Gerd Hoffmann | { /* end if list */ }
|
149 | 191bc01b | Gerd Hoffmann | }, |
150 | 191bc01b | Gerd Hoffmann | }; |
151 | 191bc01b | Gerd Hoffmann | |
152 | f31d07d1 | Gerd Hoffmann | QemuOptsList qemu_device_opts = { |
153 | f31d07d1 | Gerd Hoffmann | .name = "device",
|
154 | 72cf2d4f | Blue Swirl | .head = QTAILQ_HEAD_INITIALIZER(qemu_device_opts.head), |
155 | f31d07d1 | Gerd Hoffmann | .desc = { |
156 | f31d07d1 | Gerd Hoffmann | /*
|
157 | f31d07d1 | Gerd Hoffmann | * no elements => accept any
|
158 | f31d07d1 | Gerd Hoffmann | * sanity checking will happen later
|
159 | f31d07d1 | Gerd Hoffmann | * when setting device properties
|
160 | f31d07d1 | Gerd Hoffmann | */
|
161 | f31d07d1 | Gerd Hoffmann | { /* end if list */ }
|
162 | f31d07d1 | Gerd Hoffmann | }, |
163 | f31d07d1 | Gerd Hoffmann | }; |
164 | f31d07d1 | Gerd Hoffmann | |
165 | a1ea458f | Mark McLoughlin | QemuOptsList qemu_netdev_opts = { |
166 | a1ea458f | Mark McLoughlin | .name = "netdev",
|
167 | a1ea458f | Mark McLoughlin | .head = QTAILQ_HEAD_INITIALIZER(qemu_netdev_opts.head), |
168 | a1ea458f | Mark McLoughlin | .desc = { |
169 | a1ea458f | Mark McLoughlin | /*
|
170 | a1ea458f | Mark McLoughlin | * no elements => accept any params
|
171 | a1ea458f | Mark McLoughlin | * validation will happen later
|
172 | a1ea458f | Mark McLoughlin | */
|
173 | a1ea458f | Mark McLoughlin | { /* end of list */ }
|
174 | a1ea458f | Mark McLoughlin | }, |
175 | a1ea458f | Mark McLoughlin | }; |
176 | a1ea458f | Mark McLoughlin | |
177 | 8119b33d | Mark McLoughlin | QemuOptsList qemu_net_opts = { |
178 | 8119b33d | Mark McLoughlin | .name = "net",
|
179 | 8119b33d | Mark McLoughlin | .head = QTAILQ_HEAD_INITIALIZER(qemu_net_opts.head), |
180 | 8119b33d | Mark McLoughlin | .desc = { |
181 | 8119b33d | Mark McLoughlin | /*
|
182 | 8119b33d | Mark McLoughlin | * no elements => accept any params
|
183 | 8119b33d | Mark McLoughlin | * validation will happen later
|
184 | 8119b33d | Mark McLoughlin | */
|
185 | 8119b33d | Mark McLoughlin | { /* end of list */ }
|
186 | 8119b33d | Mark McLoughlin | }, |
187 | 8119b33d | Mark McLoughlin | }; |
188 | 8119b33d | Mark McLoughlin | |
189 | 1ed2fc1f | Jan Kiszka | QemuOptsList qemu_rtc_opts = { |
190 | 1ed2fc1f | Jan Kiszka | .name = "rtc",
|
191 | 1ed2fc1f | Jan Kiszka | .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head), |
192 | 1ed2fc1f | Jan Kiszka | .desc = { |
193 | 1ed2fc1f | Jan Kiszka | { |
194 | 1ed2fc1f | Jan Kiszka | .name = "base",
|
195 | 1ed2fc1f | Jan Kiszka | .type = QEMU_OPT_STRING, |
196 | 6875204c | Jan Kiszka | },{ |
197 | 6875204c | Jan Kiszka | .name = "clock",
|
198 | 6875204c | Jan Kiszka | .type = QEMU_OPT_STRING, |
199 | 1ed2fc1f | Jan Kiszka | #ifdef TARGET_I386
|
200 | 1ed2fc1f | Jan Kiszka | },{ |
201 | 1ed2fc1f | Jan Kiszka | .name = "driftfix",
|
202 | 1ed2fc1f | Jan Kiszka | .type = QEMU_OPT_STRING, |
203 | 1ed2fc1f | Jan Kiszka | #endif
|
204 | 1ed2fc1f | Jan Kiszka | }, |
205 | 1ed2fc1f | Jan Kiszka | { /* end if list */ }
|
206 | 1ed2fc1f | Jan Kiszka | }, |
207 | 1ed2fc1f | Jan Kiszka | }; |
208 | 1ed2fc1f | Jan Kiszka | |
209 | d0fef6fb | Gerd Hoffmann | QemuOptsList qemu_global_opts = { |
210 | d0fef6fb | Gerd Hoffmann | .name = "global",
|
211 | d0fef6fb | Gerd Hoffmann | .head = QTAILQ_HEAD_INITIALIZER(qemu_global_opts.head), |
212 | d0fef6fb | Gerd Hoffmann | .desc = { |
213 | d0fef6fb | Gerd Hoffmann | { |
214 | d0fef6fb | Gerd Hoffmann | .name = "driver",
|
215 | d0fef6fb | Gerd Hoffmann | .type = QEMU_OPT_STRING, |
216 | d0fef6fb | Gerd Hoffmann | },{ |
217 | d0fef6fb | Gerd Hoffmann | .name = "property",
|
218 | d0fef6fb | Gerd Hoffmann | .type = QEMU_OPT_STRING, |
219 | d0fef6fb | Gerd Hoffmann | },{ |
220 | d0fef6fb | Gerd Hoffmann | .name = "value",
|
221 | d0fef6fb | Gerd Hoffmann | .type = QEMU_OPT_STRING, |
222 | d0fef6fb | Gerd Hoffmann | }, |
223 | d0fef6fb | Gerd Hoffmann | { /* end if list */ }
|
224 | d0fef6fb | Gerd Hoffmann | }, |
225 | d0fef6fb | Gerd Hoffmann | }; |
226 | d0fef6fb | Gerd Hoffmann | |
227 | 88589343 | Gerd Hoffmann | QemuOptsList qemu_mon_opts = { |
228 | 88589343 | Gerd Hoffmann | .name = "mon",
|
229 | 88589343 | Gerd Hoffmann | .head = QTAILQ_HEAD_INITIALIZER(qemu_mon_opts.head), |
230 | 88589343 | Gerd Hoffmann | .desc = { |
231 | 88589343 | Gerd Hoffmann | { |
232 | 88589343 | Gerd Hoffmann | .name = "mode",
|
233 | 88589343 | Gerd Hoffmann | .type = QEMU_OPT_STRING, |
234 | 88589343 | Gerd Hoffmann | },{ |
235 | 88589343 | Gerd Hoffmann | .name = "chardev",
|
236 | 88589343 | Gerd Hoffmann | .type = QEMU_OPT_STRING, |
237 | 88589343 | Gerd Hoffmann | },{ |
238 | 88589343 | Gerd Hoffmann | .name = "default",
|
239 | 88589343 | Gerd Hoffmann | .type = QEMU_OPT_BOOL, |
240 | 88589343 | Gerd Hoffmann | }, |
241 | 88589343 | Gerd Hoffmann | { /* end if list */ }
|
242 | 88589343 | Gerd Hoffmann | }, |
243 | 88589343 | Gerd Hoffmann | }; |
244 | 88589343 | Gerd Hoffmann | |
245 | d058fe03 | Gerd Hoffmann | static QemuOptsList *lists[] = {
|
246 | d058fe03 | Gerd Hoffmann | &qemu_drive_opts, |
247 | 191bc01b | Gerd Hoffmann | &qemu_chardev_opts, |
248 | f31d07d1 | Gerd Hoffmann | &qemu_device_opts, |
249 | a1ea458f | Mark McLoughlin | &qemu_netdev_opts, |
250 | 8119b33d | Mark McLoughlin | &qemu_net_opts, |
251 | 5fdfbf7e | Jan Kiszka | &qemu_rtc_opts, |
252 | d0fef6fb | Gerd Hoffmann | &qemu_global_opts, |
253 | 88589343 | Gerd Hoffmann | &qemu_mon_opts, |
254 | d058fe03 | Gerd Hoffmann | NULL,
|
255 | d058fe03 | Gerd Hoffmann | }; |
256 | d058fe03 | Gerd Hoffmann | |
257 | ddc97855 | Gerd Hoffmann | static QemuOptsList *find_list(const char *group) |
258 | ddc97855 | Gerd Hoffmann | { |
259 | ddc97855 | Gerd Hoffmann | int i;
|
260 | ddc97855 | Gerd Hoffmann | |
261 | ddc97855 | Gerd Hoffmann | for (i = 0; lists[i] != NULL; i++) { |
262 | ddc97855 | Gerd Hoffmann | if (strcmp(lists[i]->name, group) == 0) |
263 | ddc97855 | Gerd Hoffmann | break;
|
264 | ddc97855 | Gerd Hoffmann | } |
265 | ddc97855 | Gerd Hoffmann | if (lists[i] == NULL) { |
266 | ddc97855 | Gerd Hoffmann | qemu_error("there is no option group \"%s\"\n", group);
|
267 | ddc97855 | Gerd Hoffmann | } |
268 | ddc97855 | Gerd Hoffmann | return lists[i];
|
269 | ddc97855 | Gerd Hoffmann | } |
270 | ddc97855 | Gerd Hoffmann | |
271 | d058fe03 | Gerd Hoffmann | int qemu_set_option(const char *str) |
272 | d058fe03 | Gerd Hoffmann | { |
273 | d058fe03 | Gerd Hoffmann | char group[64], id[64], arg[64]; |
274 | ddc97855 | Gerd Hoffmann | QemuOptsList *list; |
275 | d058fe03 | Gerd Hoffmann | QemuOpts *opts; |
276 | ddc97855 | Gerd Hoffmann | int rc, offset;
|
277 | d058fe03 | Gerd Hoffmann | |
278 | d058fe03 | Gerd Hoffmann | rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset);
|
279 | d058fe03 | Gerd Hoffmann | if (rc < 3 || str[offset] != '=') { |
280 | a861c453 | Gerd Hoffmann | qemu_error("can't parse: \"%s\"\n", str);
|
281 | d058fe03 | Gerd Hoffmann | return -1; |
282 | d058fe03 | Gerd Hoffmann | } |
283 | d058fe03 | Gerd Hoffmann | |
284 | ddc97855 | Gerd Hoffmann | list = find_list(group); |
285 | ddc97855 | Gerd Hoffmann | if (list == NULL) { |
286 | d058fe03 | Gerd Hoffmann | return -1; |
287 | d058fe03 | Gerd Hoffmann | } |
288 | d058fe03 | Gerd Hoffmann | |
289 | ddc97855 | Gerd Hoffmann | opts = qemu_opts_find(list, id); |
290 | d058fe03 | Gerd Hoffmann | if (!opts) {
|
291 | a861c453 | Gerd Hoffmann | qemu_error("there is no %s \"%s\" defined\n",
|
292 | ddc97855 | Gerd Hoffmann | list->name, id); |
293 | d058fe03 | Gerd Hoffmann | return -1; |
294 | d058fe03 | Gerd Hoffmann | } |
295 | d058fe03 | Gerd Hoffmann | |
296 | 3df04ac3 | Mark McLoughlin | if (qemu_opt_set(opts, arg, str+offset+1) == -1) { |
297 | d058fe03 | Gerd Hoffmann | return -1; |
298 | d058fe03 | Gerd Hoffmann | } |
299 | d058fe03 | Gerd Hoffmann | return 0; |
300 | d058fe03 | Gerd Hoffmann | } |
301 | d058fe03 | Gerd Hoffmann | |
302 | d0fef6fb | Gerd Hoffmann | int qemu_global_option(const char *str) |
303 | d0fef6fb | Gerd Hoffmann | { |
304 | d0fef6fb | Gerd Hoffmann | char driver[64], property[64]; |
305 | d0fef6fb | Gerd Hoffmann | QemuOpts *opts; |
306 | d0fef6fb | Gerd Hoffmann | int rc, offset;
|
307 | d0fef6fb | Gerd Hoffmann | |
308 | d0fef6fb | Gerd Hoffmann | rc = sscanf(str, "%63[^.].%63[^=]%n", driver, property, &offset);
|
309 | d0fef6fb | Gerd Hoffmann | if (rc < 2 || str[offset] != '=') { |
310 | d0fef6fb | Gerd Hoffmann | qemu_error("can't parse: \"%s\"\n", str);
|
311 | d0fef6fb | Gerd Hoffmann | return -1; |
312 | d0fef6fb | Gerd Hoffmann | } |
313 | d0fef6fb | Gerd Hoffmann | |
314 | d0fef6fb | Gerd Hoffmann | opts = qemu_opts_create(&qemu_global_opts, NULL, 0); |
315 | d0fef6fb | Gerd Hoffmann | qemu_opt_set(opts, "driver", driver);
|
316 | d0fef6fb | Gerd Hoffmann | qemu_opt_set(opts, "property", property);
|
317 | d0fef6fb | Gerd Hoffmann | qemu_opt_set(opts, "value", str+offset+1); |
318 | d0fef6fb | Gerd Hoffmann | return 0; |
319 | d0fef6fb | Gerd Hoffmann | } |
320 | d0fef6fb | Gerd Hoffmann | |
321 | d0fef6fb | Gerd Hoffmann | static int qemu_add_one_global(QemuOpts *opts, void *opaque) |
322 | d0fef6fb | Gerd Hoffmann | { |
323 | d0fef6fb | Gerd Hoffmann | GlobalProperty *g; |
324 | d0fef6fb | Gerd Hoffmann | |
325 | d0fef6fb | Gerd Hoffmann | g = qemu_mallocz(sizeof(*g));
|
326 | d0fef6fb | Gerd Hoffmann | g->driver = qemu_opt_get(opts, "driver");
|
327 | d0fef6fb | Gerd Hoffmann | g->property = qemu_opt_get(opts, "property");
|
328 | d0fef6fb | Gerd Hoffmann | g->value = qemu_opt_get(opts, "value");
|
329 | d0fef6fb | Gerd Hoffmann | qdev_prop_register_global(g); |
330 | d0fef6fb | Gerd Hoffmann | return 0; |
331 | d0fef6fb | Gerd Hoffmann | } |
332 | d0fef6fb | Gerd Hoffmann | |
333 | d0fef6fb | Gerd Hoffmann | void qemu_add_globals(void) |
334 | d0fef6fb | Gerd Hoffmann | { |
335 | d0fef6fb | Gerd Hoffmann | qemu_opts_foreach(&qemu_global_opts, qemu_add_one_global, NULL, 0); |
336 | d0fef6fb | Gerd Hoffmann | } |
337 | d0fef6fb | Gerd Hoffmann | |
338 | 9d993394 | Gerd Hoffmann | struct ConfigWriteData {
|
339 | 9d993394 | Gerd Hoffmann | QemuOptsList *list; |
340 | 9d993394 | Gerd Hoffmann | FILE *fp; |
341 | 9d993394 | Gerd Hoffmann | }; |
342 | 9d993394 | Gerd Hoffmann | |
343 | 9d993394 | Gerd Hoffmann | static int config_write_opt(const char *name, const char *value, void *opaque) |
344 | 9d993394 | Gerd Hoffmann | { |
345 | 9d993394 | Gerd Hoffmann | struct ConfigWriteData *data = opaque;
|
346 | 9d993394 | Gerd Hoffmann | |
347 | 9d993394 | Gerd Hoffmann | fprintf(data->fp, " %s = \"%s\"\n", name, value);
|
348 | 9d993394 | Gerd Hoffmann | return 0; |
349 | 9d993394 | Gerd Hoffmann | } |
350 | 9d993394 | Gerd Hoffmann | |
351 | 9d993394 | Gerd Hoffmann | static int config_write_opts(QemuOpts *opts, void *opaque) |
352 | 9d993394 | Gerd Hoffmann | { |
353 | 9d993394 | Gerd Hoffmann | struct ConfigWriteData *data = opaque;
|
354 | 9d993394 | Gerd Hoffmann | const char *id = qemu_opts_id(opts); |
355 | 9d993394 | Gerd Hoffmann | |
356 | 9d993394 | Gerd Hoffmann | if (id) {
|
357 | 9d993394 | Gerd Hoffmann | fprintf(data->fp, "[%s \"%s\"]\n", data->list->name, id);
|
358 | 9d993394 | Gerd Hoffmann | } else {
|
359 | 9d993394 | Gerd Hoffmann | fprintf(data->fp, "[%s]\n", data->list->name);
|
360 | 9d993394 | Gerd Hoffmann | } |
361 | 9d993394 | Gerd Hoffmann | qemu_opt_foreach(opts, config_write_opt, data, 0);
|
362 | 9d993394 | Gerd Hoffmann | fprintf(data->fp, "\n");
|
363 | 9d993394 | Gerd Hoffmann | return 0; |
364 | 9d993394 | Gerd Hoffmann | } |
365 | 9d993394 | Gerd Hoffmann | |
366 | 9d993394 | Gerd Hoffmann | void qemu_config_write(FILE *fp)
|
367 | 9d993394 | Gerd Hoffmann | { |
368 | 9d993394 | Gerd Hoffmann | struct ConfigWriteData data = { .fp = fp };
|
369 | 9d993394 | Gerd Hoffmann | int i;
|
370 | 9d993394 | Gerd Hoffmann | |
371 | 9d993394 | Gerd Hoffmann | fprintf(fp, "# qemu config file\n\n");
|
372 | 9d993394 | Gerd Hoffmann | for (i = 0; lists[i] != NULL; i++) { |
373 | 9d993394 | Gerd Hoffmann | data.list = lists[i]; |
374 | 9d993394 | Gerd Hoffmann | qemu_opts_foreach(data.list, config_write_opts, &data, 0);
|
375 | 9d993394 | Gerd Hoffmann | } |
376 | 9d993394 | Gerd Hoffmann | } |
377 | 42262ba8 | Gerd Hoffmann | |
378 | 42262ba8 | Gerd Hoffmann | int qemu_config_parse(FILE *fp)
|
379 | 42262ba8 | Gerd Hoffmann | { |
380 | 42262ba8 | Gerd Hoffmann | char line[1024], group[64], id[64], arg[64], value[1024]; |
381 | 42262ba8 | Gerd Hoffmann | QemuOptsList *list = NULL;
|
382 | 42262ba8 | Gerd Hoffmann | QemuOpts *opts = NULL;
|
383 | 42262ba8 | Gerd Hoffmann | |
384 | 42262ba8 | Gerd Hoffmann | while (fgets(line, sizeof(line), fp) != NULL) { |
385 | 42262ba8 | Gerd Hoffmann | if (line[0] == '\n') { |
386 | 42262ba8 | Gerd Hoffmann | /* skip empty lines */
|
387 | 42262ba8 | Gerd Hoffmann | continue;
|
388 | 42262ba8 | Gerd Hoffmann | } |
389 | 42262ba8 | Gerd Hoffmann | if (line[0] == '#') { |
390 | 42262ba8 | Gerd Hoffmann | /* comment */
|
391 | 42262ba8 | Gerd Hoffmann | continue;
|
392 | 42262ba8 | Gerd Hoffmann | } |
393 | 42262ba8 | Gerd Hoffmann | if (sscanf(line, "[%63s \"%63[^\"]\"]", group, id) == 2) { |
394 | 42262ba8 | Gerd Hoffmann | /* group with id */
|
395 | 42262ba8 | Gerd Hoffmann | list = find_list(group); |
396 | 42262ba8 | Gerd Hoffmann | if (list == NULL) |
397 | 42262ba8 | Gerd Hoffmann | return -1; |
398 | 42262ba8 | Gerd Hoffmann | opts = qemu_opts_create(list, id, 1);
|
399 | 42262ba8 | Gerd Hoffmann | continue;
|
400 | 42262ba8 | Gerd Hoffmann | } |
401 | 42262ba8 | Gerd Hoffmann | if (sscanf(line, "[%63[^]]]", group) == 1) { |
402 | 42262ba8 | Gerd Hoffmann | /* group without id */
|
403 | 42262ba8 | Gerd Hoffmann | list = find_list(group); |
404 | 42262ba8 | Gerd Hoffmann | if (list == NULL) |
405 | 42262ba8 | Gerd Hoffmann | return -1; |
406 | 42262ba8 | Gerd Hoffmann | opts = qemu_opts_create(list, NULL, 0); |
407 | 42262ba8 | Gerd Hoffmann | continue;
|
408 | 42262ba8 | Gerd Hoffmann | } |
409 | 42262ba8 | Gerd Hoffmann | if (sscanf(line, " %63s = \"%1023[^\"]\"", arg, value) == 2) { |
410 | 42262ba8 | Gerd Hoffmann | /* arg = value */
|
411 | 42262ba8 | Gerd Hoffmann | if (opts == NULL) { |
412 | 42262ba8 | Gerd Hoffmann | fprintf(stderr, "no group defined\n");
|
413 | 42262ba8 | Gerd Hoffmann | return -1; |
414 | 42262ba8 | Gerd Hoffmann | } |
415 | 42262ba8 | Gerd Hoffmann | if (qemu_opt_set(opts, arg, value) != 0) { |
416 | 42262ba8 | Gerd Hoffmann | fprintf(stderr, "failed to set \"%s\" for %s\n",
|
417 | 42262ba8 | Gerd Hoffmann | arg, group); |
418 | 42262ba8 | Gerd Hoffmann | return -1; |
419 | 42262ba8 | Gerd Hoffmann | } |
420 | 42262ba8 | Gerd Hoffmann | continue;
|
421 | 42262ba8 | Gerd Hoffmann | } |
422 | 42262ba8 | Gerd Hoffmann | fprintf(stderr, "parse error: %s\n", line);
|
423 | 42262ba8 | Gerd Hoffmann | return -1; |
424 | 42262ba8 | Gerd Hoffmann | } |
425 | 42262ba8 | Gerd Hoffmann | return 0; |
426 | 42262ba8 | Gerd Hoffmann | } |