Skip to contentSkip to conversation

alua path checker and prioritizer

PATCH In review Brian Bunker 2 participants 5 messages Mar 25 – Apr 25 Device mapper

lore
Share & tools
lore
#0 lore raw

cover alua path checker and prioritizer

For ALUA-capable storage arrays, multipath-tools currently uses TUR (Test Unit Ready) as the default path checker while a separate prioritizer determines ALUA state. When sysfs provides ALUA state (the common case), no RTPG command is needed for priority. However, if sysfs is unavailable or detect_prio is off, the prioritizer issues RTPG, resulting in two SCSI commands per path check cycle: TUR + RTPG.

This patch series introduces:

1. An 'alua' path checker that uses RTPG as the path check command, providing richer path state information than TUR:
* TRANSITIONING state detected and mapped to PATH_PENDING, preventing false all paths down during controller failover
* STANDBY state detected and mapped to PATH_GHOST
* UNAVAILABLE/OFFLINE states properly distinguished

2. An 'alua_cached' prioritizer that uses cached state from the alua checker, eliminating duplicate RTPG commands.

This design intentionally couples the checker and prioritizer: the alua_cached prioritizer consumes state cached by the alua checker. While this blurs the traditional separation between these components, for ALUA the path state and priority fundamentally derive from the same underlying data, making the coupling a natural fit.

The patches set the alua checker as the auto-detected default for ALUA devices. Explicitly configured checkers in the hardware table take precedence over auto-detection.

As part of this change, the common async threading infrastructure is extracted from the TUR checker into a new async_checker base class. Both TUR and ALUA checkers now extend this base, eliminating code duplication and establishing a pattern for future async checkers.

Brian Bunker (2):
checkers: add alua path checker and async checker framework
prioritizers: add alua_cached prioritizer

 libmultipath/Makefile                   |   2 +-
 libmultipath/async_checker.c            | 245 +++++++++++++++++++
 libmultipath/async_checker.h            | 122 ++++++++++
 libmultipath/checkers.c                 |   1 +
 libmultipath/checkers.h                 |   1 +
 libmultipath/checkers/Makefile          |   3 +-
 libmultipath/checkers/alua.c            | 256 ++++++++++++++++++++
 libmultipath/checkers/tur.c             | 302 +++---------------------
 libmultipath/libmultipath.version       |   8 +
 libmultipath/prio.c                     |   1 +
 libmultipath/prio.h                     |   1 +
 libmultipath/prioritizers/Makefile      |   1 +
 libmultipath/prioritizers/alua.c        |  30 ---
 libmultipath/prioritizers/alua.h        |   8 +
 libmultipath/prioritizers/alua_cached.c | 193 +++++++++++++++
 libmultipath/prioritizers/alua_rtpg.c   |  57 ++++-
 libmultipath/prioritizers/alua_rtpg.h   |   4 +
 libmultipath/prioritizers/sysfs.c       |   7 +-
 libmultipath/propsel.c                  |  29 ++-
 libmultipath/structs.c                  |   2 +
 libmultipath/structs.h                  |   3 +
 multipath/multipath.conf.5.in           |  23 +-
 22 files changed, 988 insertions(+), 311 deletions(-)
 create mode 100644 libmultipath/async_checker.c
 create mode 100644 libmultipath/async_checker.h
 create mode 100644 libmultipath/checkers/alua.c
 create mode 100644 libmultipath/prioritizers/alua_cached.c
Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw

PATCH 1/2 checkers: add alua path checker and async checker framework

Add an 'alua' path checker that uses RTPG to check path state. The checker maps ALUA Asymmetric Access States to path states:
- AAS_OPTIMIZED, AAS_NON_OPTIMIZED -> PATH_UP
- AAS_STANDBY -> PATH_GHOST
- AAS_TRANSITIONING -> PATH_PENDING
- AAS_UNAVAILABLE, AAS_OFFLINE -> PATH_DOWN

As part of this change, the common async threading infrastructure is extracted from the TUR checker into a new async_checker base class. Both TUR and ALUA checkers now extend this base, eliminating code duplication and establishing a pattern for future async checkers.

Two fields are added to struct path (alua_state, alua_timestamp) to cache ALUA state for use by prioritizers.

When detect_checker is enabled, the alua checker is auto-selected for devices with TPGS support. Explicitly configured checkers in the hardware table take precedence over auto-detection.

---
 libmultipath/Makefile                 |   2 +-
 libmultipath/async_checker.c          | 249 +++++++++++++++++++++
 libmultipath/async_checker.h          | 123 +++++++++++
 libmultipath/checkers.c               |   1 +
 libmultipath/checkers.h               |   1 +
 libmultipath/checkers/Makefile        |   3 +-
 libmultipath/checkers/alua.c          | 266 +++++++++++++++++++++++
 libmultipath/checkers/tur.c           | 302 ++++----------------------
 libmultipath/libmultipath.version     |   8 +
 libmultipath/prioritizers/alua.c      |  30 ---
 libmultipath/prioritizers/alua.h      |   8 +
 libmultipath/prioritizers/alua_rtpg.c |  62 +++++-
 libmultipath/prioritizers/alua_rtpg.h |   4 +
 libmultipath/propsel.c                |  16 +-
 libmultipath/structs.c                |   2 +
 libmultipath/structs.h                |   3 +
 multipath/multipath.conf.5.in         |  23 +-
 17 files changed, 795 insertions(+), 308 deletions(-)
 create mode 100644 libmultipath/async_checker.c
 create mode 100644 libmultipath/async_checker.h
 create mode 100644 libmultipath/checkers/alua.c
libmultipath/Makefile +1 -1
index 85767ab4..d71a835f 100644
@@ -22,7 +22,7 @@ OBJS-O := devmapper.o hwtable.o blacklist.o dmparser.o \
 	configure.o structs_vec.o sysfs.o \
 	lock.o file.o wwids.o prioritizers/alua_rtpg.o prkey.o \
 	io_err_stat.o dm-generic.o generic.o nvme-lib.o \
-	libsg.o valid.o
+	libsg.o valid.o async_checker.o
 
 OBJS := $(OBJS-O) $(OBJS-U)
 
libmultipath/async_checker.c new file +249 -0

249 lines not on this page · raw message

libmultipath/async_checker.h new file +123 -0

123 lines not on this page · raw message

libmultipath/checkers.c +1 -0
index bb6ad1ee..21aa52d4 100644
@@ -461,6 +461,7 @@ int init_checkers(void)
 		EMC_CLARIION,
 		READSECTOR0,
 		CCISS_TUR,
+		ALUA_RTPG,
 	};
 	unsigned int i;
 
libmultipath/checkers.h +1 -0
index a969e7d1..2905f3fc 100644
@@ -98,6 +98,7 @@ enum path_check_state {
 #define EMC_CLARIION "emc_clariion"
 #define READSECTOR0  "readsector0"
 #define CCISS_TUR    "cciss_tur"
+#define ALUA         "alua"
 #define NONE         "none"
 #define INVALID      "invalid"
 
libmultipath/checkers/Makefile +2 -1
index 6f7cfb95..dfdd13a1 100644
@@ -17,7 +17,8 @@ LIBS= \
 	libcheckdirectio.so \
 	libcheckemc_clariion.so \
 	libcheckhp_sw.so \
-	libcheckrdac.so
+	libcheckrdac.so \
+	libcheckalua.so
 
 all: $(LIBS)
 
libmultipath/checkers/alua.c new file +266 -0

266 lines not on this page · raw message

libmultipath/checkers/tur.c +39 -263

381 lines not on this page · raw message

libmultipath/libmultipath.version +8 -0
index 78fa2d43..efcf1c71 100644
@@ -219,12 +219,20 @@ global:
 	verify_paths;
 
 	/* checkers */
+	async_checker_check;
+	async_checker_cleanup_func;
+	async_checker_free;
+	async_checker_init;
+	async_checker_need_wait;
+	async_checker_pending;
 	checker_is_sync;
 	sg_read;
 	start_checker_thread;
 
 	/* prioritizers */
+	aas_print_string;
 	get_asymmetric_access_state;
+	get_asymmetric_access_state_fd;
 	get_prio_timeout_ms;
 	get_target_port_group;
 	get_target_port_group_support;
libmultipath/prioritizers/alua.c +0 -30
index ec68f370..5b904abb 100644
@@ -20,36 +20,6 @@
 
 #include "alua.h"
 
-#define ALUA_PRIO_NOT_SUPPORTED			1
-#define ALUA_PRIO_RTPG_FAILED			2
-#define ALUA_PRIO_GETAAS_FAILED			3
-#define ALUA_PRIO_TPGS_FAILED			4
-#define ALUA_PRIO_NO_INFORMATION		5
-
-static const char * aas_string[] = {
-	[AAS_OPTIMIZED]		= "active/optimized",
-	[AAS_NON_OPTIMIZED]	= "active/non-optimized",
-	[AAS_STANDBY]		= "standby",
-	[AAS_UNAVAILABLE]	= "unavailable",
-	[AAS_LBA_DEPENDENT]	= "logical block dependent",
-	[AAS_RESERVED]		= "ARRAY BUG: invalid TPGs state!",
-	[AAS_OFFLINE]		= "offline",
-	[AAS_TRANSITIONING]	= "transitioning between states",
-};
-
-static const char *aas_print_string(int rc)
-{
-	rc &= 0x7f;
-
-	if (rc & 0x70)
-		return aas_string[AAS_RESERVED];
-	rc &= 0x0f;
-	if (rc > AAS_RESERVED && rc < AAS_OFFLINE)
-		return aas_string[AAS_RESERVED];
-	else
-		return aas_string[rc];
-}
-
 int
 get_alua_info(struct path * pp)
 {
libmultipath/prioritizers/alua.h +8 -0
index 88fd6af4..979f98bb 100644
@@ -4,6 +4,14 @@
 #include "alua_rtpg.h"
 
 #define PRIO_ALUA "alua"
+
+/* ALUA prioritizer error codes */
+#define ALUA_PRIO_NOT_SUPPORTED			1
+#define ALUA_PRIO_RTPG_FAILED			2
+#define ALUA_PRIO_GETAAS_FAILED			3
+#define ALUA_PRIO_TPGS_FAILED			4
+#define ALUA_PRIO_NO_INFORMATION		5
+
 int prio_alua(struct path * pp);
 
 #endif
libmultipath/prioritizers/alua_rtpg.c +56 -6

101 lines not on this page · raw message

libmultipath/prioritizers/alua_rtpg.h +4 -0
index ff6ec0ef..2d086e00 100644
@@ -21,9 +21,13 @@
 #define RTPG_NO_TPG_IDENTIFIER			2
 #define RTPG_RTPG_FAILED			3
 #define RTPG_TPG_NOT_FOUND			4
+#define RTPG_LUN_DISCONNECTED			5
 
 int get_target_port_group_support(const struct path *pp);
 int get_target_port_group(const struct path *pp);
 int get_asymmetric_access_state(const struct path *pp, unsigned int tpg);
+int get_asymmetric_access_state_fd(int fd, unsigned int tpg,
+				   unsigned int timeout_ms);
+const char *aas_print_string(int rc);
 
 #endif /* ALUA_RTPG_H_INCLUDED */
libmultipath/propsel.c +12 -4
index 56895c4b..020b84d7 100644
@@ -682,6 +682,17 @@ int select_checker(struct config *conf, struct path *pp)
 
 	if (!pp->checker_timeout)
 		select_checker_timeout(conf, pp);
+	/*
+	 * Check explicit configuration first - don't override device-specific
+	 * checkers (e.g., rdac for NetApp, directio for some software-defined
+	 * storage) with auto-detected alua checker.
+	 */
+	do_set(checker_name, conf->overrides, ckr_name, overrides_origin);
+	do_set_from_hwe(checker_name, pp, ckr_name, hwe_origin);
+	do_set(checker_name, conf, ckr_name, conf_origin);
+	/*
+	 * Auto-detect only if no checker explicitly configured.
+	 */
 	if (pp->detect_checker == DETECT_CHECKER_ON) {
 		origin = autodetect_origin;
 		if (check_rdac(pp)) {
@@ -690,13 +701,10 @@ int select_checker(struct config *conf, struct path *pp)
 		}
 		(void)path_get_tpgs(pp);
 		if (pp->tpgs != TPGS_NONE && pp->tpgs != TPGS_UNDEF) {
-			ckr_name = TUR;
+			ckr_name = ALUA;
 			goto out;
 		}
 	}
-	do_set(checker_name, conf->overrides, ckr_name, overrides_origin);
-	do_set_from_hwe(checker_name, pp, ckr_name, hwe_origin);
-	do_set(checker_name, conf, ckr_name, conf_origin);
 	do_default(ckr_name, DEFAULT_CHECKER);
 out:
 	checker_get(c, ckr_name);
libmultipath/structs.c +2 -0
index f4413127..6483a568 100644
@@ -126,6 +126,8 @@ alloc_path (void)
 		pp->fd = -1;
 		pp->tpgs = TPGS_UNDEF;
 		pp->tpg_id = GROUP_ID_UNDEF;
+		pp->alua_state = -1;
+		pp->alua_timestamp = 0;
 		pp->priority = PRIO_UNDEF;
 		pp->checkint = CHECKINT_UNDEF;
 		checker_clear(&pp->checker);
libmultipath/structs.h +3 -0
index 9adedde2..c4bddee9 100644
@@ -444,6 +444,9 @@ struct path {
 	vector hwe;
 	struct gen_path generic_path;
 	int tpg_id;
+	/* Cached ALUA state from checker for prioritizer use */
+	int alua_state;		/* AAS value, -1 if not cached */
+	time_t alua_timestamp;	/* When alua_state was last updated */
 	enum ioctl_info_states ioctl_info;
 };
 
multipath/multipath.conf.5.in +20 -3
index 84cd1a0a..c65f85bf 100644
@@ -353,6 +353,14 @@ EMC VNX families with Failover Mode 1 (Passive Not Ready(PNR)).
 Generate the path priority based on the SCSI-3 ALUA settings. This prioritizer
 accepts the optional prio_arg \fIexclusive_pref_bit\fR.
 .TP
+.I alua_cached
+(Hardware-dependent)
+Generate the path priority based on SCSI-3 ALUA settings, using cached state
+from the \fIalua\fR path checker when available. Falls back to sysfs or direct
+RTPG if cached state is unavailable. This prioritizer is auto-selected when
+using the \fIalua\fR checker with \fIdetect_prio\fR enabled.
+Accepts the optional prio_arg \fIexclusive_pref_bit\fR.
+.TP
 .I ontap
 (Hardware-dependent)
 Generate the path priority for NetApp ONTAP FAS/AFF Series and rebranded arrays,
@@ -515,9 +523,9 @@ The default is: \fB0\fR
 .TP
 .B path_checker
 The default method used to determine the path's state. The synchronous
-checkers (all except \fItur\fR and \fIdirectio\fR) will cause multipathd to
+checkers (all except \fItur\fR, \fIalua\fR, and \fIdirectio\fR) will cause multipathd to
 pause most activity, waiting up to \fIchecker_timeout\fR seconds for the path
-to respond. The asynchronous checkers (\fItur\fR and \fIdirectio\fR) will not
+to respond. The asynchronous checkers (\fItur\fR, \fIalua\fR, and \fIdirectio\fR) will not
 pause multipathd. Instead, multipathd will check for a response once per
 second, until \fIchecker_timeout\fR seconds have elapsed. Possible values are:
 .RS
@@ -530,6 +538,13 @@ deprecated, please use \fItur\fR or \fIdirectio\fR instead.
 (Hardware-dependent)
 Issue a \fITEST UNIT READY\fR command to a SCSI device.
 .TP
+.I alua
+(Hardware-dependent)
+Issue a \fIREPORT TARGET PORT GROUPS\fR command to determine the path state
+from ALUA settings. This checker provides richer state information than
+\fItur\fR, including detection of transitioning and standby states. When used
+with the \fIalua_cached\fR prioritizer, avoids duplicate RTPG commands.
+.TP
 .I emc_clariion
 (Hardware-dependent)
 Query the DGC/EMC specific EVPD page 0xC0 to determine the path state
@@ -932,7 +947,9 @@ The default is: \fByes\fR
 if set to
 .I yes
 , multipath will try to detect if the device supports SCSI-3 ALUA. If so, the
-device will automatically use the \fItur\fR checker. If set to
+device will automatically use the \fIalua\fR checker, which provides richer
+path state information than \fItur\fR. Explicitly configured checkers in the
+hardware table or overrides take precedence over auto-detection. If set to
 .I no
 , the checker will be selected as usual.
 .RS
Signature · 1 line
2.50.1 (Apple Git-155)
#2 lore raw

Re: [PATCH 1/2] checkers: add alua path checker and async checker framework

Hi Brian,

Quoted 281 lines · Brian Bunker

Add an 'alua' path checker that uses RTPG to check path state. The checker maps ALUA Asymmetric Access States to path states:
  - AAS_OPTIMIZED, AAS_NON_OPTIMIZED -> PATH_UP
  - AAS_STANDBY -> PATH_GHOST
  - AAS_TRANSITIONING -> PATH_PENDING
  - AAS_UNAVAILABLE, AAS_OFFLINE -> PATH_DOWN

As part of this change, the common async threading infrastructure is extracted from the TUR checker into a new async_checker base class. Both TUR and ALUA checkers now extend this base, eliminating code duplication and establishing a pattern for future async checkers.

Two fields are added to struct path (alua_state, alua_timestamp) to cache ALUA state for use by prioritizers.

When detect_checker is enabled, the alua checker is auto-selected for devices with TPGS support. Explicitly configured checkers in the hardware table take precedence over auto-detection.

---
 libmultipath/Makefile                 |   2 +- libmultipath/async_checker.c          | 249 +++++++++++++++++++++ libmultipath/async_checker.h          | 123 +++++++++++ libmultipath/checkers.c               |   1 + libmultipath/checkers.h               |   1 + libmultipath/checkers/Makefile        |   3 +- libmultipath/checkers/alua.c          | 266 +++++++++++++++++++++++ libmultipath/checkers/tur.c           | 302 ++++-------------------- --
 libmultipath/libmultipath.version     |   8 + libmultipath/prioritizers/alua.c      |  30 --- libmultipath/prioritizers/alua.h      |   8 + libmultipath/prioritizers/alua_rtpg.c |  62 +++++- libmultipath/prioritizers/alua_rtpg.h |   4 +

 libmultipath/propsel.c                |  16 +-
 libmultipath/structs.c                |   2 +
 libmultipath/structs.h                |   3 +
 multipath/multipath.conf.5.in         |  23 +-
 17 files changed, 795 insertions(+), 308 deletions(-)

 create mode 100644 libmultipath/async_checker.c
 create mode 100644 libmultipath/async_checker.h
 create mode 100644 libmultipath/checkers/alua.c

[...]

libmultipath/checkers/alua.c new file +51 -0
new file mode 100644
index 00000000..bff1bed6
@@ -0,0 +1,266 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * ALUA Path Checker - uses RTPG to check path state
+ *
+ * Based on the TUR checker by Christophe Varoqui.
+ *
+ * Copyright (c) 2026 Brian Bunker <[email protected]>
+ * Copyright (c) 2026 Krishna Kant <[email protected]>
+ */
+#include <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/sysmacros.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <urcu/uatomic.h>
+
+#include "async_checker.h"
+#include "checkers.h"
+#include "debug.h"
+#include "prio.h"
+#include "structs.h"
+#include "time-util.h"
+#include "../prioritizers/alua.h"
+#include "../prioritizers/alua_rtpg.h"
+
+enum {
+	MSG_ALUA_RTPG_NOT_SUPPORTED = CHECKER_FIRST_MSGID,
+	MSG_ALUA_RTPG_TRANSITIONING,
+	MSG_ALUA_RUNNING,
+	MSG_ALUA_TIMEOUT,
+};
+
+#define IDX_(x) (MSG_ ## x - CHECKER_FIRST_MSGID)
+const char *libcheck_msgtable[] = {
+	[IDX_(ALUA_RTPG_NOT_SUPPORTED)] = " ALUA not supported",
+	[IDX_(ALUA_RTPG_TRANSITIONING)] = " path is transitioning",
+	[IDX_(ALUA_RUNNING)] = " still running",
+	[IDX_(ALUA_TIMEOUT)] = " timed out",
+	NULL,
+};
+
+struct alua_checker_context {
+	struct async_checker_context base;	/* Must be first */
+	/* ALUA-specific cached data for prioritizer */
+	int aas;           /* Asymmetric Access State */
+	int tpg;           /* Target Port Group */
+	time_t timestamp;  /* When this data was collected */
+	/* Data needed for RTPG in thread - copied before thread

starts */

libmultipath/checkers/alua.c new file +6 -0
+	unsigned int timeout_ms;
+};
+
+int libcheck_init(struct checker *c)
+{
+	int ret = async_checker_init(c, sizeof(struct

alua_checker_context));

libmultipath/checkers/alua.c new file +72 -0
+	if (ret == 0) {
+		struct alua_checker_context *ct = c->context;
+		ct->aas = -1;
+		ct->tpg = -1;
+	}
+	return ret;
+}
+
+void libcheck_free(struct checker *c)
+{
+	async_checker_free(c);
+}
+
+/*
+ * Map ALUA Asymmetric Access State to path state
+ */
+static int alua_state_to_path_state(int aas, short *msgid)
+{
+	switch (aas & 0x0f) {
+	case AAS_OPTIMIZED:
+	case AAS_NON_OPTIMIZED:
+		*msgid = CHECKER_MSGID_UP;
+		return PATH_UP;
+	case AAS_STANDBY:
+		*msgid = CHECKER_MSGID_GHOST;
+		return PATH_GHOST;
+	case AAS_TRANSITIONING:
+		*msgid = MSG_ALUA_RTPG_TRANSITIONING;
+		return PATH_PENDING;
+	case AAS_UNAVAILABLE:
+	case AAS_OFFLINE:
+	default:
+		*msgid = CHECKER_MSGID_DOWN;
+		return PATH_DOWN;
+	}
+}
+
+/*
+ * Main ALUA check function - uses alua_rtpg.c library.
+ * This is called either in sync mode or from the async thread.
+ */
+static int
+alua_check(struct path *pp, int *aas_out, short *msgid)
+{
+	int aas;
+
+	/* Discover TPG ID if not already set */
+	if (pp->tpg_id == GROUP_ID_UNDEF) {
+		int tpg = get_target_port_group(pp);
+		if (tpg < 0) {
+			*msgid = CHECKER_MSGID_DOWN;
+			return PATH_DOWN;
+		}
+		pp->tpg_id = tpg;
+	}
+
+	aas = get_asymmetric_access_state(pp, pp->tpg_id);
+	if (aas < 0) {
+		if (aas == -RTPG_LUN_DISCONNECTED) {
+			*msgid = CHECKER_MSGID_DISCONNECTED;
+			return PATH_DISCONNECTED;
+		}
+		*msgid = CHECKER_MSGID_DOWN;
+		return PATH_DOWN;
+	}
+
+	*aas_out = aas;
+	return alua_state_to_path_state(aas, msgid);
+}
+
+#define alua_thread_cleanup_push(ct) \
+	pthread_cleanup_push(async_checker_cleanup_func, &(ct)-
Quoted 1 line

base)

libmultipath/checkers/alua.c new file +6 -0
+#define alua_thread_cleanup_pop(ct) pthread_cleanup_pop(1)
+
+/*
+ * Async thread function.
+ * IMPORTANT: Do not access struct path from here - it may be freed.
+ * Use only data copied to context before thread start: fd, tpg,

timeout_ms.
+ */

libmultipath/checkers/alua.c new file +4 -0
+void *libcheck_thread(struct checker_context *ctx)
+{
+	struct alua_checker_context *ct =
+		container_of(ctx, struct alua_checker_context,

base.ctx);

libmultipath/checkers/alua.c new file +9 -0
+	struct timespec ts;
+	int state;
+	short msgid;
+	int aas;
+
+	/* This thread can be canceled, so setup clean up */
+	alua_thread_cleanup_push(ct);
+
+	condlog(4, "%d:%d : alua checker starting up", major(ct-
Quoted 1 line

base.devt),

libmultipath/checkers/alua.c new file +21 -0
+		minor(ct->base.devt));
+
+	/* Use fd-based check - path pointer is not safe here */
+	aas = get_asymmetric_access_state_fd(ct->base.fd, ct->tpg,
+					     ct->timeout_ms);
+	pthread_testcancel();
+
+	if (aas < 0) {
+		if (aas == -RTPG_LUN_DISCONNECTED) {
+			msgid = CHECKER_MSGID_DISCONNECTED;
+			state = PATH_DISCONNECTED;
+		} else {
+			msgid = CHECKER_MSGID_DOWN;
+			state = PATH_DOWN;
+		}
+		aas = -1;
+	} else {
+		state = alua_state_to_path_state(aas, &msgid);
+	}
+
+	/* Store results in context - will be copied to path by

libcheck_check */

libmultipath/checkers/alua.c new file +10 -0
+	get_monotonic_time(&ts);
+	pthread_mutex_lock(&ct->base.lock);
+	ct->base.state = state;
+	ct->base.msgid = msgid;
+	ct->aas = aas;
+	ct->timestamp = ts.tv_sec;
+	pthread_cond_signal(&ct->base.active);
+	pthread_mutex_unlock(&ct->base.lock);
+
+	condlog(4, "%d:%d : alua checker finished, state %s",

major(ct->base.devt),

libmultipath/checkers/alua.c new file +38 -0
+		minor(ct->base.devt), checker_state_name(state));
+
+	if (!uatomic_xchg(&ct->base.running, 0))
+		pause();
+
+	alua_thread_cleanup_pop(ct);
+
+	return ((void *)0);
+}
+
+bool libcheck_need_wait(struct checker *c)
+{
+	return async_checker_need_wait(c);
+}
+
+int libcheck_pending(struct checker *c)
+{
+	return async_checker_pending(c, MSG_ALUA_RUNNING);
+}
+
+/*
+ * Sync mode callback for async_checker_check.
+ * Safe to access path here since we're in the main thread.
+ */
+static int alua_check_callback(struct checker *c,
+			       struct async_checker_context *base_ct
+					__attribute__((unused)),
+			       short *msgid)
+{
+	struct path *pp = container_of(c, struct path, checker);
+	struct timespec ts;
+	int aas = -1;
+	int state;
+
+	state = alua_check(pp, &aas, msgid);
+
+	/* Cache ALUA state for prioritizer */
+	get_monotonic_time(&ts);

libmultipath/checkers/alua.c line 228

Quoted 10 lines
libmultipath/checkers/alua.c new file +10 -0
+	pp->alua_state = aas;
+	pp->alua_timestamp = ts.tv_sec;
+
+	return state;
+}
+
+int libcheck_check(struct checker *c)
+{
+	struct alua_checker_context *ct = c->context;
+	struct path *pp = container_of(c, struct path, checker);

I just had another look at this patch as I'm working on the checkers myself, and I have to say that this is something you absolutely cannot do, especially not when the checker thread is supposed to run asynchronously. There's a reason that we pass "struct checker *" to the checker threads and not "struct path *", and the code above is a hack to work around this design decision.

When you write a checker, you need to think carefully what information you actually need, and copy that from "struct path" to the checker context. Currently, for all checkers except emc_clariion, nothing is needed except pp->fd and pp->timeout. I understand that the alua checker needs more context, but that doesn't mean you can simply pass the entire data structure to the checker, and I believe that an ALUA can be written so that it needs just a few more fields (if any).

For the "caching" functionality for the prioritizer, I understand that you need to store the alua_state property in "struct path". So far I haven't figured out how to do this properly. I could imagine something like a "checker_private" field in "struct path" which could be handled like this:

union checker_private {
    long alua_data;
}

struct path {
...

    union checker_private c_private; 

    state = checker_get_state(c, &pp->c_private)

and checker_get_state() would do something like

int checker_get_state(struct checker *c,
union checker_private *private)

{
     ...
     if (c->set_private_data)
          c->set_private_data(private);
}

("private" is perhaps not the best name for this if it's to be shared with the prioritizer but you get the idea).

Let me know if this would be sufficient for your needs.

Btw, I'm still working on my approach for the async checker mechanism, which will be quite different from what we had before, and based on my recent "runner" patch set. I'll try to design it such that porting your code to that framework will be easy. (That's why I just had another look at your code).

Regards
Martin

#3 lore raw

Re: [PATCH 1/2] checkers: add alua path checker and async checker framework

Brian,

Quoted 10 lines · Martin Wilck

I just had another look at this patch as I'm working on the checkers myself, and I have to say that this is something you absolutely cannot
do, especially not when the checker thread is supposed to run asynchronously. There's a reason that we pass "struct checker *" to the
checker threads and not "struct path *", and the code above is a hack to work around this design decision.

Quoted 8 lines

When you write a checker, you need to think carefully what information
you actually need, and copy that from "struct path" to the checker context. Currently, for all checkers except emc_clariion, nothing is needed except pp->fd and pp->timeout. I understand that the alua checker needs more context, but that doesn't mean you can simply pass the entire data structure to the checker, and I believe that an  ALUA can be written so that it needs just a few more fields (if any).

Unless I am mistaken, the only additional property that we need for ALUA is the tpg_id. We need to refactor our inquiry and rtpg code such that it takes only the parameters that are needed (fd, timeout, and tpg_id). It would then be possible to call these functions from checkers with limited context, without the hack to pass "struct path *" to the checkers.

The tpg_id of a path will change very rarely, if at all (and we currently do not handle possible changes of the tpg_id in a clever way). We determine the tpg_id() in detect_alua(), and on every call of the alua prioritizer, which is too often, IMO. The kernel re-fetches the tpg only if a LUN is rescanned. For a first attempt of an alua checker, we could simply pass pp->tpg_id to the checker.

We might as well try to get the ALUA state from sysfs in order to avoid sending extra RTPGs (see Hannes' previous reply), in which case we'd t need the dev_t to determine the sysfs directory.

Regards
Martin

#4 lore raw

PATCH 2/2 prioritizers: add alua_cached prioritizer

In reply to Brian Bunker

Add an 'alua_cached' prioritizer that uses cached ALUA state from the alua path checker when available. This eliminates duplicate RTPG commands when both checker and prioritizer need ALUA state.

The prioritizer checks for cached state first, then falls back to sysfs, then to issuing RTPG directly. This maintains backward compatibility with other checker configurations.

When the alua checker is in use and detect_prio is enabled, the alua_cached prioritizer is auto-selected.

---
 libmultipath/prio.c                     |   1 +
 libmultipath/prio.h                     |   1 +
 libmultipath/prioritizers/Makefile      |   1 +
 libmultipath/prioritizers/alua_cached.c | 195 ++++++++++++++++++++++++
 libmultipath/prioritizers/sysfs.c       |   7 +-
 libmultipath/propsel.c                  |  13 +-
 6 files changed, 214 insertions(+), 4 deletions(-)
 create mode 100644 libmultipath/prioritizers/alua_cached.c
libmultipath/prio.c +1 -0
index 24f825bd..2d59d04e 100644
@@ -29,6 +29,7 @@ int init_prio(void)
 #ifdef LOAD_ALL_SHARED_LIBS
 	static const char *const all_prios[] = {
 		PRIO_ALUA,
+		PRIO_ALUA_CACHED,
 		PRIO_CONST,
 		PRIO_DATACORE,
 		PRIO_EMC,
libmultipath/prio.h +1 -0
index 119b75f2..b54ece0d 100644
@@ -17,6 +17,7 @@ struct path;
  * Known prioritizers for use in hwtable.c
  */
 #define PRIO_ALUA		"alua"
+#define PRIO_ALUA_CACHED	"alua_cached"
 #define PRIO_CONST		"const"
 #define PRIO_DATACORE		"datacore"
 #define PRIO_EMC		"emc"
libmultipath/prioritizers/Makefile +1 -0
index ff2524c2..201c52c0 100644
@@ -13,6 +13,7 @@ LIBDEPS = -lmultipath -lmpathutil -lm -lpthread -lrt
 # If you add or remove a prioritizer also update multipath/multipath.conf.5
 LIBS = \
 	libprioalua.so \
+	libprioalua_cached.so \
 	libprioconst.so \
 	libpriodatacore.so \
 	libprioemc.so \
libmultipath/prioritizers/alua_cached.c new file +195 -0

195 lines not on this page · raw message

libmultipath/prioritizers/sysfs.c +5 -2
index 5e8adc05..ab058ea9 100644
@@ -10,6 +10,9 @@
 #include "discovery.h"
 #include "prio.h"
 
+/* Maximum length of sysfs access_state string */
+#define ALUA_ACCESS_STATE_SIZE 32
+
 static const struct {
 	unsigned char value;
 	char *name;
@@ -39,11 +42,11 @@ int get_exclusive_pref_arg(char *args)
 int getprio (struct path * pp, char *args)
 {
 	int prio = 0, rc, i;
-	char buff[512];
+	char buff[ALUA_ACCESS_STATE_SIZE];
 	int exclusive_pref;
 
 	exclusive_pref = get_exclusive_pref_arg(args);
-	rc = sysfs_get_asymmetric_access_state(pp, buff, 512);
+	rc = sysfs_get_asymmetric_access_state(pp, buff, sizeof(buff));
 	if (rc < 0)
 		return PRIO_UNDEF;
 	prio = 0;
libmultipath/propsel.c +11 -2
index 020b84d7..7cd81462 100644
@@ -262,6 +262,7 @@ verify_alua_prio(struct multipath *mp)
 		if (!prio_selected(&pp->prio))
 			continue;
 		if (strncmp(name, PRIO_ALUA, PRIO_NAME_LEN) &&
+		    strncmp(name, PRIO_ALUA_CACHED, PRIO_NAME_LEN) &&
 		    strncmp(name, PRIO_SYSFS, PRIO_NAME_LEN))
 			 return false;
 		assume_alua = true;
@@ -775,8 +776,15 @@ void detect_prio(struct path *pp)
 		if ((tpgs == TPGS_EXPLICIT || !check_rdac(pp)) &&
 		    sysfs_get_asymmetric_access_state(pp, buff, 512) >= 0)
 			default_prio = PRIO_SYSFS;
-		else
+		else {
 			default_prio = PRIO_ALUA;
+			/* If using alua checker, use cached prioritizer */
+			if (checker_selected(&pp->checker)) {
+				const char *chk_name = checker_name(&pp->checker);
+				if (chk_name && strcmp(chk_name, ALUA) == 0)
+					default_prio = PRIO_ALUA_CACHED;
+			}
+		}
 		break;
 	default:
 		return;
@@ -839,7 +847,8 @@ out:
 	/*
 	 * fetch tpgs mode for alua, if its not already obtained
 	 */
-	if (!strncmp(prio_name(p), PRIO_ALUA, PRIO_NAME_LEN)) {
+	if (!strncmp(prio_name(p), PRIO_ALUA, PRIO_NAME_LEN) ||
+	    !strncmp(prio_name(p), PRIO_ALUA_CACHED, PRIO_NAME_LEN)) {
 		int tpgs = path_get_tpgs(pp);
 
 		if (tpgs == TPGS_NONE) {
Signature · 1 line
2.50.1 (Apple Git-155)