提交 0b5617a6 编写于 作者: E Eric Blake

snapshot: make cloning of domain definition easier

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.
上级 0f9b6ee4
......@@ -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)
......
......@@ -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);
......
......@@ -312,6 +312,7 @@ virDomainDefCheckABIStability;
virDomainDefClearDeviceAliases;
virDomainDefClearPCIAddresses;
virDomainDefCompatibleDevice;
virDomainDefCopy;
virDomainDefFormat;
virDomainDefFormatInternal;
virDomainDefFree;
......
......@@ -12189,23 +12189,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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册