[libvirt] [PATCHv2 06/11] qemu_monitor: Introduce qemuMonitorCPUModelInfoRemovePropByBoolValue

Jiri Denemark jdenemar at redhat.com
Fri Jul 13 11:17:28 UTC 2018


On Mon, Jul 09, 2018 at 22:56:50 -0500, Chris Venteicher wrote:
> Filter out cpu properties in qemuMonitorCPUModelInfo structure based on
> boolean value of true or false.
> 
> Goal is to form a list of "enabled" or "disabled" properties.
> 
> Required to convert between cpu model feature / property lists that
> indicate if property is or isn't include in model and the form of cpu
> model feature / property lists that only enumerate properties that are
> actually included in the model.
> ---
>  src/qemu/qemu_monitor.c | 29 +++++++++++++++++++++++++++++
>  src/qemu/qemu_monitor.h |  4 ++++
>  2 files changed, 33 insertions(+)
> 
> diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
> index 91b946c8b4..dd8510fbab 100644
> --- a/src/qemu/qemu_monitor.c
> +++ b/src/qemu/qemu_monitor.c
> @@ -3766,6 +3766,35 @@ qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig)
>      return NULL;
>  }
>  
> +
> +/* Squash CPU Model Info property list
> + * removing props of type boolean matching value */

The usefulness of this new function depends a question I'll ask in later
review of patch 11/11.

> +void
> +qemuMonitorCPUModelInfoRemovePropByBoolValue(qemuMonitorCPUModelInfoPtr model,
> +                                             bool value)
> +{
> +    qemuMonitorCPUPropertyPtr src, dst;
> +    size_t i, dst_size = 0;

Single variable per line, please.

> +
> +    for (i = 0; i < model->nprops; i++) {
> +        src = &(model->props[i]);
> +        dst = &(model->props[dst_size]);
> +
> +        if ((src->type == QEMU_MONITOR_CPU_PROPERTY_BOOLEAN) &&
> +            (src->value.boolean == value))

Redundant parentheses.

> +            continue;
> +
> +        *dst = *src;
> +
> +        dst_size++;
> +    }
> +
> +    model->nprops = dst_size;
> +
> +    ignore_value(VIR_REALLOC_N(model->props, dst_size)); /* not fatal */

This should call VIR_REALLOC_N_QUIET and I think the comment is not very
useful.

> +}
> +
> +
>  int
>  qemuMonitorGetCPUModelBaseline(qemuMonitorPtr mon,
>                                 qemuMonitorCPUModelInfoPtr model_a,
> diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
> index 6b4b527512..9841ab230c 100644
> --- a/src/qemu/qemu_monitor.h
> +++ b/src/qemu/qemu_monitor.h
> @@ -1028,6 +1028,10 @@ int qemuMonitorCPUModelInfoInit(const char *name, qemuMonitorCPUModelInfoPtr mod
>  qemuMonitorCPUModelInfoPtr
>  qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig);
>  
> +void qemuMonitorCPUModelInfoRemovePropByBoolValue( qemuMonitorCPUModelInfoPtr model,

s/( /(/

> +                                                   bool value)

And align this accordingly.

> +    ATTRIBUTE_NONNULL(1);
> +
>  int qemuMonitorGetCPUModelBaseline(qemuMonitorPtr mon,
>                                     qemuMonitorCPUModelInfoPtr model_a,
>                                     qemuMonitorCPUModelInfoPtr model_b,

Jirka




More information about the libvir-list mailing list