Re: [PATCH 1/5] util: storage: Convert disk locality check to switch statement

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

 



On 09/09/2014 02:45 AM, Peter Krempa wrote:
> To allow the compiler to track future additions of disk types, convert
> the function to use a switch statement with the correct type.
> ---
>  src/util/virstoragefile.c | 17 ++++++++++++++++-
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
> index 5b6b2f5..299edcd 100644
> --- a/src/util/virstoragefile.c
> +++ b/src/util/virstoragefile.c
> @@ -1956,7 +1956,22 @@ virStorageSourceGetActualType(virStorageSourcePtr def)
>  bool
>  virStorageSourceIsLocalStorage(virStorageSourcePtr src)
>  {
> -    return virStorageSourceGetActualType(src) != VIR_STORAGE_TYPE_NETWORK;
> +    virStorageType type = virStorageSourceGetActualType(src);
> +
> +    switch (type) {
> +    case VIR_STORAGE_TYPE_FILE:
> +    case VIR_STORAGE_TYPE_BLOCK:
> +    case VIR_STORAGE_TYPE_DIR:
> +        return true;
> +
> +    case VIR_STORAGE_TYPE_NETWORK:
> +    case VIR_STORAGE_TYPE_VOLUME:
> +    case VIR_STORAGE_TYPE_LAST:
> +    case VIR_STORAGE_TYPE_NONE:

Might be worth a comment that TYPE_NETWORK (and maybe TYPE_NONE) is
expected, while the other cases represent coding error (the
GetActualType should have gotten rid of TYPE_VOLUME, and TYPE_LAST
should never be present; TYPE_NONE is possible only if we hit something
that we truly do not know what type it has).

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP 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]