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(a)redhat.com>
---
src/storage/storage_backend_iscsi_direct.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/storage/storage_backend_iscsi_direct.c
b/src/storage/storage_backend_iscsi_direct.c
index 0bff1882b9..e4a14c3fd6 100644
--- a/src/storage/storage_backend_iscsi_direct.c
+++ b/src/storage/storage_backend_iscsi_direct.c
@@ -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
--
2.31.1