]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: Don't overwrite error in virISCSIDirectDisconnect()
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 2 Jun 2021 08:34:46 +0000 (10:34 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 9 Jun 2021 06:07:07 +0000 (08:07 +0200)
The iscsi-direct storage pool backend works merely like this: a
connection is established to the target (usually done via
virStorageBackendISCSIDirectSetConnection()), intended action is
executed (e.g. reporting LUNs, volume wiping), and at the end the
connection is closed via virISCSIDirectDisconnect().

The problem is that virISCSIDirectDisconnect() reports its own
errors which may overwrite error that occurred during LUN
reporting, or volume wiping or whatever.

To fix this, use virErrorPreserveLast() + virErrorRestore()
combo, which either preserves previously reported error message,
or is NOP if there's no error reported.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1797879
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/storage/storage_backend_iscsi_direct.c

index 0bff1882b9da368b629fab51f74be0b6d7cba66c..e4a14c3fd640900762976f7111d3349546d3bd29 100644 (file)
@@ -391,19 +391,28 @@ virISCSIDirectReportLuns(virStoragePoolObj *pool,
 static int
 virISCSIDirectDisconnect(struct iscsi_context *iscsi)
 {
+    virErrorPtr orig_err;
+    int ret = -1;
+
+    virErrorPreserveLast(&orig_err);
+
     if (iscsi_logout_sync(iscsi) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Failed to logout: %s"),
                        iscsi_get_error(iscsi));
-        return -1;
+        goto cleanup;
     }
     if (iscsi_disconnect(iscsi) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Failed to disconnect: %s"),
                        iscsi_get_error(iscsi));
-        return -1;
+        goto cleanup;
     }
-    return 0;
+
+    ret = 0;
+ cleanup:
+    virErrorRestore(&orig_err);
+    return ret;
 }
 
 static int