root / qemu-config.c @ c227f099
History | View | Annotate | Download (5.1 kB)
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 = QTAILQ_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)",
|
55 |
},{ |
56 |
.name = "aio",
|
57 |
.type = QEMU_OPT_STRING, |
58 |
.help = "host AIO implementation (threads, native)",
|
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 |
|
78 |
QemuOptsList qemu_chardev_opts = { |
79 |
.name = "chardev",
|
80 |
.head = QTAILQ_HEAD_INITIALIZER(qemu_chardev_opts.head), |
81 |
.desc = { |
82 |
{ |
83 |
.name = "backend",
|
84 |
.type = QEMU_OPT_STRING, |
85 |
},{ |
86 |
.name = "path",
|
87 |
.type = QEMU_OPT_STRING, |
88 |
},{ |
89 |
.name = "host",
|
90 |
.type = QEMU_OPT_STRING, |
91 |
},{ |
92 |
.name = "port",
|
93 |
.type = QEMU_OPT_STRING, |
94 |
},{ |
95 |
.name = "localaddr",
|
96 |
.type = QEMU_OPT_STRING, |
97 |
},{ |
98 |
.name = "localport",
|
99 |
.type = QEMU_OPT_STRING, |
100 |
},{ |
101 |
.name = "to",
|
102 |
.type = QEMU_OPT_NUMBER, |
103 |
},{ |
104 |
.name = "ipv4",
|
105 |
.type = QEMU_OPT_BOOL, |
106 |
},{ |
107 |
.name = "ipv6",
|
108 |
.type = QEMU_OPT_BOOL, |
109 |
},{ |
110 |
.name = "wait",
|
111 |
.type = QEMU_OPT_BOOL, |
112 |
},{ |
113 |
.name = "server",
|
114 |
.type = QEMU_OPT_BOOL, |
115 |
},{ |
116 |
.name = "delay",
|
117 |
.type = QEMU_OPT_BOOL, |
118 |
},{ |
119 |
.name = "telnet",
|
120 |
.type = QEMU_OPT_BOOL, |
121 |
},{ |
122 |
.name = "width",
|
123 |
.type = QEMU_OPT_NUMBER, |
124 |
},{ |
125 |
.name = "height",
|
126 |
.type = QEMU_OPT_NUMBER, |
127 |
},{ |
128 |
.name = "cols",
|
129 |
.type = QEMU_OPT_NUMBER, |
130 |
},{ |
131 |
.name = "rows",
|
132 |
.type = QEMU_OPT_NUMBER, |
133 |
},{ |
134 |
.name = "mux",
|
135 |
.type = QEMU_OPT_BOOL, |
136 |
}, |
137 |
{ /* end if list */ }
|
138 |
}, |
139 |
}; |
140 |
|
141 |
QemuOptsList qemu_device_opts = { |
142 |
.name = "device",
|
143 |
.head = QTAILQ_HEAD_INITIALIZER(qemu_device_opts.head), |
144 |
.desc = { |
145 |
/*
|
146 |
* no elements => accept any
|
147 |
* sanity checking will happen later
|
148 |
* when setting device properties
|
149 |
*/
|
150 |
{ /* end if list */ }
|
151 |
}, |
152 |
}; |
153 |
|
154 |
static QemuOptsList *lists[] = {
|
155 |
&qemu_drive_opts, |
156 |
&qemu_chardev_opts, |
157 |
&qemu_device_opts, |
158 |
NULL,
|
159 |
}; |
160 |
|
161 |
int qemu_set_option(const char *str) |
162 |
{ |
163 |
char group[64], id[64], arg[64]; |
164 |
QemuOpts *opts; |
165 |
int i, rc, offset;
|
166 |
|
167 |
rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset);
|
168 |
if (rc < 3 || str[offset] != '=') { |
169 |
fprintf(stderr, "can't parse: \"%s\"\n", str);
|
170 |
return -1; |
171 |
} |
172 |
|
173 |
for (i = 0; lists[i] != NULL; i++) { |
174 |
if (strcmp(lists[i]->name, group) == 0) |
175 |
break;
|
176 |
} |
177 |
if (lists[i] == NULL) { |
178 |
fprintf(stderr, "there is no option group \"%s\"\n", group);
|
179 |
return -1; |
180 |
} |
181 |
|
182 |
opts = qemu_opts_find(lists[i], id); |
183 |
if (!opts) {
|
184 |
fprintf(stderr, "there is no %s \"%s\" defined\n",
|
185 |
lists[i]->name, id); |
186 |
return -1; |
187 |
} |
188 |
|
189 |
if (qemu_opt_set(opts, arg, str+offset+1) == -1) { |
190 |
fprintf(stderr, "failed to set \"%s\" for %s \"%s\"\n",
|
191 |
arg, lists[i]->name, id); |
192 |
return -1; |
193 |
} |
194 |
return 0; |
195 |
} |
196 |
|