[libvirt] [PATCH v2 1/8] iscsi_direct: Make virStorageBackendISCSIDirectGetLun report error properly

Michal Privoznik posted 8 patches 6 years, 11 months ago
There is a newer version of this series
[libvirt] [PATCH v2 1/8] iscsi_direct: Make virStorageBackendISCSIDirectGetLun report error properly
Posted by Michal Privoznik 6 years, 11 months ago
This function reports error for one of the two error paths. This
is unfortunate as a caller see this function failing but doesn't
know right away if an error was reported.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/storage/storage_backend_iscsi_direct.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/storage_backend_iscsi_direct.c
index 786663534d..fc3b6550f7 100644
--- a/src/storage/storage_backend_iscsi_direct.c
+++ b/src/storage/storage_backend_iscsi_direct.c
@@ -605,22 +605,16 @@ static int
 virStorageBackendISCSIDirectGetLun(virStorageVolDefPtr vol,
                                    int *lun)
 {
-    const char *name = vol->name;
-    int ret = -1;
+    const char *name;
 
-    if (!STRPREFIX(name, VOL_NAME_PREFIX)) {
+    if (!(name = STRSKIP(vol->name, VOL_NAME_PREFIX)) ||
+        virStrToLong_i(name, NULL, 10, lun) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Invalid volume name %s"), name);
-        goto cleanup;
+                       _("Invalid volume name %s"), vol->name);
+        return -1;
     }
 
-    name += strlen(VOL_NAME_PREFIX);
-    if (virStrToLong_i(name, NULL, 10, lun) < 0)
-        goto cleanup;
-
-    ret = 0;
- cleanup:
-    return ret;
+    return 0;
 }
 
 static int
-- 
2.19.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 1/8] iscsi_direct: Make virStorageBackendISCSIDirectGetLun report error properly
Posted by Pavel Hrdina 6 years, 11 months ago
On Wed, Mar 06, 2019 at 03:59:11PM +0100, Michal Privoznik wrote:
> This function reports error for one of the two error paths. This
> is unfortunate as a caller see this function failing but doesn't
> know right away if an error was reported.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/storage/storage_backend_iscsi_direct.c | 18 ++++++------------
>  1 file changed, 6 insertions(+), 12 deletions(-)

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list