diff mbox series

[v2] test: storage: Fill in default vol types for every pool

Message ID dbd4d9960da1cb3e6014cb25e76980de5be1e453.1552066900.git.crobinso@redhat.com
State Accepted
Commit 4ec884e38772f17d5d4b2217210023f77c33abb2
Headers show
Series [v2] test: storage: Fill in default vol types for every pool | expand

Commit Message

Cole Robinson March 8, 2019, 5:43 p.m. UTC
Fill in a default volume type for every pool type, as reported
by the VolGetInfo API. Now that we cover the whole enum, report
an error for invalid values.

Signed-off-by: Cole Robinson <crobinso@redhat.com>

---
v2: Use virReportEnumRangeError and handle the error in the caller
index ef754658f3..08970f8d6c 100644
-- 
2.20.1

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

Comments

Andrea Bolognani March 13, 2019, 4:40 p.m. UTC | #1
On Fri, 2019-03-08 at 12:43 -0500, Cole Robinson wrote:
>  static int

>  testStorageVolumeTypeForPool(int pooltype)

>  {

> -    switch (pooltype) {

> -        case VIR_STORAGE_POOL_DIR:

> -        case VIR_STORAGE_POOL_FS:

> -        case VIR_STORAGE_POOL_NETFS:

> -            return VIR_STORAGE_VOL_FILE;

> -        default:

> -            return VIR_STORAGE_VOL_BLOCK;

> +    switch ((virStoragePoolType) pooltype) {

> +    case VIR_STORAGE_POOL_DIR:

> +    case VIR_STORAGE_POOL_FS:

> +    case VIR_STORAGE_POOL_NETFS:

> +    case VIR_STORAGE_POOL_VSTORAGE:

> +        return VIR_STORAGE_VOL_FILE;

> +    case VIR_STORAGE_POOL_SHEEPDOG:

> +    case VIR_STORAGE_POOL_ISCSI_DIRECT:

> +    case VIR_STORAGE_POOL_GLUSTER:

> +    case VIR_STORAGE_POOL_RBD:

> +        return VIR_STORAGE_VOL_NETWORK;

> +    case VIR_STORAGE_POOL_LOGICAL:

> +    case VIR_STORAGE_POOL_DISK:

> +    case VIR_STORAGE_POOL_MPATH:

> +    case VIR_STORAGE_POOL_ISCSI:

> +    case VIR_STORAGE_POOL_SCSI:

> +    case VIR_STORAGE_POOL_ZFS:

> +        return VIR_STORAGE_VOL_BLOCK;

> +    case VIR_STORAGE_POOL_LAST:

> +    default:

> +        virReportEnumRangeError(virStoragePoolType, pooltype);

> +        return -1;

>      }

>  }


This is not my area of expertise but the categorization looks
sane enough, so assuming you've done your homework... :)

  Reviewed-by: Andrea Bolognani <abologna@redhat.com>


-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
diff mbox series

Patch

--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -5164,13 +5164,28 @@  testStorageVolDelete(virStorageVolPtr vol,
 static int
 testStorageVolumeTypeForPool(int pooltype)
 {
-    switch (pooltype) {
-        case VIR_STORAGE_POOL_DIR:
-        case VIR_STORAGE_POOL_FS:
-        case VIR_STORAGE_POOL_NETFS:
-            return VIR_STORAGE_VOL_FILE;
-        default:
-            return VIR_STORAGE_VOL_BLOCK;
+    switch ((virStoragePoolType) pooltype) {
+    case VIR_STORAGE_POOL_DIR:
+    case VIR_STORAGE_POOL_FS:
+    case VIR_STORAGE_POOL_NETFS:
+    case VIR_STORAGE_POOL_VSTORAGE:
+        return VIR_STORAGE_VOL_FILE;
+    case VIR_STORAGE_POOL_SHEEPDOG:
+    case VIR_STORAGE_POOL_ISCSI_DIRECT:
+    case VIR_STORAGE_POOL_GLUSTER:
+    case VIR_STORAGE_POOL_RBD:
+        return VIR_STORAGE_VOL_NETWORK;
+    case VIR_STORAGE_POOL_LOGICAL:
+    case VIR_STORAGE_POOL_DISK:
+    case VIR_STORAGE_POOL_MPATH:
+    case VIR_STORAGE_POOL_ISCSI:
+    case VIR_STORAGE_POOL_SCSI:
+    case VIR_STORAGE_POOL_ZFS:
+        return VIR_STORAGE_VOL_BLOCK;
+    case VIR_STORAGE_POOL_LAST:
+    default:
+        virReportEnumRangeError(virStoragePoolType, pooltype);
+        return -1;
     }
 }
 
@@ -5193,7 +5208,8 @@  testStorageVolGetInfo(virStorageVolPtr vol,
         goto cleanup;
 
     memset(info, 0, sizeof(*info));
-    info->type = testStorageVolumeTypeForPool(def->type);
+    if ((info->type = testStorageVolumeTypeForPool(def->type)) < 0)
+        goto cleanup;
     info->capacity = privvol->target.capacity;
     info->allocation = privvol->target.allocation;
     ret = 0;