Add an optional --topology-status argument that calls virNodeGetInfoWithFlags and reports CPU topology as synthetic or detected. Preserve the existing API call and output when the option is omitted. Document the option and its use with read-only connections. Assisted-by: Codex:gpt-6-astra Signed-off-by: Partha Sarathi Satapathy <partha.satapathy@oracle.com> --- docs/manpages/virsh.rst | 12 +++++++++++- tools/virsh-host.c | 25 ++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index f533a10776da..b32ce1588185 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -432,11 +432,21 @@ nodeinfo :: - nodeinfo + nodeinfo [--topology-status] Returns basic information about the node, like number and type of CPU, and size of the physical memory. +With *--topology-status*, use ``virNodeGetInfoWithFlags()`` and append +``CPU topology: synthetic`` when the Linux topology consistency check +returned synthetic topology, or ``CPU topology: detected`` otherwise. +This option also works with a read-only connection, for example +``virsh -r nodeinfo --topology-status``. +The command fails if the driver or remote daemon does not support the new +API; an unsupported operation means the topology status is unknown. +Without this option, the command continues to use ``virNodeGetInfo()`` and +its output is unchanged. + Use of this command is strongly discouraged as the information provided is not guaranteed to be accurate on all hardware platforms. diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 0c18db67c438..1f9654f39b04 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -656,13 +656,29 @@ static const vshCmdInfo info_nodeinfo = { .desc = N_("Returns basic information about the node."), }; +static const vshCmdOptDef opts_nodeinfo[] = { + {.name = "topology-status", + .type = VSH_OT_BOOL, + .help = N_("report whether synthetic CPU topology was returned") + }, + {.name = NULL} +}; + static bool -cmdNodeinfo(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) +cmdNodeinfo(vshControl *ctl, const vshCmd *cmd) { virNodeInfo info; + unsigned int resultFlags = 0; + bool topologyStatus = vshCommandOptBool(cmd, "topology-status"); virshControl *priv = ctl->privData; + int ret; + + if (topologyStatus) + ret = virNodeGetInfoWithFlags(priv->conn, &info, &resultFlags, 0); + else + ret = virNodeGetInfo(priv->conn, &info); - if (virNodeGetInfo(priv->conn, &info) < 0) { + if (ret < 0) { vshError(ctl, "%s", _("failed to get node information")); return false; } @@ -675,6 +691,9 @@ cmdNodeinfo(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) vshPrint(ctl, "%-20s %d\n", _("Thread(s) per core:"), info.threads); vshPrint(ctl, "%-20s %d\n", _("NUMA cell(s):"), info.nodes); vshPrint(ctl, "%-20s %lu KiB\n", _("Memory size:"), info.memory); + if (topologyStatus) + vshPrint(ctl, "%-20s %s\n", _("CPU topology:"), + resultFlags & VIR_NODE_INFO_TOPOLOGY_FALLBACK ? _("synthetic") : _("detected")); return true; } @@ -1970,7 +1989,7 @@ const vshCmdDef hostAndHypervisorCmds[] = { }, {.name = "nodeinfo", .handler = cmdNodeinfo, - .opts = NULL, + .opts = opts_nodeinfo, .info = &info_nodeinfo, .flags = 0 }, -- 2.43.7