Patchwork [V3,12/44] virtio-net: cleanup: init and exit function.

login
register
mail settings
Submitter fred.konrad@greensocs.com
Date Jan. 15, 2013, 2:09 p.m.
Message ID <1358258998-6504-13-git-send-email-fred.konrad@greensocs.com>
Download mbox | patch
Permalink /patch/212207/
State New
Headers show

Comments

fred.konrad@greensocs.com - Jan. 15, 2013, 2:09 p.m.
From: KONRAD Frederic <fred.konrad@greensocs.com>

This remove old init and exit function as they are no longer needed.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-net.c | 95 ++++++++++++---------------------------------------------
 1 file changed, 20 insertions(+), 75 deletions(-)

Patch

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index c52e962..62b8cb5 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -1007,26 +1007,13 @@  void virtio_net_set_conf(DeviceState *dev, virtio_net_conf *net_conf,
     memcpy(&(n->nic_conf), nic_conf, sizeof(struct NICConf));
 }
 
-static VirtIODevice *virtio_net_common_init(DeviceState *dev, NICConf *conf,
-                                           virtio_net_conf *net, VirtIONet **pn)
+static int virtio_net_device_init(VirtIODevice *vdev)
 {
-    VirtIONet *n = *pn;
-    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
-
-    /*
-     * We have two cases here: the old virtio-net-pci device, and the
-     * refactored virtio-net.
-     */
-    if (n == NULL) {
-        /* virtio-net-pci */
-        n = (VirtIONet *)virtio_common_init("virtio-net", VIRTIO_ID_NET,
-                                            sizeof(struct virtio_net_config),
-                                            sizeof(VirtIONet));
-    } else {
-        /* virtio-net */
-        virtio_init(VIRTIO_DEVICE(n), "virtio-net", VIRTIO_ID_NET,
-                                      sizeof(struct virtio_net_config));
-    }
+    DeviceState *qdev = DEVICE(vdev);
+    VirtIONet *n = VIRTIO_NET(vdev);
+
+    virtio_init(VIRTIO_DEVICE(n), "virtio-net", VIRTIO_ID_NET,
+                                  sizeof(struct virtio_net_config));
 
     vdev->get_config = virtio_net_get_config;
     vdev->set_config = virtio_net_set_config;
@@ -1039,27 +1026,29 @@  static VirtIODevice *virtio_net_common_init(DeviceState *dev, NICConf *conf,
     vdev->guest_notifier_pending = virtio_net_guest_notifier_pending;
     n->rx_vq = virtio_add_queue(vdev, 256, virtio_net_handle_rx);
 
-    if (net->tx && strcmp(net->tx, "timer") && strcmp(net->tx, "bh")) {
+    if (n->net_conf.tx && strcmp(n->net_conf.tx, "timer") &&
+                           strcmp(n->net_conf.tx, "bh")) {
         error_report("virtio-net: "
                      "Unknown option tx=%s, valid options: \"timer\" \"bh\"",
-                     net->tx);
+                     n->net_conf.tx);
         error_report("Defaulting to \"bh\"");
     }
 
-    if (net->tx && !strcmp(net->tx, "timer")) {
+    if (n->net_conf.tx && !strcmp(n->net_conf.tx, "timer")) {
         n->tx_vq = virtio_add_queue(vdev, 256, virtio_net_handle_tx_timer);
         n->tx_timer = qemu_new_timer_ns(vm_clock, virtio_net_tx_timer, n);
-        n->tx_timeout = net->txtimer;
+        n->tx_timeout = n->net_conf.txtimer;
     } else {
         n->tx_vq = virtio_add_queue(vdev, 256, virtio_net_handle_tx_bh);
         n->tx_bh = qemu_bh_new(virtio_net_tx_bh, n);
     }
     n->ctrl_vq = virtio_add_queue(vdev, 64, virtio_net_handle_ctrl);
-    qemu_macaddr_default_if_unset(&conf->macaddr);
-    memcpy(&n->mac[0], &conf->macaddr, sizeof(n->mac));
+    qemu_macaddr_default_if_unset(&(n->nic_conf.macaddr));
+    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, conf, object_get_typename(OBJECT(dev)), dev->id, n);
+    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)) {
         tap_using_vnet_hdr(n->nic->nc.peer, 1);
@@ -1068,10 +1057,10 @@  static VirtIODevice *virtio_net_common_init(DeviceState *dev, NICConf *conf,
         n->host_hdr_len = 0;
     }
 
-    qemu_format_nic_info_str(&n->nic->nc, conf->macaddr.a);
+    qemu_format_nic_info_str(&n->nic->nc, n->nic_conf.macaddr.a);
 
     n->tx_waiting = 0;
-    n->tx_burst = net->txburst;
+    n->tx_burst = n->net_conf.txburst;
     virtio_net_set_mrg_rx_bufs(n, 0);
     n->promisc = 1; /* for compatibility */
 
@@ -1079,55 +1068,11 @@  static VirtIODevice *virtio_net_common_init(DeviceState *dev, NICConf *conf,
 
     n->vlans = g_malloc0(MAX_VLAN >> 3);
 
-    n->qdev = dev;
-    register_savevm(dev, "virtio-net", -1, VIRTIO_NET_VM_VERSION,
+    n->qdev = qdev;
+    register_savevm(qdev, "virtio-net", -1, VIRTIO_NET_VM_VERSION,
                     virtio_net_save, virtio_net_load, n);
 
-    add_boot_device_path(conf->bootindex, dev, "/ethernet-phy@0");
-
-    return vdev;
-}
-
-VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
-                              virtio_net_conf *net)
-{
-    VirtIONet *n = NULL;
-    return virtio_net_common_init(dev, conf, net, &n);
-}
-
-void virtio_net_exit(VirtIODevice *vdev)
-{
-    VirtIONet *n = VIRTIO_NET(vdev);
-
-    /* This will stop vhost backend if appropriate. */
-    virtio_net_set_status(vdev, 0);
-
-    qemu_purge_queued_packets(&n->nic->nc);
-
-    unregister_savevm(n->qdev, "virtio-net", n);
-
-    g_free(n->mac_table.macs);
-    g_free(n->vlans);
-
-    if (n->tx_timer) {
-        qemu_del_timer(n->tx_timer);
-        qemu_free_timer(n->tx_timer);
-    } else {
-        qemu_bh_delete(n->tx_bh);
-    }
-
-    qemu_del_net_client(&n->nic->nc);
-    virtio_cleanup(vdev);
-}
-
-static int virtio_net_device_init(VirtIODevice *vdev)
-{
-    DeviceState *qdev = DEVICE(vdev);
-    VirtIONet *n = VIRTIO_NET(vdev);
-    if (virtio_net_common_init(qdev, &(n->nic_conf),
-                               &(n->net_conf), &n) == NULL) {
-        return -1;
-    }
+    add_boot_device_path(n->nic_conf.bootindex, qdev, "/ethernet-phy@0");
     return 0;
 }