[libvirt] [PATCH v2 1/3] test_driver: use domain-private data to store managed image

Ilias Stamatis stamatis.iliass at gmail.com
Fri Aug 9 17:10:30 UTC 2019


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 at 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




More information about the libvir-list mailing list