root / spice-qemu-char.c @ dc364f4c
History | View | Annotate | Download (9 kB)
1 | cbcc6336 | Alon Levy | #include "config-host.h" |
---|---|---|---|
2 | cbcc6336 | Alon Levy | #include "trace.h" |
3 | cbcc6336 | Alon Levy | #include "ui/qemu-spice.h" |
4 | dccfcd0e | Paolo Bonzini | #include "sysemu/char.h" |
5 | cbcc6336 | Alon Levy | #include <spice.h> |
6 | cbcc6336 | Alon Levy | #include <spice-experimental.h> |
7 | 5a49d3e9 | Marc-André Lureau | #include <spice/protocol.h> |
8 | cbcc6336 | Alon Levy | |
9 | 1de7afc9 | Paolo Bonzini | #include "qemu/osdep.h" |
10 | cbcc6336 | Alon Levy | |
11 | cbcc6336 | Alon Levy | typedef struct SpiceCharDriver { |
12 | cbcc6336 | Alon Levy | CharDriverState* chr; |
13 | cbcc6336 | Alon Levy | SpiceCharDeviceInstance sin; |
14 | cbcc6336 | Alon Levy | bool active;
|
15 | ae893e5e | Hans de Goede | bool blocked;
|
16 | b010cec8 | Alon Levy | const uint8_t *datapos;
|
17 | b010cec8 | Alon Levy | int datalen;
|
18 | 7a5448ce | Marc-André Lureau | QLIST_ENTRY(SpiceCharDriver) next; |
19 | cbcc6336 | Alon Levy | } SpiceCharDriver; |
20 | cbcc6336 | Alon Levy | |
21 | ae893e5e | Hans de Goede | typedef struct SpiceCharSource { |
22 | ae893e5e | Hans de Goede | GSource source; |
23 | ae893e5e | Hans de Goede | SpiceCharDriver *scd; |
24 | ae893e5e | Hans de Goede | } SpiceCharSource; |
25 | ae893e5e | Hans de Goede | |
26 | 7a5448ce | Marc-André Lureau | static QLIST_HEAD(, SpiceCharDriver) spice_chars =
|
27 | 7a5448ce | Marc-André Lureau | QLIST_HEAD_INITIALIZER(spice_chars); |
28 | 7a5448ce | Marc-André Lureau | |
29 | cbcc6336 | Alon Levy | static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len) |
30 | cbcc6336 | Alon Levy | { |
31 | cbcc6336 | Alon Levy | SpiceCharDriver *scd = container_of(sin, SpiceCharDriver, sin); |
32 | cbcc6336 | Alon Levy | ssize_t out = 0;
|
33 | cbcc6336 | Alon Levy | ssize_t last_out; |
34 | cbcc6336 | Alon Levy | uint8_t* p = (uint8_t*)buf; |
35 | cbcc6336 | Alon Levy | |
36 | cbcc6336 | Alon Levy | while (len > 0) { |
37 | 75c439bc | Hans de Goede | int can_write = qemu_chr_be_can_write(scd->chr);
|
38 | 75c439bc | Hans de Goede | last_out = MIN(len, can_write); |
39 | 07a54d70 | Marc-André Lureau | if (last_out <= 0) { |
40 | cbcc6336 | Alon Levy | break;
|
41 | cbcc6336 | Alon Levy | } |
42 | fa5efccb | Anthony Liguori | qemu_chr_be_write(scd->chr, p, last_out); |
43 | 35106c2d | Hans de Goede | out += last_out; |
44 | 35106c2d | Hans de Goede | len -= last_out; |
45 | 35106c2d | Hans de Goede | p += last_out; |
46 | cbcc6336 | Alon Levy | } |
47 | cbcc6336 | Alon Levy | |
48 | cbcc6336 | Alon Levy | trace_spice_vmc_write(out, len + out); |
49 | cbcc6336 | Alon Levy | return out;
|
50 | cbcc6336 | Alon Levy | } |
51 | cbcc6336 | Alon Levy | |
52 | cbcc6336 | Alon Levy | static int vmc_read(SpiceCharDeviceInstance *sin, uint8_t *buf, int len) |
53 | cbcc6336 | Alon Levy | { |
54 | cbcc6336 | Alon Levy | SpiceCharDriver *scd = container_of(sin, SpiceCharDriver, sin); |
55 | cbcc6336 | Alon Levy | int bytes = MIN(len, scd->datalen);
|
56 | cbcc6336 | Alon Levy | |
57 | cbcc6336 | Alon Levy | if (bytes > 0) { |
58 | cbcc6336 | Alon Levy | memcpy(buf, scd->datapos, bytes); |
59 | cbcc6336 | Alon Levy | scd->datapos += bytes; |
60 | cbcc6336 | Alon Levy | scd->datalen -= bytes; |
61 | cbcc6336 | Alon Levy | assert(scd->datalen >= 0);
|
62 | ae893e5e | Hans de Goede | } |
63 | ae893e5e | Hans de Goede | if (scd->datalen == 0) { |
64 | ae893e5e | Hans de Goede | scd->datapos = 0;
|
65 | ae893e5e | Hans de Goede | scd->blocked = false;
|
66 | cbcc6336 | Alon Levy | } |
67 | cbcc6336 | Alon Levy | trace_spice_vmc_read(bytes, len); |
68 | cbcc6336 | Alon Levy | return bytes;
|
69 | cbcc6336 | Alon Levy | } |
70 | cbcc6336 | Alon Levy | |
71 | 5a49d3e9 | Marc-André Lureau | #if SPICE_SERVER_VERSION >= 0x000c02 |
72 | 5a49d3e9 | Marc-André Lureau | static void vmc_event(SpiceCharDeviceInstance *sin, uint8_t event) |
73 | 5a49d3e9 | Marc-André Lureau | { |
74 | 5a49d3e9 | Marc-André Lureau | SpiceCharDriver *scd = container_of(sin, SpiceCharDriver, sin); |
75 | 5a49d3e9 | Marc-André Lureau | int chr_event;
|
76 | 5a49d3e9 | Marc-André Lureau | |
77 | 5a49d3e9 | Marc-André Lureau | switch (event) {
|
78 | 5a49d3e9 | Marc-André Lureau | case SPICE_PORT_EVENT_BREAK:
|
79 | 5a49d3e9 | Marc-André Lureau | chr_event = CHR_EVENT_BREAK; |
80 | 5a49d3e9 | Marc-André Lureau | break;
|
81 | 5a49d3e9 | Marc-André Lureau | default:
|
82 | 5a49d3e9 | Marc-André Lureau | return;
|
83 | 5a49d3e9 | Marc-André Lureau | } |
84 | 5a49d3e9 | Marc-André Lureau | |
85 | 5a49d3e9 | Marc-André Lureau | trace_spice_vmc_event(chr_event); |
86 | 5a49d3e9 | Marc-André Lureau | qemu_chr_be_event(scd->chr, chr_event); |
87 | 5a49d3e9 | Marc-André Lureau | } |
88 | 5a49d3e9 | Marc-André Lureau | #endif
|
89 | 5a49d3e9 | Marc-André Lureau | |
90 | f76e4c7f | Hans de Goede | static void vmc_state(SpiceCharDeviceInstance *sin, int connected) |
91 | f76e4c7f | Hans de Goede | { |
92 | f76e4c7f | Hans de Goede | SpiceCharDriver *scd = container_of(sin, SpiceCharDriver, sin); |
93 | f76e4c7f | Hans de Goede | |
94 | 16665b94 | Hans de Goede | if ((scd->chr->be_open && connected) ||
|
95 | 16665b94 | Hans de Goede | (!scd->chr->be_open && !connected)) { |
96 | f76e4c7f | Hans de Goede | return;
|
97 | f76e4c7f | Hans de Goede | } |
98 | f76e4c7f | Hans de Goede | |
99 | f76e4c7f | Hans de Goede | qemu_chr_be_event(scd->chr, |
100 | f76e4c7f | Hans de Goede | connected ? CHR_EVENT_OPENED : CHR_EVENT_CLOSED); |
101 | f76e4c7f | Hans de Goede | } |
102 | f76e4c7f | Hans de Goede | |
103 | cbcc6336 | Alon Levy | static SpiceCharDeviceInterface vmc_interface = {
|
104 | cbcc6336 | Alon Levy | .base.type = SPICE_INTERFACE_CHAR_DEVICE, |
105 | cbcc6336 | Alon Levy | .base.description = "spice virtual channel char device",
|
106 | cbcc6336 | Alon Levy | .base.major_version = SPICE_INTERFACE_CHAR_DEVICE_MAJOR, |
107 | cbcc6336 | Alon Levy | .base.minor_version = SPICE_INTERFACE_CHAR_DEVICE_MINOR, |
108 | f76e4c7f | Hans de Goede | .state = vmc_state, |
109 | cbcc6336 | Alon Levy | .write = vmc_write, |
110 | cbcc6336 | Alon Levy | .read = vmc_read, |
111 | 5a49d3e9 | Marc-André Lureau | #if SPICE_SERVER_VERSION >= 0x000c02 |
112 | 5a49d3e9 | Marc-André Lureau | .event = vmc_event, |
113 | 5a49d3e9 | Marc-André Lureau | #endif
|
114 | cbcc6336 | Alon Levy | }; |
115 | cbcc6336 | Alon Levy | |
116 | cbcc6336 | Alon Levy | |
117 | cbcc6336 | Alon Levy | static void vmc_register_interface(SpiceCharDriver *scd) |
118 | cbcc6336 | Alon Levy | { |
119 | cbcc6336 | Alon Levy | if (scd->active) {
|
120 | cbcc6336 | Alon Levy | return;
|
121 | cbcc6336 | Alon Levy | } |
122 | cbcc6336 | Alon Levy | scd->sin.base.sif = &vmc_interface.base; |
123 | cbcc6336 | Alon Levy | qemu_spice_add_interface(&scd->sin.base); |
124 | cbcc6336 | Alon Levy | scd->active = true;
|
125 | cbcc6336 | Alon Levy | trace_spice_vmc_register_interface(scd); |
126 | cbcc6336 | Alon Levy | } |
127 | cbcc6336 | Alon Levy | |
128 | cbcc6336 | Alon Levy | static void vmc_unregister_interface(SpiceCharDriver *scd) |
129 | cbcc6336 | Alon Levy | { |
130 | cbcc6336 | Alon Levy | if (!scd->active) {
|
131 | cbcc6336 | Alon Levy | return;
|
132 | cbcc6336 | Alon Levy | } |
133 | cbcc6336 | Alon Levy | spice_server_remove_interface(&scd->sin.base); |
134 | cbcc6336 | Alon Levy | scd->active = false;
|
135 | cbcc6336 | Alon Levy | trace_spice_vmc_unregister_interface(scd); |
136 | cbcc6336 | Alon Levy | } |
137 | cbcc6336 | Alon Levy | |
138 | ae893e5e | Hans de Goede | static gboolean spice_char_source_prepare(GSource *source, gint *timeout)
|
139 | ae893e5e | Hans de Goede | { |
140 | ae893e5e | Hans de Goede | SpiceCharSource *src = (SpiceCharSource *)source; |
141 | ae893e5e | Hans de Goede | |
142 | ae893e5e | Hans de Goede | *timeout = -1;
|
143 | ae893e5e | Hans de Goede | |
144 | ae893e5e | Hans de Goede | return !src->scd->blocked;
|
145 | ae893e5e | Hans de Goede | } |
146 | ae893e5e | Hans de Goede | |
147 | ae893e5e | Hans de Goede | static gboolean spice_char_source_check(GSource *source)
|
148 | ae893e5e | Hans de Goede | { |
149 | ae893e5e | Hans de Goede | SpiceCharSource *src = (SpiceCharSource *)source; |
150 | ae893e5e | Hans de Goede | |
151 | ae893e5e | Hans de Goede | return !src->scd->blocked;
|
152 | ae893e5e | Hans de Goede | } |
153 | ae893e5e | Hans de Goede | |
154 | ae893e5e | Hans de Goede | static gboolean spice_char_source_dispatch(GSource *source,
|
155 | ae893e5e | Hans de Goede | GSourceFunc callback, gpointer user_data) |
156 | ae893e5e | Hans de Goede | { |
157 | ae893e5e | Hans de Goede | GIOFunc func = (GIOFunc)callback; |
158 | ae893e5e | Hans de Goede | |
159 | ae893e5e | Hans de Goede | return func(NULL, G_IO_OUT, user_data); |
160 | ae893e5e | Hans de Goede | } |
161 | ae893e5e | Hans de Goede | |
162 | ae893e5e | Hans de Goede | GSourceFuncs SpiceCharSourceFuncs = { |
163 | ae893e5e | Hans de Goede | .prepare = spice_char_source_prepare, |
164 | ae893e5e | Hans de Goede | .check = spice_char_source_check, |
165 | ae893e5e | Hans de Goede | .dispatch = spice_char_source_dispatch, |
166 | ae893e5e | Hans de Goede | }; |
167 | ae893e5e | Hans de Goede | |
168 | ae893e5e | Hans de Goede | static GSource *spice_chr_add_watch(CharDriverState *chr, GIOCondition cond)
|
169 | ae893e5e | Hans de Goede | { |
170 | ae893e5e | Hans de Goede | SpiceCharDriver *scd = chr->opaque; |
171 | ae893e5e | Hans de Goede | SpiceCharSource *src; |
172 | ae893e5e | Hans de Goede | |
173 | ae893e5e | Hans de Goede | assert(cond == G_IO_OUT); |
174 | ae893e5e | Hans de Goede | |
175 | ae893e5e | Hans de Goede | src = (SpiceCharSource *)g_source_new(&SpiceCharSourceFuncs, |
176 | ae893e5e | Hans de Goede | sizeof(SpiceCharSource));
|
177 | ae893e5e | Hans de Goede | src->scd = scd; |
178 | ae893e5e | Hans de Goede | |
179 | ae893e5e | Hans de Goede | return (GSource *)src;
|
180 | ae893e5e | Hans de Goede | } |
181 | cbcc6336 | Alon Levy | |
182 | cbcc6336 | Alon Levy | static int spice_chr_write(CharDriverState *chr, const uint8_t *buf, int len) |
183 | cbcc6336 | Alon Levy | { |
184 | cbcc6336 | Alon Levy | SpiceCharDriver *s = chr->opaque; |
185 | ae893e5e | Hans de Goede | int read_bytes;
|
186 | cbcc6336 | Alon Levy | |
187 | cbcc6336 | Alon Levy | assert(s->datalen == 0);
|
188 | b010cec8 | Alon Levy | s->datapos = buf; |
189 | cbcc6336 | Alon Levy | s->datalen = len; |
190 | cbcc6336 | Alon Levy | spice_server_char_device_wakeup(&s->sin); |
191 | ae893e5e | Hans de Goede | read_bytes = len - s->datalen; |
192 | ae893e5e | Hans de Goede | if (read_bytes != len) {
|
193 | ae893e5e | Hans de Goede | /* We'll get passed in the unconsumed data with the next call */
|
194 | ae893e5e | Hans de Goede | s->datalen = 0;
|
195 | ae893e5e | Hans de Goede | s->datapos = NULL;
|
196 | ae893e5e | Hans de Goede | s->blocked = true;
|
197 | ae893e5e | Hans de Goede | } |
198 | ae893e5e | Hans de Goede | return read_bytes;
|
199 | cbcc6336 | Alon Levy | } |
200 | cbcc6336 | Alon Levy | |
201 | cbcc6336 | Alon Levy | static void spice_chr_close(struct CharDriverState *chr) |
202 | cbcc6336 | Alon Levy | { |
203 | cbcc6336 | Alon Levy | SpiceCharDriver *s = chr->opaque; |
204 | cbcc6336 | Alon Levy | |
205 | cbcc6336 | Alon Levy | vmc_unregister_interface(s); |
206 | 7a5448ce | Marc-André Lureau | QLIST_REMOVE(s, next); |
207 | 5e9b473a | Hans de Goede | |
208 | 5e9b473a | Hans de Goede | g_free((char *)s->sin.subtype);
|
209 | 5e9b473a | Hans de Goede | #if SPICE_SERVER_VERSION >= 0x000c02 |
210 | 5e9b473a | Hans de Goede | g_free((char *)s->sin.portname);
|
211 | 5e9b473a | Hans de Goede | #endif
|
212 | 7267c094 | Anthony Liguori | g_free(s); |
213 | cbcc6336 | Alon Levy | } |
214 | cbcc6336 | Alon Levy | |
215 | 574b711a | Hans de Goede | static void spice_chr_set_fe_open(struct CharDriverState *chr, int fe_open) |
216 | cd8f7df2 | Hans de Goede | { |
217 | cd8f7df2 | Hans de Goede | SpiceCharDriver *s = chr->opaque; |
218 | 574b711a | Hans de Goede | if (fe_open) {
|
219 | 574b711a | Hans de Goede | vmc_register_interface(s); |
220 | 574b711a | Hans de Goede | } else {
|
221 | 574b711a | Hans de Goede | vmc_unregister_interface(s); |
222 | 574b711a | Hans de Goede | } |
223 | cd8f7df2 | Hans de Goede | } |
224 | cd8f7df2 | Hans de Goede | |
225 | be733d6d | Marc-André Lureau | static void spice_chr_fe_event(struct CharDriverState *chr, int event) |
226 | be733d6d | Marc-André Lureau | { |
227 | be733d6d | Marc-André Lureau | #if SPICE_SERVER_VERSION >= 0x000c02 |
228 | be733d6d | Marc-André Lureau | SpiceCharDriver *s = chr->opaque; |
229 | be733d6d | Marc-André Lureau | |
230 | be733d6d | Marc-André Lureau | spice_server_port_event(&s->sin, event); |
231 | be733d6d | Marc-André Lureau | #endif
|
232 | be733d6d | Marc-André Lureau | } |
233 | be733d6d | Marc-André Lureau | |
234 | cbcc6336 | Alon Levy | static void print_allowed_subtypes(void) |
235 | cbcc6336 | Alon Levy | { |
236 | cbcc6336 | Alon Levy | const char** psubtype; |
237 | cbcc6336 | Alon Levy | int i;
|
238 | cbcc6336 | Alon Levy | |
239 | cbcc6336 | Alon Levy | fprintf(stderr, "allowed names: ");
|
240 | cbcc6336 | Alon Levy | for(i=0, psubtype = spice_server_char_device_recognized_subtypes(); |
241 | cbcc6336 | Alon Levy | *psubtype != NULL; ++psubtype, ++i) {
|
242 | cbcc6336 | Alon Levy | if (i == 0) { |
243 | cbcc6336 | Alon Levy | fprintf(stderr, "%s", *psubtype);
|
244 | cbcc6336 | Alon Levy | } else {
|
245 | cbcc6336 | Alon Levy | fprintf(stderr, ", %s", *psubtype);
|
246 | cbcc6336 | Alon Levy | } |
247 | cbcc6336 | Alon Levy | } |
248 | cbcc6336 | Alon Levy | fprintf(stderr, "\n");
|
249 | cbcc6336 | Alon Levy | } |
250 | cbcc6336 | Alon Levy | |
251 | cd153e2a | Gerd Hoffmann | static CharDriverState *chr_open(const char *subtype) |
252 | cbcc6336 | Alon Levy | { |
253 | cbcc6336 | Alon Levy | CharDriverState *chr; |
254 | cbcc6336 | Alon Levy | SpiceCharDriver *s; |
255 | 71b423f4 | Marc-André Lureau | |
256 | 71b423f4 | Marc-André Lureau | chr = g_malloc0(sizeof(CharDriverState));
|
257 | 71b423f4 | Marc-André Lureau | s = g_malloc0(sizeof(SpiceCharDriver));
|
258 | 71b423f4 | Marc-André Lureau | s->chr = chr; |
259 | 71b423f4 | Marc-André Lureau | s->active = false;
|
260 | 5e9b473a | Hans de Goede | s->sin.subtype = g_strdup(subtype); |
261 | 71b423f4 | Marc-André Lureau | chr->opaque = s; |
262 | 71b423f4 | Marc-André Lureau | chr->chr_write = spice_chr_write; |
263 | ae893e5e | Hans de Goede | chr->chr_add_watch = spice_chr_add_watch; |
264 | 71b423f4 | Marc-André Lureau | chr->chr_close = spice_chr_close; |
265 | 574b711a | Hans de Goede | chr->chr_set_fe_open = spice_chr_set_fe_open; |
266 | bd5c51ee | Michael Roth | chr->explicit_be_open = true;
|
267 | be733d6d | Marc-André Lureau | chr->chr_fe_event = spice_chr_fe_event; |
268 | 71b423f4 | Marc-André Lureau | |
269 | 7a5448ce | Marc-André Lureau | QLIST_INSERT_HEAD(&spice_chars, s, next); |
270 | 7a5448ce | Marc-André Lureau | |
271 | 71b423f4 | Marc-André Lureau | return chr;
|
272 | 71b423f4 | Marc-André Lureau | } |
273 | 71b423f4 | Marc-André Lureau | |
274 | cd153e2a | Gerd Hoffmann | CharDriverState *qemu_chr_open_spice_vmc(const char *type) |
275 | 71b423f4 | Marc-André Lureau | { |
276 | 71b423f4 | Marc-André Lureau | const char **psubtype = spice_server_char_device_recognized_subtypes(); |
277 | cbcc6336 | Alon Levy | |
278 | cd153e2a | Gerd Hoffmann | if (type == NULL) { |
279 | cbcc6336 | Alon Levy | fprintf(stderr, "spice-qemu-char: missing name parameter\n");
|
280 | cbcc6336 | Alon Levy | print_allowed_subtypes(); |
281 | 1f51470d | Markus Armbruster | return NULL; |
282 | cbcc6336 | Alon Levy | } |
283 | cd153e2a | Gerd Hoffmann | for (; *psubtype != NULL; ++psubtype) { |
284 | cd153e2a | Gerd Hoffmann | if (strcmp(type, *psubtype) == 0) { |
285 | cbcc6336 | Alon Levy | break;
|
286 | cbcc6336 | Alon Levy | } |
287 | cbcc6336 | Alon Levy | } |
288 | cd153e2a | Gerd Hoffmann | if (*psubtype == NULL) { |
289 | cd153e2a | Gerd Hoffmann | fprintf(stderr, "spice-qemu-char: unsupported type: %s\n", type);
|
290 | cbcc6336 | Alon Levy | print_allowed_subtypes(); |
291 | 1f51470d | Markus Armbruster | return NULL; |
292 | cbcc6336 | Alon Levy | } |
293 | cbcc6336 | Alon Levy | |
294 | 52fe0e75 | Hans de Goede | return chr_open(type);
|
295 | cbcc6336 | Alon Levy | } |
296 | 5a49d3e9 | Marc-André Lureau | |
297 | 5a49d3e9 | Marc-André Lureau | #if SPICE_SERVER_VERSION >= 0x000c02 |
298 | cd153e2a | Gerd Hoffmann | CharDriverState *qemu_chr_open_spice_port(const char *name) |
299 | 5a49d3e9 | Marc-André Lureau | { |
300 | 5a49d3e9 | Marc-André Lureau | CharDriverState *chr; |
301 | 5a49d3e9 | Marc-André Lureau | SpiceCharDriver *s; |
302 | 5a49d3e9 | Marc-André Lureau | |
303 | 5a49d3e9 | Marc-André Lureau | if (name == NULL) { |
304 | 5a49d3e9 | Marc-André Lureau | fprintf(stderr, "spice-qemu-char: missing name parameter\n");
|
305 | 5a49d3e9 | Marc-André Lureau | return NULL; |
306 | 5a49d3e9 | Marc-André Lureau | } |
307 | 5a49d3e9 | Marc-André Lureau | |
308 | cd153e2a | Gerd Hoffmann | chr = chr_open("port");
|
309 | 5a49d3e9 | Marc-André Lureau | s = chr->opaque; |
310 | 5e9b473a | Hans de Goede | s->sin.portname = g_strdup(name); |
311 | 5a49d3e9 | Marc-André Lureau | |
312 | 5a49d3e9 | Marc-André Lureau | return chr;
|
313 | 5a49d3e9 | Marc-André Lureau | } |
314 | afd0b409 | Marc-André Lureau | |
315 | afd0b409 | Marc-André Lureau | void qemu_spice_register_ports(void) |
316 | afd0b409 | Marc-André Lureau | { |
317 | afd0b409 | Marc-André Lureau | SpiceCharDriver *s; |
318 | afd0b409 | Marc-André Lureau | |
319 | afd0b409 | Marc-André Lureau | QLIST_FOREACH(s, &spice_chars, next) { |
320 | afd0b409 | Marc-André Lureau | if (s->sin.portname == NULL) { |
321 | afd0b409 | Marc-André Lureau | continue;
|
322 | afd0b409 | Marc-André Lureau | } |
323 | afd0b409 | Marc-André Lureau | vmc_register_interface(s); |
324 | afd0b409 | Marc-André Lureau | } |
325 | afd0b409 | Marc-André Lureau | } |
326 | 5a49d3e9 | Marc-André Lureau | #endif
|
327 | 26c60614 | Anthony Liguori | |
328 | cd153e2a | Gerd Hoffmann | static void qemu_chr_parse_spice_vmc(QemuOpts *opts, ChardevBackend *backend, |
329 | cd153e2a | Gerd Hoffmann | Error **errp) |
330 | cd153e2a | Gerd Hoffmann | { |
331 | cd153e2a | Gerd Hoffmann | const char *name = qemu_opt_get(opts, "name"); |
332 | cd153e2a | Gerd Hoffmann | |
333 | cd153e2a | Gerd Hoffmann | if (name == NULL) { |
334 | cd153e2a | Gerd Hoffmann | error_setg(errp, "chardev: spice channel: no name given");
|
335 | cd153e2a | Gerd Hoffmann | return;
|
336 | cd153e2a | Gerd Hoffmann | } |
337 | cd153e2a | Gerd Hoffmann | backend->spicevmc = g_new0(ChardevSpiceChannel, 1);
|
338 | cd153e2a | Gerd Hoffmann | backend->spicevmc->type = g_strdup(name); |
339 | cd153e2a | Gerd Hoffmann | } |
340 | cd153e2a | Gerd Hoffmann | |
341 | cd153e2a | Gerd Hoffmann | static void qemu_chr_parse_spice_port(QemuOpts *opts, ChardevBackend *backend, |
342 | cd153e2a | Gerd Hoffmann | Error **errp) |
343 | cd153e2a | Gerd Hoffmann | { |
344 | cd153e2a | Gerd Hoffmann | const char *name = qemu_opt_get(opts, "name"); |
345 | cd153e2a | Gerd Hoffmann | |
346 | cd153e2a | Gerd Hoffmann | if (name == NULL) { |
347 | cd153e2a | Gerd Hoffmann | error_setg(errp, "chardev: spice port: no name given");
|
348 | cd153e2a | Gerd Hoffmann | return;
|
349 | cd153e2a | Gerd Hoffmann | } |
350 | cd153e2a | Gerd Hoffmann | backend->spiceport = g_new0(ChardevSpicePort, 1);
|
351 | cd153e2a | Gerd Hoffmann | backend->spiceport->fqdn = g_strdup(name); |
352 | cd153e2a | Gerd Hoffmann | } |
353 | cd153e2a | Gerd Hoffmann | |
354 | 26c60614 | Anthony Liguori | static void register_types(void) |
355 | 26c60614 | Anthony Liguori | { |
356 | cd153e2a | Gerd Hoffmann | register_char_driver_qapi("spicevmc", CHARDEV_BACKEND_KIND_SPICEVMC,
|
357 | cd153e2a | Gerd Hoffmann | qemu_chr_parse_spice_vmc); |
358 | cd153e2a | Gerd Hoffmann | register_char_driver_qapi("spiceport", CHARDEV_BACKEND_KIND_SPICEPORT,
|
359 | cd153e2a | Gerd Hoffmann | qemu_chr_parse_spice_port); |
360 | 26c60614 | Anthony Liguori | } |
361 | 26c60614 | Anthony Liguori | |
362 | 26c60614 | Anthony Liguori | type_init(register_types); |