Skip to contentSkip to conversation

mulitpath-tools Add purge capability to multipath-tools

PATCH New Brian Bunker 1 participant 2 messages Dec 11, 2025 Device mapper

lore
Share & tools
lore
#0 lore raw

v5 cover mulitpath-tools Add purge capability to multipath-tools

The changes represent "v5" of the purge disconnected paths feature. Here are the key modifications:

1. Renamed purge_path to disconnected with Enum States
Changed from a simple boolean purge_path to an enum path_disconnected_state with three states:
NOT_DISCONNECTED (0) - path is normal
DISCONNECTED_NO_PURGE - path was disconnected but purge was cancelled or alreadyattempted
DISCONNECTED_NEEDS_PURGE - path is disconnected and needs to be purged

2. Enhanced WWID Recheck Logic
Modified the WWID recheck condition to trigger if either:
recheck_wwid is explicitly enabled (existing behavior), OR
Path was previously disconnected (new safety feature)
This provides protection even when users don't enable recheck_wwid, since disconnected paths are much more likely to have changed WWIDs

3. Added Disconnected State Recovery
When a path recovers to UP/GHOST state, the disconnected state is cleared This happens after the WWID recheck, ensuring the WWID is validated before clearing the flag

4. Improved Purge Loop Logic
Changed from clearing purge_path flag to downgrading from DISCONNECTED_NEEDS_PURGE to DISCONNECTED_NO_PURGE
This prevents infinite retry loops if purging fails
Better error handling: if prepare_purge_path_info() fails, continue looking for other paths instead of stopping

5. Fixed prepare_purge_path_info() Error Handling Now properly cleans up and returns false if dup() fails Previously would proceed anyway; now treats it as a failure

6. Removed Redundant Code
Removed the clearing of purge_path from reinstate_path() since it's now handled earlier in update_path_state()

7. Comment Improvements
Wrapped all comments to 80 characters
Added clearer explanations of the logic flow
Better documentation of the purge loop behavior

Brian Bunker (1):
mulitpath-tools Add purge capability to multipath-tools

 libmultipath/checkers.c       |   2 +
 libmultipath/checkers.h       |   2 +
 libmultipath/checkers/tur.c   |  10 ++
 libmultipath/config.c         |   2 +
 libmultipath/config.h         |   3 +
 libmultipath/configure.c      |   1 +
 libmultipath/defaults.h       |   1 +
 libmultipath/dict.c           |  14 ++
 libmultipath/discovery.c      |   3 +-
 libmultipath/io_err_stat.c    |   1 +
 libmultipath/print.c          |   2 +
 libmultipath/propsel.c        |  16 ++
 libmultipath/propsel.h        |   1 +
 libmultipath/structs.h        |  14 ++
 libmultipath/sysfs.c          |   2 +-
 multipath/multipath.conf.5.in |  22 +++
 multipathd/main.c             | 287 +++++++++++++++++++++++++++++++++-
 17 files changed, 374 insertions(+), 9 deletions(-)
Signature · 1 line
2.52.0
#1 lore raw

PATCH v5 1/1 mulitpath-tools Add purge capability to multipath-tools

In the Linux kernel when volumes are disconnected, they are left behind to be re-enabled when the connection comes back. There are many cases where this behavior is not desirable.

The goal is to have paths appear when volumes are connected. This is handled by target initiated rescans and posting of unit attentions. Secondarily when volumes are disconnected at the target, paths should be removed.

This was discussed here in a kernel patch:
https://marc.info/?l=linux-scsi&m=164426722617834&w=2

It was suggested there that userspace would be more advantageous in handling the device removal.

An option was added to multipath-tools to purge devices that are disconnected at the target. A purge thread was implemented to handle the device removal when the path returns sense data (0x5/0x25/0x0) from the path checker. The option, purge_disconnected, is by default off but can be turned on by setting it to true.

When enabled multipathd will log:

Dec  4 16:25:54 init110-14 multipathd[1024]: sdmp: purging disconnected
path
...
Dec  4 16:25:54 init110-14 multipathd[1024]: /dev/sdmp: triggered

removal

---
 libmultipath/checkers.c       |   2 +
 libmultipath/checkers.h       |   2 +
 libmultipath/checkers/tur.c   |  10 ++
 libmultipath/config.c         |   2 +
 libmultipath/config.h         |   3 +
 libmultipath/configure.c      |   1 +
 libmultipath/defaults.h       |   1 +
 libmultipath/dict.c           |  14 ++
 libmultipath/discovery.c      |   3 +-
 libmultipath/io_err_stat.c    |   1 +
 libmultipath/print.c          |   2 +
 libmultipath/propsel.c        |  16 ++
 libmultipath/propsel.h        |   1 +
 libmultipath/structs.h        |  14 ++
 libmultipath/sysfs.c          |   2 +-
 multipath/multipath.conf.5.in |  22 +++
 multipathd/main.c             | 287 +++++++++++++++++++++++++++++++++-
 17 files changed, 374 insertions(+), 9 deletions(-)
libmultipath/checkers.c +2 -0
index e2eda58d..bb6ad1ee 100644
@@ -43,6 +43,7 @@ static const char *checker_state_names[PATH_MAX_STATE] = {
 	[PATH_TIMEOUT] = "timeout",
 	[PATH_REMOVED] = "removed",
 	[PATH_DELAYED] = "delayed",
+	[PATH_DISCONNECTED] = "disconnected",
 };
 
 static LIST_HEAD(checkers);
@@ -363,6 +364,7 @@ static const char *generic_msg[CHECKER_GENERIC_MSGTABLE_SIZE] = {
 	[CHECKER_MSGID_DOWN] = " reports path is down",
 	[CHECKER_MSGID_GHOST] = " reports path is ghost",
 	[CHECKER_MSGID_UNSUPPORTED] = " doesn't support this device",
+	[CHECKER_MSGID_DISCONNECTED] = " no access to this device",
 };
 
 const char *checker_message(const struct checker *c)
libmultipath/checkers.h +2 -0
index da91f499..903c3ebe 100644
@@ -78,6 +78,7 @@ enum path_check_state {
 	PATH_TIMEOUT,
 	PATH_REMOVED,
 	PATH_DELAYED,
+	PATH_DISCONNECTED,
 	PATH_MAX_STATE
 };
 
@@ -113,6 +114,7 @@ enum {
 	CHECKER_MSGID_DOWN,
 	CHECKER_MSGID_GHOST,
 	CHECKER_MSGID_UNSUPPORTED,
+	CHECKER_MSGID_DISCONNECTED,
 	CHECKER_GENERIC_MSGTABLE_SIZE,
 	CHECKER_FIRST_MSGID = 100,	/* lowest msgid for checkers */
 	CHECKER_MSGTABLE_SIZE = 100,	/* max msg table size for checkers */
libmultipath/checkers/tur.c +10 -0
index 0010acf8..1bb9a992 100644
@@ -199,6 +199,16 @@ retry:
 				return PATH_PENDING;
 			}
 		}
+		else if (key == 0x5) {
+			/* Illegal request */
+			if (asc == 0x25 && ascq == 0x00) {
+				/*
+				 * LOGICAL UNIT NOT SUPPORTED
+				 */
+				*msgid = CHECKER_MSGID_DISCONNECTED;
+				return PATH_DISCONNECTED;
+			}
+		}
 		*msgid = CHECKER_MSGID_DOWN;
 		return PATH_DOWN;
 	}
libmultipath/config.c +2 -0
index 8b424d18..2c66a788 100644
@@ -470,6 +470,7 @@ merge_hwe (struct hwentry * dst, struct hwentry * src)
 	merge_num(marginal_path_err_rate_threshold);
 	merge_num(marginal_path_err_recheck_gap_time);
 	merge_num(marginal_path_double_failed_time);
+	merge_num(purge_disconnected);
 
 	snprintf(id, sizeof(id), "%s/%s", dst->vendor, dst->product);
 	reconcile_features_with_options(id, &dst->features,
@@ -517,6 +518,7 @@ merge_mpe(struct mpentry *dst, struct mpentry *src)
 	merge_num(skip_kpartx);
 	merge_num(max_sectors_kb);
 	merge_num(ghost_delay);
+	merge_num(purge_disconnected);
 	merge_num(uid);
 	merge_num(gid);
 	merge_num(mode);
libmultipath/config.h +3 -0
index 5b4ebf8c..618fa572 100644
@@ -88,6 +88,7 @@ struct hwentry {
 	int marginal_path_err_rate_threshold;
 	int marginal_path_err_recheck_gap_time;
 	int marginal_path_double_failed_time;
+	int purge_disconnected;
 	int skip_kpartx;
 	int max_sectors_kb;
 	int ghost_delay;
@@ -130,6 +131,7 @@ struct mpentry {
 	int marginal_path_err_rate_threshold;
 	int marginal_path_err_recheck_gap_time;
 	int marginal_path_double_failed_time;
+	int purge_disconnected;
 	int skip_kpartx;
 	int max_sectors_kb;
 	int ghost_delay;
@@ -188,6 +190,7 @@ struct config {
 	int marginal_path_err_rate_threshold;
 	int marginal_path_err_recheck_gap_time;
 	int marginal_path_double_failed_time;
+	int purge_disconnected;
 	int uxsock_timeout;
 	int strict_timing;
 	int retrigger_tries;
libmultipath/configure.c +1 -0
index baa13573..e4431d2f 100644
@@ -355,6 +355,7 @@ int setup_map(struct multipath *mpp, char **params, struct vectors *vecs)
 	select_max_sectors_kb(conf, mpp);
 	select_ghost_delay(conf, mpp);
 	select_flush_on_last_del(conf, mpp);
+	select_purge_disconnected(conf, mpp);
 
 	sysfs_set_scsi_tmo(conf, mpp);
 	marginal_pathgroups = conf->marginal_pathgroups;
libmultipath/defaults.h +1 -0
index 134b690a..d80dd7d4 100644
@@ -58,6 +58,7 @@
 #define DEFAULT_ALL_TG_PT ALL_TG_PT_OFF
 #define DEFAULT_RECHECK_WWID RECHECK_WWID_OFF
 #define DEFAULT_AUTO_RESIZE AUTO_RESIZE_NEVER
+#define DEFAULT_PURGE_DISCONNECTED PURGE_DISCONNECTED_OFF
 /* Enable no foreign libraries by default */
 #define DEFAULT_ENABLE_FOREIGN "NONE"
 
libmultipath/dict.c +14 -0
index a06a6138..504b28b5 100644
@@ -941,6 +941,16 @@ declare_hw_snprint(skip_kpartx, print_yes_no_undef)
 declare_mp_handler(skip_kpartx, set_yes_no_undef)
 declare_mp_snprint(skip_kpartx, print_yes_no_undef)
 
+declare_def_handler(purge_disconnected, set_yes_no_undef)
+declare_def_snprint_defint(purge_disconnected, print_yes_no_undef,
+	DEFAULT_PURGE_DISCONNECTED)
+declare_ovr_handler(purge_disconnected, set_yes_no_undef)
+declare_ovr_snprint(purge_disconnected, print_yes_no_undef)
+declare_hw_handler(purge_disconnected, set_yes_no_undef)
+declare_hw_snprint(purge_disconnected, print_yes_no_undef)
+declare_mp_handler(purge_disconnected, set_yes_no_undef)
+declare_mp_snprint(purge_disconnected, print_yes_no_undef)
+
 declare_def_range_handler(remove_retries, 0, INT_MAX)
 declare_def_snprint(remove_retries, print_int)
 
@@ -2227,6 +2237,7 @@ init_keywords(vector keywords)
 	install_keyword("retrigger_delay", &def_retrigger_delay_handler, &snprint_def_retrigger_delay);
 	install_keyword("missing_uev_wait_timeout", &def_uev_wait_timeout_handler, &snprint_def_uev_wait_timeout);
 	install_keyword("skip_kpartx", &def_skip_kpartx_handler, &snprint_def_skip_kpartx);
+	install_keyword("purge_disconnected", &def_purge_disconnected_handler, &snprint_def_purge_disconnected);
 	install_keyword("disable_changed_wwids", &deprecated_disable_changed_wwids_handler, &snprint_deprecated);
 	install_keyword("remove_retries", &def_remove_retries_handler, &snprint_def_remove_retries);
 	install_keyword("max_sectors_kb", &def_max_sectors_kb_handler, &snprint_def_max_sectors_kb);
@@ -2310,6 +2321,7 @@ init_keywords(vector keywords)
 	install_keyword("marginal_path_err_recheck_gap_time", &hw_marginal_path_err_recheck_gap_time_handler, &snprint_hw_marginal_path_err_recheck_gap_time);
 	install_keyword("marginal_path_double_failed_time", &hw_marginal_path_double_failed_time_handler, &snprint_hw_marginal_path_double_failed_time);
 	install_keyword("skip_kpartx", &hw_skip_kpartx_handler, &snprint_hw_skip_kpartx);
+	install_keyword("purge_disconnected", &hw_purge_disconnected_handler, &snprint_hw_purge_disconnected);
 	install_keyword("max_sectors_kb", &hw_max_sectors_kb_handler, &snprint_hw_max_sectors_kb);
 	install_keyword("ghost_delay", &hw_ghost_delay_handler, &snprint_hw_ghost_delay);
 	install_keyword("all_tg_pt", &hw_all_tg_pt_handler, &snprint_hw_all_tg_pt);
@@ -2355,6 +2367,7 @@ init_keywords(vector keywords)
 	install_keyword("marginal_path_double_failed_time", &ovr_marginal_path_double_failed_time_handler, &snprint_ovr_marginal_path_double_failed_time);
 
 	install_keyword("skip_kpartx", &ovr_skip_kpartx_handler, &snprint_ovr_skip_kpartx);
+	install_keyword("purge_disconnected", &ovr_purge_disconnected_handler, &snprint_ovr_purge_disconnected);
 	install_keyword("max_sectors_kb", &ovr_max_sectors_kb_handler, &snprint_ovr_max_sectors_kb);
 	install_keyword("ghost_delay", &ovr_ghost_delay_handler, &snprint_ovr_ghost_delay);
 	install_keyword("all_tg_pt", &ovr_all_tg_pt_handler, &snprint_ovr_all_tg_pt);
@@ -2400,6 +2413,7 @@ init_keywords(vector keywords)
 	install_keyword("marginal_path_err_recheck_gap_time", &mp_marginal_path_err_recheck_gap_time_handler, &snprint_mp_marginal_path_err_recheck_gap_time);
 	install_keyword("marginal_path_double_failed_time", &mp_marginal_path_double_failed_time_handler, &snprint_mp_marginal_path_double_failed_time);
 	install_keyword("skip_kpartx", &mp_skip_kpartx_handler, &snprint_mp_skip_kpartx);
+	install_keyword("purge_disconnected", &mp_purge_disconnected_handler, &snprint_mp_purge_disconnected);
 	install_keyword("max_sectors_kb", &mp_max_sectors_kb_handler, &snprint_mp_max_sectors_kb);
 	install_keyword("ghost_delay", &mp_ghost_delay_handler, &snprint_mp_ghost_delay);
 	install_sublevel_end();
libmultipath/discovery.c +2 -1
index 31db8758..46274f3f 100644
@@ -2482,7 +2482,8 @@ int pathinfo(struct path *pp, struct config *conf, int mask)
 			    pp->state == PATH_UNCHECKED ||
 			    pp->state == PATH_WILD)
 				pp->chkrstate = pp->state = newstate;
-			if (pp->state == PATH_TIMEOUT)
+			if (pp->state == PATH_TIMEOUT ||
+			    pp->state == PATH_DISCONNECTED)
 				pp->state = PATH_DOWN;
 			if (pp->state == PATH_UP && !pp->size) {
 				condlog(3, "%s: device size is 0, "
libmultipath/io_err_stat.c +1 -0
index 64054c18..acb087b7 100644
@@ -397,6 +397,7 @@ static void account_async_io_state(struct io_err_stat_path *pp, int rc)
 	switch (rc) {
 	case PATH_DOWN:
 	case PATH_TIMEOUT:
+	case PATH_DISCONNECTED:
 		pp->io_err_nr++;
 		break;
 	case PATH_UNCHECKED:
libmultipath/print.c +2 -0
index 0d44a5a9..8b09b174 100644
@@ -541,6 +541,8 @@ snprint_chk_state (struct strbuf *buff, const struct path * pp)
 		return append_strbuf_str(buff, "i/o timeout");
 	case PATH_DELAYED:
 		return append_strbuf_str(buff, "delayed");
+	case PATH_DISCONNECTED:
+		return append_strbuf_str(buff, "disconnected");
 	default:
 		return append_strbuf_str(buff, "undef");
 	}
libmultipath/propsel.c +16 -0
index 4c0fbcf3..9a17f1ed 100644
@@ -1371,6 +1371,22 @@ out:
 	return 0;
 }
 
+int select_purge_disconnected (struct config *conf, struct multipath * mp)
+{
+	const char *origin;
+
+	mp_set_mpe(purge_disconnected);
+	mp_set_ovr(purge_disconnected);
+	mp_set_hwe(purge_disconnected);
+	mp_set_conf(purge_disconnected);
+	mp_set_default(purge_disconnected, DEFAULT_PURGE_DISCONNECTED);
+out:
+	condlog(3, "%s: purge_disconnected = %s %s", mp->alias,
+		(mp->purge_disconnected == PURGE_DISCONNECTED_ON)? "yes" : "no",
+		origin);
+	return 0;
+}
+
 int select_max_sectors_kb(struct config *conf, struct multipath * mp)
 {
 	const char *origin;
libmultipath/propsel.h +1 -0
index 55930050..c6c937c3 100644
@@ -39,6 +39,7 @@ int select_marginal_path_err_rate_threshold(struct config *conf, struct multipat
 int select_marginal_path_err_recheck_gap_time(struct config *conf, struct multipath *mp);
 int select_marginal_path_double_failed_time(struct config *conf, struct multipath *mp);
 int select_ghost_delay(struct config *conf, struct multipath * mp);
+int select_purge_disconnected (struct config *conf, struct multipath * mp);
 void reconcile_features_with_options(const char *id, char **features,
 				     int* no_path_retry,
 				     int *retain_hwhandler);
libmultipath/structs.h +14 -0
index 9247e74f..91397467 100644
@@ -186,6 +186,18 @@ enum auto_resize_state {
 	AUTO_RESIZE_GROW_SHRINK,
 };
 
+enum purge_disconnected_states {
+	PURGE_DISCONNECTED_UNDEF = YNU_UNDEF,
+	PURGE_DISCONNECTED_OFF = YNU_NO,
+	PURGE_DISCONNECTED_ON = YNU_YES,
+};
+
+enum path_disconnected_state {
+	NOT_DISCONNECTED = 0,
+	DISCONNECTED_NO_PURGE,
+	DISCONNECTED_NEEDS_PURGE,
+};
+
 #define PROTOCOL_UNSET -1
 
 enum scsi_protocol {
@@ -382,6 +394,7 @@ struct path {
 	int dmstate;
 	int chkrstate;
 	int oldstate;
+	enum path_disconnected_state disconnected;
 	int failcount;
 	int priority;
 	int pgindex;
@@ -483,6 +496,7 @@ struct multipath {
 	int ghost_delay;
 	int ghost_delay_tick;
 	int queue_mode;
+	int purge_disconnected;
 	unsigned int sync_tick;
 	int checker_count;
 	enum prio_update_type prio_update;
libmultipath/sysfs.c +1 -1
index af27d107..538800d8 100644
@@ -134,7 +134,7 @@ ssize_t sysfs_attr_set_value(struct udev_device *dev, const char *attr_name,
 	size = write(fd, value, value_len);
 	if (size < 0) {
 		size = -errno;
-		condlog(3, "%s: write to %s failed: %s", __func__, 
+		condlog(3, "%s: write to %s failed: %s", __func__,
 			devpath, strerror(errno));
 	} else if (size < (ssize_t)value_len)
 		condlog(3, "%s: underflow writing %zu bytes to %s. Wrote %zd bytes",
multipath/multipath.conf.5.in +22 -0
index 3c9ae097..84cd1a0a 100644
@@ -1306,6 +1306,22 @@ The default is: \fBno\fR
 .
 .
 .TP
+.B purge_disconnected
+If set to
+.I yes
+, multipathd will automatically remove devices that are in a disconnected state.
+A path is considered disconnected when the TUR (Test Unit Ready) path checker
+receives the SCSI sense code "LOGICAL UNIT NOT SUPPORTED" (sense key 0x5,
+ASC/ASCQ 0x25/0x00). This typically indicates that the LUN has been unmapped
+or is no longer presented by the storage array. This option helps clean up
+stale device entries that would otherwise remain in the system.
+.RS
+.TP
+The default is: \fBno\fR
+.RE
+.
+.
+.TP
 .B disable_changed_wwids
 (Deprecated) This option is not supported anymore, and will be ignored.
 .RE
@@ -1602,6 +1618,8 @@ section:
 .TP
 .B skip_kpartx
 .TP
+.B purge_disconnected
+.TP
 .B max_sectors_kb
 .TP
 .B ghost_delay
@@ -1797,6 +1815,8 @@ section:
 .TP
 .B skip_kpartx
 .TP
+.B purge_disconnected
+.TP
 .B max_sectors_kb
 .TP
 .B ghost_delay
@@ -1881,6 +1901,8 @@ the values are taken from the \fIdevices\fR or \fIdefaults\fR sections:
 .TP
 .B skip_kpartx
 .TP
+.B purge_disconnected
+.TP
 .B max_sectors_kb
 .TP
 .B ghost_delay
multipathd/main.c +280 -7

366 lines not on this page · raw message

Signature · 1 line
2.52.0