[Spice-devel] [PATCH v3] spice-{vmc,vdi}: implement subtype

Alon Levy alevy at redhat.com
Thu Aug 26 07:28:32 PDT 2010


v3 changes:
 subtype is now a field of SpiceCharDeviceInstance

btw, there shouldn't be a newline added before vdi_port_interface,
but I can't get git diff to admit there isn't one there. I'll make
sure there isn't one in the committed version.

---
 hw/spice-vdi.c |    2 ++
 hw/spice-vmc.c |   39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/hw/spice-vdi.c b/hw/spice-vdi.c
index 415932b..cd7594f 100644
--- a/hw/spice-vdi.c
+++ b/hw/spice-vdi.c
@@ -290,6 +290,7 @@ static int vdi_port_interface_read(SpiceCharDeviceInstance *sin,
     return actual_read;
 }
 
+
 static SpiceCharDeviceInterface vdi_port_interface = {
     .base.type          = SPICE_INTERFACE_CHAR_DEVICE,
     .base.description   = "vdi port",
@@ -505,6 +506,7 @@ static int vdi_port_init(PCIDevice *dev)
     vdi->ram_size = ram_size;
     vdi->new_gen_on_resume = false;
     vdi->running = false;
+    vdi->sin.subtype = "vdagent";
 
     pci_config_set_vendor_id(config, REDHAT_PCI_VENDOR_ID);
     pci_config_set_device_id(config, VDI_PORT_DEVICE_ID);
diff --git a/hw/spice-vmc.c b/hw/spice-vmc.c
index c58799e..0c3a834 100644
--- a/hw/spice-vmc.c
+++ b/hw/spice-vmc.c
@@ -36,6 +36,7 @@ typedef struct SpiceVirtualChannel {
     VirtIOSerialPort      port;
     VMChangeStateEntry    *vmstate;
     SpiceCharDeviceInstance  sin;
+    char                  *subtype;
     bool                  active;
     uint8_t               *buffer;
     uint8_t               *datapos;
@@ -181,18 +182,55 @@ static void vmc_reset(DeviceState *opaque)
     vmc_unregister_interface(svc);
 }
 
+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, *psubtype);
+        } else {
+            fprintf(stderr, ", %s", *psubtype);
+        }
+    }
+    fprintf(stderr, "\n");
+}
+
 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) {
+        fprintf(stderr, "spice-vmc: you must supply a subtype\n");
+        vmc_print_optional_subtypes();
+        return -1;
+    }
+
+    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;
 }
@@ -222,6 +260,7 @@ static VirtIOSerialPortInfo vmc_info = {
     .qdev.props = (Property[]) {
         DEFINE_PROP_UINT32("nr", SpiceVirtualChannel, port.id, VIRTIO_CONSOLE_BAD_ID),
         DEFINE_PROP_UINT32("debug", SpiceVirtualChannel, debug, 1),
+        DEFINE_PROP_STRING("subtype", SpiceVirtualChannel, subtype),
         DEFINE_PROP_END_OF_LIST(),
     }
 };
-- 
1.7.2



More information about the Spice-devel mailing list