提交 1cfc0a99 编写于 作者: J John Ferlan

virsh: Add iothreadpin command

https://bugzilla.redhat.com/show_bug.cgi?id=1135491

$ virsh iothread --help

  NAME
    iothreadpin - control domain IOThread affinity

  SYNOPSIS
    iothreadpin <domain> <iothread> <cpulist> [--config] [--live] [--current]

  DESCRIPTION
    Pin domain IOThreads to host physical CPUs.

  OPTIONS
    [--domain] <string>  domain name, id or uuid
    [--iothread] <number>  IOThread ID number
    [--cpulist] <string>  host cpu number(s) to set
    --config         affect next boot
    --live           affect running domain
    --current        affect current domain

Using the output from iothreadsinfo, allow changing the pinned CPUs for
a single IOThread.

$ virsh iothreadsinfo $dom
 IOThread ID    CPU Affinity
---------------------------------------------------
 1               2
 2               3
 3               0-1

$ virsh iothreadpin $dom 3 0-2

Then view the change

$ virsh iothreadsinfo $dom
 IOThread ID    CPU Affinity
---------------------------------------------------
 1               2
 2               3
 3               0-2

If an invalid value is supplied or require option missing,
then an error will be displayed:

$ virsh iothreadpin $dom 4 3
error: invalid argument: iothread value out of range 4 > 3

$ virsh iothreadpin $dom 3
error: command 'iothreadpin' requires <cpulist> option
上级 fb562614
......@@ -6877,6 +6877,106 @@ cmdIOThreadsInfo(vshControl *ctl, const vshCmd *cmd)
return niothreads >= 0;
}
/*
* "iothreadpin" command
*/
static const vshCmdInfo info_iothreadpin[] = {
{.name = "help",
.data = N_("control domain IOThread affinity")
},
{.name = "desc",
.data = N_("Pin domain IOThreads to host physical CPUs.")
},
{.name = NULL}
};
static const vshCmdOptDef opts_iothreadpin[] = {
{.name = "domain",
.type = VSH_OT_DATA,
.flags = VSH_OFLAG_REQ,
.help = N_("domain name, id or uuid")
},
{.name = "iothread",
.type = VSH_OT_INT,
.flags = VSH_OFLAG_REQ,
.help = N_("IOThread ID number")
},
{.name = "cpulist",
.type = VSH_OT_DATA,
.flags = VSH_OFLAG_REQ,
.help = N_("host cpu number(s) to set")
},
{.name = "config",
.type = VSH_OT_BOOL,
.help = N_("affect next boot")
},
{.name = "live",
.type = VSH_OT_BOOL,
.help = N_("affect running domain")
},
{.name = "current",
.type = VSH_OT_BOOL,
.help = N_("affect current domain")
},
{.name = NULL}
};
static bool
cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
const char *cpulist = NULL;
bool config = vshCommandOptBool(cmd, "config");
bool live = vshCommandOptBool(cmd, "live");
bool current = vshCommandOptBool(cmd, "current");
unsigned int iothread_id = 0;
int maxcpu;
bool ret = false;
unsigned char *cpumap = NULL;
size_t cpumaplen;
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
if (config)
flags |= VIR_DOMAIN_AFFECT_CONFIG;
if (live)
flags |= VIR_DOMAIN_AFFECT_LIVE;
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return false;
if (vshCommandOptUInt(cmd, "iothread", &iothread_id) < 0) {
vshError(ctl, "%s", _("iothreadpin: Invalid IOThread number."));
goto cleanup;
}
if (vshCommandOptString(cmd, "cpulist", &cpulist) < 0) {
vshError(ctl, "%s", _("iothreadpin: invalid cpulist."));
goto cleanup;
}
if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0)
goto cleanup;
cpumaplen = VIR_CPU_MAPLEN(maxcpu);
/* Pin mode: pinning specified vcpu to specified physical cpus*/
if (!(cpumap = vshParseCPUList(ctl, cpulist, maxcpu, cpumaplen)))
goto cleanup;
if (virDomainPinIOThread(dom, iothread_id,
cpumap, cpumaplen, flags) != 0)
goto cleanup;
ret = true;
cleanup:
VIR_FREE(cpumap);
virDomainFree(dom);
return ret;
}
/*
* "cpu-compare" command
*/
......@@ -12786,6 +12886,12 @@ const vshCmdDef domManagementCmds[] = {
.info = info_iothreads,
.flags = 0
},
{.name = "iothreadpin",
.handler = cmdIOThreadPin,
.opts = opts_iothreadpin,
.info = info_iothreadpin,
.flags = 0
},
{.name = "send-key",
.handler = cmdSendKey,
.opts = opts_send_key,
......
......@@ -1374,6 +1374,32 @@ a persistent guest.
If I<--current> is specified or I<--live> and I<--config> are not specified,
then get the IOThread data based on the current guest state.
=item B<iothreadpin> I<domain> I<iothread> I<cpulist>
[[I<--live>] [I<--config>] | [I<--current>]]
Change the pinning of a domain IOThread to host physical CPUs. In order
to retrieve a list of all IOThreads, use B<iothreadsinfo>. To pin an
I<iothread> specify the I<cpulist> desired for the IOThread ID as listed
in the B<iothreadsinfo> output.
I<cpulist> is a list of physical CPU numbers. Its syntax is a comma
separated list and a special markup using '-' and '^' (ex. '0-4', '0-3,^2') can
also be allowed. The '-' denotes the range and the '^' denotes exclusive.
If you want to reset iothreadpin setting, that is, to pin an I<iothread>
to all physical cpus, simply specify 'r' as a I<cpulist>.
If I<--live> is specified, affect a running guest. If the guest is not running,
an error is returned.
If I<--config> is specified, affect the next boot of a persistent guest.
If I<--current> is specified or I<--live> and I<--config> are not specified,
affect the current guest state.
Both I<--live> and I<--config> flags may be given if I<cpulist> is present,
but I<--current> is exclusive.
If no flag is specified, behavior is different depending on hypervisor.
B<Note>: The expression is sequentially evaluated, so "0-15,^8" is
identical to "9-14,0-7,15" but not identical to "^8,0-15".
=item B<managedsave> I<domain> [I<--bypass-cache>]
[{I<--running> | I<--paused>}] [I<--verbose>]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册