Signed-off-by: Rafael Fonseca <r4f4rfs(a)gmail.com>
---
src/conf/domain_conf.c | 39 ++++++++++++++++++---------------------
src/conf/domain_conf.h | 9 ++++++++-
src/libvirt_private.syms | 1 +
src/qemu/qemu_domain.c | 5 ++---
src/qemu/qemu_process.c | 3 +--
src/qemu/qemu_virtiofs.c | 12 +++++-------
6 files changed, 35 insertions(+), 34 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 62f49a598a..15d371df6e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2483,8 +2483,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:
@@ -2559,6 +2558,7 @@ virDomainNetDefFree(virDomainNetDefPtr def)
VIR_FREE(def);
}
+G_DEFINE_TYPE(virDomainChrSourceDef, vir_domain_chr_source_def, G_TYPE_OBJECT);
const char *
virDomainChrSourceDefGetPath(virDomainChrSourceDefPtr chr)
@@ -2691,9 +2691,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);
@@ -2704,6 +2704,8 @@ virDomainChrSourceDefDispose(void *obj)
virSecurityDeviceLabelDefFree(def->seclabels[i]);
VIR_FREE(def->seclabels);
}
+
+ G_OBJECT_CLASS(vir_domain_chr_source_def_parent_class)->finalize(obj);
}
@@ -13309,37 +13311,32 @@ 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;
+ g_autoptr(virDomainChrSourceDef) def = 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;
+ return NULL;
}
- return def;
+ return g_steal_pointer(&def);
}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 20fc734e06..2a4d8deaf6 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1192,7 +1192,7 @@ struct _virDomainChrSourceReconnectDef {
/* The host side information for a character device. */
struct _virDomainChrSourceDef {
- virObject parent;
+ GObject parent;
int type; /* virDomainChrType */
virObjectPtr privateData;
union {
@@ -1238,6 +1238,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/libvirt_private.syms b/src/libvirt_private.syms
index 4a927a26bf..5a83243d58 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -220,6 +220,7 @@ virSEVCapabilitiesFree;
# conf/domain_conf.h
+vir_domain_chr_source_def_get_type;
vir_domain_xml_option_get_type;
virBlkioDeviceArrayClear;
virDiskNameParse;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 252f2a045e..41dfba5597 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2339,7 +2339,7 @@ qemuDomainObjPrivateFree(void *data)
qemuDomainObjPrivateDataClear(priv);
- virObjectUnref(priv->monConfig);
+ g_clear_object(&priv->monConfig);
qemuDomainObjFreeJob(priv);
VIR_FREE(priv->lockState);
VIR_FREE(priv->origname);
@@ -3960,8 +3960,7 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
error:
virBitmapFree(priv->namespaces);
priv->namespaces = NULL;
- virObjectUnref(priv->monConfig);
- priv->monConfig = NULL;
+ 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 0d9a83ab89..101ec3c3d8 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -7383,8 +7383,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.26.2