Upcoming patches for revert-and-clone branching of snapshots need to be able to copy a domain definition; make this step reusable. * src/conf/domain_conf.h (virDomainDefCopy): New prototype. * src/conf/domain_conf.c (virDomainObjCopyPersistentDef): Split... (virDomainDefCopy): ...into new function. (virDomainObjSetDefTransient): Use it. * src/libvirt_private.syms (domain_conf.h): Export it. * src/qemu/qemu_driver.c (qemuDomainRevertToSnapshot): Use it. --- src/conf/domain_conf.c | 37 +++++++++++++++++++++++-------------- src/conf/domain_conf.h | 2 ++ src/libvirt_private.syms | 1 + src/qemu/qemu_driver.c | 14 ++------------ 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ed21f0f..be76c06 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1861,8 +1861,6 @@ virDomainObjSetDefTransient(virCapsPtr caps, bool live) { int ret = -1; - char *xml = NULL; - virDomainDefPtr newDef = NULL; if (!virDomainObjIsActive(domain) && !live) return 0; @@ -1873,17 +1871,11 @@ virDomainObjSetDefTransient(virCapsPtr caps, if (domain->newDef) return 0; - if (!(xml = virDomainDefFormat(domain->def, VIR_DOMAIN_XML_WRITE_FLAGS))) + if (!(domain->newDef = virDomainDefCopy(caps, domain->def, false))) goto out; - if (!(newDef = virDomainDefParseString(caps, xml, -1, - VIR_DOMAIN_XML_READ_FLAGS))) - goto out; - - domain->newDef = newDef; ret = 0; out: - VIR_FREE(xml); return ret; } @@ -14917,24 +14909,41 @@ cleanup: } +/* Copy src into a new definition; with the quality of the copy + * depending on the migratable flag (false for transitions between + * persistent and active, true for transitions across save files or + * snapshots). */ virDomainDefPtr -virDomainObjCopyPersistentDef(virCapsPtr caps, virDomainObjPtr dom) +virDomainDefCopy(virCapsPtr caps, virDomainDefPtr src, bool migratable) { char *xml; - virDomainDefPtr cur, ret; + virDomainDefPtr ret; + unsigned int write_flags = VIR_DOMAIN_XML_WRITE_FLAGS; + unsigned int read_flags = VIR_DOMAIN_XML_READ_FLAGS; - cur = virDomainObjGetPersistentDef(caps, dom); + if (migratable) + write_flags |= VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_MIGRATABLE; - xml = virDomainDefFormat(cur, VIR_DOMAIN_XML_WRITE_FLAGS); + /* Easiest to clone via a round-trip through XML. */ + xml = virDomainDefFormat(src, write_flags); if (!xml) return NULL; - ret = virDomainDefParseString(caps, xml, -1, VIR_DOMAIN_XML_READ_FLAGS); + ret = virDomainDefParseString(caps, xml, -1, read_flags); VIR_FREE(xml); return ret; } +virDomainDefPtr +virDomainObjCopyPersistentDef(virCapsPtr caps, virDomainObjPtr dom) +{ + virDomainDefPtr cur; + + cur = virDomainObjGetPersistentDef(caps, dom); + return virDomainDefCopy(caps, cur, false); +} + virDomainState virDomainObjGetState(virDomainObjPtr dom, int *reason) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 091879e..c3e8c16 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1943,6 +1943,8 @@ virDomainLiveConfigHelperMethod(virCapsPtr caps, unsigned int *flags, virDomainDefPtr *persistentDef); +virDomainDefPtr virDomainDefCopy(virCapsPtr caps, virDomainDefPtr src, + bool migratable); virDomainDefPtr virDomainObjCopyPersistentDef(virCapsPtr caps, virDomainObjPtr dom); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 5a07139..756d7bd 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -312,6 +312,7 @@ virDomainDefCheckABIStability; virDomainDefClearDeviceAliases; virDomainDefClearPCIAddresses; virDomainDefCompatibleDevice; +virDomainDefCopy; virDomainDefFormat; virDomainDefFormatInternal; virDomainDefFree; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 039cbf3..f5bbc52 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12190,23 +12190,13 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, } /* Prepare to copy the snapshot inactive xml as the config of this - * domain. Easiest way is by a round trip through xml. + * domain. * * XXX Should domain snapshots track live xml rather * than inactive xml? */ snap->def->current = true; if (snap->def->dom) { - char *xml; - if (!(xml = qemuDomainDefFormatXML(driver, - snap->def->dom, - VIR_DOMAIN_XML_INACTIVE | - VIR_DOMAIN_XML_SECURE | - VIR_DOMAIN_XML_MIGRATABLE))) - goto cleanup; - config = virDomainDefParseString(driver->caps, xml, - QEMU_EXPECTED_VIRT_TYPES, - VIR_DOMAIN_XML_INACTIVE); - VIR_FREE(xml); + config = virDomainDefCopy(driver->caps, snap->def->dom, true); if (!config) goto cleanup; } -- 1.7.11.7 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list