[libvirt] [PATCH v2 0/3] test_driver: implement the remaining ManagedSave APIs

Ilias Stamatis (3): test_driver: use domain-private data to store managed image test_driver: implement virDomainManagedSaveGetXMLDesc test_driver: implement virDomainManagedSaveDefineXML src/test/test_driver.c | 93 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-) -- 2.22.0

The managedSave APIs according to the documentation are supposed to operate on a disk file. However, this might not be appropriate in the case of the test driver since: * It's better if the test driver keeps all its state in memory only and doesn't affect the host in any way. * The test driver, apart from "emulating" the domains, it additionally "emulates" a fake physical host. Every time we start a new test connection that sort of means that a new physical host is created as well. And this fake host isn't necessarily the same. What we can do instead is operating on the already existing domain definitions. So along as a connection remains open, a domain can preserve the managed state between different shutdown / create calls. When the test connection closes this means that the fake host is destroyed as well, hence no other state is preserved after that. This way we also make sure that we don't touch the real host's filesystem. Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com> --- src/test/test_driver.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 2b5376ec28..8bd5a5296b 100755 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -396,6 +396,9 @@ struct _testDomainObjPrivate { /* used by get/set time APIs */ long long seconds; unsigned int nseconds; + + /* used by managed save APIs */ + virDomainDefPtr managedDef; }; @@ -413,6 +416,8 @@ testDomainObjPrivateAlloc(void *opaque) priv->seconds = 627319920; priv->nseconds = 0; + priv->managedDef = NULL; + return priv; } @@ -624,6 +629,7 @@ static const unsigned long long defaultPoolAlloc; static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr obj); static int testNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info); static virNetworkObjPtr testNetworkObjFindByName(testDriverPtr privconn, const char *name); +static int testDomainManagedSaveRemove(virDomainPtr dom, unsigned int flags); static virDomainObjPtr testDomObjFromDomain(virDomainPtr domain) @@ -706,6 +712,7 @@ testDomainStartState(testDriverPtr privconn, virDomainObjPtr dom, virDomainRunningReason reason) { + testDomainObjPrivatePtr priv = dom->privateData; int ret = -1; virDomainObjSetState(dom, VIR_DOMAIN_RUNNING, reason); @@ -717,7 +724,9 @@ testDomainStartState(testDriverPtr privconn, goto cleanup; } + virDomainDefFree(priv->managedDef); dom->hasManagedSave = false; + ret = 0; cleanup: if (ret < 0) @@ -4114,7 +4123,8 @@ static int testDomainUndefineFlags(virDomainPtr domain, event = virDomainEventLifecycleNewFromObj(privdom, VIR_DOMAIN_EVENT_UNDEFINED, VIR_DOMAIN_EVENT_UNDEFINED_REMOVED); - privdom->hasManagedSave = false; + + testDomainManagedSaveRemove(domain, 0); if (virDomainObjIsActive(privdom)) privdom->persistent = 0; @@ -7572,6 +7582,7 @@ static int testDomainManagedSave(virDomainPtr dom, unsigned int flags) { testDriverPtr privconn = dom->conn->privateData; + testDomainObjPrivatePtr privdom; virDomainObjPtr vm = NULL; virObjectEventPtr event = NULL; int ret = -1; @@ -7596,6 +7607,12 @@ testDomainManagedSave(virDomainPtr dom, unsigned int flags) event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED, VIR_DOMAIN_EVENT_STOPPED_SAVED); + + privdom = vm->privateData; + virDomainDefFree(privdom->managedDef); + privdom->managedDef = virDomainDefCopy(vm->def, privconn->caps, + privconn->xmlopt, NULL, false); + vm->hasManagedSave = true; ret = 0; @@ -7628,12 +7645,16 @@ static int testDomainManagedSaveRemove(virDomainPtr dom, unsigned int flags) { virDomainObjPtr vm; + testDomainObjPrivatePtr priv; virCheckFlags(0, -1); if (!(vm = testDomObjFromDomain(dom))) return -1; + priv = vm->privateData; + virDomainDefFree(priv->managedDef); + vm->hasManagedSave = false; virDomainObjEndAPI(&vm); -- 2.22.0

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com> --- src/test/test_driver.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 8bd5a5296b..211c0d737a 100755 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -7624,6 +7624,35 @@ testDomainManagedSave(virDomainPtr dom, unsigned int flags) } +static char * +testDomainManagedSaveGetXMLDesc(virDomainPtr dom, + unsigned int flags) +{ + virDomainObjPtr vm; + testDriverPtr privconn = dom->conn->privateData; + testDomainObjPrivatePtr privdom; + char *ret = NULL; + + virCheckFlags(VIR_DOMAIN_SAVE_IMAGE_XML_SECURE, NULL); + + if (!(vm = testDomObjFromDomain(dom))) + return NULL; + + if (vm->hasManagedSave == false) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("domain does not have managed save image")); + goto cleanup; + } + + privdom = vm->privateData; + ret = virDomainDefFormat(privdom->managedDef, privconn->caps, VIR_DOMAIN_DEF_FORMAT_SECURE); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + + static int testDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags) { @@ -9088,6 +9117,7 @@ static virHypervisorDriver testHypervisorDriver = { .domainSendProcessSignal = testDomainSendProcessSignal, /* 5.5.0 */ .connectGetCPUModelNames = testConnectGetCPUModelNames, /* 1.1.3 */ .domainManagedSave = testDomainManagedSave, /* 1.1.4 */ + .domainManagedSaveGetXMLDesc = testDomainManagedSaveGetXMLDesc, /* 5.7.0 */ .domainHasManagedSaveImage = testDomainHasManagedSaveImage, /* 1.1.4 */ .domainManagedSaveRemove = testDomainManagedSaveRemove, /* 1.1.4 */ .domainMemoryStats = testDomainMemoryStats, /* 5.7.0 */ -- 2.22.0

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com> --- src/test/test_driver.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 211c0d737a..a127dc69c1 100755 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -7653,6 +7653,45 @@ testDomainManagedSaveGetXMLDesc(virDomainPtr dom, } +static int +testDomainManagedSaveDefineXML(virDomainPtr dom, + const char *dxml, + unsigned int flags) +{ + virDomainObjPtr vm = NULL; + virDomainDefPtr newdef = NULL; + testDriverPtr privconn = dom->conn->privateData; + testDomainObjPrivatePtr privdom; + int ret = -1; + + virCheckFlags(VIR_DOMAIN_SAVE_BYPASS_CACHE | + VIR_DOMAIN_SAVE_RUNNING | + VIR_DOMAIN_SAVE_PAUSED, -1); + + if (!(vm = testDomObjFromDomain(dom))) + return -1; + + if (vm->hasManagedSave == false) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("domain does not have managed save image")); + goto cleanup; + } + + if ((newdef = virDomainDefParseString(dxml, privconn->caps, privconn->xmlopt, NULL, + VIR_DOMAIN_DEF_PARSE_INACTIVE)) == NULL) + goto cleanup; + + privdom = vm->privateData; + virDomainDefFree(privdom->managedDef); + privdom->managedDef = newdef; + + ret = 0; + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + + static int testDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags) { @@ -9118,6 +9157,7 @@ static virHypervisorDriver testHypervisorDriver = { .connectGetCPUModelNames = testConnectGetCPUModelNames, /* 1.1.3 */ .domainManagedSave = testDomainManagedSave, /* 1.1.4 */ .domainManagedSaveGetXMLDesc = testDomainManagedSaveGetXMLDesc, /* 5.7.0 */ + .domainManagedSaveDefineXML = testDomainManagedSaveDefineXML, /* 5.7.0 */ .domainHasManagedSaveImage = testDomainHasManagedSaveImage, /* 1.1.4 */ .domainManagedSaveRemove = testDomainManagedSaveRemove, /* 1.1.4 */ .domainMemoryStats = testDomainMemoryStats, /* 5.7.0 */ -- 2.22.0
participants (1)
-
Ilias Stamatis