Re: [PATCH 05/13] conf: utility to return alias of a controller based on type/index

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

 




On 05/05/2015 02:03 PM, Laine Stump wrote:
> Because there are multiple potential reasons for an error, this
> function logs any errors before returning NULL (since the caller won't
> have the information needed to determine which was the reason for
> failure).
> ---
>  src/conf/domain_conf.c   | 34 ++++++++++++++++++++++++++++++++++
>  src/conf/domain_conf.h   |  3 +++
>  src/libvirt_private.syms |  1 +
>  3 files changed, 38 insertions(+)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 4cd36a1..22f49c9 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -12554,6 +12554,40 @@ virDomainControllerFind(virDomainDefPtr def,
>      return -1;
>  }
>  
> +
> +const char *
> +virDomainControllerAliasFind(virDomainDefPtr def,
> +                             int type, int idx)
> +{
> +    int contIndex;
> +    const char *contTypeStr = virDomainControllerTypeToString(type);
> +
> +    if (!contTypeStr) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("Unknown controller type %d"),
> +                       type);
> +        return NULL;
> +    }

Unless this is LAST ... in which case there's a lot more places in the
code that are going to fail using the *ToString calls.

> +
> +    contIndex = virDomainControllerFind(def, type, idx);
> +    if (contIndex < 0) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("Could not find %s controller with index %d "
> +                         "required for device"),
> +                       contTypeStr, idx);
> +        return NULL;
> +    }
> +    if (!def->controllers[contIndex]->info.alias) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("Device alias was not set for %s controller "
> +                         "with index %d "),
> +                       contTypeStr, idx);
> +        return NULL;

So if the alias wasn't set for some reason we're going to start seeing
errors. Is there a reason the alias wouldn't be set... (just trying to
think/type outloud later in the day at the end of the week as my brain
is beginning to check out).


ACK - although I'm still trying to read ahead a bit and may come back to
this...


John
> +    }
> +    return def->controllers[contIndex]->info.alias;
> +}
> +
> +
>  int
>  virDomainControllerFindByType(virDomainDefPtr def,
>                                int type)
> diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
> index 087d282..7cc655b 100644
> --- a/src/conf/domain_conf.h
> +++ b/src/conf/domain_conf.h
> @@ -2754,6 +2754,9 @@ int virDomainControllerFindByType(virDomainDefPtr def, int type);
>  int virDomainControllerFindByPCIAddress(virDomainDefPtr def,
>                                          virDevicePCIAddressPtr addr);
>  virDomainControllerDefPtr virDomainControllerRemove(virDomainDefPtr def, size_t i);
> +const char *virDomainControllerAliasFind(virDomainDefPtr def,
> +                                         int type, int idx)
> +    ATTRIBUTE_NONNULL(1);
>  
>  int virDomainLeaseIndex(virDomainDefPtr def,
>                          virDomainLeaseDefPtr lease);
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index c8e6fb4..0eb5f75 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -181,6 +181,7 @@ virDomainClockBasisTypeToString;
>  virDomainClockOffsetTypeFromString;
>  virDomainClockOffsetTypeToString;
>  virDomainConfigFile;
> +virDomainControllerAliasFind;
>  virDomainControllerDefFree;
>  virDomainControllerFind;
>  virDomainControllerFindByType;
> 

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