Blame SOURCES/open-iscsi-2.0.874-7-Allow-disabling-auto-LUN-scans.patch

e88930
From 5e32aea95741a07d53153c658a0572588eae494d Mon Sep 17 00:00:00 2001
e88930
From: Gorka Eguileor <geguileo@redhat.com>
e88930
Date: Tue, 21 Feb 2017 20:01:39 +0100
e88930
Subject: Allow disabling auto LUN scans
e88930
e88930
Existing behavior of auto scanning LUNs is problematic for some
e88930
deployments, particularly in cases where we are:
e88930
e88930
- Accessing different LUNs from the same target on different machines
e88930
  and we don't want the other LUNs automatically exposed in other
e88930
  systems.
e88930
e88930
- LUNs are constantly being created and removed from the target by
e88930
  another machine and we don't want our systems polluted by no longer
e88930
  available logical units, since default udev rules don't remove them
e88930
  automatically from the system once they have been added automatically.
e88930
e88930
This is a little more problematic when working with multipaths as we end
e88930
up with a lot of leftover device maps.
e88930
e88930
This patch introduces a new configuration option at the session level
e88930
called "scan", with "auto" and "manual" as acceptable values, that
e88930
allows us to disable the autoscan in the following cases:
e88930
e88930
- On iscsid start
e88930
- On login
e88930
- On AEN/AER messages reporting LUNs data has changed.
e88930
e88930
For HW drivers all sessions will use the value defined in the
e88930
configuration file.
e88930
e88930
Default value for this new option is "auto" to maintain existing
e88930
behavior.
e88930
---
e88930
 etc/iscsid.conf      |  8 ++++++++
e88930
 usr/config.h         |  1 +
e88930
 usr/idbm.c           | 14 +++++++++++++-
e88930
 usr/idbm.h           |  1 +
e88930
 usr/idbm_fields.h    |  1 +
e88930
 usr/initiator.c      |  5 +++--
e88930
 usr/iscsi_settings.h |  3 +++
e88930
 usr/iscsi_sysfs.c    |  7 +++++--
e88930
 usr/iscsi_sysfs.h    |  2 +-
e88930
 usr/iscsiadm.c       |  2 +-
e88930
 usr/iscsid.c         |  2 +-
e88930
 usr/iscsistart.c     |  3 +++
e88930
 12 files changed, 41 insertions(+), 8 deletions(-)
e88930
e88930
diff --git a/etc/iscsid.conf b/etc/iscsid.conf
e88930
index f7ecb6b3c2ab..cb77a777062d 100644
e88930
--- a/etc/iscsid.conf
e88930
+++ b/etc/iscsid.conf
e88930
@@ -305,3 +305,11 @@ node.session.iscsi.FastAbort = Yes
e88930
 # a task management function like an ABORT TASK or LOGICAL UNIT RESET, that
e88930
 # it continue to respond to R2Ts. To enable this uncomment this line
e88930
 # node.session.iscsi.FastAbort = No
e88930
+
e88930
+# To prevent doing automatic scans that would add unwanted luns to the system
e88930
+# we can disable them and have sessions only do manually requested scans.
e88930
+# Automatic scans are performed on startup, on login, and on AEN/AER reception
e88930
+# on devices supporting it.  For HW drivers all sessions will use the value
e88930
+# defined in the configuration file.  This configuration option is independent
e88930
+# of scsi_mod scan parameter. (The default behavior is auto):
e88930
+node.session.scan = auto
e88930
diff --git a/usr/config.h b/usr/config.h
e88930
index 5b1bb1d624c5..3bcb93fe7322 100644
e88930
--- a/usr/config.h
e88930
+++ b/usr/config.h
e88930
@@ -190,6 +190,7 @@ typedef struct session_rec {
e88930
 	int					queue_depth;
e88930
 	int					initial_login_retry_max;
e88930
 	int					nr_sessions;
e88930
+	int					scan;
e88930
 	struct iscsi_auth_config		auth;
e88930
 	struct iscsi_session_timeout_config	timeo;
e88930
 	struct iscsi_error_timeout_config	err_timeo;
e88930
diff --git a/usr/idbm.c b/usr/idbm.c
e88930
index 3b8a5a20bec8..ff8d67f64c51 100644
e88930
--- a/usr/idbm.c
e88930
+++ b/usr/idbm.c
e88930
@@ -462,6 +462,9 @@ idbm_recinfo_node(node_rec_t *r, recinfo_t *ri)
e88930
 		      session.iscsi.MaxOutstandingR2T, IDBM_SHOW, num, 1);
e88930
 	__recinfo_int(SESSION_ERL, ri, r,
e88930
 		      session.iscsi.ERL, IDBM_SHOW, num, 1);
e88930
+	__recinfo_int_o2(SESSION_SCAN, ri, r,
e88930
+			 session.scan, IDBM_SHOW, "manual", "auto",
e88930
+			 num, 1);
e88930
 
e88930
 	for (i = 0; i < ISCSI_CONN_MAX; i++) {
e88930
 		char key[NAME_MAXVAL];
e88930
@@ -2490,7 +2493,7 @@ static void idbm_rm_disc_node_links(char *disc_dir)
e88930
 		log_debug(5, "disc removal removing link %s %s %s %s",
e88930
 			  target, address, port, iface_id);
e88930
 
e88930
-		memset(rec, 0, sizeof(*rec));	
e88930
+		memset(rec, 0, sizeof(*rec));
e88930
 		strlcpy(rec->name, target, TARGET_NAME_MAXLEN);
e88930
 		rec->tpgt = atoi(tpgt);
e88930
 		rec->conn[0].port = atoi(port);
e88930
@@ -2726,6 +2729,14 @@ idbm_slp_defaults(struct iscsi_slp_config *cfg)
e88930
 	       sizeof(struct iscsi_slp_config));
e88930
 }
e88930
 
e88930
+int
e88930
+idbm_session_autoscan(struct iscsi_session *session)
e88930
+{
e88930
+	if (session)
e88930
+		return session->nrec.session.scan;
e88930
+	return db->nrec.session.scan;
e88930
+}
e88930
+
e88930
 struct user_param *idbm_alloc_user_param(char *name, char *value)
e88930
 {
e88930
 	struct user_param *param;
e88930
@@ -2981,6 +2992,7 @@ void idbm_node_setup_defaults(node_rec_t *rec)
e88930
 	rec->session.info = NULL;
e88930
 	rec->session.sid = 0;
e88930
 	rec->session.multiple = 0;
e88930
+	rec->session.scan = DEF_INITIAL_SCAN;
e88930
 	idbm_setup_session_defaults(&rec->session.iscsi);
e88930
 
e88930
 	for (i=0; i
e88930
diff --git a/usr/idbm.h b/usr/idbm.h
e88930
index b9020fe4fd0a..411dd8230ece 100644
e88930
--- a/usr/idbm.h
e88930
+++ b/usr/idbm.h
e88930
@@ -140,6 +140,7 @@ extern int idbm_add_discovery(discovery_rec_t *newrec);
e88930
 extern void idbm_sendtargets_defaults(struct iscsi_sendtargets_config *cfg);
e88930
 extern void idbm_isns_defaults(struct iscsi_isns_config *cfg);
e88930
 extern void idbm_slp_defaults(struct iscsi_slp_config *cfg);
e88930
+extern int idbm_session_autoscan(struct iscsi_session *session);
e88930
 extern int idbm_discovery_read(discovery_rec_t *rec, int type, char *addr,
e88930
 				int port);
e88930
 extern int idbm_rec_read(node_rec_t *out_rec, char *target_name,
e88930
diff --git a/usr/idbm_fields.h b/usr/idbm_fields.h
e88930
index 5790a033d241..4a927584c2fc 100644
e88930
--- a/usr/idbm_fields.h
e88930
+++ b/usr/idbm_fields.h
e88930
@@ -45,6 +45,7 @@
e88930
 #define SESSION_MAX_CONNS	"node.session.iscsi.MaxConnections"
e88930
 #define SESSION_MAX_R2T		"node.session.iscsi.MaxOutstandingR2T"
e88930
 #define SESSION_ERL		"node.session.iscsi.ERL"
e88930
+#define SESSION_SCAN		"node.session.scan"
e88930
 
e88930
 /* connections fields */
e88930
 #define CONN_ADDR		"node.conn[%d].address"
e88930
diff --git a/usr/initiator.c b/usr/initiator.c
e88930
index ed174b5af38f..a86d1e6dee90 100644
e88930
--- a/usr/initiator.c
e88930
+++ b/usr/initiator.c
e88930
@@ -997,7 +997,7 @@ static void session_scan_host(struct iscsi_session *session, int hostno,
e88930
 {
e88930
 	pid_t pid;
e88930
 
e88930
-	pid = iscsi_sysfs_scan_host(hostno, 1);
e88930
+	pid = iscsi_sysfs_scan_host(hostno, 1, idbm_session_autoscan(session));
e88930
 	if (pid == 0) {
e88930
 		mgmt_ipc_write_rsp(qtask, ISCSI_SUCCESS);
e88930
 
e88930
@@ -1201,7 +1201,8 @@ static void iscsi_recv_async_msg(iscsi_conn_t *conn, struct iscsi_hdr *hdr)
e88930
 			break;
e88930
 		}
e88930
 
e88930
-		if (sshdr.asc == 0x3f && sshdr.ascq == 0x0e)
e88930
+		if (sshdr.asc == 0x3f && sshdr.ascq == 0x0e
e88930
+		    && idbm_session_autoscan(session))
e88930
 			session_scan_host(session, session->hostno, NULL);
e88930
 		break;
e88930
 	case ISCSI_ASYNC_MSG_REQUEST_LOGOUT:
e88930
diff --git a/usr/iscsi_settings.h b/usr/iscsi_settings.h
e88930
index 3d923c8ba029..296ff403b1e5 100644
e88930
--- a/usr/iscsi_settings.h
e88930
+++ b/usr/iscsi_settings.h
e88930
@@ -45,3 +45,6 @@
e88930
 
e88930
 /* login retries */
e88930
 #define DEF_INITIAL_LOGIN_RETRIES_MAX	4
e88930
+
e88930
+/* autoscan enabled */
e88930
+#define DEF_INITIAL_SCAN	1
e88930
diff --git a/usr/iscsi_sysfs.c b/usr/iscsi_sysfs.c
e88930
index 8ca668fdb3bc..2f94b632baaa 100644
e88930
--- a/usr/iscsi_sysfs.c
e88930
+++ b/usr/iscsi_sysfs.c
e88930
@@ -1883,12 +1883,15 @@ void iscsi_sysfs_rescan_device(void *data, int hostno, int target, int lun)
e88930
 			strlen(write_buf));
e88930
 }
e88930
 
e88930
-pid_t iscsi_sysfs_scan_host(int hostno, int async)
e88930
+pid_t iscsi_sysfs_scan_host(int hostno, int async, int full_scan)
e88930
 {
e88930
 	char id[NAME_SIZE];
e88930
-	char *write_buf = "- - -";
e88930
+	char write_buf[6] = "- - 0";
e88930
 	pid_t pid = 0;
e88930
 
e88930
+	if (full_scan)
e88930
+		write_buf[4] = '-';
e88930
+
e88930
 	if (async)
e88930
 		pid = fork();
e88930
 	if (pid == 0) {
e88930
diff --git a/usr/iscsi_sysfs.h b/usr/iscsi_sysfs.h
e88930
index 9a56105165b3..3492ce6e033c 100644
e88930
--- a/usr/iscsi_sysfs.h
e88930
+++ b/usr/iscsi_sysfs.h
e88930
@@ -87,7 +87,7 @@ extern void iscsi_sysfs_get_negotiated_session_conf(int sid,
e88930
 				struct iscsi_session_operational_config *conf);
e88930
 extern void iscsi_sysfs_get_negotiated_conn_conf(int sid,
e88930
 				struct iscsi_conn_operational_config *conf);
e88930
-extern pid_t iscsi_sysfs_scan_host(int hostno, int async);
e88930
+extern pid_t iscsi_sysfs_scan_host(int hostno, int async, int full);
e88930
 extern int iscsi_sysfs_get_session_state(char *state, int sid);
e88930
 extern int iscsi_sysfs_get_host_state(char *state, int host_no);
e88930
 extern int iscsi_sysfs_get_device_state(char *state, int host_no, int target,
e88930
diff --git a/usr/iscsiadm.c b/usr/iscsiadm.c
e88930
index 4b2bd34cbb2e..90e2828bcb79 100644
e88930
--- a/usr/iscsiadm.c
e88930
+++ b/usr/iscsiadm.c
e88930
@@ -773,7 +773,7 @@ static int rescan_portal(void *data, struct session_info *info)
e88930
 	iscsi_sysfs_for_each_device(NULL, host_no, info->sid,
e88930
 				    iscsi_sysfs_rescan_device);
e88930
 	/* now scan for new devices */
e88930
-	iscsi_sysfs_scan_host(host_no, 0);
e88930
+	iscsi_sysfs_scan_host(host_no, 0, 1);
e88930
 	return 0;
e88930
 }
e88930
 
e88930
diff --git a/usr/iscsid.c b/usr/iscsid.c
e88930
index 81a14f259b5f..813eb3da940d 100644
e88930
--- a/usr/iscsid.c
e88930
+++ b/usr/iscsid.c
e88930
@@ -216,7 +216,7 @@ static int sync_session(void *data, struct session_info *info)
e88930
 				  iscsi_err_to_str(err));
e88930
 			return 0;
e88930
 		}
e88930
-		iscsi_sysfs_scan_host(host_no, 0);
e88930
+		iscsi_sysfs_scan_host(host_no, 0, idbm_session_autoscan(NULL));
e88930
 		return 0;
e88930
 	}
e88930
 
e88930
diff --git a/usr/iscsistart.c b/usr/iscsistart.c
e88930
index 5cf09721636b..67ac47515f23 100644
e88930
--- a/usr/iscsistart.c
e88930
+++ b/usr/iscsistart.c
e88930
@@ -140,6 +140,7 @@ static int apply_params(struct node_rec *rec)
e88930
 	rec->session.initial_login_retry_max = -1;
e88930
 	rec->conn[0].timeo.noop_out_interval = -1;
e88930
 	rec->conn[0].timeo.noop_out_timeout = -1;
e88930
+	rec->session.scan = -1;
e88930
 
e88930
 	list_for_each_entry(param, &user_params, list) {
e88930
 		/*
e88930
@@ -183,6 +184,8 @@ static int apply_params(struct node_rec *rec)
e88930
 		rec->conn[0].timeo.noop_out_interval = 0;
e88930
 	if (rec->conn[0].timeo.noop_out_timeout == -1)
e88930
 		rec->conn[0].timeo.noop_out_timeout = 0;
e88930
+	if (rec->session.scan == -1)
e88930
+		rec->session.scan = DEF_INITIAL_SCAN;
e88930
 
e88930
 	return 0;
e88930
 }
e88930
-- 
e88930
2.9.3
e88930