From 9ebdb3b0aa62e3cdfd7ce206b839d91a48cc2c08 Mon Sep 17 00:00:00 2001 From: Ilias Stamatis Date: Sun, 4 Aug 2019 15:27:15 +0200 Subject: [PATCH] test_driver: introduce domain-private data vm-specific data can be used by APIs that need to preserve some state between calls Some of them are: - FS-related APIs for remembering which mountpoints are frozen - virDomainSetTime / virDomainGetTime for maintaining time information - virDomainSetIOThreadParams for storing the I/O thread parameters - virDomainManagedSaveDefineXML for internally storing the VM definition Signed-off-by: Ilias Stamatis Reviewed-by: Erik Skultety --- src/test/test_driver.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 6f407551e5..510cd72a59 100755 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -386,6 +386,35 @@ testBuildCapabilities(virConnectPtr conn) } +typedef struct _testDomainObjPrivate testDomainObjPrivate; +typedef testDomainObjPrivate *testDomainObjPrivatePtr; +struct _testDomainObjPrivate { + testDriverPtr driver; +}; + + +static void * +testDomainObjPrivateAlloc(void *opaque) +{ + testDomainObjPrivatePtr priv; + + if (VIR_ALLOC(priv) < 0) + return NULL; + + priv->driver = opaque; + + return priv; +} + + +static void +testDomainObjPrivateFree(void *data) +{ + testDomainObjPrivatePtr priv = data; + VIR_FREE(priv); +} + + static testDriverPtr testDriverNew(void) { @@ -401,6 +430,10 @@ testDriverNew(void) VIR_DOMAIN_DEF_FEATURE_FW_AUTOSELECT | VIR_DOMAIN_DEF_FEATURE_NET_MODEL_STRING, }; + virDomainXMLPrivateDataCallbacks privatecb = { + .alloc = testDomainObjPrivateAlloc, + .free = testDomainObjPrivateFree, + }; testDriverPtr ret; if (testDriverInitialize() < 0) @@ -409,7 +442,7 @@ testDriverNew(void) if (!(ret = virObjectLockableNew(testDriverClass))) return NULL; - if (!(ret->xmlopt = virDomainXMLOptionNew(&config, NULL, &ns, NULL, NULL)) || + if (!(ret->xmlopt = virDomainXMLOptionNew(&config, &privatecb, &ns, NULL, NULL)) || !(ret->eventState = virObjectEventStateNew()) || !(ret->ifaces = virInterfaceObjListNew()) || !(ret->domains = virDomainObjListNew()) ||