Blame SOURCES/open-iscsi-2.0.876-71-Handle-ENOTCONN-error-separately-when-reading-sysfs-values.patch

62f653
commit ae0b2ceb620e2bf527c06d21c110791d1e0e8bf4
62f653
Author: Lee Duncan <lduncan@suse.com>
62f653
Date:   Tue Sep 25 09:57:46 2018 -0700
62f653
62f653
    Handle ENOTCONN error separately when reading sysfs values.
62f653
    
62f653
    This error happens when the daemon is attempting to
62f653
    reconnect a session when starting up, so should not
62f653
    be considered an internal error.
62f653
---
62f653
 libopeniscsiusr/sysfs.c | 31 +++++++++++++++++++++++++++++++
62f653
 1 file changed, 31 insertions(+)
62f653
62f653
diff --git a/libopeniscsiusr/sysfs.c b/libopeniscsiusr/sysfs.c
62f653
index 5e6532e7746f..2c3f077bf3fa 100644
62f653
--- a/libopeniscsiusr/sysfs.c
62f653
+++ b/libopeniscsiusr/sysfs.c
62f653
@@ -184,6 +184,21 @@ int _sysfs_prop_get_str(struct iscsi_context *ctx, const char *dir_path,
62f653
 			_error(ctx, "Failed to read '%s': "
62f653
 			       "permission deny when reading '%s'", prop_name,
62f653
 			       file_path);
62f653
+		} else if (errno_save == ENOTCONN) {
62f653
+			if (default_value == NULL) {
62f653
+				rc = LIBISCSI_ERR_SYSFS_LOOKUP;
62f653
+				_error(ctx, "Failed to read '%s': "
62f653
+				       "error when reading '%s': "
62f653
+				       "Target unavailable",
62f653
+				       prop_name, file_path);
62f653
+			} else {
62f653
+				_info(ctx, "Failed to read '%s': "
62f653
+				       "error when reading '%s': "
62f653
+				       "Target unavailable, using default value '%s'",
62f653
+				       prop_name, file_path, default_value);
62f653
+				memcpy(buff, (void *) default_value,
62f653
+				       strlen(default_value) + 1);
62f653
+			}
62f653
 		} else {
62f653
 			rc = LIBISCSI_ERR_BUG;
62f653
 			_error(ctx, "Failed to read '%s': "
62f653
@@ -246,6 +261,22 @@ static int iscsi_sysfs_prop_get_ll(struct iscsi_context *ctx,
62f653
 			_error(ctx, "Permission deny when reading '%s'",
62f653
 			       file_path);
62f653
 			goto out;
62f653
+		} else if (errno_save == ENOTCONN) {
62f653
+			if (!ignore_error) {
62f653
+				rc = LIBISCSI_ERR_SYSFS_LOOKUP;
62f653
+				_error(ctx, "Failed to read '%s': "
62f653
+					"error when reading '%s': "
62f653
+					"Target unavailable",
62f653
+					prop_name, file_path);
62f653
+				goto out;
62f653
+			} else {
62f653
+				_info(ctx, "Failed to read '%s': "
62f653
+					"error when reading '%s': "
62f653
+					"Target unavailable, using default value %lld",
62f653
+					prop_name, file_path, default_value);
62f653
+				*val = default_value;
62f653
+				goto out;
62f653
+			}
62f653
 		} else {
62f653
 			rc = LIBISCSI_ERR_BUG;
62f653
 			_error(ctx, "Error when reading '%s': %d", file_path,