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

Alon Levy alevy at redhat.com
Thu Aug 26 01:46:34 PDT 2010


---
 hw/spice-vdi.c |    6 ++++++
 hw/spice-vmc.c |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/hw/spice-vdi.c b/hw/spice-vdi.c
index 415932b..f5fda4d 100644
--- a/hw/spice-vdi.c
+++ b/hw/spice-vdi.c
@@ -290,12 +290,18 @@ static int vdi_port_interface_read(SpiceCharDeviceInstance *sin,
     return actual_read;
 }
 
+static const char* vdi_port_subtype(SpiceCharDeviceInstance* sin)
+{
+    return "vdagent";
+}
+
 static SpiceCharDeviceInterface vdi_port_interface = {
     .base.type          = SPICE_INTERFACE_CHAR_DEVICE,
     .base.description   = "vdi port",
     .base.major_version = SPICE_INTERFACE_CHAR_DEVICE_MAJOR,
     .base.minor_version = SPICE_INTERFACE_CHAR_DEVICE_MINOR,
 
+    .subtype            = vdi_port_subtype,
     .write              = vdi_port_interface_write,
     .read               = vdi_port_interface_read,
 };
diff --git a/hw/spice-vmc.c b/hw/spice-vmc.c
index c58799e..b09be7a 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;
@@ -86,11 +87,20 @@ static int vmc_read(SpiceCharDeviceInstance *sin, uint8_t *buf, int len)
     return bytes;
 }
 
+static const char* vmc_subtype(SpiceCharDeviceInstance* sin)
+{
+    SpiceVirtualChannel *scd = container_of(sin, SpiceVirtualChannel, sin);
+
+    dprintf(scd, 2, "%s\n", __func__);
+    return scd->subtype;
+}
+
 static SpiceCharDeviceInterface vmc_interface = {
     .base.type          = SPICE_INTERFACE_CHAR_DEVICE,
     .base.description   = "spice virtual channel char device",
     .base.major_version = SPICE_INTERFACE_CHAR_DEVICE_MAJOR,
     .base.minor_version = SPICE_INTERFACE_CHAR_DEVICE_MINOR,
+    .subtype            = vmc_subtype,
     .write              = vmc_write,
     .read               = vmc_read,
 };
@@ -181,15 +191,51 @@ 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);
@@ -222,6 +268,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