From a1909069776dbab0beff8d7bba1651c94f8a9cd5 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Wed, 2 Jun 2021 10:34:46 +0200 Subject: [PATCH] storage: Don't overwrite error in virISCSIDirectDisconnect() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Ján Tomko --- 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