Commit 4e2d19e4 authored by Chandra Seetharaman's avatar Chandra Seetharaman Committed by Alasdair G Kergon

dm mpath: delay activate_path retry on SCSI_DH_RETRY

This patch adds a user-configurable 'pg_init_delay_msecs' feature.  Use
this feature to specify the number of milliseconds to delay before
retrying scsi_dh_activate, when SCSI_DH_RETRY is returned.

SCSI Device Handlers return SCSI_DH_IMM_RETRY if we could retry
activation immediately and SCSI_DH_RETRY in cases where it is better to
retry after some delay.

Currently we immediately retry scsi_dh_activate irrespective of
SCSI_DH_IMM_RETRY and SCSI_DH_RETRY.

The 'pg_init_delay_msecs' feature may be provided during table create or
load, e.g.:
    dmsetup create --table "0 20971520 multipath 3 queue_if_no_path \
	pg_init_delay_msecs 2500 ..." mpatha

The default for 'pg_init_delay_msecs' is 2000 milliseconds.
Maximum configurable delay is 60000 milliseconds.  Specifying a
'pg_init_delay_msecs' of 0 will cause immediate retry.
Signed-off-by: default avatarNikanth Karthikesan <knikanth@suse.de>
Signed-off-by: default avatarChandra Seetharaman <sekharan@us.ibm.com>
Acked-by: default avatarMike Christie <michaelc@cs.wisc.edu>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
Signed-off-by: default avatarAlasdair G Kergon <agk@redhat.com>
parent 052189a2
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#define DM_MSG_PREFIX "multipath" #define DM_MSG_PREFIX "multipath"
#define MESG_STR(x) x, sizeof(x) #define MESG_STR(x) x, sizeof(x)
#define DM_PG_INIT_DELAY_MSECS 2000
#define DM_PG_INIT_DELAY_DEFAULT ((unsigned) -1)
/* Path properties */ /* Path properties */
struct pgpath { struct pgpath {
...@@ -33,7 +35,7 @@ struct pgpath { ...@@ -33,7 +35,7 @@ struct pgpath {
unsigned fail_count; /* Cumulative failure count */ unsigned fail_count; /* Cumulative failure count */
struct dm_path path; struct dm_path path;
struct work_struct activate_path; struct delayed_work activate_path;
}; };
#define path_to_pgpath(__pgp) container_of((__pgp), struct pgpath, path) #define path_to_pgpath(__pgp) container_of((__pgp), struct pgpath, path)
...@@ -64,11 +66,15 @@ struct multipath { ...@@ -64,11 +66,15 @@ struct multipath {
const char *hw_handler_name; const char *hw_handler_name;
char *hw_handler_params; char *hw_handler_params;
unsigned nr_priority_groups; unsigned nr_priority_groups;
struct list_head priority_groups; struct list_head priority_groups;
wait_queue_head_t pg_init_wait; /* Wait for pg_init completion */
unsigned pg_init_required; /* pg_init needs calling? */ unsigned pg_init_required; /* pg_init needs calling? */
unsigned pg_init_in_progress; /* Only one pg_init allowed at once */ unsigned pg_init_in_progress; /* Only one pg_init allowed at once */
wait_queue_head_t pg_init_wait; /* Wait for pg_init completion */ unsigned pg_init_delay_retry; /* Delay pg_init retry? */
unsigned nr_valid_paths; /* Total number of usable paths */ unsigned nr_valid_paths; /* Total number of usable paths */
struct pgpath *current_pgpath; struct pgpath *current_pgpath;
...@@ -81,6 +87,7 @@ struct multipath { ...@@ -81,6 +87,7 @@ struct multipath {
unsigned saved_queue_if_no_path;/* Saved state during suspension */ unsigned saved_queue_if_no_path;/* Saved state during suspension */
unsigned pg_init_retries; /* Number of times to retry pg_init */ unsigned pg_init_retries; /* Number of times to retry pg_init */
unsigned pg_init_count; /* Number of times pg_init called */ unsigned pg_init_count; /* Number of times pg_init called */
unsigned pg_init_delay_msecs; /* Number of msecs before pg_init retry */
struct work_struct process_queued_ios; struct work_struct process_queued_ios;
struct list_head queued_ios; struct list_head queued_ios;
...@@ -127,7 +134,7 @@ static struct pgpath *alloc_pgpath(void) ...@@ -127,7 +134,7 @@ static struct pgpath *alloc_pgpath(void)
if (pgpath) { if (pgpath) {
pgpath->is_active = 1; pgpath->is_active = 1;
INIT_WORK(&pgpath->activate_path, activate_path); INIT_DELAYED_WORK(&pgpath->activate_path, activate_path);
} }
return pgpath; return pgpath;
...@@ -188,6 +195,7 @@ static struct multipath *alloc_multipath(struct dm_target *ti) ...@@ -188,6 +195,7 @@ static struct multipath *alloc_multipath(struct dm_target *ti)
INIT_LIST_HEAD(&m->queued_ios); INIT_LIST_HEAD(&m->queued_ios);
spin_lock_init(&m->lock); spin_lock_init(&m->lock);
m->queue_io = 1; m->queue_io = 1;
m->pg_init_delay_msecs = DM_PG_INIT_DELAY_DEFAULT;
INIT_WORK(&m->process_queued_ios, process_queued_ios); INIT_WORK(&m->process_queued_ios, process_queued_ios);
INIT_WORK(&m->trigger_event, trigger_event); INIT_WORK(&m->trigger_event, trigger_event);
init_waitqueue_head(&m->pg_init_wait); init_waitqueue_head(&m->pg_init_wait);
...@@ -227,14 +235,19 @@ static void free_multipath(struct multipath *m) ...@@ -227,14 +235,19 @@ static void free_multipath(struct multipath *m)
static void __pg_init_all_paths(struct multipath *m) static void __pg_init_all_paths(struct multipath *m)
{ {
struct pgpath *pgpath; struct pgpath *pgpath;
unsigned long pg_init_delay = 0;
m->pg_init_count++; m->pg_init_count++;
m->pg_init_required = 0; m->pg_init_required = 0;
if (m->pg_init_delay_retry)
pg_init_delay = msecs_to_jiffies(m->pg_init_delay_msecs != DM_PG_INIT_DELAY_DEFAULT ?
m->pg_init_delay_msecs : DM_PG_INIT_DELAY_MSECS);
list_for_each_entry(pgpath, &m->current_pg->pgpaths, list) { list_for_each_entry(pgpath, &m->current_pg->pgpaths, list) {
/* Skip failed paths */ /* Skip failed paths */
if (!pgpath->is_active) if (!pgpath->is_active)
continue; continue;
if (queue_work(kmpath_handlerd, &pgpath->activate_path)) if (queue_delayed_work(kmpath_handlerd, &pgpath->activate_path,
pg_init_delay))
m->pg_init_in_progress++; m->pg_init_in_progress++;
} }
} }
...@@ -782,8 +795,9 @@ static int parse_features(struct arg_set *as, struct multipath *m) ...@@ -782,8 +795,9 @@ static int parse_features(struct arg_set *as, struct multipath *m)
const char *param_name; const char *param_name;
static struct param _params[] = { static struct param _params[] = {
{0, 3, "invalid number of feature args"}, {0, 5, "invalid number of feature args"},
{1, 50, "pg_init_retries must be between 1 and 50"}, {1, 50, "pg_init_retries must be between 1 and 50"},
{0, 60000, "pg_init_delay_msecs must be between 0 and 60000"},
}; };
r = read_param(_params, shift(as), &argc, &ti->error); r = read_param(_params, shift(as), &argc, &ti->error);
...@@ -810,6 +824,14 @@ static int parse_features(struct arg_set *as, struct multipath *m) ...@@ -810,6 +824,14 @@ static int parse_features(struct arg_set *as, struct multipath *m)
continue; continue;
} }
if (!strnicmp(param_name, MESG_STR("pg_init_delay_msecs")) &&
(argc >= 1)) {
r = read_param(_params + 2, shift(as),
&m->pg_init_delay_msecs, &ti->error);
argc--;
continue;
}
ti->error = "Unrecognised multipath feature request"; ti->error = "Unrecognised multipath feature request";
r = -EINVAL; r = -EINVAL;
} while (argc && !r); } while (argc && !r);
...@@ -1022,7 +1044,7 @@ static int reinstate_path(struct pgpath *pgpath) ...@@ -1022,7 +1044,7 @@ static int reinstate_path(struct pgpath *pgpath)
m->current_pgpath = NULL; m->current_pgpath = NULL;
queue_work(kmultipathd, &m->process_queued_ios); queue_work(kmultipathd, &m->process_queued_ios);
} else if (m->hw_handler_name && (m->current_pg == pgpath->pg)) { } else if (m->hw_handler_name && (m->current_pg == pgpath->pg)) {
if (queue_work(kmpath_handlerd, &pgpath->activate_path)) if (queue_work(kmpath_handlerd, &pgpath->activate_path.work))
m->pg_init_in_progress++; m->pg_init_in_progress++;
} }
...@@ -1157,6 +1179,7 @@ static void pg_init_done(void *data, int errors) ...@@ -1157,6 +1179,7 @@ static void pg_init_done(void *data, int errors)
struct priority_group *pg = pgpath->pg; struct priority_group *pg = pgpath->pg;
struct multipath *m = pg->m; struct multipath *m = pg->m;
unsigned long flags; unsigned long flags;
unsigned delay_retry = 0;
/* device or driver problems */ /* device or driver problems */
switch (errors) { switch (errors) {
...@@ -1181,8 +1204,9 @@ static void pg_init_done(void *data, int errors) ...@@ -1181,8 +1204,9 @@ static void pg_init_done(void *data, int errors)
*/ */
bypass_pg(m, pg, 1); bypass_pg(m, pg, 1);
break; break;
/* TODO: For SCSI_DH_RETRY we should wait a couple seconds */
case SCSI_DH_RETRY: case SCSI_DH_RETRY:
/* Wait before retrying. */
delay_retry = 1;
case SCSI_DH_IMM_RETRY: case SCSI_DH_IMM_RETRY:
case SCSI_DH_RES_TEMP_UNAVAIL: case SCSI_DH_RES_TEMP_UNAVAIL:
if (pg_init_limit_reached(m, pgpath)) if (pg_init_limit_reached(m, pgpath))
...@@ -1215,6 +1239,7 @@ static void pg_init_done(void *data, int errors) ...@@ -1215,6 +1239,7 @@ static void pg_init_done(void *data, int errors)
if (!m->pg_init_required) if (!m->pg_init_required)
m->queue_io = 0; m->queue_io = 0;
m->pg_init_delay_retry = delay_retry;
queue_work(kmultipathd, &m->process_queued_ios); queue_work(kmultipathd, &m->process_queued_ios);
/* /*
...@@ -1229,7 +1254,7 @@ static void pg_init_done(void *data, int errors) ...@@ -1229,7 +1254,7 @@ static void pg_init_done(void *data, int errors)
static void activate_path(struct work_struct *work) static void activate_path(struct work_struct *work)
{ {
struct pgpath *pgpath = struct pgpath *pgpath =
container_of(work, struct pgpath, activate_path); container_of(work, struct pgpath, activate_path.work);
scsi_dh_activate(bdev_get_queue(pgpath->path.dev->bdev), scsi_dh_activate(bdev_get_queue(pgpath->path.dev->bdev),
pg_init_done, pgpath); pg_init_done, pgpath);
...@@ -1370,11 +1395,14 @@ static int multipath_status(struct dm_target *ti, status_type_t type, ...@@ -1370,11 +1395,14 @@ static int multipath_status(struct dm_target *ti, status_type_t type,
DMEMIT("2 %u %u ", m->queue_size, m->pg_init_count); DMEMIT("2 %u %u ", m->queue_size, m->pg_init_count);
else { else {
DMEMIT("%u ", m->queue_if_no_path + DMEMIT("%u ", m->queue_if_no_path +
(m->pg_init_retries > 0) * 2); (m->pg_init_retries > 0) * 2 +
(m->pg_init_delay_msecs != DM_PG_INIT_DELAY_DEFAULT) * 2);
if (m->queue_if_no_path) if (m->queue_if_no_path)
DMEMIT("queue_if_no_path "); DMEMIT("queue_if_no_path ");
if (m->pg_init_retries) if (m->pg_init_retries)
DMEMIT("pg_init_retries %u ", m->pg_init_retries); DMEMIT("pg_init_retries %u ", m->pg_init_retries);
if (m->pg_init_delay_msecs != DM_PG_INIT_DELAY_DEFAULT)
DMEMIT("pg_init_delay_msecs %u ", m->pg_init_delay_msecs);
} }
if (!m->hw_handler_name || type == STATUSTYPE_INFO) if (!m->hw_handler_name || type == STATUSTYPE_INFO)
...@@ -1643,7 +1671,7 @@ static int multipath_busy(struct dm_target *ti) ...@@ -1643,7 +1671,7 @@ static int multipath_busy(struct dm_target *ti)
*---------------------------------------------------------------*/ *---------------------------------------------------------------*/
static struct target_type multipath_target = { static struct target_type multipath_target = {
.name = "multipath", .name = "multipath",
.version = {1, 1, 1}, .version = {1, 2, 0},
.module = THIS_MODULE, .module = THIS_MODULE,
.ctr = multipath_ctr, .ctr = multipath_ctr,
.dtr = multipath_dtr, .dtr = multipath_dtr,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment