[PATCH 08/36] bhyve: convert virBhyveDriverConfig to GObject

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

 



Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx>
---
 src/bhyve/bhyve_capabilities.c |  3 +--
 src/bhyve/bhyve_conf.c         | 34 +++++++++++++++++-----------------
 src/bhyve/bhyve_driver.c       |  3 ++-
 src/bhyve/bhyve_utils.h        | 11 +++++++++--
 4 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c
index 66442e50ba..00f7613594 100644
--- a/src/bhyve/bhyve_capabilities.c
+++ b/src/bhyve/bhyve_capabilities.c
@@ -131,7 +131,7 @@ virBhyveDomainCapsBuild(bhyveConnPtr conn,
     DIR *dir;
     struct dirent *entry;
     size_t firmwares_alloc = 0;
-    virBhyveDriverConfigPtr cfg = virBhyveDriverGetConfig(conn);
+    g_autoptr(virBhyveDriverConfig) cfg = virBhyveDriverGetConfig(conn);
     const char *firmware_dir = cfg->firmwareDir;
     virDomainCapsStringValuesPtr firmwares = NULL;
 
@@ -167,7 +167,6 @@ virBhyveDomainCapsBuild(bhyveConnPtr conn,
  cleanup:
     VIR_FREE(firmwares);
     VIR_DIR_CLOSE(dir);
-    virObjectUnref(cfg);
     return caps;
 }
 
diff --git a/src/bhyve/bhyve_conf.c b/src/bhyve/bhyve_conf.c
index f3e2ebf7c7..19ea5c5a03 100644
--- a/src/bhyve/bhyve_conf.c
+++ b/src/bhyve/bhyve_conf.c
@@ -32,29 +32,27 @@
 
 VIR_LOG_INIT("bhyve.bhyve_conf");
 
-static virClassPtr virBhyveDriverConfigClass;
-static void virBhyveDriverConfigDispose(void *obj);
+G_DEFINE_TYPE(virBhyveDriverConfig, vir_bhyve_driver_config, G_TYPE_OBJECT);
+static void virBhyveDriverConfigFinalize(GObject *obj);
 
-static int virBhyveConfigOnceInit(void)
+static void
+vir_bhyve_driver_config_init(virBhyveDriverConfig *cfg G_GNUC_UNUSED)
 {
-    if (!VIR_CLASS_NEW(virBhyveDriverConfig, virClassForObject()))
-        return -1;
-
-    return 0;
 }
 
-VIR_ONCE_GLOBAL_INIT(virBhyveConfig);
+static void
+vir_bhyve_driver_config_class_init(virBhyveDriverConfigClass *klass)
+{
+    GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+    obj->finalize = virBhyveDriverConfigFinalize;
+}
 
 virBhyveDriverConfigPtr
 virBhyveDriverConfigNew(void)
 {
-    virBhyveDriverConfigPtr cfg;
-
-    if (virBhyveConfigInitialize() < 0)
-        return NULL;
-
-    if (!(cfg = virObjectNew(virBhyveDriverConfigClass)))
-        return NULL;
+    virBhyveDriverConfigPtr cfg =
+        VIR_BHYVE_DRIVER_CONFIG(g_object_new(VIR_TYPE_BHYVE_DRIVER_CONFIG, NULL));
 
     cfg->firmwareDir = g_strdup(DATADIR "/uefi-firmware");
 
@@ -93,11 +91,13 @@ virBhyveDriverGetConfig(bhyveConnPtr driver)
 }
 
 static void
-virBhyveDriverConfigDispose(void *obj)
+virBhyveDriverConfigFinalize(GObject *obj)
 {
-    virBhyveDriverConfigPtr cfg = obj;
+    virBhyveDriverConfigPtr cfg = VIR_BHYVE_DRIVER_CONFIG(obj);
 
     VIR_FREE(cfg->firmwareDir);
+
+    G_OBJECT_CLASS(vir_bhyve_driver_config_parent_class)->finalize(obj);
 }
 
 void
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 2224395128..275c095b20 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -1188,7 +1188,8 @@ bhyveStateCleanup(void)
     virSysinfoDefFree(bhyve_driver->hostsysinfo);
     virObjectUnref(bhyve_driver->closeCallbacks);
     virObjectUnref(bhyve_driver->domainEventState);
-    virObjectUnref(bhyve_driver->config);
+    if (bhyve_driver->config)
+        g_object_unref(bhyve_driver->config);
     virPortAllocatorRangeFree(bhyve_driver->remotePorts);
 
     if (bhyve_driver->lockFD != -1)
diff --git a/src/bhyve/bhyve_utils.h b/src/bhyve/bhyve_utils.h
index f3e80b6121..675b859098 100644
--- a/src/bhyve/bhyve_utils.h
+++ b/src/bhyve/bhyve_utils.h
@@ -29,16 +29,23 @@
 #include "hypervisor/virclosecallbacks.h"
 #include "virportallocator.h"
 
+#include <glib-object.h>
+
 #define BHYVE_AUTOSTART_DIR    SYSCONFDIR "/libvirt/bhyve/autostart"
 #define BHYVE_CONFIG_DIR       SYSCONFDIR "/libvirt/bhyve"
 #define BHYVE_STATE_DIR        RUNSTATEDIR "/libvirt/bhyve"
 #define BHYVE_LOG_DIR          LOCALSTATEDIR "/log/libvirt/bhyve"
 
-typedef struct _virBhyveDriverConfig virBhyveDriverConfig;
+#define VIR_TYPE_BHYVE_DRIVER_CONFIG vir_bhyve_driver_config_get_type()
+G_DECLARE_FINAL_TYPE(virBhyveDriverConfig,
+                     vir_bhyve_driver_config,
+                     VIR,
+                     BHYVE_DRIVER_CONFIG,
+                     GObject);
 typedef struct _virBhyveDriverConfig *virBhyveDriverConfigPtr;
 
 struct _virBhyveDriverConfig {
-    virObject parent;
+    GObject parent;
 
     char *firmwareDir;
 };
-- 
2.25.1






[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