Add sub-command nodesevinfo to get node infomation of AMD SEV feature. Signed-off-by: Han Han <hhan@xxxxxxxxxx> --- tools/virsh-host.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++ tools/virsh.pod | 5 ++++ 2 files changed, 71 insertions(+) diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 16f504bafe..0bcd71a2b8 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -952,6 +952,67 @@ cmdNodeMemStats(vshControl *ctl, const vshCmd *cmd) return ret; } +/* + * "nodesevinfo" command + */ +static const vshCmdInfo info_nodesevinfo[] = { + {.name = "help", + .data = N_("AMD SEV feature information.") + }, + {.name = "desc", + .data = N_("Returns information of SEV feature about the node.") + }, + {.name = NULL} +}; + +static bool +cmdNodesevinfo(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) +{ + virTypedParameterPtr params = NULL; + int nparams = 0; + unsigned int flags = 0; + bool ret = false; + size_t i; + virshControlPtr priv = ctl->privData; + + if (nparams == 0) { + /* Get the number of SEV info parameters */ + if (virNodeGetSEVInfo(priv->conn, NULL, &nparams, flags) != 0) { + vshError(ctl, "%s", + _("Unable to get number of SEV info parameters")); + goto cleanup; + } + } + + if (nparams == 0) { + ret = true; + goto cleanup; + } + + /* Now get all the SEV info parameters */ + params = vshCalloc(ctl, nparams, sizeof(params)); + if (virNodeGetSEVInfo(priv->conn, ¶ms, &nparams, flags) != 0) { + vshError(ctl, "%s", _("Unable to get SEV info parameters")); + goto cleanup; + } + + /* XXX: Need to sort the returned params once new parameter + * fields not of shared memory are added. + */ + vshPrint(ctl, _("SEV info:\n")); + for (i = 0; i < nparams; i++) { + char *str = vshGetTypedParamValue(ctl, ¶ms[i]); + vshPrint(ctl, "\t%-15s %s\n", params[i].field, str); + VIR_FREE(str); + } + + ret = true; + + cleanup: + virTypedParamsFree(params, nparams); + return ret; +} + /* * "nodesuspend" command */ @@ -1900,6 +1961,11 @@ const vshCmdDef hostAndHypervisorCmds[] = { .info = info_nodememstats, .flags = 0 }, + {.name = "nodesevinfo", + .handler = cmdNodesevinfo, + .info = info_nodesevinfo, + .flags = 0 + }, {.name = "nodesuspend", .handler = cmdNodeSuspend, .opts = opts_node_suspend, diff --git a/tools/virsh.pod b/tools/virsh.pod index 4e118851f8..ea513c0acc 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -317,6 +317,11 @@ of cpu statistics during 1 second. Returns memory stats of the node. If I<cell> is specified, this will print the specified cell statistics only. +=item B<nodesevinfo> + +Display AMD's SEV feature of this host, including PDH, cert-chain, cbitpos +and reduced-phys-bits. + =item B<nodesuspend> [I<target>] [I<duration>] Puts the node (host machine) into a system-wide sleep state and schedule -- 2.18.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list