Skip to contentSkip to conversation

virtio-net: fix netclient id and type.

PATCH Applied [email protected] 3 participants 7 messages May 15, 2013 – May 16, 2013

lore
Share & tools
lore
#0 lore raw

cover virtio-net: fix netclient id and type.

From: KONRAD Frederic <[email protected]>

This fixes this bug: https://bugs.launchpad.net/qemu/+bug/1179357

The name, and the type is replaced by virtio-net-x's id and virtio-net-x's type to restore the behaviour of "info network" command.

Thanks,
Fred

KONRAD Frederic (2):
virtio-net: add virtio_net_set_netclient_name.
virtio-net-x: forward the netclient name and type.

 hw/net/virtio-net.c            | 45 ++++++++++++++++++++++++++++++++++++++++--
 hw/s390x/s390-virtio-bus.c     |  3 +++
 hw/s390x/virtio-ccw.c          |  3 +++
 hw/virtio/virtio-pci.c         |  3 +++
 include/hw/virtio/virtio-net.h |  4 ++++
 5 files changed, 56 insertions(+), 2 deletions(-)
Signature · 1 line
1.7.11.7
#1 lore raw

PATCH 1/2 virtio-net: add virtio_net_set_netclient_name.

From: KONRAD Frederic <[email protected]>

This adds virtio_net_set_netclient_name, which is used to set the name and type shown in "info network" command.

---
 hw/net/virtio-net.c            | 45 ++++++++++++++++++++++++++++++++++++++++--
 include/hw/virtio/virtio-net.h |  4 ++++
 2 files changed, 47 insertions(+), 2 deletions(-)
hw/net/virtio-net.c +43 -2
index 9f18d6a..bed0822 100644
@@ -1275,6 +1275,29 @@ void virtio_net_set_config_size(VirtIONet *n, uint32_t host_features)
     n->config_size = config_size;
 }
 
+void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
+                                   const char *type)
+{
+    /*
+     * The name can be NULL, the netclient name will be type.x.
+     */
+    assert(type != NULL);
+
+    if (n->netclient_name) {
+        g_free(n->netclient_name);
+        n->netclient_name = NULL;
+    }
+    if (n->netclient_type) {
+        g_free(n->netclient_type);
+        n->netclient_type = NULL;
+    }
+
+    if (name != NULL) {
+        n->netclient_name = g_strdup(name);
+    }
+    n->netclient_type = g_strdup(type);
+}
+
 static int virtio_net_device_init(VirtIODevice *vdev)
 {
     int i;
@@ -1315,8 +1338,17 @@ static int virtio_net_device_init(VirtIODevice *vdev)
     memcpy(&n->mac[0], &n->nic_conf.macaddr, sizeof(n->mac));
     n->status = VIRTIO_NET_S_LINK_UP;
 
-    n->nic = qemu_new_nic(&net_virtio_info, &n->nic_conf,
-                          object_get_typename(OBJECT(qdev)), qdev->id, n);
+    if (n->netclient_type) {
+        /*
+         * Happen when virtio_net_set_netclient_name has been called.
+         */
+        n->nic = qemu_new_nic(&net_virtio_info, &n->nic_conf,
+                              n->netclient_type, n->netclient_name, n);
+    } else {
+        n->nic = qemu_new_nic(&net_virtio_info, &n->nic_conf,
+                              object_get_typename(OBJECT(qdev)), qdev->id, n);
+    }
+
     peer_test_vnet_hdr(n);
     if (peer_has_vnet_hdr(n)) {
         for (i = 0; i < n->max_queues; i++) {
@@ -1357,6 +1389,15 @@ static int virtio_net_device_exit(DeviceState *qdev)
 
     unregister_savevm(qdev, "virtio-net", n);
 
+    if (n->netclient_name) {
+        g_free(n->netclient_name);
+        n->netclient_name = NULL;
+    }
+    if (n->netclient_type) {
+        g_free(n->netclient_type);
+        n->netclient_type = NULL;
+    }
+
     g_free(n->mac_table.macs);
     g_free(n->vlans);
 
include/hw/virtio/virtio-net.h +4 -0
index ce4ab50..beeead7 100644
@@ -188,6 +188,8 @@ typedef struct VirtIONet {
     uint16_t max_queues;
     uint16_t curr_queues;
     size_t config_size;
+    char *netclient_name;
+    char *netclient_type;
 } VirtIONet;
 
 #define VIRTIO_NET_CTRL_MAC    1
@@ -255,5 +257,7 @@ struct virtio_net_ctrl_mq {
     DEFINE_PROP_STRING("tx", _state, _field.tx)
 
 void virtio_net_set_config_size(VirtIONet *n, uint32_t host_features);
+void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
+                                   const char *type);
 
 #endif
Signature · 1 line
1.7.11.7
#2 lore raw

Re: [Qemu-devel] [PATCH for-1.5 1/2] virtio-net: add virtio_net_set_netclient_name.

Quoted 6 lines · On Wed, May 15, 2013 at 02:12:49PM +0200, [email protected] wrote:
hw/net/virtio-net.c +0 -2
@@ -1315,8 +1338,17 @@ static int virtio_net_device_init(VirtIODevice *vdev)
     memcpy(&n->mac[0], &n->nic_conf.macaddr, sizeof(n->mac));
     n->status = VIRTIO_NET_S_LINK_UP;
 
-    n->nic = qemu_new_nic(&net_virtio_info, &n->nic_conf,
-                          object_get_typename(OBJECT(qdev)), qdev->id, n);

hw/net/virtio-net.c static int virtio_net_device_init(VirtIODevice *vdev) · line 1350

Quoted 10 lines
hw/net/virtio-net.c +10 -0
+    if (n->netclient_type) {
+        /*
+         * Happen when virtio_net_set_netclient_name has been called.
+         */
+        n->nic = qemu_new_nic(&net_virtio_info, &n->nic_conf,
+                              n->netclient_type, n->netclient_name, n);
+    } else {
+        n->nic = qemu_new_nic(&net_virtio_info, &n->nic_conf,
+                              object_get_typename(OBJECT(qdev)), qdev->id, n);
+    }

Does the 'else' case ever happen? In the next patch you update all callers to invoke virtio_net_set_netclient_name().

#3 lore raw

Re: [Qemu-devel] [PATCH for-1.5 1/2] virtio-net: add virtio_net_set_netclient_name.

Quoted 5 lines · Stefan Hajnoczi
Quoted 4 lines · On Wed, May 15, 2013 at 02:12:49PM +0200, [email protected] wrote:
hw/net/virtio-net.c +0 -0
@@ -1315,8 +1338,17 @@ static int virtio_net_device_init(VirtIODevice *vdev)
      memcpy(&n->mac[0], &n->nic_conf.macaddr, sizeof(n->mac));
      n->status = VIRTIO_NET_S_LINK_UP;
 
Quoted 15 lines

hw/net/virtio-net.c static int virtio_net_device_init(VirtIODevice *vdev) · line 1350

Quoted 12 lines
hw/net/virtio-net.c +10 -2
-    n->nic = qemu_new_nic(&net_virtio_info, &n->nic_conf,
-                          object_get_typename(OBJECT(qdev)), qdev->id, n);
+    if (n->netclient_type) {
+        /*
+         * Happen when virtio_net_set_netclient_name has been called.
+         */
+        n->nic = qemu_new_nic(&net_virtio_info, &n->nic_conf,
+                              n->netclient_type, n->netclient_name, n);
+    } else {
+        n->nic = qemu_new_nic(&net_virtio_info, &n->nic_conf,
+                              object_get_typename(OBJECT(qdev)), qdev->id, n);
+    }

Does the 'else' case ever happen? In the next patch you update all callers to invoke virtio_net_set_netclient_name().

Yes, we made virtio-bus hot-plugguable for virtio-mmio, which won't work like pci, s390 or CCW. So virtio_net_set_netclient_name will not be called in that case.

Maybe worth to remove it and push it with virtio-mmio series? Peter?

Thanks,
Fred

#4 lore raw

PATCH 2/2 virtio-net-x: forward the netclient name and type.

In reply to [email protected]

From: KONRAD Frederic <[email protected]>

This forwards the name and the type of virtio-net-x to fix the bad behaviour of "info network" command.

---
 hw/s390x/s390-virtio-bus.c | 3 +++
 hw/s390x/virtio-ccw.c      | 3 +++
 hw/virtio/virtio-pci.c     | 3 +++
 3 files changed, 9 insertions(+)
hw/s390x/s390-virtio-bus.c +3 -0
index 5a3d97c..a1cdfb0 100644
@@ -152,10 +152,13 @@ static int s390_virtio_device_init(VirtIOS390Device *dev, VirtIODevice *vdev)
 
 static int s390_virtio_net_init(VirtIOS390Device *s390_dev)
 {
+    DeviceState *qdev = DEVICE(s390_dev);
     VirtIONetS390 *dev = VIRTIO_NET_S390(s390_dev);
     DeviceState *vdev = DEVICE(&dev->vdev);
 
     virtio_net_set_config_size(&dev->vdev, s390_dev->host_features);
+    virtio_net_set_netclient_name(&dev->vdev, qdev->id,
+                                  object_get_typename(OBJECT(qdev)));
     qdev_set_parent_bus(vdev, BUS(&s390_dev->bus));
     if (qdev_init(vdev) < 0) {
         return -1;
hw/s390x/virtio-ccw.c +3 -0
index 76e6d32..5f5e267 100644
@@ -550,10 +550,13 @@ static int virtio_ccw_exit(VirtioCcwDevice *dev)
 
 static int virtio_ccw_net_init(VirtioCcwDevice *ccw_dev)
 {
+    DeviceState *qdev = DEVICE(ccw_dev);
     VirtIONetCcw *dev = VIRTIO_NET_CCW(ccw_dev);
     DeviceState *vdev = DEVICE(&dev->vdev);
 
     virtio_net_set_config_size(&dev->vdev, ccw_dev->host_features[0]);
+    virtio_net_set_netclient_name(&dev->vdev, qdev->id,
+                                  object_get_typename(OBJECT(qdev)));
     qdev_set_parent_bus(vdev, BUS(&ccw_dev->bus));
     if (qdev_init(vdev) < 0) {
         return -1;
hw/virtio/virtio-pci.c +3 -0
index 113fbd9..70d2c6b 100644
@@ -1398,10 +1398,13 @@ static Property virtio_net_properties[] = {
 
 static int virtio_net_pci_init(VirtIOPCIProxy *vpci_dev)
 {
+    DeviceState *qdev = DEVICE(vpci_dev);
     VirtIONetPCI *dev = VIRTIO_NET_PCI(vpci_dev);
     DeviceState *vdev = DEVICE(&dev->vdev);
 
     virtio_net_set_config_size(&dev->vdev, vpci_dev->host_features);
+    virtio_net_set_netclient_name(&dev->vdev, qdev->id,
+                                  object_get_typename(OBJECT(qdev)));
     qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
     if (qdev_init(vdev) < 0) {
         return -1;
Signature · 1 line
1.7.11.7
Reviewed-by on the v1 series
#5 lore raw
In reply to [email protected]
Quoted 14 lines · On Wed, May 15, 2013 at 02:12:48PM +0200, [email protected] wrote:

From: KONRAD Frederic <[email protected]>

This fixes this bug: https://bugs.launchpad.net/qemu/+bug/1179357

The name, and the type is replaced by virtio-net-x's id and virtio-net-x's type to restore the behaviour of "info network" command.

Thanks,
Fred

KONRAD Frederic (2):
virtio-net: add virtio_net_set_netclient_name.
virtio-net-x: forward the netclient name and type.

Quoted 6 lines
 hw/net/virtio-net.c            | 45 ++++++++++++++++++++++++++++++++++++++++--
 hw/s390x/s390-virtio-bus.c     |  3 +++
 hw/s390x/virtio-ccw.c          |  3 +++
 hw/virtio/virtio-pci.c         |  3 +++
 include/hw/virtio/virtio-net.h |  4 ++++
 5 files changed, 56 insertions(+), 2 deletions(-)