Re: [PATCH 4/4] conf: Add iterators for RNG and Redirdev

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

 



On Fri, Oct 21, 2016 at 07:25:40PM -0400, John Ferlan wrote:
> Add the virDomainRNGDefForeach and +virDomainRedirdevDefForeach iterators
> to traverse all the RNG and Redirdevs just like the Smartcard's and Chr's

Those are simple for loops over one array and I don't see any benefit of those
helpers.  If someone want's to iterate over RNG or Redirect devices they can
use a simple for loop without a need to create an extra iterator function.

I would rather remove the helper for Smartcards because it's the same case,
the only one that make sense is for char devices, because there are four
arrays and you usually wants to iterate over all of the char devices.

Pavel

> Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
> ---
>  src/conf/domain_conf.c   | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
>  src/conf/domain_conf.h   | 18 ++++++++++++++++++
>  src/libvirt_private.syms |  2 ++
>  3 files changed, 68 insertions(+)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index de7df5c..30f2d6d 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -24559,6 +24559,54 @@ virDomainSmartcardDefForeach(virDomainDefPtr def,
>  
>  
>  int
> +virDomainRNGDefForeach(virDomainDefPtr def,
> +                       bool abortOnError,
> +                       virDomainRNGDefIterator iter,
> +                       void *opaque)
> +{
> +    size_t i;
> +    int rc = 0;
> +
> +    for (i = 0; i < def->nrngs; i++) {
> +        if ((iter)(def,
> +                   def->rngs[i],
> +                   opaque) < 0)
> +            rc = -1;
> +
> +        if (abortOnError && rc != 0)
> +            goto done;
> +    }
> +
> + done:
> +    return rc;
> +}
> +
> +
> +int
> +virDomainRedirdevDefForeach(virDomainDefPtr def,
> +                            bool abortOnError,
> +                            virDomainRedirdevDefIterator iter,
> +                            void *opaque)
> +{
> +    size_t i;
> +    int rc = 0;
> +
> +    for (i = 0; i < def->nredirdevs; i++) {
> +        if ((iter)(def,
> +                   def->redirdevs[i],
> +                   opaque) < 0)
> +            rc = -1;
> +
> +        if (abortOnError && rc != 0)
> +            goto done;
> +    }
> +
> + done:
> +    return rc;
> +}
> +
> +
> +int
>  virDomainUSBDeviceDefForeach(virDomainDefPtr def,
>                               virDomainUSBDeviceDefIterator iter,
>                               void *opaque,
> diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
> index df216e8..df962d7 100644
> --- a/src/conf/domain_conf.h
> +++ b/src/conf/domain_conf.h
> @@ -2948,6 +2948,24 @@ int virDomainChrDefForeach(virDomainDefPtr def,
>                             virDomainChrDefIterator iter,
>                             void *opaque);
>  
> +typedef int (*virDomainRNGDefIterator)(virDomainDefPtr def,
> +                                       virDomainRNGDefPtr dev,
> +                                       void *opaque);
> +
> +int virDomainRNGDefForeach(virDomainDefPtr def,
> +                           bool abortOnError,
> +                           virDomainRNGDefIterator iter,
> +                           void *opaque);
> +
> +typedef int (*virDomainRedirdevDefIterator)(virDomainDefPtr def,
> +                                            virDomainRedirdevDefPtr dev,
> +                                            void *opaque);
> +
> +int virDomainRedirdevDefForeach(virDomainDefPtr def,
> +                                bool abortOnError,
> +                                virDomainRedirdevDefIterator iter,
> +                                void *opaque);
> +
>  typedef int (*virDomainDiskDefPathIterator)(virDomainDiskDefPtr disk,
>                                              const char *path,
>                                              size_t depth,
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index bf503a5..c777738 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -453,9 +453,11 @@ virDomainPMSuspendedReasonTypeToString;
>  virDomainRedirdevBusTypeFromString;
>  virDomainRedirdevBusTypeToString;
>  virDomainRedirdevDefFind;
> +virDomainRedirdevDefForeach;
>  virDomainRedirdevDefFree;
>  virDomainRedirdevDefRemove;
>  virDomainRNGBackendTypeToString;
> +virDomainRNGDefForeach;
>  virDomainRNGDefFree;
>  virDomainRNGFind;
>  virDomainRNGModelTypeToString;
> -- 
> 2.7.4
> 
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list

Attachment: signature.asc
Description: Digital signature

--
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]