[PATCH 33/36] qemu: convert virQEMUDriverConfig to GObject

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

 



Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx>
---
 src/qemu/qemu_conf.c   | 36 ++++++++++++++++++------------------
 src/qemu/qemu_conf.h   | 19 ++++++++++++-------
 src/qemu/qemu_driver.c |  3 ++-
 tests/domaincapstest.c |  3 ++-
 tests/testutilsqemu.c  |  3 ++-
 5 files changed, 36 insertions(+), 28 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 68df8a419a..b0e4ac8ef4 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -68,18 +68,21 @@ VIR_LOG_INIT("qemu.qemu_conf");
 #define QEMU_MIGRATION_PORT_MIN 49152
 #define QEMU_MIGRATION_PORT_MAX 49215
 
-static virClassPtr virQEMUDriverConfigClass;
-static void virQEMUDriverConfigDispose(void *obj);
+G_DEFINE_TYPE(virQEMUDriverConfig, vir_qemu_driver_config, G_TYPE_OBJECT);
+static void virQEMUDriverConfigFinalize(GObject *obj);
 
-static int virQEMUConfigOnceInit(void)
+static void
+vir_qemu_driver_config_init(virQEMUDriverConfig *cfg G_GNUC_UNUSED)
 {
-    if (!VIR_CLASS_NEW(virQEMUDriverConfig, virClassForObject()))
-        return -1;
-
-    return 0;
 }
 
-VIR_ONCE_GLOBAL_INIT(virQEMUConfig);
+static void
+vir_qemu_driver_config_class_init(virQEMUDriverConfigClass *klass)
+{
+    GObjectClass *obj = G_OBJECT_CLASS(klass);
+
+    obj->finalize = virQEMUDriverConfigFinalize;
+}
 
 
 static void
@@ -105,13 +108,8 @@ qemuDriverUnlock(virQEMUDriverPtr driver)
 virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged,
                                               const char *root)
 {
-    g_autoptr(virQEMUDriverConfig) cfg = NULL;
-
-    if (virQEMUConfigInitialize() < 0)
-        return NULL;
-
-    if (!(cfg = virObjectNew(virQEMUDriverConfigClass)))
-        return NULL;
+    g_autoptr(virQEMUDriverConfig) cfg =
+        VIR_QEMU_DRIVER_CONFIG(g_object_new(VIR_TYPE_QEMU_DRIVER_CONFIG, NULL));
 
     if (root) {
         cfg->uri = g_strdup_printf("qemu:///embed?root=%s", root);
@@ -294,9 +292,9 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged,
 }
 
 
-static void virQEMUDriverConfigDispose(void *obj)
+static void virQEMUDriverConfigFinalize(GObject *obj)
 {
-    virQEMUDriverConfigPtr cfg = obj;
+    virQEMUDriverConfigPtr cfg = VIR_QEMU_DRIVER_CONFIG(obj);
 
     virBitmapFree(cfg->namespaces);
 
@@ -370,6 +368,8 @@ static void virQEMUDriverConfigDispose(void *obj)
     VIR_FREE(cfg->swtpmStorageDir);
 
     virStringListFree(cfg->capabilityfilters);
+
+    G_OBJECT_CLASS(vir_qemu_driver_config_parent_class)->finalize(obj);
 }
 
 
@@ -1219,7 +1219,7 @@ virQEMUDriverConfigPtr virQEMUDriverGetConfig(virQEMUDriverPtr driver)
 {
     virQEMUDriverConfigPtr conf;
     qemuDriverLock(driver);
-    conf = virObjectRef(driver->config);
+    conf = g_object_ref(driver->config);
     qemuDriverUnlock(driver);
     return conf;
 }
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 14f9b9e81e..e9a60d5628 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -48,15 +48,13 @@
 #include "virfile.h"
 #include "virfilecache.h"
 #include "virfirmware.h"
+#include <glib-object.h>
 
 #define QEMU_DRIVER_NAME "QEMU"
 
 typedef struct _virQEMUDriver virQEMUDriver;
 typedef virQEMUDriver *virQEMUDriverPtr;
 
-typedef struct _virQEMUDriverConfig virQEMUDriverConfig;
-typedef virQEMUDriverConfig *virQEMUDriverConfigPtr;
-
 /* Main driver config. The data in these object
  * instances is immutable, so can be accessed
  * without locking. Threads must, however, hold
@@ -65,15 +63,15 @@ typedef virQEMUDriverConfig *virQEMUDriverConfigPtr;
  *
  * eg
  *  qemuDriverLock(driver);
- *  virQEMUDriverConfigPtr cfg = virObjectRef(driver->config);
+ *  virQEMUDriverConfigPtr cfg = g_object_ref(driver->config);
  *  qemuDriverUnlock(driver);
  *
  *  ...do stuff with 'cfg'..
  *
- *  virObjectUnref(cfg);
+ *  g_object_unref(cfg);
  */
 struct _virQEMUDriverConfig {
-    virObject parent;
+    GObject parent;
 
     char *uri;
     char *root; /* The root directory for embed driver,
@@ -222,7 +220,14 @@ struct _virQEMUDriverConfig {
     char **capabilityfilters;
 };
 
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(virQEMUDriverConfig, virObjectUnref);
+#define VIR_TYPE_QEMU_DRIVER_CONFIG vir_qemu_driver_config_get_type()
+G_DECLARE_FINAL_TYPE(virQEMUDriverConfig,
+                     vir_qemu_driver_config,
+                     VIR,
+                     QEMU_DRIVER_CONFIG,
+                     GObject);
+typedef virQEMUDriverConfig *virQEMUDriverConfigPtr;
+
 
 
 /* Main driver state */
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 630ece6cc6..3e92629d19 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1146,7 +1146,8 @@ qemuStateCleanup(void)
     if (qemu_driver->lockFD != -1)
         virPidFileRelease(qemu_driver->config->stateDir, "driver", qemu_driver->lockFD);
 
-    virObjectUnref(qemu_driver->config);
+    if (qemu_driver->config)
+        g_object_unref(qemu_driver->config);
     virMutexDestroy(&qemu_driver->lock);
     VIR_FREE(qemu_driver);
 
diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c
index d6f0021665..c4440f478b 100644
--- a/tests/domaincapstest.c
+++ b/tests/domaincapstest.c
@@ -450,7 +450,8 @@ mymain(void)
      * file has been added, run "VIR_TEST_REGENERATE_OUTPUT=1 make check".
      */
 
-    virObjectUnref(cfg);
+    if (cfg)
+        g_object_unref(cfg);
 
     virFileWrapperClearPrefixes();
 
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index a37865bc14..7d27bfa72a 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -307,11 +307,12 @@ void qemuTestDriverFree(virQEMUDriver *driver)
         virFileDeleteTree(driver->config->configDir);
     }
     virObjectUnref(driver->qemuCapsCache);
+    if (driver->config)
+        g_object_unref(driver->config);
     if (driver->xmlopt)
         g_object_unref(driver->xmlopt);
     if (driver->caps)
         g_object_unref(driver->caps);
-    virObjectUnref(driver->config);
     virObjectUnref(driver->securityManager);
 }
 
-- 
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