Signed-off-by: Rafael Fonseca <r4f4rfs(a)gmail.com>
---
src/hypervisor/virhostdev.c | 31 +++++++++++++++++++++----------
src/hypervisor/virhostdev.h | 13 +++++++++----
src/libxl/libxl_driver.c | 3 ++-
src/lxc/lxc_driver.c | 3 ++-
src/qemu/qemu_driver.c | 3 ++-
5 files changed, 36 insertions(+), 17 deletions(-)
diff --git a/src/hypervisor/virhostdev.c b/src/hypervisor/virhostdev.c
index 9017cc3be8..83298e7674 100644
--- a/src/hypervisor/virhostdev.c
+++ b/src/hypervisor/virhostdev.c
@@ -44,8 +44,21 @@ 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 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->finalize = virHostdevManagerFinalize;
+}
+
static virHostdevManagerPtr virHostdevManagerNew(void);
struct virHostdevIsPCINodeDeviceUsedData {
@@ -112,9 +125,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,9 +134,9 @@ static int virHostdevManagerOnceInit(void)
VIR_ONCE_GLOBAL_INIT(virHostdevManager);
static void
-virHostdevManagerDispose(void *obj)
+virHostdevManagerFinalize(GObject *obj)
{
- virHostdevManagerPtr hostdevMgr = obj;
+ virHostdevManagerPtr hostdevMgr = VIR_HOSTDEV_MANAGER(obj);
virObjectUnref(hostdevMgr->activePCIHostdevs);
virObjectUnref(hostdevMgr->inactivePCIHostdevs);
@@ -136,6 +146,8 @@ virHostdevManagerDispose(void *obj)
virObjectUnref(hostdevMgr->activeMediatedHostdevs);
virObjectUnref(hostdevMgr->activeNVMeHostdevs);
VIR_FREE(hostdevMgr->stateDir);
+
+ G_OBJECT_CLASS(vir_hostdev_manager_parent_class)->finalize(obj);
}
static virHostdevManagerPtr
@@ -144,8 +156,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 +217,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 eab8945e48..313918acde 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -505,7 +505,8 @@ libxlStateCleanup(void)
if (!libxl_driver)
return -1;
- virObjectUnref(libxl_driver->hostdevMgr);
+ if (libxl_driver->hostdevMgr)
+ g_object_unref(libxl_driver->hostdevMgr);
if (libxl_driver->xmlopt)
g_object_unref(libxl_driver->xmlopt);
virObjectUnref(libxl_driver->domains);
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 07bc7219f1..86f84fd152 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -1603,7 +1603,8 @@ static int lxcStateCleanup(void)
virSysinfoDefFree(lxc_driver->hostsysinfo);
- virObjectUnref(lxc_driver->hostdevMgr);
+ if (lxc_driver->hostdevMgr)
+ g_object_unref(lxc_driver->hostdevMgr);
if (lxc_driver->caps)
g_object_unref(lxc_driver->caps);
virObjectUnref(lxc_driver->securityManager);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index bc28f65a3a..630ece6cc6 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1127,7 +1127,8 @@ qemuStateCleanup(void)
virPortAllocatorRangeFree(qemu_driver->webSocketPorts);
virPortAllocatorRangeFree(qemu_driver->remotePorts);
virHashFree(qemu_driver->sharedDevices);
- virObjectUnref(qemu_driver->hostdevMgr);
+ if (qemu_driver->hostdevMgr)
+ g_object_unref(qemu_driver->hostdevMgr);
virObjectUnref(qemu_driver->securityManager);
virObjectUnref(qemu_driver->domainEventState);
virObjectUnref(qemu_driver->qemuCapsCache);
--
2.25.1