virsh: domain: Extract the code converting domain job stats to virDomainJobInfo

To simplify the stats printer code we convert the new statistics from
the typed parameter list into the old stats structure.

Extract this code since it takes a lot of space.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Peter Krempa 2019-11-22 15:06:08 +01:00
parent 0279a51b83
commit 54a9d6e51e

View File

@ -6065,6 +6065,42 @@ virshDomainJobOperationToString(int op)
return str ? _(str) : _("unknown");
}
static int
virshDomainJobStatsToDomainJobInfo(virTypedParameterPtr params,
int nparams,
virDomainJobInfo *info)
{
if (virTypedParamsGetULLong(params, nparams, VIR_DOMAIN_JOB_TIME_ELAPSED,
&info->timeElapsed) < 0 ||
virTypedParamsGetULLong(params, nparams, VIR_DOMAIN_JOB_TIME_REMAINING,
&info->timeRemaining) < 0 ||
virTypedParamsGetULLong(params, nparams, VIR_DOMAIN_JOB_DATA_TOTAL,
&info->dataTotal) < 0 ||
virTypedParamsGetULLong(params, nparams, VIR_DOMAIN_JOB_DATA_PROCESSED,
&info->dataProcessed) < 0 ||
virTypedParamsGetULLong(params, nparams, VIR_DOMAIN_JOB_DATA_REMAINING,
&info->dataRemaining) < 0 ||
virTypedParamsGetULLong(params, nparams, VIR_DOMAIN_JOB_MEMORY_TOTAL,
&info->memTotal) < 0 ||
virTypedParamsGetULLong(params, nparams, VIR_DOMAIN_JOB_MEMORY_PROCESSED,
&info->memProcessed) < 0 ||
virTypedParamsGetULLong(params, nparams, VIR_DOMAIN_JOB_MEMORY_REMAINING,
&info->memRemaining) < 0 ||
virTypedParamsGetULLong(params, nparams, VIR_DOMAIN_JOB_DISK_TOTAL,
&info->fileTotal) < 0 ||
virTypedParamsGetULLong(params, nparams, VIR_DOMAIN_JOB_DISK_PROCESSED,
&info->fileProcessed) < 0 ||
virTypedParamsGetULLong(params, nparams, VIR_DOMAIN_JOB_DISK_REMAINING,
&info->fileRemaining) < 0) {
vshSaveLibvirtError();
return -1;
}
return 0;
}
static bool
cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd)
{
@ -6091,40 +6127,8 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd)
rc = virDomainGetJobStats(dom, &info.type, &params, &nparams, flags);
if (rc == 0) {
if (virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_TIME_ELAPSED,
&info.timeElapsed) < 0 ||
virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_TIME_REMAINING,
&info.timeRemaining) < 0 ||
virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_DATA_TOTAL,
&info.dataTotal) < 0 ||
virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_DATA_PROCESSED,
&info.dataProcessed) < 0 ||
virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_DATA_REMAINING,
&info.dataRemaining) < 0 ||
virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_MEMORY_TOTAL,
&info.memTotal) < 0 ||
virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_MEMORY_PROCESSED,
&info.memProcessed) < 0 ||
virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_MEMORY_REMAINING,
&info.memRemaining) < 0 ||
virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_DISK_TOTAL,
&info.fileTotal) < 0 ||
virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_DISK_PROCESSED,
&info.fileProcessed) < 0 ||
virTypedParamsGetULLong(params, nparams,
VIR_DOMAIN_JOB_DISK_REMAINING,
&info.fileRemaining) < 0)
goto save_error;
if (virshDomainJobStatsToDomainJobInfo(params, nparams, &info) < 0)
goto cleanup;
} else if (last_error->code == VIR_ERR_NO_SUPPORT) {
if (flags) {
vshError(ctl, "%s", _("Optional flags are not supported by the "