[PATCH 17/36] virStorageSourceIsSameLocation: Use switch statement for individual storage types

Peter Krempa posted 36 patches 3 years, 1 month ago
There is a newer version of this series
[PATCH 17/36] virStorageSourceIsSameLocation: Use switch statement for individual storage types
Posted by Peter Krempa 3 years, 1 month ago
Convert to a switch instead of a bunch of 'if (type == ...).

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/conf/storage_source_conf.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/conf/storage_source_conf.c b/src/conf/storage_source_conf.c
index 2b4cf5e241..84df8d28fa 100644
--- a/src/conf/storage_source_conf.c
+++ b/src/conf/storage_source_conf.c
@@ -929,7 +929,8 @@ virStorageSourceIsSameLocation(virStorageSource *a,
         STRNEQ_NULLABLE(a->snapshot, b->snapshot))
         return false;

-    if (a->type == VIR_STORAGE_TYPE_NETWORK) {
+    switch ((virStorageType) virStorageSourceGetActualType(a)) {
+    case VIR_STORAGE_TYPE_NETWORK:
         if (a->protocol != b->protocol ||
             a->nhosts != b->nhosts)
             return false;
@@ -941,11 +942,23 @@ virStorageSourceIsSameLocation(virStorageSource *a,
                 STRNEQ_NULLABLE(a->hosts[i].socket, b->hosts[i].socket))
                 return false;
         }
-    }
+        break;

-    if (a->type == VIR_STORAGE_TYPE_NVME &&
-        !virStorageSourceNVMeDefIsEqual(a->nvme, b->nvme))
-        return false;
+    case VIR_STORAGE_TYPE_NVME:
+        if (!virStorageSourceNVMeDefIsEqual(a->nvme, b->nvme))
+            return false;
+        break;
+
+    case VIR_STORAGE_TYPE_VHOST_USER:
+    case VIR_STORAGE_TYPE_NONE:
+    case VIR_STORAGE_TYPE_FILE:
+    case VIR_STORAGE_TYPE_BLOCK:
+    case VIR_STORAGE_TYPE_DIR:
+    case VIR_STORAGE_TYPE_LAST:
+    case VIR_STORAGE_TYPE_VOLUME:
+        /* nothing to do */
+        break;
+    }

     return true;
 }
-- 
2.38.1
Re: [PATCH 17/36] virStorageSourceIsSameLocation: Use switch statement for individual storage types
Posted by Pavel Hrdina 3 years, 1 month ago
On Thu, Jan 05, 2023 at 05:30:06PM +0100, Peter Krempa wrote:
> Convert to a switch instead of a bunch of 'if (type == ...).
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  src/conf/storage_source_conf.c | 23 ++++++++++++++++++-----
>  1 file changed, 18 insertions(+), 5 deletions(-)
> 
> diff --git a/src/conf/storage_source_conf.c b/src/conf/storage_source_conf.c
> index 2b4cf5e241..84df8d28fa 100644
> --- a/src/conf/storage_source_conf.c
> +++ b/src/conf/storage_source_conf.c
> @@ -929,7 +929,8 @@ virStorageSourceIsSameLocation(virStorageSource *a,
>          STRNEQ_NULLABLE(a->snapshot, b->snapshot))
>          return false;
> 
> -    if (a->type == VIR_STORAGE_TYPE_NETWORK) {
> +    switch ((virStorageType) virStorageSourceGetActualType(a)) {

The typecast is probably not necessary as it already returns correct
type but it doesn't hurt as well.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>