提交 b9057c63 编写于 作者: S Simon Kobyda 提交者: Michal Privoznik

virsh: Set up cmdDomblkinfo() and cmdDomblkinfoPrint() for vshTable API implementation

I've moved all the printing from cmdDomblkinfoPrint() to cmdDomblkinfo(),
and renamed the cmdDomblkinfoPrint() to cmdDomblkinfoGet(), since nature of
that function changed from gathering and printing informations only to
gathering information. This I believe simplifies the functions and
makes the implementation of vshTable API simpler.
Signed-off-by: NSimon Kobyda <skobyda@redhat.com>
上级 b0b1ed2f
...@@ -406,33 +406,23 @@ static const vshCmdOptDef opts_domblkinfo[] = { ...@@ -406,33 +406,23 @@ static const vshCmdOptDef opts_domblkinfo[] = {
{.name = NULL} {.name = NULL}
}; };
static void static bool
cmdDomblkinfoPrint(vshControl *ctl, cmdDomblkinfoGet(vshControl *ctl,
const virDomainBlockInfo *info, const virDomainBlockInfo *info,
const char *device, char **cap,
bool human, bool title) char **alloc,
char **phy,
bool human)
{ {
char *cap = NULL;
char *alloc = NULL;
char *phy = NULL;
if (title) {
vshPrintExtra(ctl, "%-10s %-15s %-15s %-15s\n", _("Target"),
_("Capacity"), _("Allocation"), _("Physical"));
vshPrintExtra(ctl, "-----------------------------"
"------------------------\n");
return;
}
if (info->capacity == 0 && info->allocation == 0 && info->physical == 0) { if (info->capacity == 0 && info->allocation == 0 && info->physical == 0) {
cap = vshStrdup(ctl, "-"); *cap = vshStrdup(ctl, "-");
alloc = vshStrdup(ctl, "-"); *alloc = vshStrdup(ctl, "-");
phy = vshStrdup(ctl, "-"); *phy = vshStrdup(ctl, "-");
} else if (!human) { } else if (!human) {
if (virAsprintf(&cap, "%llu", info->capacity) < 0 || if (virAsprintf(cap, "%llu", info->capacity) < 0 ||
virAsprintf(&alloc, "%llu", info->allocation) < 0 || virAsprintf(alloc, "%llu", info->allocation) < 0 ||
virAsprintf(&phy, "%llu", info->physical) < 0) virAsprintf(phy, "%llu", info->physical) < 0)
goto cleanup; return false;
} else { } else {
double val_cap, val_alloc, val_phy; double val_cap, val_alloc, val_phy;
const char *unit_cap, *unit_alloc, *unit_phy; const char *unit_cap, *unit_alloc, *unit_phy;
...@@ -441,24 +431,13 @@ cmdDomblkinfoPrint(vshControl *ctl, ...@@ -441,24 +431,13 @@ cmdDomblkinfoPrint(vshControl *ctl,
val_alloc = vshPrettyCapacity(info->allocation, &unit_alloc); val_alloc = vshPrettyCapacity(info->allocation, &unit_alloc);
val_phy = vshPrettyCapacity(info->physical, &unit_phy); val_phy = vshPrettyCapacity(info->physical, &unit_phy);
if (virAsprintf(&cap, "%.3lf %s", val_cap, unit_cap) < 0 || if (virAsprintf(cap, "%.3lf %s", val_cap, unit_cap) < 0 ||
virAsprintf(&alloc, "%.3lf %s", val_alloc, unit_alloc) < 0 || virAsprintf(alloc, "%.3lf %s", val_alloc, unit_alloc) < 0 ||
virAsprintf(&phy, "%.3lf %s", val_phy, unit_phy) < 0) virAsprintf(phy, "%.3lf %s", val_phy, unit_phy) < 0)
goto cleanup; return false;
}
if (device) {
vshPrint(ctl, "%-10s %-15s %-15s %-15s\n", device, cap, alloc, phy);
} else {
vshPrint(ctl, "%-15s %s\n", _("Capacity:"), cap);
vshPrint(ctl, "%-15s %s\n", _("Allocation:"), alloc);
vshPrint(ctl, "%-15s %s\n", _("Physical:"), phy);
} }
cleanup: return true;
VIR_FREE(cap);
VIR_FREE(alloc);
VIR_FREE(phy);
} }
...@@ -478,6 +457,9 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) ...@@ -478,6 +457,9 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd)
xmlNodePtr *disks = NULL; xmlNodePtr *disks = NULL;
char *target = NULL; char *target = NULL;
char *protocol = NULL; char *protocol = NULL;
char *cap = NULL;
char *alloc = NULL;
char *phy = NULL;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
return false; return false;
...@@ -502,7 +484,10 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) ...@@ -502,7 +484,10 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd)
goto cleanup; goto cleanup;
/* print the title */ /* print the title */
cmdDomblkinfoPrint(ctl, NULL, NULL, false, true); vshPrintExtra(ctl, "%-10s %-15s %-15s %-15s\n", _("Target"),
_("Capacity"), _("Allocation"), _("Physical"));
vshPrintExtra(ctl, "-----------------------------"
"------------------------\n");
for (i = 0; i < ndisks; i++) { for (i = 0; i < ndisks; i++) {
ctxt->node = disks[i]; ctxt->node = disks[i];
...@@ -525,7 +510,9 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) ...@@ -525,7 +510,9 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd)
} }
} }
cmdDomblkinfoPrint(ctl, &info, target, human, false); if (!cmdDomblkinfoGet(ctl, &info, &cap, &alloc, &phy, human))
goto cleanup;
vshPrint(ctl, "%-10s %-15s %-15s %-15s\n", target, cap, alloc, phy);
VIR_FREE(target); VIR_FREE(target);
VIR_FREE(protocol); VIR_FREE(protocol);
...@@ -534,12 +521,19 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) ...@@ -534,12 +521,19 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd)
if (virDomainGetBlockInfo(dom, device, &info, 0) < 0) if (virDomainGetBlockInfo(dom, device, &info, 0) < 0)
goto cleanup; goto cleanup;
cmdDomblkinfoPrint(ctl, &info, NULL, human, false); if (!cmdDomblkinfoGet(ctl, &info, &cap, &alloc, &phy, human))
goto cleanup;
vshPrint(ctl, "%-15s %s\n", _("Capacity:"), cap);
vshPrint(ctl, "%-15s %s\n", _("Allocation:"), alloc);
vshPrint(ctl, "%-15s %s\n", _("Physical:"), phy);
} }
ret = true; ret = true;
cleanup: cleanup:
VIR_FREE(cap);
VIR_FREE(alloc);
VIR_FREE(phy);
virshDomainFree(dom); virshDomainFree(dom);
VIR_FREE(target); VIR_FREE(target);
VIR_FREE(protocol); VIR_FREE(protocol);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册