提交 28f8dfdc 编写于 作者: J Jiri Denemark

Add MIGRATABLE flag for virDomainGetXMLDesc

Using VIR_DOMAIN_XML_MIGRATABLE flag, one can request domain's XML
configuration that is suitable for migration or save/restore. Such XML
may contain extra run-time stuff internal to libvirt and some default
configuration may be removed for better compatibility of the XML with
older libvirt releases.

This flag may serve as an easy way to get the XML that can be passed
(after desired modifications) to APIs that accept custom XMLs, such as
virDomainMigrate{,ToURI}2 or virDomainSaveFlags.
上级 edc9269a
...@@ -1651,6 +1651,7 @@ typedef enum { ...@@ -1651,6 +1651,7 @@ typedef enum {
VIR_DOMAIN_XML_SECURE = (1 << 0), /* dump security sensitive information too */ VIR_DOMAIN_XML_SECURE = (1 << 0), /* dump security sensitive information too */
VIR_DOMAIN_XML_INACTIVE = (1 << 1), /* dump inactive domain information */ VIR_DOMAIN_XML_INACTIVE = (1 << 1), /* dump inactive domain information */
VIR_DOMAIN_XML_UPDATE_CPU = (1 << 2), /* update guest CPU requirements according to host CPU */ VIR_DOMAIN_XML_UPDATE_CPU = (1 << 2), /* update guest CPU requirements according to host CPU */
VIR_DOMAIN_XML_MIGRATABLE = (1 << 3), /* dump XML suitable for migration */
} virDomainXMLFlags; } virDomainXMLFlags;
char * virDomainGetXMLDesc (virDomainPtr domain, char * virDomainGetXMLDesc (virDomainPtr domain,
......
...@@ -13314,7 +13314,8 @@ virDomainHubDefFormat(virBufferPtr buf, ...@@ -13314,7 +13314,8 @@ virDomainHubDefFormat(virBufferPtr buf,
#define DUMPXML_FLAGS \ #define DUMPXML_FLAGS \
(VIR_DOMAIN_XML_SECURE | \ (VIR_DOMAIN_XML_SECURE | \
VIR_DOMAIN_XML_INACTIVE | \ VIR_DOMAIN_XML_INACTIVE | \
VIR_DOMAIN_XML_UPDATE_CPU) VIR_DOMAIN_XML_UPDATE_CPU | \
VIR_DOMAIN_XML_MIGRATABLE)
verify(((VIR_DOMAIN_XML_INTERNAL_STATUS | verify(((VIR_DOMAIN_XML_INTERNAL_STATUS |
VIR_DOMAIN_XML_INTERNAL_ACTUAL_NET | VIR_DOMAIN_XML_INTERNAL_ACTUAL_NET |
......
...@@ -46,10 +46,6 @@ ...@@ -46,10 +46,6 @@
#define QEMU_NAMESPACE_HREF "http://libvirt.org/schemas/domain/qemu/1.0" #define QEMU_NAMESPACE_HREF "http://libvirt.org/schemas/domain/qemu/1.0"
#define QEMU_DOMAIN_FORMAT_LIVE_FLAGS \
(VIR_DOMAIN_XML_SECURE | \
VIR_DOMAIN_XML_UPDATE_CPU)
VIR_ENUM_IMPL(qemuDomainJob, QEMU_JOB_LAST, VIR_ENUM_IMPL(qemuDomainJob, QEMU_JOB_LAST,
"none", "none",
"query", "query",
...@@ -1220,7 +1216,6 @@ int ...@@ -1220,7 +1216,6 @@ int
qemuDomainDefFormatBuf(struct qemud_driver *driver, qemuDomainDefFormatBuf(struct qemud_driver *driver,
virDomainDefPtr def, virDomainDefPtr def,
unsigned int flags, unsigned int flags,
bool compatible,
virBuffer *buf) virBuffer *buf)
{ {
int ret = -1; int ret = -1;
...@@ -1245,7 +1240,7 @@ qemuDomainDefFormatBuf(struct qemud_driver *driver, ...@@ -1245,7 +1240,7 @@ qemuDomainDefFormatBuf(struct qemud_driver *driver,
def->cpu = cpu; def->cpu = cpu;
} }
if (compatible) { if ((flags & VIR_DOMAIN_XML_MIGRATABLE)) {
int i; int i;
virDomainControllerDefPtr usb = NULL; virDomainControllerDefPtr usb = NULL;
...@@ -1297,12 +1292,11 @@ cleanup: ...@@ -1297,12 +1292,11 @@ cleanup:
char *qemuDomainDefFormatXML(struct qemud_driver *driver, char *qemuDomainDefFormatXML(struct qemud_driver *driver,
virDomainDefPtr def, virDomainDefPtr def,
unsigned int flags, unsigned int flags)
bool compatible)
{ {
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
if (qemuDomainDefFormatBuf(driver, def, flags, compatible, &buf) < 0) { if (qemuDomainDefFormatBuf(driver, def, flags, &buf) < 0) {
virBufferFreeAndReset(&buf); virBufferFreeAndReset(&buf);
return NULL; return NULL;
} }
...@@ -1318,8 +1312,7 @@ char *qemuDomainDefFormatXML(struct qemud_driver *driver, ...@@ -1318,8 +1312,7 @@ char *qemuDomainDefFormatXML(struct qemud_driver *driver,
char *qemuDomainFormatXML(struct qemud_driver *driver, char *qemuDomainFormatXML(struct qemud_driver *driver,
virDomainObjPtr vm, virDomainObjPtr vm,
unsigned int flags, unsigned int flags)
bool compatible)
{ {
virDomainDefPtr def; virDomainDefPtr def;
...@@ -1328,7 +1321,7 @@ char *qemuDomainFormatXML(struct qemud_driver *driver, ...@@ -1328,7 +1321,7 @@ char *qemuDomainFormatXML(struct qemud_driver *driver,
else else
def = vm->def; def = vm->def;
return qemuDomainDefFormatXML(driver, def, flags, compatible); return qemuDomainDefFormatXML(driver, def, flags);
} }
char * char *
...@@ -1341,8 +1334,10 @@ qemuDomainDefFormatLive(struct qemud_driver *driver, ...@@ -1341,8 +1334,10 @@ qemuDomainDefFormatLive(struct qemud_driver *driver,
if (inactive) if (inactive)
flags |= VIR_DOMAIN_XML_INACTIVE; flags |= VIR_DOMAIN_XML_INACTIVE;
if (compatible)
flags |= VIR_DOMAIN_XML_MIGRATABLE;
return qemuDomainDefFormatXML(driver, def, flags, compatible); return qemuDomainDefFormatXML(driver, def, flags);
} }
......
...@@ -39,6 +39,10 @@ ...@@ -39,6 +39,10 @@
(1 << VIR_DOMAIN_VIRT_KVM) | \ (1 << VIR_DOMAIN_VIRT_KVM) | \
(1 << VIR_DOMAIN_VIRT_XEN)) (1 << VIR_DOMAIN_VIRT_XEN))
# define QEMU_DOMAIN_FORMAT_LIVE_FLAGS \
(VIR_DOMAIN_XML_SECURE | \
VIR_DOMAIN_XML_UPDATE_CPU)
# if ULONG_MAX == 4294967295 # if ULONG_MAX == 4294967295
/* Qemu has a 64-bit limit, but we are limited by our historical choice of /* Qemu has a 64-bit limit, but we are limited by our historical choice of
* representing bandwidth in a long instead of a 64-bit int. */ * representing bandwidth in a long instead of a 64-bit int. */
...@@ -253,18 +257,15 @@ void qemuDomainObjExitRemoteWithDriver(struct qemud_driver *driver, ...@@ -253,18 +257,15 @@ void qemuDomainObjExitRemoteWithDriver(struct qemud_driver *driver,
int qemuDomainDefFormatBuf(struct qemud_driver *driver, int qemuDomainDefFormatBuf(struct qemud_driver *driver,
virDomainDefPtr vm, virDomainDefPtr vm,
unsigned int flags, unsigned int flags,
bool compatible,
virBuffer *buf); virBuffer *buf);
char *qemuDomainDefFormatXML(struct qemud_driver *driver, char *qemuDomainDefFormatXML(struct qemud_driver *driver,
virDomainDefPtr vm, virDomainDefPtr vm,
unsigned int flags, unsigned int flags);
bool compatible);
char *qemuDomainFormatXML(struct qemud_driver *driver, char *qemuDomainFormatXML(struct qemud_driver *driver,
virDomainObjPtr vm, virDomainObjPtr vm,
unsigned int flags, unsigned int flags);
bool compatible);
char *qemuDomainDefFormatLive(struct qemud_driver *driver, char *qemuDomainDefFormatLive(struct qemud_driver *driver,
virDomainDefPtr def, virDomainDefPtr def,
......
...@@ -4966,7 +4966,7 @@ qemuDomainSaveImageGetXMLDesc(virConnectPtr conn, const char *path, ...@@ -4966,7 +4966,7 @@ qemuDomainSaveImageGetXMLDesc(virConnectPtr conn, const char *path,
if (fd < 0) if (fd < 0)
goto cleanup; goto cleanup;
ret = qemuDomainDefFormatXML(driver, def, flags, false); ret = qemuDomainDefFormatXML(driver, def, flags);
cleanup: cleanup:
virDomainDefFree(def); virDomainDefFree(def);
...@@ -5010,8 +5010,8 @@ qemuDomainSaveImageDefineXML(virConnectPtr conn, const char *path, ...@@ -5010,8 +5010,8 @@ qemuDomainSaveImageDefineXML(virConnectPtr conn, const char *path,
xml = qemuDomainDefFormatXML(driver, def, xml = qemuDomainDefFormatXML(driver, def,
VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_INACTIVE |
VIR_DOMAIN_XML_SECURE, VIR_DOMAIN_XML_SECURE |
true); VIR_DOMAIN_XML_MIGRATABLE);
if (!xml) if (!xml)
goto cleanup; goto cleanup;
len = strlen(xml) + 1; len = strlen(xml) + 1;
...@@ -5161,7 +5161,10 @@ endjob: ...@@ -5161,7 +5161,10 @@ endjob:
} }
} }
ret = qemuDomainFormatXML(driver, vm, flags, false); if ((flags & VIR_DOMAIN_XML_MIGRATABLE))
flags |= QEMU_DOMAIN_FORMAT_LIVE_FLAGS;
ret = qemuDomainFormatXML(driver, vm, flags);
cleanup: cleanup:
if (vm) if (vm)
...@@ -5201,7 +5204,7 @@ static char *qemuDomainXMLFromNative(virConnectPtr conn, ...@@ -5201,7 +5204,7 @@ static char *qemuDomainXMLFromNative(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
xml = qemuDomainDefFormatXML(driver, def, VIR_DOMAIN_XML_INACTIVE, false); xml = qemuDomainDefFormatXML(driver, def, VIR_DOMAIN_XML_INACTIVE);
cleanup: cleanup:
virDomainDefFree(def); virDomainDefFree(def);
...@@ -11732,8 +11735,7 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, ...@@ -11732,8 +11735,7 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
if (!(xml = qemuDomainDefFormatXML(driver, if (!(xml = qemuDomainDefFormatXML(driver,
snap->def->dom, snap->def->dom,
VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_INACTIVE |
VIR_DOMAIN_XML_SECURE, VIR_DOMAIN_XML_SECURE)))
false)))
goto cleanup; goto cleanup;
config = virDomainDefParseString(driver->caps, xml, config = virDomainDefParseString(driver->caps, xml,
QEMU_EXPECTED_VIRT_TYPES, QEMU_EXPECTED_VIRT_TYPES,
......
...@@ -432,8 +432,8 @@ qemuMigrationCookieXMLFormat(struct qemud_driver *driver, ...@@ -432,8 +432,8 @@ qemuMigrationCookieXMLFormat(struct qemud_driver *driver,
if (qemuDomainDefFormatBuf(driver, if (qemuDomainDefFormatBuf(driver,
mig->persistent, mig->persistent,
VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_INACTIVE |
VIR_DOMAIN_XML_SECURE, VIR_DOMAIN_XML_SECURE |
true, VIR_DOMAIN_XML_MIGRATABLE,
buf) < 0) buf) < 0)
return -1; return -1;
virBufferAdjustIndent(buf, -2); virBufferAdjustIndent(buf, -2);
...@@ -1264,7 +1264,7 @@ qemuMigrationPrepareAny(struct qemud_driver *driver, ...@@ -1264,7 +1264,7 @@ qemuMigrationPrepareAny(struct qemud_driver *driver,
int hookret; int hookret;
if (!(xml = qemuDomainDefFormatXML(driver, def, if (!(xml = qemuDomainDefFormatXML(driver, def,
VIR_DOMAIN_XML_SECURE, false))) VIR_DOMAIN_XML_SECURE)))
goto cleanup; goto cleanup;
hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, def->name, hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, def->name,
...@@ -2213,9 +2213,8 @@ static int doPeer2PeerMigrate2(struct qemud_driver *driver, ...@@ -2213,9 +2213,8 @@ static int doPeer2PeerMigrate2(struct qemud_driver *driver,
* and pass it to Prepare2. * and pass it to Prepare2.
*/ */
if (!(dom_xml = qemuDomainFormatXML(driver, vm, if (!(dom_xml = qemuDomainFormatXML(driver, vm,
VIR_DOMAIN_XML_SECURE | QEMU_DOMAIN_FORMAT_LIVE_FLAGS |
VIR_DOMAIN_XML_UPDATE_CPU, VIR_DOMAIN_XML_MIGRATABLE)))
true)))
return -1; return -1;
if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED) if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED)
......
...@@ -3139,7 +3139,7 @@ qemuProcessReconnect(void *opaque) ...@@ -3139,7 +3139,7 @@ qemuProcessReconnect(void *opaque)
/* Run an hook to allow admins to do some magic */ /* Run an hook to allow admins to do some magic */
if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
char *xml = qemuDomainDefFormatXML(driver, obj->def, 0, false); char *xml = qemuDomainDefFormatXML(driver, obj->def, 0);
int hookret; int hookret;
hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, obj->def->name, hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, obj->def->name,
...@@ -3367,7 +3367,7 @@ int qemuProcessStart(virConnectPtr conn, ...@@ -3367,7 +3367,7 @@ int qemuProcessStart(virConnectPtr conn,
/* Run an early hook to set-up missing devices */ /* Run an early hook to set-up missing devices */
if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
char *xml = qemuDomainDefFormatXML(driver, vm->def, 0, false); char *xml = qemuDomainDefFormatXML(driver, vm->def, 0);
int hookret; int hookret;
hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name, hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name,
...@@ -3584,7 +3584,7 @@ int qemuProcessStart(virConnectPtr conn, ...@@ -3584,7 +3584,7 @@ int qemuProcessStart(virConnectPtr conn,
/* now that we know it is about to start call the hook if present */ /* now that we know it is about to start call the hook if present */
if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
char *xml = qemuDomainDefFormatXML(driver, vm->def, 0, false); char *xml = qemuDomainDefFormatXML(driver, vm->def, 0);
int hookret; int hookret;
hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name, hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name,
...@@ -3825,7 +3825,7 @@ int qemuProcessStart(virConnectPtr conn, ...@@ -3825,7 +3825,7 @@ int qemuProcessStart(virConnectPtr conn,
/* finally we can call the 'started' hook script if any */ /* finally we can call the 'started' hook script if any */
if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
char *xml = qemuDomainDefFormatXML(driver, vm->def, 0, false); char *xml = qemuDomainDefFormatXML(driver, vm->def, 0);
int hookret; int hookret;
hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name, hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name,
...@@ -4005,7 +4005,7 @@ void qemuProcessStop(struct qemud_driver *driver, ...@@ -4005,7 +4005,7 @@ void qemuProcessStop(struct qemud_driver *driver,
/* now that we know it's stopped call the hook if present */ /* now that we know it's stopped call the hook if present */
if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
char *xml = qemuDomainDefFormatXML(driver, vm->def, 0, false); char *xml = qemuDomainDefFormatXML(driver, vm->def, 0);
/* we can't stop the operation even if the script raised an error */ /* we can't stop the operation even if the script raised an error */
virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name, virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name,
...@@ -4100,7 +4100,7 @@ retry: ...@@ -4100,7 +4100,7 @@ retry:
/* The "release" hook cleans up additional resources */ /* The "release" hook cleans up additional resources */
if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
char *xml = qemuDomainDefFormatXML(driver, vm->def, 0, false); char *xml = qemuDomainDefFormatXML(driver, vm->def, 0);
/* we can't stop the operation even if the script raised an error */ /* we can't stop the operation even if the script raised an error */
virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name, virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name,
...@@ -4302,7 +4302,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED, ...@@ -4302,7 +4302,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED,
/* Run an hook to allow admins to do some magic */ /* Run an hook to allow admins to do some magic */
if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) { if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
char *xml = qemuDomainDefFormatXML(driver, vm->def, 0, false); char *xml = qemuDomainDefFormatXML(driver, vm->def, 0);
int hookret; int hookret;
hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name, hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, vm->def->name,
......
...@@ -6399,6 +6399,7 @@ static const vshCmdOptDef opts_dumpxml[] = { ...@@ -6399,6 +6399,7 @@ static const vshCmdOptDef opts_dumpxml[] = {
{"inactive", VSH_OT_BOOL, 0, N_("show inactive defined XML")}, {"inactive", VSH_OT_BOOL, 0, N_("show inactive defined XML")},
{"security-info", VSH_OT_BOOL, 0, N_("include security sensitive information in XML dump")}, {"security-info", VSH_OT_BOOL, 0, N_("include security sensitive information in XML dump")},
{"update-cpu", VSH_OT_BOOL, 0, N_("update guest CPU according to host CPU")}, {"update-cpu", VSH_OT_BOOL, 0, N_("update guest CPU according to host CPU")},
{"migratable", VSH_OT_BOOL, 0, N_("provide XML suitable for migrations")},
{NULL, 0, 0, NULL} {NULL, 0, 0, NULL}
}; };
...@@ -6412,6 +6413,7 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd) ...@@ -6412,6 +6413,7 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd)
bool inactive = vshCommandOptBool(cmd, "inactive"); bool inactive = vshCommandOptBool(cmd, "inactive");
bool secure = vshCommandOptBool(cmd, "security-info"); bool secure = vshCommandOptBool(cmd, "security-info");
bool update = vshCommandOptBool(cmd, "update-cpu"); bool update = vshCommandOptBool(cmd, "update-cpu");
bool migratable = vshCommandOptBool(cmd, "migratable");
if (inactive) if (inactive)
flags |= VIR_DOMAIN_XML_INACTIVE; flags |= VIR_DOMAIN_XML_INACTIVE;
...@@ -6419,6 +6421,8 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd) ...@@ -6419,6 +6421,8 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd)
flags |= VIR_DOMAIN_XML_SECURE; flags |= VIR_DOMAIN_XML_SECURE;
if (update) if (update)
flags |= VIR_DOMAIN_XML_UPDATE_CPU; flags |= VIR_DOMAIN_XML_UPDATE_CPU;
if (migratable)
flags |= VIR_DOMAIN_XML_MIGRATABLE;
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return false; return false;
......
...@@ -948,7 +948,7 @@ NOTE: Some hypervisors may require the user to manually ensure proper ...@@ -948,7 +948,7 @@ NOTE: Some hypervisors may require the user to manually ensure proper
permissions on file and path specified by argument I<corefilepath>. permissions on file and path specified by argument I<corefilepath>.
=item B<dumpxml> I<domain> [I<--inactive>] [I<--security-info>] =item B<dumpxml> I<domain> [I<--inactive>] [I<--security-info>]
[I<--update-cpu>] [I<--update-cpu>] [I<--migratable>]
Output the domain information as an XML dump to stdout, this format can be used Output the domain information as an XML dump to stdout, this format can be used
by the B<create> command. Additional options affecting the XML dump may be by the B<create> command. Additional options affecting the XML dump may be
...@@ -956,7 +956,10 @@ used. I<--inactive> tells virsh to dump domain configuration that will be used ...@@ -956,7 +956,10 @@ used. I<--inactive> tells virsh to dump domain configuration that will be used
on next start of the domain as opposed to the current domain configuration. on next start of the domain as opposed to the current domain configuration.
Using I<--security-info> will also include security sensitive information Using I<--security-info> will also include security sensitive information
in the XML dump. I<--update-cpu> updates domain CPU requirements according to in the XML dump. I<--update-cpu> updates domain CPU requirements according to
host CPU. host CPU. With I<--migratable> one can request an XML that is suitable for
migrations, i.e., compatible with older libvirt releases and possibly amended
with internal run-time options. This option may automatically enable other
options (I<--update-cpu>, I<--security-info>, ...) as necessary.
=item B<edit> I<domain> =item B<edit> I<domain>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册