diff mbox

[for-1.5,1/2] virtio-net: add virtio_net_set_netclient_name.

Message ID 1368619970-23892-2-git-send-email-fred.konrad@greensocs.com
State New
Headers show

Commit Message

fred.konrad@greensocs.com May 15, 2013, 12:12 p.m. UTC
From: KONRAD Frederic <fred.konrad@greensocs.com>

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

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/net/virtio-net.c            | 45 ++++++++++++++++++++++++++++++++++++++++--
 include/hw/virtio/virtio-net.h |  4 ++++
 2 files changed, 47 insertions(+), 2 deletions(-)

Comments

Stefan Hajnoczi May 15, 2013, 1:16 p.m. UTC | #1
On Wed, May 15, 2013 at 02:12:49PM +0200, fred.konrad@greensocs.com wrote:
> @@ -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);
> +    }

Does the 'else' case ever happen?  In the next patch you update all
callers to invoke virtio_net_set_netclient_name().
fred.konrad@greensocs.com May 15, 2013, 1:28 p.m. UTC | #2
On 15/05/2013 15:16, Stefan Hajnoczi wrote:
> On Wed, May 15, 2013 at 02:12:49PM +0200, fred.konrad@greensocs.com wrote:
>> @@ -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);
>> +    }
> 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
diff mbox

Patch

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 9f18d6a..bed0822 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -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);
 
diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
index ce4ab50..beeead7 100644
--- a/include/hw/virtio/virtio-net.h
+++ b/include/hw/virtio/virtio-net.h
@@ -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