提交 2bbe624e 编写于 作者: V Viktor Mihajlovski 提交者: Eric Blake

virsh: Use virNodeGetCPUMap if possible

Modified the places where virNodeGetInfo was used for the purpose
of obtaining the maximum node CPU number. Transparently falling
back to virNodeGetInfo in case of failure.
Wrote utility function vshNodeGetCPUCount to compute node CPU
number.
Signed-off-by: NViktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
上级 a0db6566
......@@ -125,6 +125,27 @@ vshDomainVcpuStateToString(int state)
return N_("no state");
}
/*
* Determine number of CPU nodes present by trying
* virNodeGetCPUMap and falling back to virNodeGetInfo
* if needed.
*/
static int
vshNodeGetCPUCount(virConnectPtr conn)
{
int ret;
virNodeInfo nodeinfo;
if ((ret = virNodeGetCPUMap(conn, NULL, NULL, 0)) < 0) {
/* fall back to nodeinfo */
vshResetLibvirtError();
if (virNodeGetInfo(conn, &nodeinfo) == 0) {
ret = VIR_NODEINFO_MAXCPUS(nodeinfo);
}
}
return ret;
}
/*
* "attach-device" command
*/
......@@ -4497,7 +4518,6 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
{
virDomainInfo info;
virDomainPtr dom;
virNodeInfo nodeinfo;
virVcpuInfoPtr cpuinfo;
unsigned char *cpumaps;
int ncpus, maxcpu;
......@@ -4508,7 +4528,7 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return false;
if (virNodeGetInfo(ctl->conn, &nodeinfo) != 0) {
if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0) {
virDomainFree(dom);
return false;
}
......@@ -4519,7 +4539,6 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
}
cpuinfo = vshMalloc(ctl, sizeof(virVcpuInfo)*info.nrVirtCpu);
maxcpu = VIR_NODEINFO_MAXCPUS(nodeinfo);
cpumaplen = VIR_CPU_MAPLEN(maxcpu);
cpumaps = vshMalloc(ctl, info.nrVirtCpu * cpumaplen);
......@@ -4645,7 +4664,6 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
{
virDomainInfo info;
virDomainPtr dom;
virNodeInfo nodeinfo;
int vcpu = -1;
const char *cpulist = NULL;
bool ret = true;
......@@ -4695,7 +4713,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
return false;
}
if (virNodeGetInfo(ctl->conn, &nodeinfo) != 0) {
if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0) {
virDomainFree(dom);
return false;
}
......@@ -4712,7 +4730,6 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
return false;
}
maxcpu = VIR_NODEINFO_MAXCPUS(nodeinfo);
cpumaplen = VIR_CPU_MAPLEN(maxcpu);
/* Query mode: show CPU affinity information then exit.*/
......@@ -4864,7 +4881,6 @@ static bool
cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
virNodeInfo nodeinfo;
const char *cpulist = NULL;
bool ret = true;
unsigned char *cpumap = NULL;
......@@ -4905,12 +4921,11 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd)
}
query = !cpulist;
if (virNodeGetInfo(ctl->conn, &nodeinfo) != 0) {
if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0) {
virDomainFree(dom);
return false;
}
maxcpu = VIR_NODEINFO_MAXCPUS(nodeinfo);
cpumaplen = VIR_CPU_MAPLEN(maxcpu);
/* Query mode: show CPU affinity information then exit.*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册