Add the VIR_DOMAIN_DEF_COPY_NEWGENID to indicate that the generated
domain definition should adjust the genid value before returning the
@def to the caller.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/conf/domain_conf.c | 12 ++++++++++++
src/conf/domain_conf.h | 5 +++++
src/qemu/qemu_driver.c | 3 ++-
src/test/test_driver.c | 3 ++-
4 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1411034e7c..6d4db50998 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -27909,6 +27909,18 @@ virDomainDefCopy(virDomainDefPtr src,
ret = virDomainDefParseString(xml, caps, xmlopt, parseOpaque, parse_flags);
+ /* If we have a genid and we're being called from a path that would
+ * require a different genid value, then regardless of whether it was
+ * generated or not generate a new one. */
+ if (ret && ret->genidRequested && (flags &
VIR_DOMAIN_DEF_COPY_NEWGENID)) {
+ if (virUUIDGenerate(ret->genid)) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Failed to generate a new genid"));
+ virDomainDefFree(ret);
+ ret = NULL;
+ }
+ }
+
VIR_FREE(xml);
return ret;
}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 1b61fd8c03..910b3ca4d1 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2875,6 +2875,11 @@ virDomainDefPtr virDomainObjGetOneDef(virDomainObjPtr vm, unsigned
int flags);
typedef enum {
/* Set when creating a copy of a definition for the purpose of migration */
VIR_DOMAIN_DEF_COPY_MIGRATABLE = 1 << 0,
+
+ /* Set when the copy should create a new genid value if supported
+ * the domain def.
+ */
+ VIR_DOMAIN_DEF_COPY_NEWGENID = 1 << 1,
} virDomainDefCopyFlags;
virDomainDefPtr virDomainDefCopy(virDomainDefPtr src,
virCapsPtr caps,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 61e49bea24..bfb7973100 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15858,7 +15858,8 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
if (snap->def->dom) {
config = virDomainDefCopy(snap->def->dom, caps,
driver->xmlopt, NULL,
- VIR_DOMAIN_DEF_COPY_MIGRATABLE);
+ VIR_DOMAIN_DEF_COPY_MIGRATABLE |
+ VIR_DOMAIN_DEF_COPY_NEWGENID);
if (!config)
goto endjob;
}
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 8877a467f6..7bac017e1a 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -6690,7 +6690,8 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
snap->def->current = true;
config = virDomainDefCopy(snap->def->dom, privconn->caps,
privconn->xmlopt, NULL,
- VIR_DOMAIN_DEF_COPY_MIGRATABLE);
+ VIR_DOMAIN_DEF_COPY_MIGRATABLE |
+ VIR_DOMAIN_DEF_COPY_NEWGENID);
if (!config)
goto cleanup;
--
2.13.6