Blob Blame History Raw
From d60a5ab6fd5ba1ef21687eb995c7c2c2ffbd892c Mon Sep 17 00:00:00 2001
Message-Id: <d60a5ab6fd5ba1ef21687eb995c7c2c2ffbd892c@dist-git>
From: Eric Blake <eblake@redhat.com>
Date: Thu, 22 Jan 2015 15:53:54 +0100
Subject: [PATCH] metadata: track title edits across libvirtd restart

https://bugzilla.redhat.com/show_bug.cgi?id=1184929
https://bugzilla.redhat.com/show_bug.cgi?id=1122205

Although the edits were changing in-memory XML, it was not flushed
to disk; so unless some other action changes XML, a libvirtd restart
would lose the changed information.

* src/conf/domain_conf.c (virDomainObjSetMetadata): Add parameter,
to save live status across restarts.
(virDomainSaveXML): Allow for test driver.
* src/conf/domain_conf.h (virDomainObjSetMetadata): Adjust
signature.
* src/bhyve/bhyve_driver.c (bhyveDomainSetMetadata): Adjust caller.
* src/lxc/lxc_driver.c (lxcDomainSetMetadata): Likewise.
* src/qemu/qemu_driver.c (qemuDomainSetMetadata): Likewise.
* src/test/test_driver.c (testDomainSetMetadata): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 60e49440598b4aeb4a32bf23bfa5ed85672cbd6a)

Conflicts:
	src/bhyve/bhyve_driver.c - bhyve driver is missing
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/conf/domain_conf.c | 13 +++++++++++--
 src/conf/domain_conf.h |  1 +
 src/lxc/lxc_driver.c   |  3 ++-
 src/qemu/qemu_driver.c |  3 ++-
 src/test/test_driver.c |  2 +-
 5 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a2c0d6c..36b9ba7 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -17491,6 +17491,9 @@ virDomainSaveXML(const char *configDir,
     char *configFile = NULL;
     int ret = -1;
 
+    if (!configDir)
+        return 0;
+
     if ((configFile = virDomainConfigFile(configDir, def->name)) == NULL)
         goto cleanup;
 
@@ -19123,6 +19126,7 @@ virDomainObjSetMetadata(virDomainObjPtr vm,
                         const char *uri,
                         virCapsPtr caps,
                         virDomainXMLOptionPtr xmlopt,
+                        const char *stateDir,
                         const char *configDir,
                         unsigned int flags)
 {
@@ -19135,12 +19139,17 @@ virDomainObjSetMetadata(virDomainObjPtr vm,
                                         &persistentDef) < 0)
         return -1;
 
-    if (flags & VIR_DOMAIN_AFFECT_LIVE)
+    if (flags & VIR_DOMAIN_AFFECT_LIVE) {
         if (virDomainDefSetMetadata(vm->def, type, metadata, key, uri) < 0)
             return -1;
 
+        if (virDomainSaveStatus(xmlopt, stateDir, vm) < 0)
+            return -1;
+    }
+
     if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
-        if (virDomainDefSetMetadata(persistentDef, type, metadata, key, uri) < 0)
+        if (virDomainDefSetMetadata(persistentDef, type, metadata, key,
+                                    uri) < 0)
             return -1;
 
         if (virDomainSaveConfig(configDir, persistentDef) < 0)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index eaeea03..ef64d88 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2785,6 +2785,7 @@ int virDomainObjSetMetadata(virDomainObjPtr vm,
                             const char *uri,
                             virCapsPtr caps,
                             virDomainXMLOptionPtr xmlopt,
+                            const char *stateDir,
                             const char *configDir,
                             unsigned int flags);
 
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index e9f2f51..c47a206 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -4731,7 +4731,8 @@ lxcDomainSetMetadata(virDomainPtr dom,
         goto cleanup;
 
     ret = virDomainObjSetMetadata(vm, type, metadata, key, uri, caps,
-                                  driver->xmlopt, cfg->configDir, flags);
+                                  driver->xmlopt, cfg->stateDir,
+                                  cfg->configDir, flags);
 
 cleanup:
     virObjectUnlock(vm);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 57583e8..2ee3582 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15887,7 +15887,8 @@ qemuDomainSetMetadata(virDomainPtr dom,
         goto cleanup;
 
     ret = virDomainObjSetMetadata(vm, type, metadata, key, uri, caps,
-                                  driver->xmlopt, cfg->configDir, flags);
+                                  driver->xmlopt, cfg->stateDir,
+                                  cfg->configDir, flags);
 
 cleanup:
     virObjectUnlock(vm);
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 4d23738..e398130 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -2585,7 +2585,7 @@ static int testDomainSetMetadata(virDomainPtr dom,
 
     ret = virDomainObjSetMetadata(privdom, type, metadata, key, uri,
                                   privconn->caps, privconn->xmlopt,
-                                  NULL, flags);
+                                  NULL, NULL, flags);
 
 cleanup:
     if (privdom)
-- 
2.2.1