From 6ecbd9a477c002a309ae3c1785a9449bde7234e3 Mon Sep 17 00:00:00 2001 From: Amit Shah Date: Tue, 19 Aug 2014 10:09:24 +0200 Subject: [PATCH 2/4] virtio-serial: create a linked list of all active devices Message-id: <7f2c1dccc51dae825c74066ef090cd3083ee068f.1408441426.git.amit.shah@redhat.com> Patchwork-id: 60624 O-Subject: [PATCH qemu-kvm-rhev RHEV7.1 1/2] virtio-serial: create a linked list of all active devices Bugzilla: 1003432 RH-Acked-by: Laszlo Ersek RH-Acked-by: Amos Kong RH-Acked-by: Markus Armbruster To ensure two virtserialports don't get added to the system with the same 'name' parameter, we need to access all the ports on all the devices added, and compare the names. We currently don't have a list of all VirtIOSerial devices added to the system. This commit adds a simple linked list in which devices are put when they're initialized, and removed when they go away. Signed-off-by: Amit Shah Reviewed-by: Markus Armbruster (cherry picked from commit a1857ad1acbddbefe7ce8adb24b0e40991c5c38f) Signed-off-by: Amit Shah --- hw/char/virtio-serial-bus.c | 10 ++++++++++ include/hw/virtio/virtio-serial.h | 2 ++ 2 files changed, 12 insertions(+) Signed-off-by: Miroslav Rezanina --- hw/char/virtio-serial-bus.c | 10 ++++++++++ include/hw/virtio/virtio-serial.h | 2 ++ 2 files changed, 12 insertions(+), 0 deletions(-) diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c index 23123b7..49a9867 100644 --- a/hw/char/virtio-serial-bus.c +++ b/hw/char/virtio-serial-bus.c @@ -26,6 +26,10 @@ #include "hw/virtio/virtio-serial.h" #include "hw/virtio/virtio-access.h" +struct VirtIOSerialDevices { + QLIST_HEAD(, VirtIOSerial) devices; +} vserdevices; + static VirtIOSerialPort *find_port_by_id(VirtIOSerial *vser, uint32_t id) { VirtIOSerialPort *port; @@ -983,6 +987,8 @@ static void virtio_serial_device_realize(DeviceState *dev, Error **errp) */ register_savevm(dev, "virtio-console", -1, 3, virtio_serial_save, virtio_serial_load, vser); + + QLIST_INSERT_HEAD(&vserdevices.devices, vser, next); } static void virtio_serial_port_class_init(ObjectClass *klass, void *data) @@ -1011,6 +1017,8 @@ static void virtio_serial_device_unrealize(DeviceState *dev, Error **errp) VirtIODevice *vdev = VIRTIO_DEVICE(dev); VirtIOSerial *vser = VIRTIO_SERIAL(dev); + QLIST_REMOVE(vser, next); + unregister_savevm(dev, "virtio-console", vser); g_free(vser->ivqs); @@ -1035,6 +1043,8 @@ static void virtio_serial_class_init(ObjectClass *klass, void *data) DeviceClass *dc = DEVICE_CLASS(klass); VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); + QLIST_INIT(&vserdevices.devices); + dc->props = virtio_serial_properties; set_bit(DEVICE_CATEGORY_INPUT, dc->categories); vdc->realize = virtio_serial_device_realize; diff --git a/include/hw/virtio/virtio-serial.h b/include/hw/virtio/virtio-serial.h index 4746312..a679e54 100644 --- a/include/hw/virtio/virtio-serial.h +++ b/include/hw/virtio/virtio-serial.h @@ -202,6 +202,8 @@ struct VirtIOSerial { QTAILQ_HEAD(, VirtIOSerialPort) ports; + QLIST_ENTRY(VirtIOSerial) next; + /* bitmap for identifying active ports */ uint32_t *ports_map; -- 1.7.1