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

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