[libvirt] [PATCH 1/9] virsh: domain: Extract the code converting domain job stats to virDomainJobInfo
Eric Blake
eblake at redhat.com
Tue Nov 26 14:42:30 UTC 2019
On 11/25/19 9:01 AM, Peter Krempa wrote:
> 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 at redhat.com>
> ---
> tools/virsh-domain.c | 72 +++++++++++++++++++++++---------------------
> 1 file changed, 38 insertions(+), 34 deletions(-)
>
A wash in lines of code for now, but aids reusability later.
Reviewed-by: Eric Blake <eblake at redhat.com>
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> index 6be9780836..99194c2f81 100644
> --- a/tools/virsh-domain.c
> +++ b/tools/virsh-domain.c
> @@ -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;
> + }
Any additional parameters not mapping to the old struct are silently
ignored. I guess that's okay, especially since here it's just code motion.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
More information about the libvir-list
mailing list