[PATCH V2 9/9] virsh: Add set and get multi-thread migration parameters commands

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

 



From: Eli Qiao <liyong.qiao@xxxxxxxxx>

Add command to allow set and get  multi-thread migration parameters
for a domain.

Signed-off-by: ShaoHe Feng <shaohe.feng@xxxxxxxxx>
Signed-off-by: Eli Qiao <liyong.qiao@xxxxxxxxx>
---
 tools/virsh-domain.c | 171 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 tools/virsh.pod      |  14 +++++
 2 files changed, 184 insertions(+), 1 deletion(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 98f3f76..2f40204 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -10249,7 +10249,7 @@ static const vshCmdInfo info_migrate_setspeed[] = {
     },
     {.name = "desc",
      .data = N_("Set the maximum migration bandwidth (in MiB/s) for a domain "
-                "which is being migrated to another host.")
+                "before migrating another host.")
     },
     {.name = NULL}
 };
@@ -10336,6 +10336,163 @@ cmdMigrateGetMaxSpeed(vshControl *ctl, const vshCmd *cmd)
 }
 
 /*
+ * "migrate-setparameters" command
+ */
+static const vshCmdInfo info_migrate_setparameters[] = {
+    {.name = "help",
+     .data = N_("Set the multi-thread migration parameters")
+    },
+    {.name = "desc",
+     .data = N_("Set the multi-thread migration parameters for a domain "
+                "which is being migrated to another host.")
+    },
+    {.name = NULL}
+};
+
+static const vshCmdOptDef opts_migrate_setparameters[] = {
+    {.name = "domain",
+     .type = VSH_OT_DATA,
+     .flags = VSH_OFLAG_REQ,
+     .help = N_("domain name, id or uuid")
+    },
+    {.name = "level",
+     .type = VSH_OT_INT,
+     .help = N_("compression level, from 1-9, 0 means use default level")
+    },
+    {.name = "threads",
+     .type = VSH_OT_INT,
+     .help = N_("compression thread count for multi-thread migration")
+    },
+    {.name = "dthreads",
+     .type = VSH_OT_INT,
+     .help = N_("decompression thread count for multi-thread migration")
+    },
+    {.name = NULL}
+};
+
+static bool
+cmdMigrateSetParameters(vshControl *ctl, const vshCmd *cmd)
+{
+    virDomainPtr dom = NULL;
+    virTypedParameterPtr params = NULL;
+    int flags = 0;
+    unsigned int level = 0;
+    unsigned int threads = 0;
+    unsigned int dthreads = 0;
+    int nparams = 0;
+    int maxparams = 0;
+    bool ret = false;
+    int rv = 0;
+
+    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+        return false;
+
+    if ((rv = vshCommandOptUIntWrap(cmd, "level", &level)) < 0) {
+        vshError(ctl,
+                 _("Numeric value for <%s> option is malformed or out of range"),
+                 "level");
+        goto done;
+    } else if (rv > 0) {
+        if (virTypedParamsAddUInt(&params, &nparams, &maxparams,
+                                  VIR_DOMAIN_MIRGRATE_COMPRESSION_LEVEL,
+                                  level) < 0)
+            goto done;
+    }
+
+    if ((rv = vshCommandOptUIntWrap(cmd, "threads", &threads)) < 0) {
+        vshError(ctl,
+                 _("Numeric value for <%s> option is malformed or out of range"),
+                 "threads");
+        goto done;
+    } else if (rv > 0) {
+        if (virTypedParamsAddUInt(&params, &nparams, &maxparams,
+                                  VIR_DOMAIN_MIRGRATE_COMPRESSION_THREADS,
+                                  threads) < 0)
+            goto done;
+    }
+
+    if ((rv = vshCommandOptUIntWrap(cmd, "dthreads", &dthreads)) < 0) {
+        vshError(ctl,
+                 _("Numeric value for <%s> option is malformed or out of range"),
+                 "dthreads");
+        goto done;
+    } else if (rv > 0) {
+        if (virTypedParamsAddUInt(&params, &nparams, &maxparams,
+                                  VIR_DOMAIN_MIRGRATE_DECOMPRESSION_THREADS,
+                                  dthreads) < 0)
+            goto done;
+    }
+
+    if (virDomainMigrateSetParameters(dom, params, nparams, flags) < 0)
+        goto done;
+
+    ret = true;
+
+ done:
+    virDomainFree(dom);
+    virTypedParamsFree(params, nparams);
+    return ret;
+}
+
+/*
+ * "migrate-getparameters" command
+ */
+static const vshCmdInfo info_migrate_getparameters[] = {
+    {.name = "help",
+     .data = N_("Get the mutit-thread migration parameters")
+    },
+    {.name = "desc",
+     .data = N_("Get the mutit-thread migration parameters for a domain.")
+    },
+    {.name = NULL}
+};
+
+static const vshCmdOptDef opts_migrate_getparameters[] = {
+    {.name = "domain",
+     .type = VSH_OT_DATA,
+     .flags = VSH_OFLAG_REQ,
+     .help = N_("domain name, id or uuid")
+    },
+    {.name = NULL}
+};
+
+static bool
+cmdMigrateGetParameters(vshControl *ctl, const vshCmd *cmd)
+{
+    virDomainPtr dom = NULL;
+    int flags = 0;
+    int i = 0;
+    int nparams = 0;
+    virTypedParameterPtr params = NULL;
+    bool ret = false;
+
+    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+        return false;
+
+    /* probe the compress param number of migrate. Now it supports 3 params. */
+    if (virDomainMigrateGetParameters(dom, NULL, &nparams, 0) < 0)
+        goto done;
+
+    params = vshCalloc(ctl, nparams, sizeof(*params));
+
+    if (virDomainMigrateGetParameters(dom, params, &nparams, flags) < 0)
+        goto done;
+
+    for (i = 0; i < nparams; i++) {
+        char *str = vshGetTypedParamValue(ctl, &params[i]);
+        vshPrint(ctl, "%-15s: %s\n", params[i].field, str);
+        VIR_FREE(str);
+    }
+
+    ret = true;
+
+ done:
+    virDomainFree(dom);
+    virTypedParamsFree(params, nparams);
+    return ret;
+}
+
+/*
  * "domdisplay" command
  */
 static const vshCmdInfo info_domdisplay[] = {
@@ -13186,6 +13343,18 @@ const vshCmdDef domManagementCmds[] = {
      .info = info_migrate_getspeed,
      .flags = 0
     },
+    {.name = "migrate-setparameters",
+     .handler = cmdMigrateSetParameters,
+     .opts = opts_migrate_setparameters,
+     .info = info_migrate_setparameters,
+     .flags = 0
+    },
+    {.name = "migrate-getparameters",
+     .handler = cmdMigrateGetParameters,
+     .opts = opts_migrate_getparameters,
+     .info = info_migrate_getparameters,
+     .flags = 0
+    },
     {.name = "numatune",
      .handler = cmdNumatune,
      .opts = opts_numatune,
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 1ba2c43..a8c4536 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1687,6 +1687,20 @@ reject the value or convert it to the maximum value allowed.
 
 Get the maximum migration bandwidth (in MiB/s) for a domain.
 
+=item B<migrate-setparameters> I<domain> [I<level> B<number>]
+[I<threads> B<number>] [I<dthreads> B<number>]
+
+Set the multi-thread parameters for live migration. I<level> is interpreted as
+an unsigned int value from 0-9. O means hypervisor choose an default value.
+Specifying a negative value results in an essentially unlimited value being
+provided to the hypervisor. The hypervisor can choose whether to reject the
+value or convert it to the maximum value allowed. I<threads> is interpreted as
+an unsigned int value. I<dthreads> is interpreted as an unsigned int value.
+
+=item B<migrate-getspeed> I<domain>
+
+Get the multi-thread migration parameters for a domain.
+
 =item B<numatune> I<domain> [I<--mode> B<mode>] [I<--nodeset> B<nodeset>]
 [[I<--config>] [I<--live>] | [I<--current>]]
 
-- 
2.1.4

--
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]