[Spice-devel] [RFC 2/2] qemu, spice-vmc, vdi: update to use SpiceCharDevice* instead of SpiceVDIPort*
Alon Levy
alevy at redhat.com
Wed Aug 25 03:54:03 PDT 2010
---
hw/spice-vdi.c | 22 ++++++++++++++--------
hw/spice-vmc.c | 39 ++++++++++++++++++++++++++++-----------
2 files changed, 42 insertions(+), 19 deletions(-)
diff --git a/hw/spice-vdi.c b/hw/spice-vdi.c
index 23cbbe1..b2ea54a 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,12 +290,18 @@ static int vdi_port_interface_read(SpiceVDIPortInstance *sin,
return actual_read;
}
-static SpiceVDIPortInterface vdi_port_interface = {
- .base.type = SPICE_INTERFACE_VDI_PORT,
+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_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,
+ .subtype = vdi_port_subtype,
.write = vdi_port_interface_write,
.read = vdi_port_interface_read,
};
@@ -354,7 +360,7 @@ static void vdi_port_dev_disconnect(PCIVDIPortDevice *d)
static void vdi_port_dev_notify(PCIVDIPortDevice *d)
{
- spice_server_vdi_port_wakeup(&d->sin);
+ (*d->sin.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 fad3bdd..23ee87b 100644
--- a/hw/spice-vmc.c
+++ b/hw/spice-vmc.c
@@ -35,7 +35,8 @@
typedef struct SpiceVirtualChannel {
VirtIOSerialPort port;
VMChangeStateEntry *vmstate;
- SpiceVDIPortInstance sin;
+ SpiceCharDeviceInstance sin;
+ char *subtype;
bool active;
uint8_t *buffer;
uint8_t *datapos;
@@ -43,7 +44,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 +67,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 +87,20 @@ 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 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,
};
@@ -122,7 +132,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);
+ (*svc->sin.wakeup)(&svc->sin);
}
}
@@ -152,7 +162,7 @@ static void vmc_guest_ready(VirtIOSerialPort *port)
dprintf(svc, 1, "%s\n", __func__);
if (svc->active)
- spice_server_vdi_port_wakeup(&svc->sin);
+ (*svc->sin.wakeup)(&svc->sin);
}
static void vmc_have_data(VirtIOSerialPort *port, const uint8_t *buf, size_t len)
@@ -169,7 +179,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);
+ (*svc->sin.wakeup)(&svc->sin);
}
static void vmc_reset(void *opaque)
@@ -189,6 +199,12 @@ static int vmc_initfn(VirtIOSerialDevice *dev)
return -1;
dprintf(svc, 1, "%s\n", __func__);
+ if (!spice_server_char_device_recognized_subtype(svc->subtype)) {
+ fprintf(stderr, "spice-vmc: unsupported subtype\n");
+ fprintf(stderr, "supported subtypes: %s\n",
+ spice_server_char_device_supported_subtypes());
+ return 0;
+ }
port->name = qemu_strdup(VMC_GUEST_DEVICE_NAME);
svc->vmstate = qemu_add_vm_change_state_handler(
vmc_change_state_handler, svc);
@@ -221,6 +237,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