Signed-off-by: Rafael Fonseca <r4f4rfs@xxxxxxxxx> --- src/bhyve/bhyve_driver.c | 2 +- src/conf/domain_conf.c | 29 +++++++++++++++++++---------- src/conf/domain_conf.h | 9 +++++++++ src/esx/esx_driver.c | 2 +- src/libvirt_private.syms | 1 + src/libxl/libxl_driver.c | 2 +- src/lxc/lxc_controller.c | 2 +- src/lxc/lxc_driver.c | 2 +- src/openvz/openvz_conf.c | 2 +- src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_process.c | 15 +++++---------- src/security/virt-aa-helper.c | 2 +- src/test/test_driver.c | 2 +- src/vbox/vbox_common.c | 2 +- src/vmware/vmware_conf.c | 2 +- src/vz/vz_driver.c | 2 +- tests/bhyveargv2xmltest.c | 2 +- tests/bhyvexml2argvtest.c | 2 +- tests/bhyvexml2xmltest.c | 2 +- tests/domainconftest.c | 2 +- tests/genericxml2xmltest.c | 2 +- tests/openvzutilstest.c | 2 +- tests/testutilslxc.c | 2 +- tests/testutilsqemu.c | 2 +- tests/testutilsxen.c | 2 +- tests/vmx2xmltest.c | 2 +- tests/xml2vmxtest.c | 4 ++-- 27 files changed, 58 insertions(+), 44 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index bbaf6ea1f5..6a37c7973b 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -1182,7 +1182,7 @@ bhyveStateCleanup(void) virObjectUnref(bhyve_driver->domains); g_clear_object(&bhyve_driver->caps); - virObjectUnref(bhyve_driver->xmlopt); + g_clear_object(&bhyve_driver->xmlopt); virSysinfoDefFree(bhyve_driver->hostsysinfo); virObjectUnref(bhyve_driver->closeCallbacks); virObjectUnref(bhyve_driver->domainEventState); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 674cfa408e..8126423a18 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -70,7 +70,7 @@ VIR_LOG_INIT("conf.domain_conf"); /* This structure holds various callbacks and data needed * while parsing and creating domain XMLs */ struct _virDomainXMLOption { - virObject parent; + GObject parent; /* XML parser callbacks and defaults */ virDomainDefParserConfig config; @@ -1280,18 +1280,26 @@ VIR_ENUM_IMPL(virDomainLaunchSecurity, ); static virClassPtr virDomainObjClass; -static virClassPtr virDomainXMLOptionClass; static void virDomainObjDispose(void *obj); -static void virDomainXMLOptionDispose(void *obj); +G_DEFINE_TYPE(virDomainXMLOption, vir_domain_xml_option, G_TYPE_OBJECT); +static void virDomainXMLOptionFinalize(GObject *obj); + +static void vir_domain_xml_option_init(virDomainXMLOption *option G_GNUC_UNUSED) +{ +} + +static void vir_domain_xml_option_class_init(virDomainXMLOptionClass *klass) +{ + GObjectClass *obj = G_OBJECT_CLASS(klass); + + obj->finalize = virDomainXMLOptionFinalize; +} static int virDomainObjOnceInit(void) { if (!VIR_CLASS_NEW(virDomainObj, virClassForObjectLockable())) return -1; - if (!VIR_CLASS_NEW(virDomainXMLOption, virClassForObject())) - return -1; - return 0; } @@ -1299,12 +1307,14 @@ VIR_ONCE_GLOBAL_INIT(virDomainObj); static void -virDomainXMLOptionDispose(void *obj) +virDomainXMLOptionFinalize(GObject *obj) { - virDomainXMLOptionPtr xmlopt = obj; + virDomainXMLOptionPtr xmlopt = VIR_DOMAIN_XML_OPTION(obj); if (xmlopt->config.privFree) (xmlopt->config.privFree)(xmlopt->config.priv); + + G_OBJECT_CLASS(vir_domain_xml_option_parent_class)->finalize(obj); } /** @@ -1431,8 +1441,7 @@ virDomainXMLOptionNew(virDomainDefParserConfigPtr config, if (virDomainObjInitialize() < 0) return NULL; - if (!(xmlopt = virObjectNew(virDomainXMLOptionClass))) - return NULL; + xmlopt = VIR_DOMAIN_XML_OPTION(g_object_new(VIR_TYPE_DOMAIN_XML_OPTION, NULL)); if (priv) xmlopt->privateData = *priv; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 7d8f1aa31b..964f51f8d5 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -58,6 +58,8 @@ #include "virresctrl.h" #include "virenum.h" +#include <glib-object.h> + /* Flags for the 'type' field in virDomainDeviceDef */ typedef enum { VIR_DOMAIN_DEVICE_NONE = 0, @@ -2816,6 +2818,13 @@ struct _virDomainABIStability { virDomainABIStabilityDomain domain; }; +#define VIR_TYPE_DOMAIN_XML_OPTION vir_domain_xml_option_get_type() +G_DECLARE_FINAL_TYPE(virDomainXMLOption, + vir_domain_xml_option, + VIR, + DOMAIN_XML_OPTION, + GObject); + virDomainXMLOptionPtr virDomainXMLOptionNew(virDomainDefParserConfigPtr config, virDomainXMLPrivateDataCallbacksPtr priv, virXMLNamespacePtr xmlns, diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 39412f746a..42f6ab9392 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -70,7 +70,7 @@ esxFreePrivate(esxPrivate **priv) esxVI_Context_Free(&(*priv)->vCenter); esxUtil_FreeParsedUri(&(*priv)->parsedUri); g_clear_object(&(*priv)->caps); - virObjectUnref((*priv)->xmlopt); + g_clear_object(&(*priv)->xmlopt); VIR_FREE(*priv); } diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 4286efdd36..043a3afae8 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -219,6 +219,7 @@ virSEVCapabilitiesFree; # conf/domain_conf.h +vir_domain_xml_option_get_type; virBlkioDeviceArrayClear; virDiskNameParse; virDiskNameToBusDeviceIndex; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 980984b199..0fce6225d8 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -507,7 +507,7 @@ libxlStateCleanup(void) return -1; virObjectUnref(libxl_driver->hostdevMgr); - virObjectUnref(libxl_driver->xmlopt); + g_clear_object(&libxl_driver->xmlopt); virObjectUnref(libxl_driver->domains); virPortAllocatorRangeFree(libxl_driver->reservedGraphicsPorts); virPortAllocatorRangeFree(libxl_driver->migrationPorts); diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index f078c1c425..0aa56f6d24 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -180,7 +180,7 @@ virLXCControllerDriverFree(virLXCDriverPtr driver) { if (!driver) return; - virObjectUnref(driver->xmlopt); + g_clear_object(&driver->xmlopt); g_clear_object(&driver->caps); virMutexDestroy(&driver->lock); g_free(driver); diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 0cce0d70b7..09a2721ca3 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1613,7 +1613,7 @@ static int lxcStateCleanup(void) virObjectUnref(lxc_driver->hostdevMgr); g_clear_object(&lxc_driver->caps); virObjectUnref(lxc_driver->securityManager); - virObjectUnref(lxc_driver->xmlopt); + g_clear_object(&lxc_driver->xmlopt); if (lxc_driver->lockFD != -1) virPidFileRelease(lxc_driver->config->stateDir, "driver", lxc_driver->lockFD); diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 0d11d71dfd..474f75840f 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -479,7 +479,7 @@ openvzFreeDriver(struct openvz_driver *driver) if (!driver) return; - virObjectUnref(driver->xmlopt); + g_clear_object(&driver->xmlopt); virObjectUnref(driver->domains); g_clear_object(&driver->caps); VIR_FREE(driver); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index bf0a817ff1..9b353c6f07 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1121,7 +1121,7 @@ qemuStateCleanup(void) virObjectUnref(qemu_driver->securityManager); virObjectUnref(qemu_driver->domainEventState); virObjectUnref(qemu_driver->qemuCapsCache); - virObjectUnref(qemu_driver->xmlopt); + g_clear_object(&qemu_driver->xmlopt); virCPUDefFree(qemu_driver->hostcpu); virCapabilitiesHostNUMAUnref(qemu_driver->hostnuma); g_clear_object(&qemu_driver->caps); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index b35377d42b..509e47926d 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8565,9 +8565,8 @@ qemuProcessQMPInitMonitor(qemuMonitorPtr mon) static int qemuProcessQMPConnectMonitor(qemuProcessQMPPtr proc) { - virDomainXMLOptionPtr xmlopt = NULL; + g_autoptr(virDomainXMLOption) xmlopt = NULL; virDomainChrSourceDef monConfig; - int ret = -1; VIR_DEBUG("proc=%p, emulator=%s, proc->pid=%lld", proc, proc->binary, (long long)proc->pid); @@ -8579,25 +8578,21 @@ qemuProcessQMPConnectMonitor(qemuProcessQMPPtr proc) if (!(xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL)) || !(proc->vm = virDomainObjNew(xmlopt)) || !(proc->vm->def = virDomainDefNew())) - goto cleanup; + return -1; proc->vm->pid = proc->pid; if (!(proc->mon = qemuMonitorOpen(proc->vm, &monConfig, true, 0, virEventThreadGetContext(proc->eventThread), &callbacks, NULL))) - goto cleanup; + return -1; virObjectLock(proc->mon); if (qemuProcessQMPInitMonitor(proc->mon) < 0) - goto cleanup; - - ret = 0; + return -1; - cleanup: - virObjectUnref(xmlopt); - return ret; + return 0; } diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 02c0dc7fbc..dcfd3e95f8 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -80,7 +80,7 @@ vahDeinit(vahControl * ctl) VIR_FREE(ctl->def); g_clear_object(&ctl->caps); - virObjectUnref(ctl->xmlopt); + g_clear_object(&ctl->xmlopt); VIR_FREE(ctl->files); VIR_FREE(ctl->virtType); VIR_FREE(ctl->os); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 00ee8f7c59..5b9a49d685 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -159,7 +159,7 @@ testDriverDispose(void *obj) size_t i; g_clear_object(&driver->caps); - virObjectUnref(driver->xmlopt); + g_clear_object(&driver->xmlopt); virObjectUnref(driver->domains); virNodeDeviceObjListFree(driver->devs); virObjectUnref(driver->networks); diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index febf843cd5..7ca314d0dc 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -123,7 +123,7 @@ vboxDriverDispose(void *obj) vboxDriverPtr driver = obj; g_clear_object(&driver->caps); - virObjectUnref(driver->xmlopt); + g_clear_object(&driver->xmlopt); } static int diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index c8115ede3c..f9471752d2 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -55,7 +55,7 @@ vmwareFreeDriver(struct vmware_driver *driver) virMutexDestroy(&driver->lock); virObjectUnref(driver->domains); g_clear_object(&driver->caps); - virObjectUnref(driver->xmlopt); + g_clear_object(&driver->xmlopt); VIR_FREE(driver->vmrun); VIR_FREE(driver); } diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 85dac9a682..4fe072233e 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -149,7 +149,7 @@ static void vzDriverDispose(void * obj) prlsdkDisconnect(driver); virObjectUnref(driver->domains); g_clear_object(&driver->caps); - virObjectUnref(driver->xmlopt); + g_clear_object(&driver->xmlopt); virObjectUnref(driver->domainEventState); virSysinfoDefFree(driver->hostsysinfo); } diff --git a/tests/bhyveargv2xmltest.c b/tests/bhyveargv2xmltest.c index 3150c4583f..7abbf9a7fd 100644 --- a/tests/bhyveargv2xmltest.c +++ b/tests/bhyveargv2xmltest.c @@ -196,7 +196,7 @@ mymain(void) DO_TEST_FAIL("extraargs"); g_clear_object(&driver.caps); - virObjectUnref(driver.xmlopt); + g_clear_object(&driver.xmlopt); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c index 0429394246..0f2caa011b 100644 --- a/tests/bhyvexml2argvtest.c +++ b/tests/bhyvexml2argvtest.c @@ -250,7 +250,7 @@ mymain(void) DO_TEST_FAILURE("cputopology"); g_clear_object(&driver.caps); - virObjectUnref(driver.xmlopt); + g_clear_object(&driver.xmlopt); virPortAllocatorRangeFree(driver.remotePorts); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/tests/bhyvexml2xmltest.c b/tests/bhyvexml2xmltest.c index 27b9abb204..782741aab7 100644 --- a/tests/bhyvexml2xmltest.c +++ b/tests/bhyvexml2xmltest.c @@ -128,7 +128,7 @@ mymain(void) DO_TEST_DIFFERENT("input-xhci-tablet"); g_clear_object(&driver.caps); - virObjectUnref(driver.xmlopt); + g_clear_object(&driver.xmlopt); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/domainconftest.c b/tests/domainconftest.c index 54fdd72c25..361628dcf4 100644 --- a/tests/domainconftest.c +++ b/tests/domainconftest.c @@ -104,7 +104,7 @@ mymain(void) DO_TEST_GET_FS("/doesnotexist", false); g_clear_object(&caps); - virObjectUnref(xmlopt); + g_clear_object(&xmlopt); cleanup: return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; diff --git a/tests/genericxml2xmltest.c b/tests/genericxml2xmltest.c index a92f5dc613..139e2326ff 100644 --- a/tests/genericxml2xmltest.c +++ b/tests/genericxml2xmltest.c @@ -199,7 +199,7 @@ mymain(void) g_clear_object(&caps); - virObjectUnref(xmlopt); + g_clear_object(&xmlopt); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c index 124f17c3ce..00ed653835 100644 --- a/tests/openvzutilstest.c +++ b/tests/openvzutilstest.c @@ -131,7 +131,7 @@ testReadNetworkConf(const void *data G_GNUC_UNUSED) result = 0; cleanup: - virObjectUnref(driver.xmlopt); + g_clear_object(&driver.xmlopt); g_clear_object(&driver.caps); VIR_FREE(actual); virDomainDefFree(def); diff --git a/tests/testutilslxc.c b/tests/testutilslxc.c index bffc3ba440..c871f3b920 100644 --- a/tests/testutilslxc.c +++ b/tests/testutilslxc.c @@ -76,7 +76,7 @@ testLXCDriverInit(void) void testLXCDriverFree(virLXCDriverPtr driver) { - virObjectUnref(driver->xmlopt); + g_clear_object(&driver->xmlopt); g_clear_object(&driver->caps); virMutexDestroy(&driver->lock); g_free(driver); diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 440c91868f..eece670aa0 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -307,7 +307,7 @@ void qemuTestDriverFree(virQEMUDriver *driver) virFileDeleteTree(driver->config->configDir); } virObjectUnref(driver->qemuCapsCache); - virObjectUnref(driver->xmlopt); + g_clear_object(&driver->xmlopt); g_clear_object(&driver->caps); virObjectUnref(driver->config); virObjectUnref(driver->securityManager); diff --git a/tests/testutilsxen.c b/tests/testutilsxen.c index 7da90cdd1e..d680fe36e3 100644 --- a/tests/testutilsxen.c +++ b/tests/testutilsxen.c @@ -112,7 +112,7 @@ libxlDriverPrivatePtr testXLInitDriver(void) void testXLFreeDriver(libxlDriverPrivatePtr driver) { virObjectUnref(driver->config); - virObjectUnref(driver->xmlopt); + g_clear_object(&driver->xmlopt); virMutexDestroy(&driver->lock); g_free(driver); } diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index 613331cabc..07cb718f12 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -282,7 +282,7 @@ mymain(void) DO_TEST("datacenterpath", "datacenterpath"); g_clear_object(&caps); - virObjectUnref(xmlopt); + g_clear_object(&xmlopt); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c index 5d5fb8e69a..58e8adafcb 100644 --- a/tests/xml2vmxtest.c +++ b/tests/xml2vmxtest.c @@ -60,7 +60,7 @@ testCapsInit(void) failure: g_clear_object(&caps); - virObjectUnref(xmlopt); + g_clear_object(&xmlopt); } static int @@ -291,7 +291,7 @@ mymain(void) DO_TEST("datacenterpath", "datacenterpath", 4); g_clear_object(&caps); - virObjectUnref(xmlopt); + g_clear_object(&xmlopt); return result == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -- 2.25.3