Permalink
Browse files

Allow disabling auto LUN scans

Existing behavior of auto scanning LUNs is problematic for some
deployments, particularly in cases where we are:

- Accessing different LUNs from the same target on different machines
  and we don't want the other LUNs automatically exposed in other
  systems.

- LUNs are constantly being created and removed from the target by
  another machine and we don't want our systems polluted by no longer
  available logical units, since default udev rules don't remove them
  automatically from the system once they have been added automatically.

This is a little more problematic when working with multipaths as we end
up with a lot of leftover device maps.

This patches introduces a new configuration option at the session level
called "autoscan_en" that allows us to disable the autoscan in the
following cases:

- On iscsid start
- On login
- On AEN/AER messages reporting LUNs data has changed.

For HW drivers all sessions will use the value defined in the
configuration file.

Default value for this new option is "Yes" to maintain existing
behavior.
  • Loading branch information...
Akrog committed Feb 12, 2017
1 parent 86e8892 commit af5af04b38c414583c7774b96a666025e126e22e
Showing with 40 additions and 9 deletions.
  1. +8 −2 etc/iscsid.conf
  2. +1 −0 usr/config.h
  3. +12 −0 usr/idbm.c
  4. +1 −0 usr/idbm.h
  5. +1 −0 usr/idbm_fields.h
  6. +3 −2 usr/initiator.c
  7. +3 −0 usr/iscsi_settings.h
  8. +5 −2 usr/iscsi_sysfs.c
  9. +1 −1 usr/iscsi_sysfs.h
  10. +1 −1 usr/iscsiadm.c
  11. +1 −1 usr/iscsid.c
  12. +3 −0 usr/iscsistart.c
@@ -18,7 +18,7 @@
#
# Default for Fedora and RHEL. (uncomment to activate).
# iscsid.startup = /etc/rc.d/init.d/iscsid force-start
#
#
# Default for upstream open-iscsi scripts (uncomment to activate).
iscsid.startup = /sbin/iscsid
@@ -258,7 +258,7 @@ node.conn[0].iscsi.MaxXmitDataSegmentLength = 0
#
# The value is the number of bytes in the range of 512 to (2^24-1) and
# the default is 32768
#
#
discovery.sendtargets.iscsi.MaxRecvDataSegmentLength = 32768
# To allow the targets to control the setting of the digest checking,
@@ -305,3 +305,9 @@ node.session.iscsi.FastAbort = Yes
# a task management function like an ABORT TASK or LOGICAL UNIT RESET, that
# it continue to respond to R2Ts. To enable this uncomment this line
# node.session.iscsi.FastAbort = No
# To prevent doing automatic scans that would add unwanted luns to the system.
# These automatic scans are performed on startup, on login, and on AEN/AER
# reception on devices supporting it. For HW drivers all sessions will use
# the value defined in the configuration file. (The default behavior is Yes):
node.session.autoscan_en = Yes
@@ -190,6 +190,7 @@ typedef struct session_rec {
int queue_depth;
int initial_login_retry_max;
int nr_sessions;
int autoscan_en;
struct iscsi_auth_config auth;
struct iscsi_session_timeout_config timeo;
struct iscsi_error_timeout_config err_timeo;
@@ -462,6 +462,9 @@ idbm_recinfo_node(node_rec_t *r, recinfo_t *ri)
session.iscsi.MaxOutstandingR2T, IDBM_SHOW, num, 1);
__recinfo_int(SESSION_ERL, ri, r,
session.iscsi.ERL, IDBM_SHOW, num, 1);
__recinfo_int_o2(SESSION_AUTOSCAN_EN, ri, r,
session.autoscan_en, IDBM_SHOW, "No", "Yes",
num, 1);
for (i = 0; i < ISCSI_CONN_MAX; i++) {
char key[NAME_MAXVAL];
@@ -2726,6 +2729,14 @@ idbm_slp_defaults(struct iscsi_slp_config *cfg)
sizeof(struct iscsi_slp_config));
}
int
idbm_session_autoscan(struct iscsi_session *session)
{
if (session)
return session->nrec.session.autoscan_en;
return db->nrec.session.autoscan_en;
}
struct user_param *idbm_alloc_user_param(char *name, char *value)
{
struct user_param *param;
@@ -2981,6 +2992,7 @@ void idbm_node_setup_defaults(node_rec_t *rec)
rec->session.info = NULL;
rec->session.sid = 0;
rec->session.multiple = 0;
rec->session.autoscan_en = DEF_INITIAL_AUTOSCAN_EN;
idbm_setup_session_defaults(&rec->session.iscsi);
for (i=0; i<ISCSI_CONN_MAX; i++) {
@@ -140,6 +140,7 @@ extern int idbm_add_discovery(discovery_rec_t *newrec);
extern void idbm_sendtargets_defaults(struct iscsi_sendtargets_config *cfg);
extern void idbm_isns_defaults(struct iscsi_isns_config *cfg);
extern void idbm_slp_defaults(struct iscsi_slp_config *cfg);
extern int idbm_session_autoscan(struct iscsi_session *session);
extern int idbm_discovery_read(discovery_rec_t *rec, int type, char *addr,
int port);
extern int idbm_rec_read(node_rec_t *out_rec, char *target_name,
@@ -45,6 +45,7 @@
#define SESSION_MAX_CONNS "node.session.iscsi.MaxConnections"
#define SESSION_MAX_R2T "node.session.iscsi.MaxOutstandingR2T"
#define SESSION_ERL "node.session.iscsi.ERL"
#define SESSION_AUTOSCAN_EN "node.session.autoscan_en"
/* connections fields */
#define CONN_ADDR "node.conn[%d].address"
@@ -997,7 +997,7 @@ static void session_scan_host(struct iscsi_session *session, int hostno,
{
pid_t pid;
pid = iscsi_sysfs_scan_host(hostno, 1);
pid = iscsi_sysfs_scan_host(hostno, 1, idbm_session_autoscan(session));
if (pid == 0) {
mgmt_ipc_write_rsp(qtask, ISCSI_SUCCESS);
@@ -1201,7 +1201,8 @@ static void iscsi_recv_async_msg(iscsi_conn_t *conn, struct iscsi_hdr *hdr)
break;
}
if (sshdr.asc == 0x3f && sshdr.ascq == 0x0e)
if (sshdr.asc == 0x3f && sshdr.ascq == 0x0e
&& idbm_session_autoscan(session))
session_scan_host(session, session->hostno, NULL);
break;
case ISCSI_ASYNC_MSG_REQUEST_LOGOUT:
@@ -45,3 +45,6 @@
/* login retries */
#define DEF_INITIAL_LOGIN_RETRIES_MAX 4
/* autoscan enabled */
#define DEF_INITIAL_AUTOSCAN_EN 1
@@ -1883,12 +1883,15 @@ void iscsi_sysfs_rescan_device(void *data, int hostno, int target, int lun)
strlen(write_buf));
}
pid_t iscsi_sysfs_scan_host(int hostno, int async)
pid_t iscsi_sysfs_scan_host(int hostno, int async, int full_scan)
{
char id[NAME_SIZE];
char *write_buf = "- - -";
char write_buf[6] = "- - 0";
pid_t pid = 0;
if (full_scan)
write_buf[4] = '-';
if (async)
pid = fork();
if (pid == 0) {
@@ -87,7 +87,7 @@ extern void iscsi_sysfs_get_negotiated_session_conf(int sid,
struct iscsi_session_operational_config *conf);
extern void iscsi_sysfs_get_negotiated_conn_conf(int sid,
struct iscsi_conn_operational_config *conf);
extern pid_t iscsi_sysfs_scan_host(int hostno, int async);
extern pid_t iscsi_sysfs_scan_host(int hostno, int async, int full);
extern int iscsi_sysfs_get_session_state(char *state, int sid);
extern int iscsi_sysfs_get_host_state(char *state, int host_no);
extern int iscsi_sysfs_get_device_state(char *state, int host_no, int target,
@@ -773,7 +773,7 @@ static int rescan_portal(void *data, struct session_info *info)
iscsi_sysfs_for_each_device(NULL, host_no, info->sid,
iscsi_sysfs_rescan_device);
/* now scan for new devices */
iscsi_sysfs_scan_host(host_no, 0);
iscsi_sysfs_scan_host(host_no, 0, 1);
return 0;
}
@@ -216,7 +216,7 @@ static int sync_session(void *data, struct session_info *info)
iscsi_err_to_str(err));
return 0;
}
iscsi_sysfs_scan_host(host_no, 0);
iscsi_sysfs_scan_host(host_no, 0, idbm_session_autoscan(NULL));
return 0;
}
@@ -140,6 +140,7 @@ static int apply_params(struct node_rec *rec)
rec->session.initial_login_retry_max = -1;
rec->conn[0].timeo.noop_out_interval = -1;
rec->conn[0].timeo.noop_out_timeout = -1;
rec->session.autoscan_en = -1;
list_for_each_entry(param, &user_params, list) {
/*
@@ -183,6 +184,8 @@ static int apply_params(struct node_rec *rec)
rec->conn[0].timeo.noop_out_interval = 0;
if (rec->conn[0].timeo.noop_out_timeout == -1)
rec->conn[0].timeo.noop_out_timeout = 0;
if (rec->session.autoscan_en == -1)
rec->session.autoscan_en = DEF_INITIAL_AUTOSCAN_EN;
return 0;
}

0 comments on commit af5af04

Please sign in to comment.