mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
virsh: Implement vshTable API to vcpupin, iothreadinfo, domfsinfo
Signed-off-by: Simon Kobyda <skobyda@redhat.com>
This commit is contained in:
parent
063509a193
commit
3072ded354
@ -59,6 +59,7 @@
|
||||
#include "virxml.h"
|
||||
#include "virsh-nodedev.h"
|
||||
#include "viruri.h"
|
||||
#include "vsh-table.h"
|
||||
|
||||
/* Gnulib doesn't guarantee SA_SIGINFO support. */
|
||||
#ifndef SA_SIGINFO
|
||||
@ -6905,6 +6906,7 @@ virshVcpuPinQuery(vshControl *ctl,
|
||||
size_t i;
|
||||
int ncpus;
|
||||
bool ret = false;
|
||||
vshTablePtr table = NULL;
|
||||
|
||||
if ((ncpus = virshCPUCountCollect(ctl, dom, countFlags, true)) < 0) {
|
||||
if (ncpus == -1) {
|
||||
@ -6913,7 +6915,7 @@ virshVcpuPinQuery(vshControl *ctl,
|
||||
else
|
||||
vshError(ctl, "%s", _("cannot get vcpupin for transient domain"));
|
||||
}
|
||||
return false;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (got_vcpu && vcpu >= ncpus) {
|
||||
@ -6927,28 +6929,39 @@ virshVcpuPinQuery(vshControl *ctl,
|
||||
vshError(ctl,
|
||||
_("vcpu %d is out of range of persistent cpu count %d"),
|
||||
vcpu, ncpus);
|
||||
return false;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
cpumaplen = VIR_CPU_MAPLEN(maxcpu);
|
||||
cpumap = vshMalloc(ctl, ncpus * cpumaplen);
|
||||
if ((ncpus = virDomainGetVcpuPinInfo(dom, ncpus, cpumap,
|
||||
cpumaplen, flags)) >= 0) {
|
||||
vshPrintExtra(ctl, "%s %s\n", _("VCPU:"), _("CPU Affinity"));
|
||||
vshPrintExtra(ctl, "----------------------------------\n");
|
||||
table = vshTableNew(_("VCPU"), _("CPU Affinity"), NULL);
|
||||
if (!table)
|
||||
goto cleanup;
|
||||
|
||||
for (i = 0; i < ncpus; i++) {
|
||||
VIR_AUTOFREE(char *) pinInfo = NULL;
|
||||
VIR_AUTOFREE(char *) vcpuStr = NULL;
|
||||
if (got_vcpu && i != vcpu)
|
||||
continue;
|
||||
|
||||
vshPrint(ctl, "%4zu: ", i);
|
||||
ret = virshPrintPinInfo(ctl, VIR_GET_CPUMAP(cpumap, cpumaplen, i),
|
||||
cpumaplen);
|
||||
vshPrint(ctl, "\n");
|
||||
if (!ret)
|
||||
break;
|
||||
if (!(pinInfo = virBitmapDataFormat(cpumap, cpumaplen)))
|
||||
goto cleanup;
|
||||
|
||||
if (virAsprintf(&vcpuStr, "%lu", i) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (vshTableRowAppend(table, vcpuStr, pinInfo, NULL) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
vshTablePrintToStdout(table, ctl);
|
||||
}
|
||||
|
||||
ret = true;
|
||||
cleanup:
|
||||
vshTableFree(table);
|
||||
VIR_FREE(cpumap);
|
||||
return ret;
|
||||
}
|
||||
@ -7520,6 +7533,7 @@ cmdIOThreadInfo(vshControl *ctl, const vshCmd *cmd)
|
||||
int maxcpu;
|
||||
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
||||
virshControlPtr priv = ctl->privData;
|
||||
vshTablePtr table = NULL;
|
||||
|
||||
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
||||
VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
|
||||
@ -7545,19 +7559,30 @@ cmdIOThreadInfo(vshControl *ctl, const vshCmd *cmd)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
vshPrintExtra(ctl, " %-15s %-15s\n",
|
||||
_("IOThread ID"), _("CPU Affinity"));
|
||||
vshPrintExtra(ctl, "---------------------------------------------------\n");
|
||||
for (i = 0; i < niothreads; i++) {
|
||||
table = vshTableNew(_("IOThread ID"), _("CPU Affinity"), NULL);
|
||||
if (!table)
|
||||
goto cleanup;
|
||||
|
||||
vshPrint(ctl, " %-15u ", info[i]->iothread_id);
|
||||
ignore_value(virshPrintPinInfo(ctl, info[i]->cpumap, info[i]->cpumaplen));
|
||||
vshPrint(ctl, "\n");
|
||||
virDomainIOThreadInfoFree(info[i]);
|
||||
for (i = 0; i < niothreads; i++) {
|
||||
VIR_AUTOFREE(char *) pinInfo = NULL;
|
||||
VIR_AUTOFREE(char *) iothreadIdStr = NULL;
|
||||
|
||||
if (virAsprintf(&iothreadIdStr, "%u", info[i]->iothread_id) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ignore_value(pinInfo = virBitmapDataFormat(info[i]->cpumap, info[i]->cpumaplen));
|
||||
|
||||
if (vshTableRowAppend(table, iothreadIdStr, pinInfo ? pinInfo : "", NULL) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
VIR_FREE(info);
|
||||
|
||||
vshTablePrintToStdout(table, ctl);
|
||||
|
||||
cleanup:
|
||||
for (i = 0; i < niothreads; i++)
|
||||
virDomainIOThreadInfoFree(info[i]);
|
||||
VIR_FREE(info);
|
||||
vshTableFree(table);
|
||||
virshDomainFree(dom);
|
||||
return niothreads >= 0;
|
||||
}
|
||||
@ -13778,6 +13803,7 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd)
|
||||
int ret = -1;
|
||||
size_t i, j;
|
||||
virDomainFSInfoPtr *info;
|
||||
vshTablePtr table = NULL;
|
||||
|
||||
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||
return false;
|
||||
@ -13793,25 +13819,41 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd)
|
||||
}
|
||||
|
||||
if (info) {
|
||||
vshPrintExtra(ctl, "%-36s %-8s %-8s %s\n",
|
||||
_("Mountpoint"), _("Name"), _("Type"), _("Target"));
|
||||
vshPrintExtra(ctl, "-------------------------------------------------------------------\n");
|
||||
for (i = 0; i < ret; i++) {
|
||||
vshPrint(ctl, "%-36s %-8s %-8s ",
|
||||
info[i]->mountpoint, info[i]->name, info[i]->fstype);
|
||||
for (j = 0; j < info[i]->ndevAlias; j++) {
|
||||
vshPrint(ctl, "%s", info[i]->devAlias[j]);
|
||||
if (j != info[i]->ndevAlias - 1)
|
||||
vshPrint(ctl, ",");
|
||||
}
|
||||
vshPrint(ctl, "\n");
|
||||
table = vshTableNew(_("Mountpoint"), _("Name"), _("Type"), _("Target"), NULL);
|
||||
if (!table)
|
||||
goto cleanup;
|
||||
|
||||
virDomainFSInfoFree(info[i]);
|
||||
for (i = 0; i < ret; i++) {
|
||||
virBuffer targetsBuff = VIR_BUFFER_INITIALIZER;
|
||||
VIR_AUTOFREE(char *) targets = NULL;
|
||||
|
||||
for (j = 0; j < info[i]->ndevAlias; j++) {
|
||||
virBufferAdd(&targetsBuff, info[i]->devAlias[j], -1);
|
||||
if (j != info[i]->ndevAlias - 1)
|
||||
virBufferAddChar(&targetsBuff, ',');
|
||||
}
|
||||
|
||||
targets = virBufferContentAndReset(&targetsBuff);
|
||||
|
||||
if (vshTableRowAppend(table,
|
||||
info[i]->mountpoint,
|
||||
info[i]->name,
|
||||
info[i]->fstype,
|
||||
targets,
|
||||
NULL) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
VIR_FREE(info);
|
||||
|
||||
vshTablePrintToStdout(table, ctl);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if (info) {
|
||||
for (i = 0; i < ret; i++)
|
||||
virDomainFSInfoFree(info[i]);
|
||||
VIR_FREE(info);
|
||||
}
|
||||
vshTableFree(table);
|
||||
virshDomainFree(dom);
|
||||
return ret >= 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user