Patchwork [for-next,v2,13/22] virtio-net: Convert to QOM realize

login
register
mail settings
Submitter Andreas Färber
Date Aug. 1, 2013, 2:17 a.m.
Message ID <1375323463-32747-14-git-send-email-afaerber@suse.de>
Download mbox | patch
Permalink /patch/263862/
State New
Headers show

Comments

Andreas Färber - Aug. 1, 2013, 2:17 a.m.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
 hw/net/virtio-net.c            | 18 ++++++++++--------
 include/hw/virtio/virtio-net.h |  2 ++
 2 files changed, 12 insertions(+), 8 deletions(-)

Patch

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 05ad605..16c230f 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -1484,10 +1484,12 @@  void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
     n->netclient_type = g_strdup(type);
 }
 
-static int virtio_net_device_init(VirtIODevice *vdev)
+static void virtio_net_device_realize(DeviceState *dev, Error **errp)
 {
-    DeviceState *dev = DEVICE(vdev);
+    VirtIODevice *vdev = VIRTIO_DEVICE(dev);
     VirtIONet *n = VIRTIO_NET(dev);
+    ObjectClass *parent_oc = VIRTIO_NET_GET_PARENT_CLASS(dev);
+    DeviceClass *parent_dc = DEVICE_CLASS(parent_oc);
     NetClientState *nc;
     int i;
 
@@ -1563,10 +1565,11 @@  static int virtio_net_device_init(VirtIODevice *vdev)
                     virtio_net_save, virtio_net_load, n);
 
     add_boot_device_path(n->nic_conf.bootindex, dev, "/ethernet-phy@0");
-    return 0;
+
+    parent_dc->realize(dev, errp);
 }
 
-static int virtio_net_device_exit(DeviceState *dev)
+static void virtio_net_device_unrealize(DeviceState *dev, Error **errp)
 {
     VirtIODevice *vdev = VIRTIO_DEVICE(dev);
     VirtIONet *n = VIRTIO_NET(dev);
@@ -1606,8 +1609,6 @@  static int virtio_net_device_exit(DeviceState *dev)
     g_free(n->vqs);
     qemu_del_nic(n->nic);
     virtio_cleanup(vdev);
-
-    return 0;
 }
 
 static void virtio_net_instance_init(Object *obj)
@@ -1634,10 +1635,11 @@  static void virtio_net_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
     VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
-    dc->exit = virtio_net_device_exit;
+
+    dc->realize = virtio_net_device_realize;
+    dc->unrealize = virtio_net_device_unrealize;
     dc->props = virtio_net_properties;
     set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
-    vdc->init = virtio_net_device_init;
     vdc->get_config = virtio_net_get_config;
     vdc->set_config = virtio_net_set_config;
     vdc->get_features = virtio_net_get_features;
diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
index df60f16..f1efed2 100644
--- a/include/hw/virtio/virtio-net.h
+++ b/include/hw/virtio/virtio-net.h
@@ -20,6 +20,8 @@ 
 #define TYPE_VIRTIO_NET "virtio-net-device"
 #define VIRTIO_NET(obj) \
         OBJECT_CHECK(VirtIONet, (obj), TYPE_VIRTIO_NET)
+#define VIRTIO_NET_GET_PARENT_CLASS(obj) \
+        OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_NET)
 
 #define ETH_ALEN    6