Signed-off-by: Cristian Klein <cristiklein(a)gmail.com>
---
tools/virsh-domain.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++--
tools/virsh.pod | 5 +++++
2 files changed, 63 insertions(+), 2 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 1753f6e..52e91d9 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -9439,6 +9439,10 @@ static const vshCmdOptDef opts_migrate[] = {
.type = VSH_OT_BOOL,
.help = N_("enable (but do not start) post-copy migration; to start post-copy
use migrate-start-postcopy")
},
+ {.name = "postcopy-after",
+ .type = VSH_OT_INT,
+ .help = N_("switch to post-copy migration if live migration exceeds timeout (in
seconds)")
+ },
{.name = "xml",
.type = VSH_OT_STRING,
.help = N_("filename containing updated XML for the target")
@@ -9522,6 +9526,8 @@ doMigrate(void *opaque)
if (vshCommandOptBool(cmd, "enable-postcopy"))
flags |= VIR_MIGRATE_ENABLE_POSTCOPY;
+ if (vshCommandOptBool(cmd, "postcopy-after")) /* actually an int */
+ flags |= VIR_MIGRATE_ENABLE_POSTCOPY;
if (vshCommandOptBool(cmd, "live"))
flags |= VIR_MIGRATE_LIVE;
if (vshCommandOptBool(cmd, "p2p"))
@@ -9612,6 +9618,20 @@ vshMigrationTimeout(vshControl *ctl,
virDomainSuspend(dom);
}
+static void
+vshMigrationPostCopyAfter(vshControl *ctl,
+ virDomainPtr dom,
+ void *opaque ATTRIBUTE_UNUSED)
+{
+ vshDebug(ctl, VSH_ERR_DEBUG, "starting post-copy\n");
+ int rv = virDomainMigrateStartPostCopy(dom, 0);
+ if (rv < 0) {
+ vshError(ctl, "%s", _("start post-copy command failed"));
+ } else {
+ vshDebug(ctl, VSH_ERR_INFO, "switched to post-copy\n");
+ }
+}
+
static bool
cmdMigrate(vshControl *ctl, const vshCmd *cmd)
{
@@ -9621,8 +9641,10 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd)
bool verbose = false;
bool functionReturn = false;
int timeout = 0;
+ int postCopyAfter = 0;
bool live_flag = false;
vshCtrlData data = { .dconn = NULL };
+ int rv;
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return false;
@@ -9640,6 +9662,35 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd)
goto cleanup;
}
+ rv = vshCommandOptInt(cmd, "postcopy-after", &postCopyAfter);
+ if (rv < 0 || (rv > 0 && postCopyAfter < 0)) {
+ vshError(ctl, "%s", _("invalid postcopy-after parameter"));
+ goto cleanup;
+ }
+ if (rv > 0) {
+ /* Ensure that we can multiply by 1000 without overflowing. */
+ if (postCopyAfter > INT_MAX / 1000) {
+ vshError(ctl, "%s", _("post-copy after parameter is too
large"));
+ goto cleanup;
+ }
+ postCopyAfter *= 1000;
+ /* 0 is a special value inside virsh, which means no timeout, so
+ * use 1ms instead for "start post-copy immediately"
+ */
+ if (postCopyAfter == 0)
+ postCopyAfter = 1;
+ }
+
+ if (postCopyAfter > 0 && !live_flag) {
+ vshError(ctl, "%s",
+ _("migrate: Unexpected postcopy-after for offline
migration"));
+ goto cleanup;
+ } else if (postCopyAfter > 0 && timeout > 0) {
+ vshError(ctl, "%s",
+ _("migrate: --postcopy-after is incompatible with
--timeout"));
+ goto cleanup;
+ }
+
if (pipe(p) < 0)
goto cleanup;
@@ -9669,8 +9720,13 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd)
doMigrate,
&data) < 0)
goto cleanup;
- functionReturn = vshWatchJob(ctl, dom, verbose, p[0], timeout,
- vshMigrationTimeout, NULL, _("Migration"));
+ if (postCopyAfter != 0) {
+ functionReturn = vshWatchJob(ctl, dom, verbose, p[0], postCopyAfter,
+ vshMigrationPostCopyAfter, NULL,
_("Migration"));
+ } else {
+ functionReturn = vshWatchJob(ctl, dom, verbose, p[0], timeout,
+ vshMigrationTimeout, NULL,
_("Migration"));
+ }
virThreadJoin(&workerThread);
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 18c6a23..a4c5d34 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1429,6 +1429,7 @@ to the I<uri> namespace is displayed instead of being
modified.
I<domain> I<desturi> [I<migrateuri>] [I<graphicsuri>]
[I<listen-address>]
[I<dname>] [I<--timeout> B<seconds>] [I<--xml> B<file>]
[I<--enable-postcopy>]
+[I<--postcopy-after> B<seconds>]
Migrate domain to another host. Add I<--live> for live migration; <--p2p>
for peer-2-peer migration; I<--direct> for direct migration; or
I<--tunnelled>
@@ -1481,6 +1482,10 @@ actually start post-copy, i.e., migration is started in pre-copy
mode.
Once migration started, the user may switch to post-copy using the
B<migrate-start-postcopy> command sent from another virsh instance.
+I<--postcopy-after> switches to post-copy migration when pre-copy migration
+exceeds that many seconds. Zero means start post-copy as soon as possible.
+It can only be used with I<--live>.
+
Running migration can be canceled by interrupting virsh (usually using
C<Ctrl-C>) or by B<domjobabort> command sent from another virsh instance.
--
1.9.1