Blame SOURCES/0025-libopeniscsiusr-skip-over-removed-sessions.patch

9a267a
From a744d91046865416a50ea27f143ef0f02fcaf1c6 Mon Sep 17 00:00:00 2001
9a267a
From: Chris Leech <cleech@redhat.com>
9a267a
Date: Wed, 17 Feb 2021 12:22:17 -0800
9a267a
Subject: [PATCH] libopeniscsiusr: skip over removed sessions
9a267a
9a267a
When looping over all sessions with iscsi_sessions_get, it's possible to
9a267a
race against sessions being destroyed and have the sysfs attribute files
9a267a
be removed before they're read. Let's not treat this as an error, and
9a267a
simply drop the session that failed to read from the list. I think it
9a267a
makes sense to treat session that disapear while they're being read as
9a267a
if they were already gone when the sessions directory was first scanned.
9a267a
9a267a
Apparently having iscsiadm exit with an error when trying to get a list
9a267a
of sessions is a problem for OpenStack deployments.
9a267a
9a267a
Signed-off-by: Chris Leech <cleech@redhat.com>
9a267a
---
9a267a
 libopeniscsiusr/session.c | 18 ++++++++++++++++--
9a267a
 1 file changed, 16 insertions(+), 2 deletions(-)
9a267a
9a267a
diff --git a/libopeniscsiusr/session.c b/libopeniscsiusr/session.c
9a267a
index f122fe3..4a724c8 100644
9a267a
--- a/libopeniscsiusr/session.c
9a267a
+++ b/libopeniscsiusr/session.c
9a267a
@@ -246,6 +246,7 @@ int iscsi_sessions_get(struct iscsi_context *ctx,
9a267a
 {
9a267a
 	int rc = LIBISCSI_OK;
9a267a
 	uint32_t i = 0;
9a267a
+	uint32_t j = 0;
9a267a
 	uint32_t *sids = NULL;
9a267a
 
9a267a
 	assert(ctx != NULL);
9a267a
@@ -264,9 +265,22 @@ int iscsi_sessions_get(struct iscsi_context *ctx,
9a267a
 
9a267a
 	for (i = 0; i < *session_count; ++i) {
9a267a
 		_debug(ctx, "sid %" PRIu32, sids[i]);
9a267a
-		_good(iscsi_session_get(ctx, sids[i], &((*sessions)[i])),
9a267a
-		      rc, out);
9a267a
+		rc = iscsi_session_get(ctx, sids[i], &((*sessions)[j]));
9a267a
+		if (rc == LIBISCSI_OK) {
9a267a
+			/* if session info was successfully read from sysfs, advance the sessions pointer */
9a267a
+			j++;
9a267a
+		} else {
9a267a
+			/* if not, just ignore the issue and keep trying with the next session ID,
9a267a
+			 * there's always going to be an inherent race against session removal when collecting
9a267a
+			 * attribute data from sysfs
9a267a
+			 */
9a267a
+			_debug(ctx, "Problem reading session %" PRIu32 ", skipping.", sids[i]);
9a267a
+			rc = LIBISCSI_OK;
9a267a
+		}
9a267a
 	}
9a267a
+	/* reset session count and sessions array length to what we were able to read from sysfs */
9a267a
+	*session_count = j;
9a267a
+	*sessions = reallocarray(*sessions, *session_count, sizeof(struct iscsi_session *));
9a267a
 
9a267a
 out:
9a267a
 	free(sids);
9a267a
-- 
9a267a
2.26.2
9a267a