Turn virCapabilities into a virObject

To enable virCapabilities instances to be reference counted,
turn it into a virObject. All cases of virCapabilitiesFree
turn into virObjectUnref

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2013-02-01 12:26:18 +00:00
parent 5b984370f6
commit fed92f08db
39 changed files with 83 additions and 75 deletions

View File

@ -40,6 +40,22 @@ VIR_ENUM_DECL(virCapsHostPMTarget)
VIR_ENUM_IMPL(virCapsHostPMTarget, VIR_NODE_SUSPEND_TARGET_LAST,
"suspend_mem", "suspend_disk", "suspend_hybrid");
static virClassPtr virCapsClass;
static void virCapabilitiesDispose(void *obj);
static int virCapabilitiesOnceInit(void)
{
if (!(virCapsClass = virClassNew(virClassForObject(),
"virCaps",
sizeof(virCaps),
virCapabilitiesDispose)))
return -1;
return 0;
}
VIR_ONCE_GLOBAL_INIT(virCapabilities)
/**
* virCapabilitiesNew:
* @hostarch: host machine architecture
@ -55,7 +71,10 @@ virCapabilitiesNew(virArch hostarch,
{
virCapsPtr caps;
if (VIR_ALLOC(caps) < 0)
if (virCapabilitiesInitialize() < 0)
return NULL;
if (!(caps = virObjectNew(virCapsClass)))
return NULL;
caps->host.arch = hostarch;
@ -165,17 +184,11 @@ virCapabilitiesFreeNUMAInfo(virCapsPtr caps)
caps->host.nnumaCell = 0;
}
/**
* virCapabilitiesFree:
* @caps: object to free
*
* Free all memory associated with capabilities
*/
void
virCapabilitiesFree(virCapsPtr caps) {
static void
virCapabilitiesDispose(void *object)
{
virCapsPtr caps = object;
int i;
if (caps == NULL)
return;
for (i = 0 ; i < caps->nguests ; i++)
virCapabilitiesFreeGuest(caps->guests[i]);
@ -198,8 +211,6 @@ virCapabilitiesFree(virCapsPtr caps) {
VIR_FREE(caps->host.secModels);
virCPUDefFree(caps->host.cpu);
VIR_FREE(caps);
}

View File

@ -29,6 +29,7 @@
# include "cpu_conf.h"
# include "virarch.h"
# include "virmacaddr.h"
# include "virobject.h"
# include <libxml/xpath.h>
@ -152,6 +153,8 @@ struct _virDomainXMLNamespace {
typedef struct _virCaps virCaps;
typedef virCaps* virCapsPtr;
struct _virCaps {
virObject parent;
virCapsHost host;
size_t nguests;
size_t nguests_max;
@ -177,9 +180,6 @@ virCapabilitiesNew(virArch hostarch,
int offlineMigrate,
int liveMigrate);
extern void
virCapabilitiesFree(virCapsPtr caps);
extern void
virCapabilitiesFreeNUMAInfo(virCapsPtr caps);

View File

@ -70,7 +70,7 @@ esxFreePrivate(esxPrivate **priv)
esxVI_Context_Free(&(*priv)->host);
esxVI_Context_Free(&(*priv)->vCenter);
esxUtil_FreeParsedUri(&(*priv)->parsedUri);
virCapabilitiesFree((*priv)->caps);
virObjectUnref((*priv)->caps);
VIR_FREE(*priv);
}
@ -642,7 +642,7 @@ esxCapsInit(esxPrivate *priv)
return caps;
failure:
virCapabilitiesFree(caps);
virObjectUnref(caps);
return NULL;
}

View File

@ -62,7 +62,6 @@ virCapabilitiesDefaultGuestArch;
virCapabilitiesDefaultGuestEmulator;
virCapabilitiesDefaultGuestMachine;
virCapabilitiesFormatXML;
virCapabilitiesFree;
virCapabilitiesFreeMachines;
virCapabilitiesFreeNUMAInfo;
virCapabilitiesGenerateMac;

View File

@ -169,7 +169,7 @@ libxlBuildCapabilities(virArch hostarch,
return caps;
no_memory:
virCapabilitiesFree(caps);
virObjectUnref(caps);
return NULL;
}
@ -297,7 +297,7 @@ libxlMakeCapabilitiesInternal(virArch hostarch,
no_memory:
virReportOOMError();
virCapabilitiesFree(caps);
virObjectUnref(caps);
return NULL;
}

View File

@ -1074,7 +1074,7 @@ libxlShutdown(void)
return -1;
libxlDriverLock(libxl_driver);
virCapabilitiesFree(libxl_driver->caps);
virObjectUnref(libxl_driver->caps);
virObjectUnref(libxl_driver->domains);
libxl_ctx_free(libxl_driver->ctx);
xtl_logger_destroy(libxl_driver->logger);

View File

@ -150,7 +150,7 @@ no_memory:
virReportOOMError();
error:
virCapabilitiesFree(caps);
virObjectUnref(caps);
return NULL;
}

View File

@ -182,7 +182,7 @@ static virLXCControllerPtr virLXCControllerNew(const char *name)
cleanup:
VIR_FREE(configFile);
virCapabilitiesFree(caps);
virObjectUnref(caps);
return ctrl;
no_memory:

View File

@ -1559,7 +1559,7 @@ static int lxcShutdown(void)
virLXCProcessAutoDestroyShutdown(lxc_driver);
virCapabilitiesFree(lxc_driver->caps);
virObjectUnref(lxc_driver->caps);
virSecurityManagerFree(lxc_driver->securityManager);
VIR_FREE(lxc_driver->configDir);
VIR_FREE(lxc_driver->autostartDir);

View File

@ -210,7 +210,7 @@ virCapsPtr openvzCapsInit(void)
return caps;
no_memory:
virCapabilitiesFree(caps);
virObjectUnref(caps);
return NULL;
}
@ -559,7 +559,7 @@ openvzFreeDriver(struct openvz_driver *driver)
return;
virObjectUnref(driver->domains);
virCapabilitiesFree(driver->caps);
virObjectUnref(driver->caps);
VIR_FREE(driver);
}

View File

@ -157,7 +157,7 @@ parallelsBuildCapabilities(void)
no_memory:
virReportOOMError();
virCapabilitiesFree(caps);
virObjectUnref(caps);
return NULL;
}
@ -941,7 +941,7 @@ parallelsOpenDefault(virConnectPtr conn)
error:
virObjectUnref(privconn->domains);
virCapabilitiesFree(privconn->caps);
virObjectUnref(privconn->caps);
virStoragePoolObjListFree(&privconn->pools);
VIR_FREE(privconn);
return VIR_DRV_OPEN_ERROR;
@ -986,7 +986,7 @@ parallelsClose(virConnectPtr conn)
parallelsConnPtr privconn = conn->privateData;
parallelsDriverLock(privconn);
virCapabilitiesFree(privconn->caps);
virObjectUnref(privconn->caps);
virObjectUnref(privconn->domains);
conn->privateData = NULL;

View File

@ -346,7 +346,7 @@ phypCapsInit(void)
return caps;
no_memory:
virCapabilitiesFree(caps);
virObjectUnref(caps);
return NULL;
}
@ -1222,7 +1222,7 @@ phypOpen(virConnectPtr conn,
failure:
if (phyp_driver != NULL) {
virCapabilitiesFree(phyp_driver->caps);
virObjectUnref(phyp_driver->caps);
VIR_FREE(phyp_driver->managed_system);
VIR_FREE(phyp_driver);
}
@ -1251,7 +1251,7 @@ phypClose(virConnectPtr conn)
libssh2_session_disconnect(session, "Disconnecting...");
libssh2_session_free(session);
virCapabilitiesFree(phyp_driver->caps);
virObjectUnref(phyp_driver->caps);
phypUUIDTable_Free(phyp_driver->uuid_table);
VIR_FREE(phyp_driver->managed_system);
VIR_FREE(phyp_driver);

View File

@ -932,7 +932,7 @@ virCapsPtr qemuCapsInit(qemuCapsCachePtr cache)
return caps;
error:
virCapabilitiesFree(caps);
virObjectUnref(caps);
return NULL;
}

View File

@ -483,7 +483,7 @@ no_memory:
virReportOOMError();
err_exit:
VIR_FREE(sec_managers);
virCapabilitiesFree(caps);
virObjectUnref(caps);
virObjectUnref(cfg);
return NULL;
}
@ -1054,7 +1054,7 @@ qemuShutdown(void) {
virObjectUnref(qemu_driver->inactivePciHostdevs);
virObjectUnref(qemu_driver->activeUsbHostdevs);
virHashFree(qemu_driver->sharedDisks);
virCapabilitiesFree(qemu_driver->caps);
virObjectUnref(qemu_driver->caps);
qemuCapsCacheFree(qemu_driver->capsCache);
virObjectUnref(qemu_driver->domains);
@ -1281,12 +1281,10 @@ static char *qemuGetCapabilities(virConnectPtr conn) {
qemuDriverLock(driver);
if ((caps = qemuCreateCapabilities(qemu_driver)) == NULL) {
virCapabilitiesFree(caps);
if ((caps = qemuCreateCapabilities(qemu_driver)) == NULL)
goto cleanup;
}
virCapabilitiesFree(qemu_driver->caps);
virObjectUnref(qemu_driver->caps);
qemu_driver->caps = caps;
if ((xml = virCapabilitiesFormatXML(driver->caps)) == NULL)

View File

@ -84,7 +84,7 @@ vahDeinit(vahControl * ctl)
return -1;
VIR_FREE(ctl->def);
virCapabilitiesFree(ctl->caps);
virObjectUnref(ctl->caps);
VIR_FREE(ctl->files);
VIR_FREE(ctl->hvm);
VIR_FREE(ctl->newfile);

View File

@ -230,7 +230,7 @@ testBuildCapabilities(virConnectPtr conn) {
no_memory:
virReportOOMError();
virCapabilitiesFree(caps);
virObjectUnref(caps);
return NULL;
}
@ -651,7 +651,7 @@ error:
virInterfaceObjListFree(&privconn->ifaces);
virStoragePoolObjListFree(&privconn->pools);
virNodeDeviceObjListFree(&privconn->devs);
virCapabilitiesFree(privconn->caps);
virObjectUnref(privconn->caps);
testDriverUnlock(privconn);
conn->privateData = NULL;
VIR_FREE(privconn);
@ -1183,7 +1183,7 @@ static int testClose(virConnectPtr conn)
{
testConnPtr privconn = conn->privateData;
testDriverLock(privconn);
virCapabilitiesFree(privconn->caps);
virObjectUnref(privconn->caps);
virObjectUnref(privconn->domains);
virNodeDeviceObjListFree(&privconn->devs);
virNetworkObjListFree(&privconn->networks);

View File

@ -107,7 +107,7 @@ virCapsPtr umlCapsInit(void) {
return caps;
error:
virCapabilitiesFree(caps);
virObjectUnref(caps);
return NULL;
}

View File

@ -631,7 +631,7 @@ umlShutdown(void) {
if (uml_driver->inotifyWatch != -1)
virEventRemoveHandle(uml_driver->inotifyWatch);
VIR_FORCE_CLOSE(uml_driver->inotifyFD);
virCapabilitiesFree(uml_driver->caps);
virObjectUnref(uml_driver->caps);
/* shutdown active VMs
* XXX allow them to stay around & reconnect */

View File

@ -886,7 +886,7 @@ static virCapsPtr vboxCapsInit(void)
return caps;
no_memory:
virCapabilitiesFree(caps);
virObjectUnref(caps);
return NULL;
}
@ -977,7 +977,7 @@ static void vboxUninitialize(vboxGlobalData *data) {
if (data->pFuncs)
data->pFuncs->pfnComUninitialize();
virCapabilitiesFree(data->caps);
virObjectUnref(data->caps);
#if VBOX_API_VERSION == 2002
/* No domainEventCallbacks in 2.2.* version */
#else /* !(VBOX_API_VERSION == 2002) */

View File

@ -44,7 +44,7 @@ vmwareFreeDriver(struct vmware_driver *driver)
virMutexDestroy(&driver->lock);
virObjectUnref(driver->domains);
virCapabilitiesFree(driver->caps);
virObjectUnref(driver->caps);
VIR_FREE(driver);
}
@ -133,7 +133,7 @@ cleanup:
return caps;
error:
virCapabilitiesFree(caps);
virObjectUnref(caps);
goto cleanup;
}

View File

@ -447,7 +447,7 @@ xenUnifiedClose(virConnectPtr conn)
GET_PRIVATE(conn);
int i;
virCapabilitiesFree(priv->caps);
virObjectUnref(priv->caps);
virDomainEventStateFree(priv->domainEvents);
for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)

View File

@ -2343,7 +2343,7 @@ xenHypervisorBuildCapabilities(virConnectPtr conn,
if (hv_versions.sys_interface >= SYS_IFACE_MIN_VERS_NUMA && conn != NULL) {
if (xenDaemonNodeGetTopology(conn, caps) != 0) {
virCapabilitiesFree(caps);
virObjectUnref(caps);
return NULL;
}
}
@ -2444,7 +2444,7 @@ xenHypervisorBuildCapabilities(virConnectPtr conn,
return caps;
no_memory:
virCapabilitiesFree(caps);
virObjectUnref(caps);
return NULL;
}
@ -2708,7 +2708,7 @@ xenHypervisorMakeCapabilitiesInternal(virConnectPtr conn,
no_memory:
virReportOOMError();
virCapabilitiesFree(caps);
virObjectUnref(caps);
return NULL;
}

View File

@ -88,7 +88,7 @@ getCapsObject(void)
return caps;
error_cleanup:
virCapabilitiesFree(caps);
virObjectUnref(caps);
return NULL;
}
@ -207,7 +207,7 @@ xenapiOpen(virConnectPtr conn, virConnectAuthPtr auth,
VIR_FREE(password);
if (privP != NULL) {
virCapabilitiesFree(privP->caps);
virObjectUnref(privP->caps);
if (privP->session != NULL)
xenSessionFree(privP->session);
@ -230,7 +230,7 @@ xenapiClose(virConnectPtr conn)
{
struct _xenapiPrivate *priv = conn->privateData;
virCapabilitiesFree(priv->caps);
virObjectUnref(priv->caps);
if (priv->session != NULL) {
xen_session_logout(priv->session);

View File

@ -112,7 +112,7 @@ mymain(void)
DO_TEST("metadata", "c7a5fdbd-edaf-9455-926a-d65c16db1809", 0);
DO_TEST("external_vm", "c7a5fdbd-edaf-9455-926a-d65c16db1809", 0);
virCapabilitiesFree(driver.caps);
virObjectUnref(driver.caps);
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
}

View File

@ -123,7 +123,7 @@ mymain(void)
DO_TEST("systemd");
DO_TEST("hostdev");
virCapabilitiesFree(caps);
virObjectUnref(caps);
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
}

View File

@ -243,7 +243,7 @@ mymain(void)
DO_TEST_FULL("qemu-ns-no-env", 1, NULL);
virObjectUnref(driver.config);
virCapabilitiesFree(driver.caps);
virObjectUnref(driver.caps);
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
}

View File

@ -462,7 +462,7 @@ mymain(void)
DO_TEST(GetCPUDefinitions);
DO_TEST(GetCommands);
virCapabilitiesFree(caps);
virObjectUnref(caps);
return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}

View File

@ -883,7 +883,7 @@ mymain(void)
QEMU_CAPS_DEVICE_QXL, QEMU_CAPS_DEVICE_QXL_VGA);
virObjectUnref(driver.config);
virCapabilitiesFree(driver.caps);
virObjectUnref(driver.caps);
VIR_FREE(map);
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;

View File

@ -258,7 +258,7 @@ mymain(void)
DO_TEST_DIFFERENT("metadata");
virCapabilitiesFree(driver.caps);
virObjectUnref(driver.caps);
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
}

View File

@ -251,7 +251,7 @@ mymain(void)
DO_TEST("qemu-ns-commandline-ns1", false, NONE);
virObjectUnref(driver.config);
virCapabilitiesFree(driver.caps);
virObjectUnref(driver.caps);
VIR_FREE(map);
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;

View File

@ -183,7 +183,7 @@ mymain(void)
DO_TEST("boot-grub", "boot-grub", 1);
virCapabilitiesFree(caps);
virObjectUnref(caps);
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
}

View File

@ -58,7 +58,7 @@ virCapsPtr testLXCCapsInit(void) {
return caps;
error:
virCapabilitiesFree(caps);
virObjectUnref(caps);
return NULL;
}
#endif

View File

@ -261,7 +261,7 @@ virCapsPtr testQemuCapsInit(void) {
cleanup:
virCapabilitiesFreeMachines(machines, nmachines);
virCapabilitiesFree(caps);
virObjectUnref(caps);
return NULL;
}
#endif

View File

@ -75,6 +75,6 @@ virCapsPtr testXenCapsInit(void) {
cleanup:
virCapabilitiesFreeMachines(machines, nmachines);
virCapabilitiesFree(caps);
virObjectUnref(caps);
return NULL;
}

View File

@ -71,7 +71,7 @@ testCapsInit(void)
return;
failure:
virCapabilitiesFree(caps);
virObjectUnref(caps);
caps = NULL;
}
@ -295,7 +295,7 @@ mymain(void)
DO_TEST("svga", "svga");
virCapabilitiesFree(caps);
virObjectUnref(caps);
return result == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}

View File

@ -62,7 +62,7 @@ testCompareFiles(virArch hostmachine, const char *xml_rel,
VIR_FORCE_FCLOSE(fp1);
VIR_FORCE_FCLOSE(fp2);
virCapabilitiesFree(caps);
virObjectUnref(caps);
return ret;
}

View File

@ -245,7 +245,7 @@ mymain(void)
DO_TEST("no-source-cdrom", 2);
DO_TEST("pci-devs", 2);
virCapabilitiesFree(caps);
virObjectUnref(caps);
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
}

View File

@ -168,7 +168,7 @@ mymain(void)
DO_TEST("boot-grub", "boot-grub", "fvtest", 1);
DO_TEST("escape", "escape", "fvtest", 1);
virCapabilitiesFree(caps);
virObjectUnref(caps);
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
}

View File

@ -71,7 +71,7 @@ testCapsInit(void)
return;
failure:
virCapabilitiesFree(caps);
virObjectUnref(caps);
caps = NULL;
}
@ -305,7 +305,7 @@ mymain(void)
DO_TEST("svga", "svga", 4);
virCapabilitiesFree(caps);
virObjectUnref(caps);
return result == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}