Re: [PATCH 2/4] conf: Introduce virCPUDefFindFeature

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Oct 11, 2017 at 12:11 PM +0200, Jiri Denemark <jdenemar@xxxxxxxxxx> wrote:
> Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
> ---
>  src/conf/cpu_conf.c      | 40 +++++++++++++++++++++++++++-------------
>  src/conf/cpu_conf.h      |  4 ++++
>  src/libvirt_private.syms |  1 +
>  3 files changed, 32 insertions(+), 13 deletions(-)
>
> diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
> index 76f04c3531..669935acf8 100644
> --- a/src/conf/cpu_conf.c
> +++ b/src/conf/cpu_conf.c
> @@ -773,24 +773,22 @@ virCPUDefUpdateFeatureInternal(virCPUDefPtr def,
>                                 int policy,
>                                 bool update)
>  {
> -    size_t i;
> +    virCPUFeatureDefPtr feat;
>
>      if (def->type == VIR_CPU_TYPE_HOST)
>          policy = -1;
>
> -    for (i = 0; i < def->nfeatures; i++) {
> -        if (STREQ(name, def->features[i].name)) {
> -            if (update) {
> -                def->features[i].policy = policy;
> -                return 0;
> -            }
> -
> -            virReportError(VIR_ERR_INTERNAL_ERROR,
> -                           _("CPU feature '%s' specified more than once"),
> -                           name);
> -
> -            return -1;
> +    if ((feat = virCPUDefFindFeature(def, name))) {
> +        if (update) {
> +            feat->policy = policy;
> +            return 0;
>          }
> +
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("CPU feature '%s' specified more than once"),
> +                       name);
> +
> +        return -1;
>      }
>
>      if (VIR_RESIZE_N(def->features, def->nfeatures_max,
> @@ -822,6 +820,22 @@ virCPUDefAddFeature(virCPUDefPtr def,
>      return virCPUDefUpdateFeatureInternal(def, name, policy, false);
>  }
>
> +
> +virCPUFeatureDefPtr
> +virCPUDefFindFeature(virCPUDefPtr def,
> +                     const char *name)
> +{
> +    size_t i;
> +
> +    for (i = 0; i < def->nfeatures; i++) {
> +        if (STREQ(name, def->features[i].name))
> +            return def->features + i;
                      ^^^^^^^^^^^^^^^^^^
                      I prefer
                      return &def->features[i]

> +    }
> +
> +    return NULL;
> +}
> +
> +
>  bool
>  virCPUDefIsEqual(virCPUDefPtr src,
>                   virCPUDefPtr dst,
> diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h
> index b1a512b19a..d1983f5d4f 100644
> --- a/src/conf/cpu_conf.h
> +++ b/src/conf/cpu_conf.h
> @@ -215,6 +215,10 @@ virCPUDefUpdateFeature(virCPUDefPtr cpu,
>                         const char *name,
>                         int policy);
>
> +virCPUFeatureDefPtr
> +virCPUDefFindFeature(virCPUDefPtr def,
> +                     const char *name);
> +
>  virCPUDefPtr *
>  virCPUDefListParse(const char **xmlCPUs,
>                     unsigned int ncpus,
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index 26b1ae2850..7e116b19c4 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -75,6 +75,7 @@ virCPUDefCopy;
>  virCPUDefCopyModel;
>  virCPUDefCopyModelFilter;
>  virCPUDefCopyWithoutModel;
> +virCPUDefFindFeature;
>  virCPUDefFormat;
>  virCPUDefFormatBuf;
>  virCPUDefFormatBufFull;
> --
> 2.14.2
>
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list
>
--
Beste Grüße / Kind regards
   Marc Hartmayer

IBM Deutschland Research & Development GmbH
Vorsitzende des Aufsichtsrats: Martina Koederitz
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294


--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux