[libvirt] [PATCH v2 5/5] Add migrate-setmaxdowntime command to virsh

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 tools/virsh.c   |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/virsh.pod |    6 +++++
 2 files changed, 72 insertions(+), 0 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index aa85ee6..3dd9314 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -227,6 +227,8 @@ static vshCmdOpt *vshCommandOpt(const vshCmd *cmd, const char *name);
 static int vshCommandOptInt(const vshCmd *cmd, const char *name, int *found);
 static char *vshCommandOptString(const vshCmd *cmd, const char *name,
                                  int *found);
+static long long vshCommandOptLongLong(const vshCmd *cmd, const char *name,
+                                       int *found);
 #if 0
 static int vshCommandOptStringList(const vshCmd *cmd, const char *name, char ***data);
 #endif
@@ -2828,6 +2830,51 @@ cmdMigrate (vshControl *ctl, const vshCmd *cmd)
 }
 
 /*
+ * "migrate-setmaxdowntime" command
+ */
+static const vshCmdInfo info_migrate_setmaxdowntime[] = {
+    {"help", N_("set maximum tolerable downtime")},
+    {"desc", N_("Set maximum tolerable downtime of a domain which is being live-migrated to another host.")},
+    {NULL, NULL}
+};
+
+static const vshCmdOptDef opts_migrate_setmaxdowntime[] = {
+    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
+    {"downtime", VSH_OT_DATA, VSH_OFLAG_REQ, N_("maximum tolerable downtime (in nanoseconds) for migration")},
+    {NULL, 0, 0, NULL}
+};
+
+static int
+cmdMigrateSetMaxDowntime(vshControl *ctl, const vshCmd *cmd)
+{
+    virDomainPtr dom = NULL;
+    long long downtime;
+    int found;
+    int ret = FALSE;
+
+    if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
+        return FALSE;
+
+    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+        return FALSE;
+
+    downtime = vshCommandOptLongLong(cmd, "downtime", &found);
+    if (!found || downtime < 1) {
+        vshError(ctl, "%s", _("migrate: Invalid downtime"));
+        goto done;
+    }
+
+    if (virDomainMigrateSetMaxDowntime(dom, downtime, 0))
+        goto done;
+
+    ret = TRUE;
+
+done:
+    virDomainFree(dom);
+    return ret;
+}
+
+/*
  * "net-autostart" command
  */
 static const vshCmdInfo info_network_autostart[] = {
@@ -7726,6 +7773,7 @@ static const vshCmdDef commands[] = {
     {"hostname", cmdHostname, NULL, info_hostname},
     {"list", cmdList, opts_list, info_list},
     {"migrate", cmdMigrate, opts_migrate, info_migrate},
+    {"migrate-setmaxdowntime", cmdMigrateSetMaxDowntime, opts_migrate_setmaxdowntime, info_migrate_setmaxdowntime},
 
     {"net-autostart", cmdNetworkAutostart, opts_network_autostart, info_network_autostart},
     {"net-create", cmdNetworkCreate, opts_network_create, info_network_create},
@@ -8065,6 +8113,24 @@ vshCommandOptString(const vshCmd *cmd, const char *name, int *found)
     return arg && arg->data && *arg->data ? arg->data : NULL;
 }
 
+/*
+ * Returns option as long long
+ */
+static long long
+vshCommandOptLongLong(const vshCmd *cmd, const char *name, int *found)
+{
+    vshCmdOpt *arg = vshCommandOpt(cmd, name);
+    int num_found = FALSE;
+    long long res = 0;
+    char *end_p = NULL;
+
+    if ((arg != NULL) && (arg->data != NULL))
+        num_found = !virStrToLong_ll(arg->data, &end_p, 10, &res);
+    if (found)
+        *found = num_found;
+    return res;
+}
+
 #if 0
 static int
 vshCommandOptStringList(const vshCmd *cmd, const char *name, char ***data)
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 8f6df19..1c7cfce 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -334,6 +334,12 @@ leaves the domain paused on the destination host. The I<desturi> is the
 connection URI of the destination host, and I<migrateuri> is the
 migration URI, which usually can be omitted.
 
+=item B<migrate-setmaxdowntime> I<domain-id> I<downtime>
+
+Set maximum tolerable downtime for a domain which is being live-migrated to
+another host.  The I<downtime> is a number of nanoseconds the guest is allowed
+to be down at the end of live migration.
+
 =item B<reboot> I<domain-id>
 
 Reboot a domain.  This acts just as if the domain had the B<reboot>
-- 
1.7.0.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]