diff mbox

[for-1.5,2/4] virtio-serial: fix command line compatibility.

Message ID 1367248365-27260-3-git-send-email-fred.konrad@greensocs.com
State New
Headers show

Commit Message

fred.konrad@greensocs.com April 29, 2013, 3:12 p.m. UTC
From: KONRAD Frederic <fred.konrad@greensocs.com>

The bus name is wrong since the refactoring.

This keep the behaviour of the command line.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/char/virtio-serial-bus.c       | 16 +++++++++++++++-
 hw/s390x/s390-virtio-bus.c        |  8 ++++++++
 hw/s390x/virtio-ccw.c             |  9 +++++++++
 hw/virtio/virtio-pci.c            |  9 +++++++++
 include/hw/virtio/virtio-serial.h |  8 ++++++++
 5 files changed, 49 insertions(+), 1 deletion(-)

Comments

Paolo Bonzini April 29, 2013, 3:45 p.m. UTC | #1
Il 29/04/2013 17:12, fred.konrad@greensocs.com ha scritto:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
> 
> The bus name is wrong since the refactoring.
> 
> This keep the behaviour of the command line.
> 
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
> ---
>  hw/char/virtio-serial-bus.c       | 16 +++++++++++++++-
>  hw/s390x/s390-virtio-bus.c        |  8 ++++++++
>  hw/s390x/virtio-ccw.c             |  9 +++++++++
>  hw/virtio/virtio-pci.c            |  9 +++++++++
>  include/hw/virtio/virtio-serial.h |  8 ++++++++
>  5 files changed, 49 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
> index 3787ad2..0817041 100644
> --- a/hw/char/virtio-serial-bus.c
> +++ b/hw/char/virtio-serial-bus.c
> @@ -889,6 +889,15 @@ static int virtser_port_qdev_exit(DeviceState *qdev)
>      return 0;
>  }
>  
> +void set_virtio_serial_bus_name(DeviceState *dev, const char *bus_name)
> +{
> +    VirtIOSerial *vser = VIRTIO_SERIAL(dev);
> +    if (bus_name) {
> +        vser->bus_name = g_malloc(strlen(bus_name) + 3);
> +        snprintf(vser->bus_name, strlen(bus_name) + 3, "%s.0", bus_name);
> +    }
> +}

Same comment as for virtio-scsi.

Thanks,

Paolo

>  static int virtio_serial_device_init(VirtIODevice *vdev)
>  {
>      DeviceState *qdev = DEVICE(vdev);
> @@ -911,7 +920,8 @@ static int virtio_serial_device_init(VirtIODevice *vdev)
>                  sizeof(struct virtio_console_config));
>  
>      /* Spawn a new virtio-serial bus on which the ports will ride as devices */
> -    qbus_create_inplace(&vser->bus.qbus, TYPE_VIRTIO_SERIAL_BUS, qdev, NULL);
> +    qbus_create_inplace(&vser->bus.qbus, TYPE_VIRTIO_SERIAL_BUS, qdev,
> +                        vser->bus_name);
>      vser->bus.qbus.allow_hotplug = 1;
>      vser->bus.vser = vser;
>      QTAILQ_INIT(&vser->ports);
> @@ -992,6 +1002,10 @@ static int virtio_serial_device_exit(DeviceState *dev)
>  
>      unregister_savevm(dev, "virtio-console", vser);
>  
> +    if (vser->bus_name) {
> +        g_free(vser->bus_name);
> +    }
> +
>      g_free(vser->ivqs);
>      g_free(vser->ovqs);
>      g_free(vser->ports_map);
> diff --git a/hw/s390x/s390-virtio-bus.c b/hw/s390x/s390-virtio-bus.c
> index d52a547..6620d29 100644
> --- a/hw/s390x/s390-virtio-bus.c
> +++ b/hw/s390x/s390-virtio-bus.c
> @@ -200,6 +200,14 @@ static int s390_virtio_serial_init(VirtIOS390Device *s390_dev)
>  
>      bus = DO_UPCAST(VirtIOS390Bus, bus, qdev->parent_bus);
>  
> +    /*
> +     * For command line compatibility, this set the virtio-serial-device bus
> +     * name as before.
> +     */
> +    if (qdev->id) {
> +        set_virtio_serial_bus_name(vdev, qdev->id);
> +    }
> +
>      qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
>      if (qdev_init(vdev) < 0) {
>          return -1;
> diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
> index ef99080..daa94d6 100644
> --- a/hw/s390x/virtio-ccw.c
> +++ b/hw/s390x/virtio-ccw.c
> @@ -593,6 +593,15 @@ static int virtio_ccw_serial_init(VirtioCcwDevice *ccw_dev)
>  {
>      VirtioSerialCcw *dev = VIRTIO_SERIAL_CCW(ccw_dev);
>      DeviceState *vdev = DEVICE(&dev->vdev);
> +    DeviceState *proxy = DEVICE(ccw_dev);
> +
> +    /*
> +     * For command line compatibility, this set the virtio-serial-device bus
> +     * name as before.
> +     */
> +    if (proxy->id) {
> +        set_virtio_serial_bus_name(vdev, proxy->id);
> +    }
>  
>      qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
>      if (qdev_init(vdev) < 0) {
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index 070df44..598876f 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -1297,6 +1297,7 @@ static int virtio_serial_pci_init(VirtIOPCIProxy *vpci_dev)
>  {
>      VirtIOSerialPCI *dev = VIRTIO_SERIAL_PCI(vpci_dev);
>      DeviceState *vdev = DEVICE(&dev->vdev);
> +    DeviceState *proxy = DEVICE(vpci_dev);
>  
>      if (vpci_dev->class_code != PCI_CLASS_COMMUNICATION_OTHER &&
>          vpci_dev->class_code != PCI_CLASS_DISPLAY_OTHER && /* qemu 0.10 */
> @@ -1310,6 +1311,14 @@ static int virtio_serial_pci_init(VirtIOPCIProxy *vpci_dev)
>          vpci_dev->nvectors = dev->vdev.serial.max_virtserial_ports + 1;
>      }
>  
> +    /*
> +     * For command line compatibility, this set the virtio-serial-device bus
> +     * name as before.
> +     */
> +    if (proxy->id) {
> +        set_virtio_serial_bus_name(vdev, proxy->id);
> +    }
> +
>      qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
>      if (qdev_init(vdev) < 0) {
>          return -1;
> diff --git a/include/hw/virtio/virtio-serial.h b/include/hw/virtio/virtio-serial.h
> index 1d2040b..786e76b 100644
> --- a/include/hw/virtio/virtio-serial.h
> +++ b/include/hw/virtio/virtio-serial.h
> @@ -194,6 +194,9 @@ typedef struct VirtIOSerialPostLoad {
>  struct VirtIOSerial {
>      VirtIODevice parent_obj;
>  
> +    /* bus_name, for command line compatibility */
> +    char *bus_name;
> +
>      VirtQueue *c_ivq, *c_ovq;
>      /* Arrays of ivqs and ovqs: one per port */
>      VirtQueue **ivqs, **ovqs;
> @@ -244,6 +247,11 @@ size_t virtio_serial_guest_ready(VirtIOSerialPort *port);
>   */
>  void virtio_serial_throttle_port(VirtIOSerialPort *port, bool throttle);
>  
> +/*
> + * For command line back compatibility, set the bus name before initialisation.
> + */
> +void set_virtio_serial_bus_name(DeviceState *dev, const char *bus_name);
> +
>  #define TYPE_VIRTIO_SERIAL "virtio-serial-device"
>  #define VIRTIO_SERIAL(obj) \
>          OBJECT_CHECK(VirtIOSerial, (obj), TYPE_VIRTIO_SERIAL)
>
diff mbox

Patch

diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index 3787ad2..0817041 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -889,6 +889,15 @@  static int virtser_port_qdev_exit(DeviceState *qdev)
     return 0;
 }
 
+void set_virtio_serial_bus_name(DeviceState *dev, const char *bus_name)
+{
+    VirtIOSerial *vser = VIRTIO_SERIAL(dev);
+    if (bus_name) {
+        vser->bus_name = g_malloc(strlen(bus_name) + 3);
+        snprintf(vser->bus_name, strlen(bus_name) + 3, "%s.0", bus_name);
+    }
+}
+
 static int virtio_serial_device_init(VirtIODevice *vdev)
 {
     DeviceState *qdev = DEVICE(vdev);
@@ -911,7 +920,8 @@  static int virtio_serial_device_init(VirtIODevice *vdev)
                 sizeof(struct virtio_console_config));
 
     /* Spawn a new virtio-serial bus on which the ports will ride as devices */
-    qbus_create_inplace(&vser->bus.qbus, TYPE_VIRTIO_SERIAL_BUS, qdev, NULL);
+    qbus_create_inplace(&vser->bus.qbus, TYPE_VIRTIO_SERIAL_BUS, qdev,
+                        vser->bus_name);
     vser->bus.qbus.allow_hotplug = 1;
     vser->bus.vser = vser;
     QTAILQ_INIT(&vser->ports);
@@ -992,6 +1002,10 @@  static int virtio_serial_device_exit(DeviceState *dev)
 
     unregister_savevm(dev, "virtio-console", vser);
 
+    if (vser->bus_name) {
+        g_free(vser->bus_name);
+    }
+
     g_free(vser->ivqs);
     g_free(vser->ovqs);
     g_free(vser->ports_map);
diff --git a/hw/s390x/s390-virtio-bus.c b/hw/s390x/s390-virtio-bus.c
index d52a547..6620d29 100644
--- a/hw/s390x/s390-virtio-bus.c
+++ b/hw/s390x/s390-virtio-bus.c
@@ -200,6 +200,14 @@  static int s390_virtio_serial_init(VirtIOS390Device *s390_dev)
 
     bus = DO_UPCAST(VirtIOS390Bus, bus, qdev->parent_bus);
 
+    /*
+     * For command line compatibility, this set the virtio-serial-device bus
+     * name as before.
+     */
+    if (qdev->id) {
+        set_virtio_serial_bus_name(vdev, qdev->id);
+    }
+
     qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
     if (qdev_init(vdev) < 0) {
         return -1;
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index ef99080..daa94d6 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -593,6 +593,15 @@  static int virtio_ccw_serial_init(VirtioCcwDevice *ccw_dev)
 {
     VirtioSerialCcw *dev = VIRTIO_SERIAL_CCW(ccw_dev);
     DeviceState *vdev = DEVICE(&dev->vdev);
+    DeviceState *proxy = DEVICE(ccw_dev);
+
+    /*
+     * For command line compatibility, this set the virtio-serial-device bus
+     * name as before.
+     */
+    if (proxy->id) {
+        set_virtio_serial_bus_name(vdev, proxy->id);
+    }
 
     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
     if (qdev_init(vdev) < 0) {
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 070df44..598876f 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -1297,6 +1297,7 @@  static int virtio_serial_pci_init(VirtIOPCIProxy *vpci_dev)
 {
     VirtIOSerialPCI *dev = VIRTIO_SERIAL_PCI(vpci_dev);
     DeviceState *vdev = DEVICE(&dev->vdev);
+    DeviceState *proxy = DEVICE(vpci_dev);
 
     if (vpci_dev->class_code != PCI_CLASS_COMMUNICATION_OTHER &&
         vpci_dev->class_code != PCI_CLASS_DISPLAY_OTHER && /* qemu 0.10 */
@@ -1310,6 +1311,14 @@  static int virtio_serial_pci_init(VirtIOPCIProxy *vpci_dev)
         vpci_dev->nvectors = dev->vdev.serial.max_virtserial_ports + 1;
     }
 
+    /*
+     * For command line compatibility, this set the virtio-serial-device bus
+     * name as before.
+     */
+    if (proxy->id) {
+        set_virtio_serial_bus_name(vdev, proxy->id);
+    }
+
     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
     if (qdev_init(vdev) < 0) {
         return -1;
diff --git a/include/hw/virtio/virtio-serial.h b/include/hw/virtio/virtio-serial.h
index 1d2040b..786e76b 100644
--- a/include/hw/virtio/virtio-serial.h
+++ b/include/hw/virtio/virtio-serial.h
@@ -194,6 +194,9 @@  typedef struct VirtIOSerialPostLoad {
 struct VirtIOSerial {
     VirtIODevice parent_obj;
 
+    /* bus_name, for command line compatibility */
+    char *bus_name;
+
     VirtQueue *c_ivq, *c_ovq;
     /* Arrays of ivqs and ovqs: one per port */
     VirtQueue **ivqs, **ovqs;
@@ -244,6 +247,11 @@  size_t virtio_serial_guest_ready(VirtIOSerialPort *port);
  */
 void virtio_serial_throttle_port(VirtIOSerialPort *port, bool throttle);
 
+/*
+ * For command line back compatibility, set the bus name before initialisation.
+ */
+void set_virtio_serial_bus_name(DeviceState *dev, const char *bus_name);
+
 #define TYPE_VIRTIO_SERIAL "virtio-serial-device"
 #define VIRTIO_SERIAL(obj) \
         OBJECT_CHECK(VirtIOSerial, (obj), TYPE_VIRTIO_SERIAL)