As pointed out by Ćukasz Mierzwa <[email protected]>, it would be nice if
there was an option to automatically make a domain persistent on the destination
during a live migration. The attached patch adds this simple capability. Note
that this has to be applied on top of my previous secure migration patch,
otherwise you'll have conflicts.
Signed-off-by: Chris Lalancette <[email protected]>
diff --git a/include/libvirt/libvirt.h b/include/libvirt/libvirt.h
index 195a6ee..72a7b21 100644
--- a/include/libvirt/libvirt.h
+++ b/include/libvirt/libvirt.h
@@ -320,6 +320,7 @@ typedef virDomainInterfaceStatsStruct *virDomainInterfaceStatsPtr;
typedef enum {
VIR_MIGRATE_LIVE = 1, /* live migration */
VIR_MIGRATE_SECURE = 2, /* secure migration */
+ VIR_MIGRATE_PERSISTENT = 4, /* persistent the VM on the destination */
} virDomainMigrateFlags;
/* Domain migration. */
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 688d13e..1103c73 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -320,6 +320,7 @@ typedef virDomainInterfaceStatsStruct *virDomainInterfaceStatsPtr;
typedef enum {
VIR_MIGRATE_LIVE = 1, /* live migration */
VIR_MIGRATE_SECURE = 2, /* secure migration */
+ VIR_MIGRATE_PERSISTENT = 4, /* persistent the VM on the destination */
} virDomainMigrateFlags;
/* Domain migration. */
diff --git a/src/libvirt.c b/src/libvirt.c
index 90e9c1b..942d014 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -2660,8 +2660,10 @@ error:
* host given by dconn (a connection to the destination host).
*
* Flags may be one of more of the following:
- * VIR_MIGRATE_LIVE Attempt a live migration.
- * VIR_MIGRATE_SECURE Attempt to do a secure migration
+ * VIR_MIGRATE_LIVE Attempt a live migration.
+ * VIR_MIGRATE_SECURE Attempt to do a secure migration
+ * VIR_MIGRATE_PERSISTENT If the migration is successful, persist the domain
+ * XML on the destination host.
*
* If a hypervisor supports renaming domains during migration,
* then you may set the dname parameter to the new name (otherwise
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 8747eb1..c77be7a 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -5264,6 +5264,7 @@ qemudDomainMigrateFinish2 (virConnectPtr dconn,
virDomainEventPtr event = NULL;
char *info = NULL;
struct secure_mig *secureMigData;
+ int newVM = 1;
qemuDriverLock(driver);
vm = virDomainFindByName(&driver->domains, dname);
@@ -5291,6 +5292,32 @@ qemudDomainMigrateFinish2 (virConnectPtr dconn,
* object, but if no, clean up the empty qemu process.
*/
if (retcode == 0) {
+ if (flags & VIR_MIGRATE_PERSISTENT) {
+ if (vm->persistent)
+ newVM = 0;
+ vm->persistent = 1;
+
+ if (virDomainSaveConfig(dconn, driver->configDir, vm->def) < 0) {
+ /* Hmpf. Migration was successful, but making it persistent
+ * was not. If we report successful, then when this domain
+ * shuts down, management tools are in for a surprise. On the
+ * other hand, if we report failure, then the management tools
+ * might try to restart the domain on the source side, even
+ * though the domain is actually running on the destination.
+ * Return a NULL dom pointer, and hope that this is a rare
+ * situation and management tools are smart.
+ */
+ vm = NULL;
+ goto cleanup;
+ }
+
+ event = virDomainEventNewFromObj(vm,
+ VIR_DOMAIN_EVENT_DEFINED,
+ newVM ?
+ VIR_DOMAIN_EVENT_DEFINED_ADDED :
+ VIR_DOMAIN_EVENT_DEFINED_UPDATED);
+
+ }
dom = virGetDomain (dconn, vm->def->name, vm->def->uuid);
VIR_FREE(info);
vm->state = VIR_DOMAIN_RUNNING;
diff --git a/src/virsh.c b/src/virsh.c
index cd31633..20dc472 100644
--- a/src/virsh.c
+++ b/src/virsh.c
@@ -2321,6 +2321,7 @@ static const vshCmdInfo info_migrate[] = {
static const vshCmdOptDef opts_migrate[] = {
{"live", VSH_OT_BOOL, 0, gettext_noop("live migration")},
{"secure", VSH_OT_BOOL, 0, gettext_noop("secure migration")},
+ {"persistent", VSH_OT_BOOL, 0, gettext_noop("persist VM on destination")},
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("domain name, id or uuid")},
{"desturi", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("connection URI of the destination host")},
{"migrateuri", VSH_OT_DATA, 0, gettext_noop("migration URI, usually can be omitted")},
@@ -2361,6 +2362,9 @@ cmdMigrate (vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptBool (cmd, "secure"))
flags |= VIR_MIGRATE_SECURE;
+ if (vshCommandOptBool (cmd, "persistent"))
+ flags |= VIR_MIGRATE_PERSISTENT;
+
/* Temporarily connect to the destination host. */
dconn = virConnectOpenAuth (desturi, virConnectAuthPtrDefault, 0);
if (!dconn) goto done;
--
Libvir-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/libvir-list