aboutsummaryrefslogtreecommitdiff
path: root/hw/net
diff options
context:
space:
mode:
authorKONRAD Frederic <fred.konrad@greensocs.com>2013-05-15 14:12:49 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2013-05-15 08:48:25 -0500
commit8a253ec26ec6eb636c962a47767370f6032b8cf5 (patch)
tree4d336470e8b8739eaf58bd9c9d167c4025a80746 /hw/net
parent110db9b48c0a6379fca122801c3ae48e349aa6d4 (diff)
virtio-net: add virtio_net_set_netclient_name.
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> Message-id: 1368619970-23892-2-git-send-email-fred.konrad@greensocs.com Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/net')
-rw-r--r--hw/net/virtio-net.c45
1 files changed, 43 insertions, 2 deletions
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 9f18d6ab09..bed0822f0a 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);