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@xxxxxxxxxx> --- 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 5fdcddfa91..385ba4ce8c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27908,6 +27908,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 9da3b23393..dc748162b9 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2870,6 +2870,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 261b680775..56ac64630f 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -15850,7 +15850,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 f16bcf75de..d6be51795f 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -6723,7 +6723,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 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list