Skip to content

Commit 27f204c

Browse files
bmarzinsMikulas Patocka
authored andcommitted
dm-mpath: Simplify the setup_scsi_dh code
There's no point to the MPATHF_RETAIN_ATTACHED_HW_HANDLER flag any more. The way setup_scsi_dh() worked, if that flag wasn't set, it would attempt to attach any passed in hardware handler. This would always fail if a different hardware handler was attached, which caused setup_scsi_dh() to rerun as if the flag was set. So the code would already retain any attached handler, because attaching a different one would always fail. Also, the code had a bug. If attached_handler_name was NULL but there was a scsi device handler attached (because either scsi_dh_attached_handler_name failed() to allocate a name, a handler got attached after it was called) the code would loop endlessly. Instead, ignore MPATHF_RETAIN_ATTACHED_HW_HANDLER, and always free the passed in handler if *attached_handler_name is set. This simplifies the code, and avoids the endless loop bug, while keeping the functionality the same. Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
1 parent 4efe85b commit 27f204c

1 file changed

Lines changed: 23 additions & 38 deletions

File tree

drivers/md/dm-mpath.c

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static void queue_if_no_path_timeout_work(struct timer_list *t);
131131
#define MPATHF_QUEUE_IO 0 /* Must we queue all I/O? */
132132
#define MPATHF_QUEUE_IF_NO_PATH 1 /* Queue I/O if last path fails? */
133133
#define MPATHF_SAVED_QUEUE_IF_NO_PATH 2 /* Saved state during suspension */
134-
#define MPATHF_RETAIN_ATTACHED_HW_HANDLER 3 /* If there's already a hw_handler present, don't change it. */
134+
/* MPATHF_RETAIN_ATTACHED_HW_HANDLER no longer has any effect */
135135
#define MPATHF_PG_INIT_DISABLED 4 /* pg_init is not currently allowed */
136136
#define MPATHF_PG_INIT_REQUIRED 5 /* pg_init needs calling? */
137137
#define MPATHF_PG_INIT_DELAY_RETRY 6 /* Delay pg_init retry? */
@@ -237,16 +237,10 @@ static struct multipath *alloc_multipath(struct dm_target *ti)
237237

238238
static int alloc_multipath_stage2(struct dm_target *ti, struct multipath *m)
239239
{
240-
if (m->queue_mode == DM_TYPE_NONE) {
240+
if (m->queue_mode == DM_TYPE_NONE)
241241
m->queue_mode = DM_TYPE_REQUEST_BASED;
242-
} else if (m->queue_mode == DM_TYPE_BIO_BASED) {
242+
else if (m->queue_mode == DM_TYPE_BIO_BASED)
243243
INIT_WORK(&m->process_queued_bios, process_queued_bios);
244-
/*
245-
* bio-based doesn't support any direct scsi_dh management;
246-
* it just discovers if a scsi_dh is attached.
247-
*/
248-
set_bit(MPATHF_RETAIN_ATTACHED_HW_HANDLER, &m->flags);
249-
}
250244

251245
dm_table_set_type(ti->table, m->queue_mode);
252246

@@ -887,36 +881,30 @@ static int setup_scsi_dh(struct block_device *bdev, struct multipath *m,
887881
struct request_queue *q = bdev_get_queue(bdev);
888882
int r;
889883

890-
if (mpath_double_check_test_bit(MPATHF_RETAIN_ATTACHED_HW_HANDLER, m)) {
891-
retain:
892-
if (*attached_handler_name) {
893-
/*
894-
* Clear any hw_handler_params associated with a
895-
* handler that isn't already attached.
896-
*/
897-
if (m->hw_handler_name && strcmp(*attached_handler_name, m->hw_handler_name)) {
898-
kfree(m->hw_handler_params);
899-
m->hw_handler_params = NULL;
900-
}
901-
902-
/*
903-
* Reset hw_handler_name to match the attached handler
904-
*
905-
* NB. This modifies the table line to show the actual
906-
* handler instead of the original table passed in.
907-
*/
908-
kfree(m->hw_handler_name);
909-
m->hw_handler_name = *attached_handler_name;
910-
*attached_handler_name = NULL;
884+
if (*attached_handler_name) {
885+
/*
886+
* Clear any hw_handler_params associated with a
887+
* handler that isn't already attached.
888+
*/
889+
if (m->hw_handler_name && strcmp(*attached_handler_name,
890+
m->hw_handler_name)) {
891+
kfree(m->hw_handler_params);
892+
m->hw_handler_params = NULL;
911893
}
894+
895+
/*
896+
* Reset hw_handler_name to match the attached handler
897+
*
898+
* NB. This modifies the table line to show the actual
899+
* handler instead of the original table passed in.
900+
*/
901+
kfree(m->hw_handler_name);
902+
m->hw_handler_name = *attached_handler_name;
903+
*attached_handler_name = NULL;
912904
}
913905

914906
if (m->hw_handler_name) {
915907
r = scsi_dh_attach(q, m->hw_handler_name);
916-
if (r == -EBUSY) {
917-
DMINFO("retaining handler on device %pg", bdev);
918-
goto retain;
919-
}
920908
if (r < 0) {
921909
*error = "error attaching hardware handler";
922910
return r;
@@ -1138,7 +1126,7 @@ static int parse_features(struct dm_arg_set *as, struct multipath *m)
11381126
}
11391127

11401128
if (!strcasecmp(arg_name, "retain_attached_hw_handler")) {
1141-
set_bit(MPATHF_RETAIN_ATTACHED_HW_HANDLER, &m->flags);
1129+
/* no longer has any effect */
11421130
continue;
11431131
}
11441132

@@ -1823,7 +1811,6 @@ static void multipath_status(struct dm_target *ti, status_type_t type,
18231811
DMEMIT("%u ", test_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags) +
18241812
(m->pg_init_retries > 0) * 2 +
18251813
(m->pg_init_delay_msecs != DM_PG_INIT_DELAY_DEFAULT) * 2 +
1826-
test_bit(MPATHF_RETAIN_ATTACHED_HW_HANDLER, &m->flags) +
18271814
(m->queue_mode != DM_TYPE_REQUEST_BASED) * 2);
18281815

18291816
if (test_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags))
@@ -1832,8 +1819,6 @@ static void multipath_status(struct dm_target *ti, status_type_t type,
18321819
DMEMIT("pg_init_retries %u ", m->pg_init_retries);
18331820
if (m->pg_init_delay_msecs != DM_PG_INIT_DELAY_DEFAULT)
18341821
DMEMIT("pg_init_delay_msecs %u ", m->pg_init_delay_msecs);
1835-
if (test_bit(MPATHF_RETAIN_ATTACHED_HW_HANDLER, &m->flags))
1836-
DMEMIT("retain_attached_hw_handler ");
18371822
if (m->queue_mode != DM_TYPE_REQUEST_BASED) {
18381823
switch (m->queue_mode) {
18391824
case DM_TYPE_BIO_BASED:

0 commit comments

Comments
 (0)