[PATCH 12/36] conf: convert virDomainChrSourceDef to GObject

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

 



Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx>
---
 src/conf/domain_conf.c   | 35 ++++++++++++++++-------------------
 src/conf/domain_conf.h   |  9 ++++++++-
 src/qemu/qemu_domain.c   |  7 ++++---
 src/qemu/qemu_process.c  |  3 +--
 src/qemu/qemu_virtiofs.c | 12 +++++-------
 5 files changed, 34 insertions(+), 32 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 38a0c04c1f..a29e6681a5 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2421,8 +2421,7 @@ virDomainNetDefClear(virDomainNetDefPtr def)
 
     switch (def->type) {
     case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
-        virObjectUnref(def->data.vhostuser);
-        def->data.vhostuser = NULL;
+        g_clear_object(&def->data.vhostuser);
         break;
 
     case VIR_DOMAIN_NET_TYPE_SERVER:
@@ -2497,6 +2496,7 @@ virDomainNetDefFree(virDomainNetDefPtr def)
     VIR_FREE(def);
 }
 
+G_DEFINE_TYPE(virDomainChrSourceDef, vir_domain_chr_source_def, G_TYPE_OBJECT);
 
 const char *
 virDomainChrSourceDefGetPath(virDomainChrSourceDefPtr chr)
@@ -2629,9 +2629,9 @@ virDomainChrSourceDefCopy(virDomainChrSourceDefPtr dest,
 }
 
 static void
-virDomainChrSourceDefDispose(void *obj)
+virDomainChrSourceDefFinalize(GObject *obj)
 {
-    virDomainChrSourceDefPtr def = obj;
+    virDomainChrSourceDefPtr def = VIR_DOMAIN_CHR_SOURCE_DEF(obj);
     size_t i;
 
     virDomainChrSourceDefClear(def);
@@ -2642,6 +2642,8 @@ virDomainChrSourceDefDispose(void *obj)
             virSecurityDeviceLabelDefFree(def->seclabels[i]);
         VIR_FREE(def->seclabels);
     }
+
+    G_OBJECT_CLASS(vir_domain_chr_source_def_parent_class)->finalize(obj);
 }
 
 
@@ -13215,34 +13217,29 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
 }
 
 
-static virClassPtr virDomainChrSourceDefClass;
+static void
+vir_domain_chr_source_def_init(virDomainChrSourceDef *def G_GNUC_UNUSED)
+{
+}
 
-static int
-virDomainChrSourceDefOnceInit(void)
+static void
+vir_domain_chr_source_def_class_init(virDomainChrSourceDefClass *klass)
 {
-    if (!VIR_CLASS_NEW(virDomainChrSourceDef, virClassForObject()))
-        return -1;
+    GObjectClass *obj = G_OBJECT_CLASS(klass);
 
-    return 0;
+    obj->finalize = virDomainChrSourceDefFinalize;
 }
 
-VIR_ONCE_GLOBAL_INIT(virDomainChrSourceDef);
-
 virDomainChrSourceDefPtr
 virDomainChrSourceDefNew(virDomainXMLOptionPtr xmlopt)
 {
     virDomainChrSourceDefPtr def = NULL;
 
-    if (virDomainChrSourceDefInitialize() < 0)
-        return NULL;
-
-    if (!(def = virObjectNew(virDomainChrSourceDefClass)))
-        return NULL;
+    def = VIR_DOMAIN_CHR_SOURCE_DEF(g_object_new(VIR_TYPE_DOMAIN_CHR_SOURCE_DEF, NULL));
 
     if (xmlopt && xmlopt->privateData.chrSourceNew &&
         !(def->privateData = xmlopt->privateData.chrSourceNew())) {
-        virObjectUnref(def);
-        def = NULL;
+        g_clear_object(&def);
     }
 
     return def;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 7e2792ae62..b6b2a72dd4 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1173,7 +1173,7 @@ struct _virDomainChrSourceReconnectDef {
 
 /* The host side information for a character device.  */
 struct _virDomainChrSourceDef {
-    virObject parent;
+    GObject parent;
     int type; /* virDomainChrType */
     virObjectPtr privateData;
     union {
@@ -1219,6 +1219,13 @@ struct _virDomainChrSourceDef {
     virSecurityDeviceLabelDefPtr *seclabels;
 };
 
+#define VIR_TYPE_DOMAIN_CHR_SOURCE_DEF vir_domain_chr_source_def_get_type()
+G_DECLARE_FINAL_TYPE(virDomainChrSourceDef,
+                     vir_domain_chr_source_def,
+                     VIR,
+                     DOMAIN_CHR_SOURCE_DEF,
+                     GObject);
+
 /* A complete character device, both host and domain views.  */
 struct _virDomainChrDef {
     int deviceType; /* enum virDomainChrDeviceType */
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 32dd69892a..2506fa2eea 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2315,7 +2315,8 @@ qemuDomainObjPrivateFree(void *data)
 
     qemuDomainObjPrivateDataClear(priv);
 
-    virObjectUnref(priv->monConfig);
+    if (priv->monConfig)
+        g_object_unref(priv->monConfig);
     qemuDomainObjFreeJob(priv);
     VIR_FREE(priv->lockState);
     VIR_FREE(priv->origname);
@@ -3934,8 +3935,8 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
  error:
     virBitmapFree(priv->namespaces);
     priv->namespaces = NULL;
-    virObjectUnref(priv->monConfig);
-    priv->monConfig = NULL;
+    if (priv->monConfig)
+        g_clear_object(&priv->monConfig);
     virStringListFree(priv->qemuDevices);
     priv->qemuDevices = NULL;
     return -1;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index ef34dd8cfd..817e858ac2 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -7390,8 +7390,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
     if (priv->monConfig) {
         if (priv->monConfig->type == VIR_DOMAIN_CHR_TYPE_UNIX)
             unlink(priv->monConfig->data.nix.path);
-        virObjectUnref(priv->monConfig);
-        priv->monConfig = NULL;
+        g_clear_object(&priv->monConfig);
     }
 
     qemuDomainObjStopWorker(vm);
diff --git a/src/qemu/qemu_virtiofs.c b/src/qemu/qemu_virtiofs.c
index 2e239cad66..483af5c798 100644
--- a/src/qemu/qemu_virtiofs.c
+++ b/src/qemu/qemu_virtiofs.c
@@ -80,7 +80,7 @@ qemuVirtioFSOpenChardev(virQEMUDriverPtr driver,
                         virDomainObjPtr vm,
                         const char *socket_path)
 {
-    virDomainChrSourceDefPtr chrdev = virDomainChrSourceDefNew(NULL);
+    g_autoptr(virDomainChrSourceDef) chrdev = virDomainChrSourceDefNew(NULL);
     virDomainChrDef chr = { .source = chrdev };
     VIR_AUTOCLOSE fd = -1;
     int ret = -1;
@@ -90,23 +90,21 @@ qemuVirtioFSOpenChardev(virQEMUDriverPtr driver,
     chrdev->data.nix.path = g_strdup(socket_path);
 
     if (qemuSecuritySetDaemonSocketLabel(driver->securityManager, vm->def) < 0)
-        goto cleanup;
+        return ret;
     fd = qemuOpenChrChardevUNIXSocket(chrdev);
     if (fd < 0) {
         ignore_value(qemuSecurityClearSocketLabel(driver->securityManager, vm->def));
-        goto cleanup;
+        return ret;
     }
     if (qemuSecurityClearSocketLabel(driver->securityManager, vm->def) < 0)
-        goto cleanup;
+        return ret;
 
     if (qemuSecuritySetChardevLabel(driver, vm, &chr) < 0)
-        goto cleanup;
+        return ret;
 
     ret = fd;
     fd = -1;
 
- cleanup:
-    virObjectUnref(chrdev);
     return ret;
 }
 
-- 
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