Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx> --- src/conf/domain_conf.c | 52 +++++++++++++++++++++++----------------- 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, 47 insertions(+), 35 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8126423a18..85afadeb06 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2439,8 +2439,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: @@ -2515,6 +2514,7 @@ virDomainNetDefFree(virDomainNetDefPtr def) VIR_FREE(def); } +G_DEFINE_TYPE(virDomainChrSourceDef, vir_domain_chr_source_def, G_TYPE_OBJECT); const char * virDomainChrSourceDefGetPath(virDomainChrSourceDefPtr chr) @@ -2647,19 +2647,31 @@ virDomainChrSourceDefCopy(virDomainChrSourceDefPtr dest, } static void -virDomainChrSourceDefDispose(void *obj) +virDomainChrSourceDefDispose(GObject *obj) { - virDomainChrSourceDefPtr def = obj; + virDomainChrSourceDefPtr def = VIR_DOMAIN_CHR_SOURCE_DEF(obj); + + virObjectUnref(def->privateData); + def->privateData = NULL; + + G_OBJECT_CLASS(vir_domain_chr_source_def_parent_class)->dispose(obj); +} + +static void +virDomainChrSourceDefFinalize(GObject *obj) +{ + virDomainChrSourceDefPtr def = VIR_DOMAIN_CHR_SOURCE_DEF(obj); size_t i; virDomainChrSourceDefClear(def); - virObjectUnref(def->privateData); if (def->seclabels) { for (i = 0; i < def->nseclabels; i++) virSecurityDeviceLabelDefFree(def->seclabels[i]); VIR_FREE(def->seclabels); } + + G_OBJECT_CLASS(vir_domain_chr_source_def_parent_class)->finalize(obj); } @@ -13276,37 +13288,33 @@ 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->dispose = virDomainChrSourceDefDispose; + 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 964f51f8d5..c9a44ecfd8 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1188,7 +1188,7 @@ struct _virDomainChrSourceReconnectDef { /* The host side information for a character device. */ struct _virDomainChrSourceDef { - virObject parent; + GObject parent; int type; /* virDomainChrType */ virObjectPtr privateData; union { @@ -1234,6 +1234,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 5b6f97bd97..1a46ec3e3e 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 0ee0972902..c6980a53b6 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2315,7 +2315,7 @@ qemuDomainObjPrivateFree(void *data) qemuDomainObjPrivateDataClear(priv); - virObjectUnref(priv->monConfig); + g_clear_object(&priv->monConfig); qemuDomainObjFreeJob(priv); VIR_FREE(priv->lockState); VIR_FREE(priv->origname); @@ -3934,8 +3934,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 509e47926d..d7a7389f8f 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7388,8 +7388,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.3