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

[libvirt] [PATCH 06/11] virsh-domain-monitor: Implement command to map guest vCPUs



Add support for the virDomainGetVCPUMap API. The code is based on node
vcpu mapping.
---
 tools/virsh-domain-monitor.c | 110 +++++++++++++++++++++++++++++++++++++++++++
 tools/virsh.pod              |  23 +++++++++
 2 files changed, 133 insertions(+)

diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 936fa8e..8814705 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -1806,6 +1806,111 @@ cleanup:
 }
 #undef FILTER

+static const vshCmdInfo info_VCPUMap[] = {
+    {.name = "help",
+     .data = N_("request map of virtual processors of a domain")
+    },
+    {.name = "desc",
+     .data = N_("Returns the map of virtual processors of a domain")
+    },
+    {.name = NULL}
+};
+
+static const vshCmdOptDef opts_VCPUMap[] = {
+    {.name = "domain",
+     .type = VSH_OT_DATA,
+     .flags = VSH_OFLAG_REQ,
+     .help = N_("domain name, id or uuid")
+    },
+    {.name = "agent",
+     .type = VSH_OT_BOOL,
+     .help = N_("use guest agent")
+    },
+    {.name = "hypervisor",
+     .type = VSH_OT_BOOL,
+     .help = N_("show hypervisor data")
+    },
+    {.name = "online",
+     .type = VSH_OT_BOOL,
+     .help = N_("show online cpus")
+    },
+    {.name = "offlinable",
+     .type = VSH_OT_BOOL,
+     .help = N_("show offlinable vCPUs")
+    },
+    {.name = "offline",
+     .type = VSH_OT_BOOL,
+     .help = N_("show offline cpus")
+    },
+    {.name = "possible",
+     .type = VSH_OT_BOOL,
+     .help = N_("show all possible vCPUs")
+    },
+    {.name = "active",
+     .type = VSH_OT_BOOL,
+     .help = N_("show currently active vCPUs")
+    },
+    {.name = NULL}
+};
+
+static bool
+cmdVCPUMap(vshControl *ctl, const vshCmd *cmd)
+{
+    int cpu, cpunum;
+    unsigned char *cpumap = NULL;
+    bool ret = false;
+    virDomainPtr dom = NULL;
+    unsigned int flags = 0;
+    bool agent = vshCommandOptBool(cmd, "agent");
+    bool hypervisor = vshCommandOptBool(cmd, "hypervisor");
+    bool online = vshCommandOptBool(cmd, "online");
+    bool offline = vshCommandOptBool(cmd, "offline");
+
+    VSH_EXCLUSIVE_OPTIONS_VAR(agent, hypervisor);
+    VSH_EXCLUSIVE_OPTIONS_VAR(online, offline);
+
+    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+        return false;
+
+    if (agent)
+        flags |= VIR_DOMAIN_VCPU_MAP_AGENT;
+
+    if (hypervisor)
+        flags |= VIR_DOMAIN_VCPU_MAP_HYPERVISOR;
+
+    if (online)
+        flags |= VIR_DOMAIN_VCPU_MAP_ONLINE;
+
+    if (offline)
+        flags |= VIR_DOMAIN_VCPU_MAP_OFFLINE;
+
+    if (vshCommandOptBool(cmd, "offlinable"))
+        flags |= VIR_DOMAIN_VCPU_MAP_OFFLINABLE;
+
+    if (vshCommandOptBool(cmd, "possible"))
+        flags |= VIR_DOMAIN_VCPU_MAP_POSSIBLE;
+
+    if (vshCommandOptBool(cmd, "active"))
+        flags |= VIR_DOMAIN_VCPU_MAP_ACTIVE;
+
+    if ((cpunum = virDomainGetVCPUMap(dom, &cpumap, flags)) < 0) {
+        vshError(ctl, "%s", _("Unable to get cpu map"));
+        goto cleanup;
+    }
+
+    vshPrint(ctl, "%-15s ", _("CPU map:"));
+    for (cpu = 0; cpu < cpunum; cpu++)
+        vshPrint(ctl, "%c", VIR_CPU_USED(cpumap, cpu) ? 'y' : '-');
+    vshPrint(ctl, "\n");
+
+    ret = true;
+
+cleanup:
+    virDomainFree(dom);
+    VIR_FREE(cpumap);
+    return ret;
+}
+
 const vshCmdDef domMonitoringCmds[] = {
     {.name = "domblkerror",
      .handler = cmdDomBlkError,
@@ -1879,5 +1984,10 @@ const vshCmdDef domMonitoringCmds[] = {
      .info = info_list,
      .flags = 0
     },
+    {.name = "vcpumap",
+     .handler = cmdVCPUMap,
+     .opts = opts_VCPUMap,
+     .info = info_VCPUMap,
+    },
     {.name = NULL}
 };
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 11984bc..8037a0d 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1797,6 +1797,29 @@ If no flag is specified, behavior is different depending on hypervisor.
 Output the IP address and port number for the VNC display. If the information
 is not available the processes will provide an exit code of 1.

+=item B<vcpumap> I<domain> [I<--hypervisor> | I<--agent>]
+[I<--active> | I<--online> | I<--offline> | I<--offlinable> | I<--possible>]
+
+Query a map of vCPUs of a domain.
+
+When I<--agent> is specified the guest agent is queried for the state of the
+vCPUs from the point of view of the guest. Otherwise I<--hypervisor> is
+assumed.
+
+If I<--possible> is specified all cpu ID's referenced by the guest are listed.
+The I<--offlinable> flag limits the view on vCPUs that can be disabled.
+I<--online> and I<--offline> limit the output according to the state of the
+vCPU. With I<--active> specified only vCPUs that are active are listed.
+The flags may be combined to filter the results further.
+
+With no flag specified, libvirt assumes that I<--online> and I<--hypervisor>
+is requested.
+
+I<--agent> and I<--hypervisor> as well as I<--online> and I<--offline> are
+mutually exclusive options.
+
+B<Note>: Some flags may not be supported with both query modes.
+
 =back

 =head1 DEVICE COMMANDS
-- 
1.8.2.1


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