[PATCH] storage_util: Fix the false condition in virStorageBackendDeviceIsEmpty

Han Han posted 1 patch 4 months, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20231227024518.20209-1-hhan@redhat.com
src/storage/storage_util.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
[PATCH] storage_util: Fix the false condition in virStorageBackendDeviceIsEmpty
Posted by Han Han 4 months, 1 week ago
In virStorageBackendDeviceIsEmpty, the return value for
virStorageBackendPARTEDValidLabel is -1 or 0. That makes the later
condition 'ret == -2' make always false. Remove the always false
condition.

Found by Linux Verification Center (portal.linuxtesting.ru) with SVACE.

Fixes: https://gitlab.com/libvirt/libvirt/-/issues/576

Signed-off-by: Han Han <hhan@redhat.com>
---
 src/storage/storage_util.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index 7bf815d978..82bcfa5838 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -3352,15 +3352,9 @@ virStorageBackendDeviceIsEmpty(const char *devpath,
                                                writelabel)) == -2)
         ret = virStorageBackendPARTEDValidLabel(devpath, format, writelabel);
 
-    if (ret == -2 && !writelabel)
+    if (!writelabel)
         ret = 0;
 
-    if (ret == -2) {
-        virReportError(VIR_ERR_OPERATION_INVALID,
-                       _("Unable to probe '%1$s' for existing data, forced overwrite is necessary"),
-                       devpath);
-    }
-
     return ret == 0;
 }
 
-- 
2.43.0
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org
Re: [PATCH] storage_util: Fix the false condition in virStorageBackendDeviceIsEmpty
Posted by Ján Tomko 4 months ago
On a Wednesday in 2023, Han Han wrote:
>In virStorageBackendDeviceIsEmpty, the return value for
>virStorageBackendPARTEDValidLabel is -1 or 0. That makes the later
>condition 'ret == -2' make always false. Remove the always false
>condition.
>
>Found by Linux Verification Center (portal.linuxtesting.ru) with SVACE.
>
>Fixes: https://gitlab.com/libvirt/libvirt/-/issues/576
>

As Michal pointed out in the linked issue, the functions return -2 if
the functionality was not compiled in.

Jano

>Signed-off-by: Han Han <hhan@redhat.com>
>---
> src/storage/storage_util.c | 8 +-------
> 1 file changed, 1 insertion(+), 7 deletions(-)
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org