Signed-off-by: Jiang Jiacheng <jiangjiach...@huawei.com>
---
 tools/virsh-domain.c | 69 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 2d162cf8c0..e17c526850 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -13760,6 +13760,69 @@ cmdDomDirtyRateCalc(vshControl *ctl, const vshCmd *cmd)
 }
 
 
+/*
+ * "migrationpin" command
+ */
+static const vshCmdInfo info_migrationpin[] = {
+    {.name = "help",
+     .data = N_("control domain migrationThreads affinity")
+    },
+    {.name = "desc",
+     .data = N_("Pin domain migrationThreads to host physical CPUs.")
+    },
+    {.name = NULL}
+};
+
+static const vshCmdOptDef opts_migrationpin[] = {
+    VIRSH_COMMON_OPT_DOMAIN_FULL(0),
+    {.name = "cpulist",
+     .type = VSH_OT_DATA,
+     .flags = VSH_OFLAG_REQ,
+     .help = N_("host cpu number(s) to set")
+    },
+    {.name = NULL}
+};
+
+static bool
+cmdMigrationPin(vshControl *ctl, const vshCmd *cmd)
+{
+    g_autoptr(virshDomain) dom = NULL;
+    const char *name = NULL;
+    const char *cpulist = NULL;
+    int maxcpu;
+    g_autofree unsigned char *cpumap = NULL;
+    int cpumaplen;
+    virshControl *priv = ctl->privData;
+
+    dom = virshCommandOptDomain(ctl, cmd, NULL);
+    if (!dom)
+        return false;
+
+    if (vshCommandOptStringReq(ctl, cmd, "domain", &name) < 0)
+        return false;
+
+    if (vshCommandOptStringReq(ctl, cmd, "cpulist", &cpulist) < 0)
+        return false;
+
+    maxcpu = virshNodeGetCPUCount(priv->conn);
+    if (maxcpu < 0)
+        return false;
+
+    cpumap = virshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu);
+    if (!cpumap)
+        return false;
+
+    if (virDomainPinMigrationThread(dom, cpumap,
+                                    cpumaplen) != 0)
+        return false;
+
+    vshPrintExtra(ctl, _("Pin domain %s's migration thread "
+                         "to cpulist %s success.\n"), name, cpulist);
+
+    return true;
+}
+
+
 const vshCmdDef domManagementCmds[] = {
     {.name = "attach-device",
      .handler = cmdAttachDevice,
@@ -14417,5 +14480,11 @@ const vshCmdDef domManagementCmds[] = {
      .info = info_domdirtyrate_calc,
      .flags = 0
     },
+    {.name = "migrationpin",
+     .handler = cmdMigrationPin,
+     .opts = opts_migrationpin,
+     .info = info_migrationpin,
+     .flags = 0
+    },
     {.name = NULL}
 };
-- 
2.33.0

Reply via email to