[libvirt] [PATCH v5 28/36] qemu_capabilities: Introduce virCPUDef to CPUModelInfo function

Jiri Denemark jdenemar at redhat.com
Fri Jan 4 20:05:37 UTC 2019


On Sun, Dec 02, 2018 at 23:10:22 -0600, Chris Venteicher wrote:
> Create public function to convert virCPUDef data structure into
> qemuMonitorCPUModelInfoPtr data structure.
> 
> There was no existing code to reuse to create this function
> so this new virQEMUCapsCPUModelInfoFromCPUDef function was based on
> reversing the action of the existing virQEMUCapsCPUModelInfoToCPUDef
> function.
> 
> Signed-off-by: Chris Venteicher <cventeic at redhat.com>
> ---
>  src/qemu/qemu_capabilities.c | 46 ++++++++++++++++++++++++++++++++++++
>  src/qemu/qemu_capabilities.h |  1 +
>  2 files changed, 47 insertions(+)
> 
> diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
> index 74f670459f..b36ccda090 100644
> --- a/src/qemu/qemu_capabilities.c
> +++ b/src/qemu/qemu_capabilities.c
> @@ -3642,6 +3642,51 @@ virQEMUCapsLoadCache(virArch hostArch,
>  }
>  
>  
> +/* virCPUDef model    => qemuMonitorCPUModelInfo name
> + * virCPUDef features => qemuMonitorCPUModelInfo boolean properties */
> +qemuMonitorCPUModelInfoPtr
> +virQEMUCapsCPUModelInfoFromCPUDef(const virCPUDef *cpuDef)
> +{
> +    size_t i;
> +    qemuMonitorCPUModelInfoPtr cpuModel = NULL;
> +    qemuMonitorCPUModelInfoPtr ret = NULL;
> +
> +    if (!cpuDef || (VIR_ALLOC(cpuModel) < 0))
> +        goto cleanup;
> +
> +    VIR_DEBUG("cpuDef->model = %s", NULLSTR(cpuDef->model));

Similar comment to the one in the previous patch.

> +
> +    if (VIR_STRDUP(cpuModel->name, cpuDef->model) < 0 ||
> +        VIR_ALLOC_N(cpuModel->props, cpuDef->nfeatures) < 0)
> +        goto cleanup;
> +
> +    cpuModel->nprops = 0;
> +
> +    for (i = 0; i < cpuDef->nfeatures; i++) {
> +        qemuMonitorCPUPropertyPtr prop = &(cpuModel->props[cpuModel->nprops]);
> +        virCPUFeatureDefPtr feature = &(cpuDef->features[i]);
> +
> +        if (!(feature->name) ||

I don't think there's any need to check for feature->name == NULL. If
there's a feature in cpuDef, its name is not NULL.

> +            VIR_STRDUP(prop->name, feature->name) < 0)
> +            goto cleanup;
> +
> +        prop->type = QEMU_MONITOR_CPU_PROPERTY_BOOLEAN;
> +
> +        prop->value.boolean = feature->policy == -1 || /* policy undefined */
> +                              feature->policy == VIR_CPU_FEATURE_FORCE ||
> +                              feature->policy == VIR_CPU_FEATURE_REQUIRE;

This semantics should be documented and probably even configurable in
some way. -1 is easy, it's only used in host CPUs and the feature is
either there (with policy -1) or missing. But I can imagine that
VIR_CPU_FEATURE_FORCE would need to be ignored in some cases.
Alternatively we could define the function only for -1 and REQUIRE and
let the caller adapt the input cpuDef if they need something else.

> +
> +        cpuModel->nprops++;
> +    }
> +
> +    VIR_STEAL_PTR(ret, cpuModel);
> +
> + cleanup:
> +    qemuMonitorCPUModelInfoFree(cpuModel);
> +    return ret;
> +}
> +
> +
>  /* qemuMonitorCPUModelInfo name               => virCPUDef model
>   * qemuMonitorCPUModelInfo boolean properties => virCPUDef features
>   *
> @@ -3693,6 +3738,7 @@ virQEMUCapsCPUModelInfoToCPUDef(bool migratable, qemuMonitorCPUModelInfoPtr mode
>      return ret;
>  }
>  
> +
>  static void
>  virQEMUCapsFormatHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
>                                    virBufferPtr buf,

This hunk does not belong to this patch.

> diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
> index 52e36e76b6..9bc6773263 100644
> --- a/src/qemu/qemu_capabilities.h
> +++ b/src/qemu/qemu_capabilities.h
> @@ -579,6 +579,7 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
>  void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
>                                      const char *machineType);
>  
> +qemuMonitorCPUModelInfoPtr virQEMUCapsCPUModelInfoFromCPUDef(const virCPUDef *cpuDef);
>  virCPUDefPtr virQEMUCapsCPUModelInfoToCPUDef(bool migratable,
>                                               qemuMonitorCPUModelInfoPtr model);
>  

Jirka




More information about the libvir-list mailing list