[PATCH v2 37/40] 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 |  2 +-
 tests/domaincapstest.c |  2 +-
 tests/testutilsqemu.c  |  2 +-
 5 files changed, 33 insertions(+), 28 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index c29b543b16..1e7d1a8e9d 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -69,18 +69,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
@@ -106,13 +109,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);
 
@@ -369,6 +367,8 @@ static void virQEMUDriverConfigDispose(void *obj)
     VIR_FREE(cfg->swtpmStorageDir);
 
     virStringListFree(cfg->capabilityfilters);
+
+    G_OBJECT_CLASS(vir_qemu_driver_config_parent_class)->finalize(obj);
 }
 
 
@@ -1229,7 +1229,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 b9ef4551a3..0a07188962 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;
 
@@ -220,7 +218,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 346edb47d6..4d0f76fb21 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1129,7 +1129,7 @@ qemuStateCleanup(void)
     if (qemu_driver->lockFD != -1)
         virPidFileRelease(qemu_driver->config->stateDir, "driver", qemu_driver->lockFD);
 
-    virObjectUnref(qemu_driver->config);
+    g_clear_object(&qemu_driver->config);
     virMutexDestroy(&qemu_driver->lock);
     VIR_FREE(qemu_driver);
 
diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c
index 2393e312d1..1bbd6a3e61 100644
--- a/tests/domaincapstest.c
+++ b/tests/domaincapstest.c
@@ -450,7 +450,7 @@ mymain(void)
      * file has been added, run "VIR_TEST_REGENERATE_OUTPUT=1 make check".
      */
 
-    virObjectUnref(cfg);
+    g_clear_object(&cfg);
 
     virFileWrapperClearPrefixes();
 
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index eece670aa0..e149e36ffe 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -309,7 +309,7 @@ void qemuTestDriverFree(virQEMUDriver *driver)
     virObjectUnref(driver->qemuCapsCache);
     g_clear_object(&driver->xmlopt);
     g_clear_object(&driver->caps);
-    virObjectUnref(driver->config);
+    g_clear_object(&driver->config);
     virObjectUnref(driver->securityManager);
 }
 
-- 
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