[PATCH v2 34/40] hypervisor: convert virHostdevManager to GObject

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx>
---
 src/hypervisor/virhostdev.c | 49 +++++++++++++++++++++++++++++--------
 src/hypervisor/virhostdev.h | 13 +++++++---
 src/libxl/libxl_driver.c    |  2 +-
 src/lxc/lxc_driver.c        |  2 +-
 src/qemu/qemu_driver.c      |  2 +-
 5 files changed, 51 insertions(+), 17 deletions(-)

diff --git a/src/hypervisor/virhostdev.c b/src/hypervisor/virhostdev.c
index 9017cc3be8..b484603f5d 100644
--- a/src/hypervisor/virhostdev.c
+++ b/src/hypervisor/virhostdev.c
@@ -44,8 +44,23 @@ VIR_LOG_INIT("util.hostdev");
 
 static virHostdevManagerPtr manager; /* global hostdev manager, never freed */
 
-static virClassPtr virHostdevManagerClass;
-static void virHostdevManagerDispose(void *obj);
+G_DEFINE_TYPE(virHostdevManager, vir_hostdev_manager, G_TYPE_OBJECT);
+
+static void virHostdevManagerDispose(GObject *obj);
+static void virHostdevManagerFinalize(GObject *obj);
+
+static void vir_hostdev_manager_init(virHostdevManager *mgr G_GNUC_UNUSED)
+{
+}
+
+static void vir_hostdev_manager_class_init(virHostdevManagerClass *klass)
+{
+    GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+    obj->dispose = virHostdevManagerDispose;
+    obj->finalize = virHostdevManagerFinalize;
+}
+
 static virHostdevManagerPtr virHostdevManagerNew(void);
 
 struct virHostdevIsPCINodeDeviceUsedData {
@@ -112,9 +127,6 @@ static int virHostdevIsPCINodeDeviceUsed(virPCIDeviceAddressPtr devAddr, void *o
 
 static int virHostdevManagerOnceInit(void)
 {
-    if (!VIR_CLASS_NEW(virHostdevManager, virClassForObject()))
-        return -1;
-
     if (!(manager = virHostdevManagerNew()))
         return -1;
 
@@ -124,18 +136,36 @@ static int virHostdevManagerOnceInit(void)
 VIR_ONCE_GLOBAL_INIT(virHostdevManager);
 
 static void
-virHostdevManagerDispose(void *obj)
+virHostdevManagerDispose(GObject *obj)
 {
-    virHostdevManagerPtr hostdevMgr = obj;
+    virHostdevManagerPtr hostdevMgr = VIR_HOSTDEV_MANAGER(obj);
 
     virObjectUnref(hostdevMgr->activePCIHostdevs);
+    hostdevMgr->activePCIHostdevs = NULL;
     virObjectUnref(hostdevMgr->inactivePCIHostdevs);
+    hostdevMgr->inactivePCIHostdevs = NULL;
     virObjectUnref(hostdevMgr->activeUSBHostdevs);
+    hostdevMgr->activeUSBHostdevs = NULL;
     virObjectUnref(hostdevMgr->activeSCSIHostdevs);
+    hostdevMgr->activeSCSIHostdevs = NULL;
     virObjectUnref(hostdevMgr->activeSCSIVHostHostdevs);
+    hostdevMgr->activeSCSIVHostHostdevs = NULL;
     virObjectUnref(hostdevMgr->activeMediatedHostdevs);
+    hostdevMgr->activeMediatedHostdevs = NULL;
     virObjectUnref(hostdevMgr->activeNVMeHostdevs);
+    hostdevMgr->activeNVMeHostdevs = NULL;
+
+    G_OBJECT_CLASS(vir_hostdev_manager_parent_class)->dispose(obj);
+}
+
+static void
+virHostdevManagerFinalize(GObject *obj)
+{
+    virHostdevManagerPtr hostdevMgr = VIR_HOSTDEV_MANAGER(obj);
+
     VIR_FREE(hostdevMgr->stateDir);
+
+    G_OBJECT_CLASS(vir_hostdev_manager_parent_class)->finalize(obj);
 }
 
 static virHostdevManagerPtr
@@ -144,8 +174,7 @@ virHostdevManagerNew(void)
     g_autoptr(virHostdevManager) hostdevMgr = NULL;
     bool privileged = geteuid() == 0;
 
-    if (!(hostdevMgr = virObjectNew(virHostdevManagerClass)))
-        return NULL;
+    hostdevMgr = VIR_HOSTDEV_MANAGER(g_object_new(VIR_TYPE_HOSTDEV_MANAGER, NULL));
 
     if (!(hostdevMgr->activePCIHostdevs = virPCIDeviceListNew()))
         return NULL;
@@ -206,7 +235,7 @@ virHostdevManagerGetDefault(void)
     if (virHostdevManagerInitialize() < 0)
         return NULL;
 
-    return virObjectRef(manager);
+    return g_object_ref(manager);
 }
 
 /**
diff --git a/src/hypervisor/virhostdev.h b/src/hypervisor/virhostdev.h
index 811bda40ed..be5345992c 100644
--- a/src/hypervisor/virhostdev.h
+++ b/src/hypervisor/virhostdev.h
@@ -30,6 +30,7 @@
 #include "conf/domain_conf.h"
 #include "virmdev.h"
 #include "virnvme.h"
+#include <glib-object.h>
 
 typedef enum {
     VIR_HOSTDEV_STRICT_ACS_CHECK     = (1 << 0), /* strict acs check */
@@ -41,10 +42,8 @@ typedef enum {
 } virHostdevFlag;
 
 
-typedef struct _virHostdevManager virHostdevManager;
-typedef virHostdevManager *virHostdevManagerPtr;
 struct _virHostdevManager {
-    virObject parent;
+    GObject parent;
 
     char *stateDir;
 
@@ -59,7 +58,13 @@ struct _virHostdevManager {
     virNVMeDeviceListPtr activeNVMeHostdevs;
 };
 
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(virHostdevManager, virObjectUnref);
+#define VIR_TYPE_HOSTDEV_MANAGER vir_hostdev_manager_get_type()
+G_DECLARE_FINAL_TYPE(virHostdevManager,
+                     vir_hostdev_manager,
+                     VIR,
+                     HOSTDEV_MANAGER,
+                     GObject);
+typedef virHostdevManager *virHostdevManagerPtr;
 
 
 virHostdevManagerPtr virHostdevManagerGetDefault(void);
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index affae0e86e..dbcbbdc96d 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -505,7 +505,7 @@ libxlStateCleanup(void)
     if (!libxl_driver)
         return -1;
 
-    virObjectUnref(libxl_driver->hostdevMgr);
+    g_clear_object(&libxl_driver->hostdevMgr);
     g_clear_object(&libxl_driver->xmlopt);
     virObjectUnref(libxl_driver->domains);
     virPortAllocatorRangeFree(libxl_driver->reservedGraphicsPorts);
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 288d394989..cbd7fbfcb0 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -1603,7 +1603,7 @@ static int lxcStateCleanup(void)
 
     virSysinfoDefFree(lxc_driver->hostsysinfo);
 
-    virObjectUnref(lxc_driver->hostdevMgr);
+    g_clear_object(&lxc_driver->hostdevMgr);
     g_clear_object(&lxc_driver->caps);
     virObjectUnref(lxc_driver->securityManager);
     g_clear_object(&lxc_driver->xmlopt);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c05803f08a..346edb47d6 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1113,7 +1113,7 @@ qemuStateCleanup(void)
     virPortAllocatorRangeFree(qemu_driver->webSocketPorts);
     virPortAllocatorRangeFree(qemu_driver->remotePorts);
     virHashFree(qemu_driver->sharedDevices);
-    virObjectUnref(qemu_driver->hostdevMgr);
+    g_clear_object(&qemu_driver->hostdevMgr);
     virObjectUnref(qemu_driver->securityManager);
     virObjectUnref(qemu_driver->domainEventState);
     virObjectUnref(qemu_driver->qemuCapsCache);
-- 
2.25.3






[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux