[Spice-commits] Branch 'spice.kvm.v14' - 2 commits - hw/spice-vdi.c hw/spice-vmc.c

Alon Levy alon at kemper.freedesktop.org
Tue Aug 31 01:37:27 PDT 2010


 hw/spice-vdi.c |   18 +++++++++-------
 hw/spice-vmc.c |   61 ++++++++++++++++++++++++++++++++++++++++++++++-----------
 2 files changed, 60 insertions(+), 19 deletions(-)

New commits:
commit ec545d35e836715961f33abb4cc68d16265fe080
Author: Alon Levy <alevy at redhat.com>
Date:   Tue Aug 31 10:52:28 2010 +0300

    spice-{vmc,vdi}: implement subtype

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 b3410c0..434c70f 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;
@@ -172,18 +173,55 @@ static void vmc_have_data(VirtIOSerialPort *port, const uint8_t *buf, size_t len
     spice_server_char_device_wakeup(&svc->sin);
 }
 
+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;
 }
@@ -212,6 +250,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(),
     }
 };
commit 3a80db1a2927009c5c95c8268cf842fa257c97bb
Author: Alon Levy <alevy at redhat.com>
Date:   Tue Aug 31 10:49:37 2010 +0300

    spice-{vdi,vmc}: rename SpiceVDIPort* to SpiceCharDevice*

diff --git a/hw/spice-vdi.c b/hw/spice-vdi.c
index 23cbbe1..415932b 100644
--- a/hw/spice-vdi.c
+++ b/hw/spice-vdi.c
@@ -104,7 +104,7 @@ typedef struct PCIVDIPortDevice {
     int running;
     int new_gen_on_resume;
     int active_interface;
-    SpiceVDIPortInstance sin;
+    SpiceCharDeviceInstance sin;
     int plug_read_pos;
 } PCIVDIPortDevice;
 
@@ -178,7 +178,7 @@ static void vdi_port_notify_guest(PCIVDIPortDevice *d)
     vdi_port_set_dirty(d, &d->ram->int_pending, sizeof(d->ram->int_pending));
 }
 
-static int vdi_port_interface_write(SpiceVDIPortInstance *sin,
+static int vdi_port_interface_write(SpiceCharDeviceInstance *sin,
                                     const uint8_t *buf, int len)
 {
     PCIVDIPortDevice *d = container_of(sin, PCIVDIPortDevice, sin);
@@ -224,7 +224,7 @@ static int vdi_port_interface_write(SpiceVDIPortInstance *sin,
     return actual_write;
 }
 
-static int vdi_port_interface_read(SpiceVDIPortInstance *sin,
+static int vdi_port_interface_read(SpiceCharDeviceInstance *sin,
                                    uint8_t *buf, int len)
 {
     PCIVDIPortDevice *d = container_of(sin, PCIVDIPortDevice, sin);
@@ -290,11 +290,11 @@ static int vdi_port_interface_read(SpiceVDIPortInstance *sin,
     return actual_read;
 }
 
-static SpiceVDIPortInterface vdi_port_interface = {
-    .base.type          = SPICE_INTERFACE_VDI_PORT,
+static SpiceCharDeviceInterface vdi_port_interface = {
+    .base.type          = SPICE_INTERFACE_CHAR_DEVICE,
     .base.description   = "vdi port",
-    .base.major_version = SPICE_INTERFACE_VDI_PORT_MAJOR,
-    .base.minor_version = SPICE_INTERFACE_VDI_PORT_MINOR,
+    .base.major_version = SPICE_INTERFACE_CHAR_DEVICE_MAJOR,
+    .base.minor_version = SPICE_INTERFACE_CHAR_DEVICE_MINOR,
 
     .write              = vdi_port_interface_write,
     .read               = vdi_port_interface_read,
@@ -354,7 +354,7 @@ static void vdi_port_dev_disconnect(PCIVDIPortDevice *d)
 
 static void vdi_port_dev_notify(PCIVDIPortDevice *d)
 {
-    spice_server_vdi_port_wakeup(&d->sin);
+    spice_server_char_device_wakeup(&d->sin);
 }
 
 static void vdi_port_write_dword(void *opaque, uint32_t addr, uint32_t val)
diff --git a/hw/spice-vmc.c b/hw/spice-vmc.c
index 2ddecf4..b3410c0 100644
--- a/hw/spice-vmc.c
+++ b/hw/spice-vmc.c
@@ -35,7 +35,7 @@
 typedef struct SpiceVirtualChannel {
     VirtIOSerialPort      port;
     VMChangeStateEntry    *vmstate;
-    SpiceVDIPortInstance  sin;
+    SpiceCharDeviceInstance  sin;
     bool                  active;
     uint8_t               *buffer;
     uint8_t               *datapos;
@@ -43,7 +43,7 @@ typedef struct SpiceVirtualChannel {
     uint32_t              debug;
 } SpiceVirtualChannel;
 
-static int vmc_write(SpiceVDIPortInstance *sin, const uint8_t *buf, int len)
+static int vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len)
 {
     SpiceVirtualChannel *svc = container_of(sin, SpiceVirtualChannel, sin);
     ssize_t out = 0;
@@ -66,7 +66,7 @@ static int vmc_write(SpiceVDIPortInstance *sin, const uint8_t *buf, int len)
     return out;
 }
 
-static int vmc_read(SpiceVDIPortInstance *sin, uint8_t *buf, int len)
+static int vmc_read(SpiceCharDeviceInstance *sin, uint8_t *buf, int len)
 {
     SpiceVirtualChannel *svc = container_of(sin, SpiceVirtualChannel, sin);
     int bytes = MIN(len, svc->datalen);
@@ -86,11 +86,11 @@ static int vmc_read(SpiceVDIPortInstance *sin, uint8_t *buf, int len)
     return bytes;
 }
 
-static SpiceVDIPortInterface vmc_interface = {
-    .base.type          = SPICE_INTERFACE_VDI_PORT,
-    .base.description   = "spice virtual channel vdi port",
-    .base.major_version = SPICE_INTERFACE_VDI_PORT_MAJOR,
-    .base.minor_version = SPICE_INTERFACE_VDI_PORT_MINOR,
+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,
     .write              = vmc_write,
     .read               = vmc_read,
 };
@@ -122,7 +122,7 @@ static void vmc_change_state_handler(void *opaque, int running, int reason)
     SpiceVirtualChannel *svc = opaque;
 
     if (running && svc->active) {
-        spice_server_vdi_port_wakeup(&svc->sin);
+        spice_server_char_device_wakeup(&svc->sin);
     }
 }
 
@@ -152,7 +152,7 @@ static void vmc_guest_ready(VirtIOSerialPort *port)
 
     dprintf(svc, 1, "%s\n", __func__);
     if (svc->active)
-        spice_server_vdi_port_wakeup(&svc->sin);
+        spice_server_char_device_wakeup(&svc->sin);
 }
 
 static void vmc_have_data(VirtIOSerialPort *port, const uint8_t *buf, size_t len)
@@ -169,7 +169,7 @@ static void vmc_have_data(VirtIOSerialPort *port, const uint8_t *buf, size_t len
     svc->datapos = svc->buffer;
     svc->datalen = len;
     virtio_serial_throttle_port(&svc->port, true);
-    spice_server_vdi_port_wakeup(&svc->sin);
+    spice_server_char_device_wakeup(&svc->sin);
 }
 
 static int vmc_initfn(VirtIOSerialDevice *dev)


More information about the Spice-commits mailing list