diff options
author | Chris Leech <cleech@redhat.com> | 2021-03-11 11:28:45 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-11 11:28:45 -0800 |
commit | 2fdafe7a074ae205f6562ce6ac57bd9825d6a7ea (patch) | |
tree | 3e6391b33607d4de0f20632a5a967c10cf66147c | |
parent | a70e599ef0710328d065ab48d4235e2b4be94b9a (diff) | |
parent | b21066fc07261e05590ccab839bf5eee2249d358 (diff) | |
download | open-iscsi-2fdafe7a074ae205f6562ce6ac57bd9825d6a7ea.tar.gz |
Merge pull request #253 from cleech/iscsi_sessions_get
Iscsi sessions get
-rw-r--r-- | libopeniscsiusr/libopeniscsiusr/libopeniscsiusr.h | 2 | ||||
-rw-r--r-- | libopeniscsiusr/session.c | 41 | ||||
-rw-r--r-- | libopeniscsiusr/sysfs.c | 8 |
3 files changed, 38 insertions, 13 deletions
diff --git a/libopeniscsiusr/libopeniscsiusr/libopeniscsiusr.h b/libopeniscsiusr/libopeniscsiusr/libopeniscsiusr.h index 4395902..a29d5b1 100644 --- a/libopeniscsiusr/libopeniscsiusr/libopeniscsiusr.h +++ b/libopeniscsiusr/libopeniscsiusr/libopeniscsiusr.h @@ -288,7 +288,7 @@ __DLL_EXPORT void iscsi_sessions_free(struct iscsi_session **ses, * Output pointer of 'struct iscsi_session' pointer. Its memory * should be freed by iscsi_session_free(). * If this pointer is NULL, your program will be terminated by assert. - * If specified iSCSI session does not exists, this pointer will be set to + * If specified iSCSI session does not exist, this pointer will be set to * NULL with LIBISCSI_OK returned. * * Return: diff --git a/libopeniscsiusr/session.c b/libopeniscsiusr/session.c index 7ace4d6..6b06241 100644 --- a/libopeniscsiusr/session.c +++ b/libopeniscsiusr/session.c @@ -101,8 +101,8 @@ _iscsi_getter_func_gen(iscsi_session, address, const char *); _iscsi_getter_func_gen(iscsi_session, port, int32_t); _iscsi_getter_func_gen(iscsi_session, iface, struct iscsi_iface *); -int iscsi_session_get(struct iscsi_context *ctx, uint32_t sid, - struct iscsi_session **se) +int _iscsi_session_get(struct iscsi_context *ctx, uint32_t sid, + struct iscsi_session **se, bool verbose) { int rc = LIBISCSI_OK; char *sysfs_se_dir_path = NULL; @@ -127,18 +127,24 @@ int iscsi_session_get(struct iscsi_context *ctx, uint32_t sid, _alloc_null_check(ctx, *se , rc, out); if (! _file_exists(sysfs_se_dir_path)) { - _info(ctx, "Sysfs path '%s' does not exists", + _info(ctx, "Sysfs path '%s' does not exist", sysfs_se_dir_path); rc = LIBISCSI_ERR_SESS_NOT_FOUND; } if (! _file_exists(sysfs_con_dir_path)) { - _info(ctx, "Sysfs path '%s' does not exists", + _info(ctx, "Sysfs path '%s' does not exist", sysfs_se_dir_path); rc = LIBISCSI_ERR_SESS_NOT_FOUND; } if (rc == LIBISCSI_ERR_SESS_NOT_FOUND) { - _error(ctx, "Specified SID %" PRIu32, "does not exists", - sid); + /* don't complain loudly if called through iscsi_sessions_get() + * the caller is not looking for a specific session, + * and the list could be changing as we work through it + */ + if (verbose) { + _error(ctx, "Specified SID %" PRIu32 " does not exist", + sid); + } goto out; } @@ -240,12 +246,18 @@ out: return rc; } +int iscsi_session_get(struct iscsi_context *ctx, uint32_t sid, + struct iscsi_session **se) { + return _iscsi_session_get(ctx, sid, se, true); +} + int iscsi_sessions_get(struct iscsi_context *ctx, struct iscsi_session ***sessions, uint32_t *session_count) { int rc = LIBISCSI_OK; uint32_t i = 0; + uint32_t j = 0; uint32_t *sids = NULL; assert(ctx != NULL); @@ -264,9 +276,22 @@ int iscsi_sessions_get(struct iscsi_context *ctx, for (i = 0; i < *session_count; ++i) { _debug(ctx, "sid %" PRIu32, sids[i]); - _good(iscsi_session_get(ctx, sids[i], &((*sessions)[i])), - rc, out); + rc = _iscsi_session_get(ctx, sids[i], &((*sessions)[j]), false); + if (rc == LIBISCSI_OK) { + /* if session info was successfully read from sysfs, advance the sessions pointer */ + j++; + } else { + /* if not, just ignore the issue and keep trying with the next session ID, + * there's always going to be an inherent race against session removal when collecting + * attribute data from sysfs + */ + _debug(ctx, "Problem reading session %" PRIu32 ", skipping.", sids[i]); + rc = LIBISCSI_OK; + } } + /* reset session count and sessions array length to what we were able to read from sysfs */ + *session_count = j; + *sessions = reallocarray(*sessions, *session_count, sizeof(struct iscsi_session *)); out: free(sids); diff --git a/libopeniscsiusr/sysfs.c b/libopeniscsiusr/sysfs.c index 2c3f077..355ad55 100644 --- a/libopeniscsiusr/sysfs.c +++ b/libopeniscsiusr/sysfs.c @@ -169,11 +169,11 @@ int _sysfs_prop_get_str(struct iscsi_context *ctx, const char *dir_path, if (default_value == NULL) { rc = LIBISCSI_ERR_SYSFS_LOOKUP; _error(ctx, "Failed to read '%s': " - "file '%s' does not exists", prop_name, + "file '%s' does not exist", prop_name, file_path); } else { _info(ctx, "Failed to read '%s': " - "file '%s' does not exists, " + "file '%s' does not exist, " "using default value %s", prop_name, file_path, default_value); memcpy(buff, (void *) default_value, @@ -244,13 +244,13 @@ static int iscsi_sysfs_prop_get_ll(struct iscsi_context *ctx, if (! ignore_error) { rc = LIBISCSI_ERR_SYSFS_LOOKUP; _error(ctx, "Failed to read '%s': " - "file '%s' does not exists", + "file '%s' does not exist", prop_name, file_path); goto out; } else { _info(ctx, "Failed to read '%s': " - "File '%s' does not exists, using ", + "File '%s' does not exist, using ", "default value %lld", prop_name, file_path, default_value); *val = default_value; |