static int vmc_initfn(VirtIOSerialDevice *dev) { VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, &dev->qdev); SpiceVirtualChannel *svc = DO_UPCAST(SpiceVirtualChannel, port, port); const char** psubtype = spice_server_char_device_recognized_subtypes(); const char *subtype = NULL; if (!using_spice) { return -1; } dprintf(svc, 1, "%s\n", __func__); if (svc->subtype == NULL) { svc->subtype = strdup("vdagent"); } for(;*psubtype != NULL; ++psubtype) { if (strcmp(svc->subtype, *psubtype) == 0) { subtype = *psubtype; break; } } if (subtype == NULL) { fprintf(stderr, "spice-vmc: unsupported subtype\n"); vmc_print_optional_subtypes(); return -1; } port->name = qemu_strdup(VMC_GUEST_DEVICE_NAME); svc->vmstate = qemu_add_vm_change_state_handler (vmc_change_state_handler, svc); svc->sin.subtype = svc->subtype; virtio_serial_open(port); return 0; }
static void vmc_print_optional_subtypes(void) { const char** psubtype = spice_server_char_device_recognized_subtypes(); int i; fprintf(stderr, "supported subtypes: "); for(i=0; *psubtype != NULL; ++psubtype, ++i) { if (i == 0) { fprintf(stderr, "%s", *psubtype); } else { fprintf(stderr, ", %s", *psubtype); } } fprintf(stderr, "\n"); }
static void print_allowed_subtypes(void) { const char** psubtype; int i; fprintf(stderr, "allowed names: "); for(i=0, psubtype = spice_server_char_device_recognized_subtypes(); *psubtype != NULL; ++psubtype, ++i) { if (i == 0) { fprintf(stderr, "%s", *psubtype); } else { fprintf(stderr, ", %s", *psubtype); } } fprintf(stderr, "\n"); }
CharDriverState *qemu_chr_open_spice(QemuOpts *opts) { CharDriverState *chr; SpiceCharDriver *s; const char* name = qemu_opt_get(opts, "name"); uint32_t debug = qemu_opt_get_number(opts, "debug", 0); const char** psubtype = spice_server_char_device_recognized_subtypes(); const char *subtype = NULL; if (name == NULL) { fprintf(stderr, "spice-qemu-char: missing name parameter\n"); print_allowed_subtypes(); return NULL; } for(;*psubtype != NULL; ++psubtype) { if (strcmp(name, *psubtype) == 0) { subtype = *psubtype; break; } } if (subtype == NULL) { fprintf(stderr, "spice-qemu-char: unsupported name: %s\n", name); print_allowed_subtypes(); return NULL; } chr = g_malloc0(sizeof(CharDriverState)); s = g_malloc0(sizeof(SpiceCharDriver)); s->chr = chr; s->debug = debug; s->active = false; s->sin.subtype = subtype; chr->opaque = s; chr->chr_write = spice_chr_write; chr->chr_close = spice_chr_close; chr->chr_guest_open = spice_chr_guest_open; chr->chr_guest_close = spice_chr_guest_close; #if SPICE_SERVER_VERSION < 0x000901 /* See comment in vmc_state() */ if (strcmp(subtype, "vdagent") == 0) { qemu_chr_generic_open(chr); } #endif return chr; }
CharDriverState *qemu_chr_open_spice_vmc(const char *type) { CharDriverState *chr; SpiceCharDriver *s; const char **psubtype = spice_server_char_device_recognized_subtypes(); if (type == NULL) { fprintf(stderr, "spice-qemu-char: missing name parameter\n"); print_allowed_subtypes(); return NULL; } for (; *psubtype != NULL; ++psubtype) { if (strcmp(type, *psubtype) == 0) { break; } } if (*psubtype == NULL) { fprintf(stderr, "spice-qemu-char: unsupported type: %s\n", type); print_allowed_subtypes(); return NULL; } chr = qemu_mallocz(sizeof(CharDriverState)); s = qemu_mallocz(sizeof(SpiceCharDriver)); s->chr = chr; s->active = false; s->sin.subtype = *psubtype; chr->opaque = s; chr->chr_write = spice_chr_write; chr->chr_add_watch = spice_chr_add_watch; chr->chr_close = spice_chr_close; chr->chr_guest_open = spice_chr_guest_open; chr->chr_guest_close = spice_chr_guest_close; #if SPICE_SERVER_VERSION < 0x000901 /* See comment in vmc_state() */ if (strcmp(type, "vdagent") == 0) { qemu_chr_generic_open(chr); } #endif return chr; }