Skip to contentSkip to conversation

Make prio timeouts work like checkers

RFC PATCH Superseded Benjamin Marzinski 2 participants 9 messages Jul 28, 2023 – Aug 30, 2023 Device mapper

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

cover Make prio timeouts work like checkers

This patchset changes how prioritizers set their timeouts, to make them match how the checker functions work, and also cleans up some minor timeout issues. I did this to make out timeouts consistent, but if someone has a good reason to object to that, I don't feel strongly that it's necessary, and I can resend just the bugfixes.

Benjamin Marzinski (4):
libmultipath: don't bother to reset default timeout value
libmultipath: make prioritizer timeouts work like checker timeouts
libmultipath: fix timeouts for detect_alua()
libmultipath: fix timeouts for path_latency prioritizer

 libmultipath/discovery.c                 | 13 +++++++------
 libmultipath/prio.c                      | 14 +++++++++-----
 libmultipath/prio.h                      |  3 +--
 libmultipath/prioritizers/alua.c         |  2 +-
 libmultipath/prioritizers/alua_rtpg.c    |  5 ++---
 libmultipath/prioritizers/emc.c          |  5 +++--
 libmultipath/prioritizers/hds.c          |  4 ++--
 libmultipath/prioritizers/hp_sw.c        |  4 ++--
 libmultipath/prioritizers/ontap.c        |  7 +++----
 libmultipath/prioritizers/path_latency.c |  5 +++--
 libmultipath/prioritizers/rdac.c         |  4 ++--
 11 files changed, 35 insertions(+), 31 deletions(-)
Signature · 6 lines
2.17.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
author maintainer
#1 lore raw

RFC PATCH 1/4 libmultipath: don't bother to reset default timeout value

by the time get_state() is rechecking the sysfs timeout value, c->timeout has already been set. The only reason why this check exists is to deal with the possiblity that the sysfs value has changed. If the sysfs value doesn't exist (which likely means that the device is not a scsi device), then there's no reason to reset the default value, since that can't have changed.

---
 libmultipath/discovery.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
libmultipath/discovery.c +2 -3
index 5626d48d..2b1a11d5 100644
@@ -1965,9 +1965,8 @@ get_state (struct path * pp, struct config *conf, int daemon, int oldstate)
 		checker_set_async(c);
 	else
 		checker_set_sync(c);
-	if (!conf->checker_timeout &&
-	    sysfs_get_timeout(pp, &(c->timeout)) <= 0)
-		c->timeout = DEF_TIMEOUT;
+	if (!conf->checker_timeout)
+	    sysfs_get_timeout(pp, &(c->timeout));
 	state = checker_check(c, oldstate);
 	condlog(3, "%s: %s state = %s", pp->dev,
 		checker_name(c), checker_state_name(state));
Signature · 6 lines
2.17.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
Reviewed-by on v1 1/4
#2 lore raw

Re: [dm-devel] [RFC PATCH 1/4] libmultipath: don't bother to reset default timeout value

Quoted 11 lines · Benjamin Marzinski

by the time get_state() is rechecking the sysfs timeout value, c->timeout has already been set.  The only reason why this check exists
is to deal with the possiblity that the sysfs value has changed. If the
sysfs value doesn't exist (which likely means that the device is not a
scsi device), then there's no reason to reset the default value, since
that can't have changed.

Quoted 1 line

Thinking about it, I am not sure if it's wise to re-read the timeout from sysfs every time we retrieve a path state. It's inefficient, and I wonder if we even want to do this if someone modifies SCSI timeouts in sysfs while multipathd is running. It would be cleaner to set checker_timeout and reload multipathd.

But that's no reason to reject this patch.

Quoted 13 lines

---
 libmultipath/discovery.c | 5 ++---

 1 file changed, 2 insertions(+), 3 deletions(-)
libmultipath/discovery.c +0 -0
index 5626d48d..2b1a11d5 100644
@@ -1965,9 +1965,8 @@ get_state (struct path * pp, struct config
 *conf, int daemon, int oldstate)
                 checker_set_async(c);

        else
                checker_set_sync(c);

Quoted 8 lines

-       if (!conf->checker_timeout &&
-           sysfs_get_timeout(pp, &(c->timeout)) <= 0) -               c->timeout = DEF_TIMEOUT;
+       if (!conf->checker_timeout)
+           sysfs_get_timeout(pp, &(c->timeout)); state = checker_check(c, oldstate); condlog(3, "%s: %s state = %s", pp->dev, checker_name(c), checker_state_name(state));

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

author maintainer
#3 lore raw

RFC PATCH 2/4 libmultipath: make prioritizer timeouts work like checker timeouts

In reply to Benjamin Marzinski

Multipath's prioritizers previously didn't use the sysfs timeout for scsi devices, and used a prioritizer specific default timeout (although in practice, all the prioritizers except hds used 60 seconds). Now prioritizers deal with timeouts the same way as the checkers. They first use checker_time if set, then use the sysfs tiemout for scsi devices, or 30 seconds for non-scsi devices.

---
 libmultipath/prio.c                   | 14 +++++++++-----
 libmultipath/prio.h                   |  3 +--
 libmultipath/prioritizers/alua.c      |  2 +-
 libmultipath/prioritizers/alua_rtpg.c |  5 ++---
 libmultipath/prioritizers/emc.c       |  5 +++--
 libmultipath/prioritizers/hds.c       |  4 ++--
 libmultipath/prioritizers/hp_sw.c     |  4 ++--
 libmultipath/prioritizers/ontap.c     |  7 +++----
 libmultipath/prioritizers/rdac.c      |  4 ++--
 9 files changed, 25 insertions(+), 23 deletions(-)
libmultipath/prio.c +9 -5
index cdd37529..69b71578 100644
@@ -3,20 +3,24 @@
 #include <stddef.h>
 #include <dlfcn.h>
 #include <sys/stat.h>
+#include <libudev.h>
 
 #include "debug.h"
 #include "util.h"
 #include "prio.h"
+#include "structs.h"
+#include "discovery.h"
 
 static const char * const prio_dir = MULTIPATH_DIR;
 static LIST_HEAD(prioritizers);
 
-unsigned int get_prio_timeout(unsigned int timeout_ms,
-			      unsigned int default_timeout)
+unsigned int get_prio_timeout(struct path *pp, unsigned int timeout)
 {
-	if (timeout_ms)
-		return timeout_ms;
-	return default_timeout;
+	if (timeout)
+		return timeout;
+	timeout = DEF_TIMEOUT;
+	sysfs_get_timeout(pp, &timeout);
+	return timeout * 1000;
 }
 
 int init_prio(void)
libmultipath/prio.h +1 -2
index 184bf65f..20808fd7 100644
@@ -52,8 +52,7 @@ struct prio {
 	int (*getprio)(struct path *, char *, unsigned int);
 };
 
-unsigned int get_prio_timeout(unsigned int checker_timeout,
-			      unsigned int default_timeout);
+unsigned int get_prio_timeout(struct path *pp, unsigned int checker_timeout);
 int init_prio(void);
 void cleanup_prio (void);
 struct prio * add_prio (const char *);
libmultipath/prioritizers/alua.c +1 -1
index a28bca05..d3ba367f 100644
@@ -109,7 +109,7 @@ int getprio (struct path * pp, char * args, unsigned int timeout)
 		return -ALUA_PRIO_NO_INFORMATION;
 
 	exclusive_pref = get_exclusive_pref_arg(args);
-	rc = get_alua_info(pp, timeout);
+	rc = get_alua_info(pp, get_prio_timeout(pp, timeout));
 	if (rc >= 0) {
 		aas = (rc & 0x0f);
 		priopath = (rc & 0x80);
libmultipath/prioritizers/alua_rtpg.c +2 -3
index 2db91536..49982545 100644
@@ -31,7 +31,6 @@
 #include "alua_rtpg.h"
 
 #define SENSE_BUFF_LEN  32
-#define SGIO_TIMEOUT     60000
 
 #define PRINT_DEBUG(f, a...) \
 	condlog(4, "alua: " f, ##a)
@@ -162,7 +161,7 @@ retry:
 	hdr.dxfer_len		= resplen;
 	hdr.sbp			= sense;
 	hdr.mx_sb_len		= sizeof(sense);
-	hdr.timeout		= get_prio_timeout(timeout, SGIO_TIMEOUT);
+	hdr.timeout		= timeout;
 
 	if (ioctl(fd, SG_IO, &hdr) < 0) {
 		PRINT_DEBUG("do_inquiry: IOCTL failed!");
@@ -316,7 +315,7 @@ retry:
 	hdr.dxfer_len		= resplen;
 	hdr.mx_sb_len		= sizeof(sense);
 	hdr.sbp			= sense;
-	hdr.timeout		= get_prio_timeout(timeout, SGIO_TIMEOUT);
+	hdr.timeout		= timeout;
 
 	if (ioctl(fd, SG_IO, &hdr) < 0) {
 		condlog(2, "%s: sg ioctl failed: %s",
libmultipath/prioritizers/emc.c +3 -2
index 3b63cca0..97fde31b 100644
@@ -31,7 +31,7 @@ int emc_clariion_prio(const char *dev, int fd, unsigned int timeout)
 	io_hdr.dxferp = sense_buffer;
 	io_hdr.cmdp = inqCmdBlk;
 	io_hdr.sbp = sb;
-	io_hdr.timeout = get_prio_timeout(timeout, 60000);
+	io_hdr.timeout = timeout;
 	io_hdr.pack_id = 0;
 	if (ioctl(fd, SG_IO, &io_hdr) < 0) {
 		pp_emc_log(0, "sending query command failed");
@@ -84,5 +84,6 @@ out:
 int getprio (struct path *pp, __attribute__((unused)) char *args,
 	     unsigned int timeout)
 {
-	return emc_clariion_prio(pp->dev, pp->fd, timeout);
+	return emc_clariion_prio(pp->dev, pp->fd,
+				 get_prio_timeout(pp, timeout));
 }
libmultipath/prioritizers/hds.c +2 -2
index d569f2d7..13f497cc 100644
@@ -114,7 +114,7 @@ int hds_modular_prio (const char *dev, int fd, unsigned int timeout)
 	io_hdr.dxferp = inqBuff;
 	io_hdr.cmdp = inqCmdBlk;
 	io_hdr.sbp = sense_buffer;
-	io_hdr.timeout = get_prio_timeout(timeout, 2000); /* TimeOut = 2 seconds */
+	io_hdr.timeout = timeout;
 
 	if (ioctl (fd, SG_IO, &io_hdr) < 0) {
 		pp_hds_log(0, "SG_IO error");
@@ -171,5 +171,5 @@ int hds_modular_prio (const char *dev, int fd, unsigned int timeout)
 int getprio (struct path * pp, __attribute__((unused)) char *args,
 	     unsigned int timeout)
 {
-	return hds_modular_prio(pp->dev, pp->fd, timeout);
+	return hds_modular_prio(pp->dev, pp->fd, get_prio_timeout(pp, timeout));
 }
libmultipath/prioritizers/hp_sw.c +2 -2
index 5b85ad2e..b4cbc58f 100644
@@ -46,7 +46,7 @@ int hp_sw_prio(const char *dev, int fd, unsigned int timeout)
 	io_hdr.dxfer_direction = SG_DXFER_NONE;
 	io_hdr.cmdp = turCmdBlk;
 	io_hdr.sbp = sb;
-	io_hdr.timeout = get_prio_timeout(timeout, 60000);
+	io_hdr.timeout = timeout;
 	io_hdr.pack_id = 0;
 retry:
 	if (ioctl(fd, SG_IO, &io_hdr) < 0) {
@@ -98,5 +98,5 @@ out:
 int getprio (struct path *pp, __attribute__((unused)) char *args,
 	     unsigned int timeout)
 {
-	return hp_sw_prio(pp->dev, pp->fd, timeout);
+	return hp_sw_prio(pp->dev, pp->fd, get_prio_timeout(pp, timeout));
 }
libmultipath/prioritizers/ontap.c +3 -4
index 262e69d2..b9860974 100644
@@ -28,7 +28,6 @@
 #define INQUIRY_CMDLEN	6
 #define DEFAULT_PRIOVAL	10
 #define RESULTS_MAX	256
-#define SG_TIMEOUT	60000
 
 #define pp_ontap_log(prio, fmt, args...) \
 	condlog(prio, "%s: ontap prio: " fmt, dev, ##args)
@@ -90,7 +89,7 @@ static int send_gva(const char *dev, int fd, unsigned char pg,
 	io_hdr.dxferp = results;
 	io_hdr.cmdp = cdb;
 	io_hdr.sbp = sb;
-	io_hdr.timeout = get_prio_timeout(timeout, SG_TIMEOUT);
+	io_hdr.timeout = timeout;
 	io_hdr.pack_id = 0;
 	if (ioctl(fd, SG_IO, &io_hdr) < 0) {
 		pp_ontap_log(0, "SG_IO ioctl failed, errno=%d", errno);
@@ -142,7 +141,7 @@ static int get_proxy(const char *dev, int fd, unsigned int timeout)
 	io_hdr.dxferp = results;
 	io_hdr.cmdp = cdb;
 	io_hdr.sbp = sb;
-	io_hdr.timeout = get_prio_timeout(timeout, SG_TIMEOUT);
+	io_hdr.timeout = timeout;
 	io_hdr.pack_id = 0;
 	if (ioctl(fd, SG_IO, &io_hdr) < 0) {
 		pp_ontap_log(0, "ioctl sending inquiry command failed, "
@@ -244,5 +243,5 @@ prio_select:
 int getprio (struct path *pp, __attribute__((unused)) char *args,
 	     unsigned int timeout)
 {
-	return ontap_prio(pp->dev, pp->fd, timeout);
+	return ontap_prio(pp->dev, pp->fd, get_prio_timeout(pp, timeout));
 }
libmultipath/prioritizers/rdac.c +2 -2
index 92a2fb85..0faa8155 100644
@@ -31,7 +31,7 @@ int rdac_prio(const char *dev, int fd, unsigned int timeout)
 	io_hdr.dxferp = sense_buffer;
 	io_hdr.cmdp = inqCmdBlk;
 	io_hdr.sbp = sb;
-	io_hdr.timeout = get_prio_timeout(timeout, 60000);
+	io_hdr.timeout = timeout;
 	io_hdr.pack_id = 0;
 	if (ioctl(fd, SG_IO, &io_hdr) < 0) {
 		pp_rdac_log(0, "sending inquiry command failed");
@@ -94,5 +94,5 @@ out:
 int getprio (struct path *pp, __attribute__((unused)) char *args,
 	     unsigned int timeout)
 {
-	return rdac_prio(pp->dev, pp->fd, timeout);
+	return rdac_prio(pp->dev, pp->fd, get_prio_timeout(pp, timeout));
 }
Signature · 6 lines
2.17.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
author maintainer
#4 lore raw

RFC PATCH 3/4 libmultipath: fix timeouts for detect_alua()

In reply to Benjamin Marzinski

detect_alua calls prioritizer functions that expect the timeout to be in milliseconds instead of seconds. Fix this and also respect the checker_timeout setting.

---
 libmultipath/discovery.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
libmultipath/discovery.c +5 -3
index 2b1a11d5..9392134f 100644
@@ -1016,15 +1016,17 @@ detect_alua(struct path * pp)
 	int ret;
 	int tpgs;
 	unsigned int timeout;
+	struct config *conf;
 
 
 	if (pp->bus != SYSFS_BUS_SCSI) {
 		pp->tpgs = TPGS_NONE;
 		return;
 	}
-
-	if (sysfs_get_timeout(pp, &timeout) <= 0)
-		timeout = DEF_TIMEOUT;
+	conf = get_multipath_config();
+	timeout = conf->checker_timeout * 1000;
+	put_multipath_config(conf);
+	timeout = get_prio_timeout(pp, timeout);
 
 	tpgs = get_target_port_group_support(pp, timeout);
 	if (tpgs == -RTPG_INQUIRY_FAILED)
Signature · 6 lines
2.17.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
author maintainer
#5 lore raw

RFC PATCH 4/4 libmultipath: fix timeouts for path_latency prioritizer

In reply to Benjamin Marzinski

The path_latency prioritizer didn't call get_prio_timeout, so that the timeout could possibly be 0. Also, it was assuming that the timeout was in seconds, instead of milliseconds.

---
 libmultipath/prioritizers/path_latency.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
libmultipath/prioritizers/path_latency.c +3 -2
index 2f5be9b9..d48535d2 100644
@@ -107,7 +107,7 @@ static void cleanup_directio_read(int fd, char *buf, int restore_flags)
 static int do_directio_read(int fd, unsigned int timeout, char *buf, int sz)
 {
 	fd_set read_fds;
-	struct timeval tm = { .tv_sec = timeout };
+	struct timeval tm = { .tv_sec = timeout / 1000 };
 	int ret;
 	int num_read;
 
@@ -247,7 +247,8 @@ int getprio(struct path *pp, char *args, unsigned int timeout)
 
 		(void)clock_gettime(CLOCK_MONOTONIC, &tv_before);
 
-		if (do_directio_read(pp->fd, timeout, buf, blksize)) {
+		if (do_directio_read(pp->fd, get_prio_timeout(pp, timeout),
+				     buf, blksize)) {
 			pp_pl_log(0, "%s: path down", pp->dev);
 			cleanup_directio_read(pp->fd, buf, restore_flags);
 			return -1;
Signature · 6 lines
2.17.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
author maintainer
#6 lore raw
In reply to Benjamin Marzinski

On Fri, Jul 28, 2023 at 02:05:51PM -0500, Benjamin Marzinski wrote:

Ping. Perhaps this patchset got overlooked.

-Ben

Quoted 12 lines

This patchset changes how prioritizers set their timeouts, to make them match how the checker functions work, and also cleans up some minor timeout issues. I did this to make out timeouts consistent, but if someone has a good reason to object to that, I don't feel strongly that it's necessary, and I can resend just the bugfixes.

Benjamin Marzinski (4):
libmultipath: don't bother to reset default timeout value
libmultipath: make prioritizer timeouts work like checker timeouts
libmultipath: fix timeouts for detect_alua()
libmultipath: fix timeouts for path_latency prioritizer

Quoted 20 lines
 libmultipath/discovery.c                 | 13 +++++++------
 libmultipath/prio.c                      | 14 +++++++++-----
 libmultipath/prio.h                      |  3 +--
 libmultipath/prioritizers/alua.c         |  2 +-
 libmultipath/prioritizers/alua_rtpg.c    |  5 ++---
 libmultipath/prioritizers/emc.c          |  5 +++--
 libmultipath/prioritizers/hds.c          |  4 ++--
 libmultipath/prioritizers/hp_sw.c        |  4 ++--
 libmultipath/prioritizers/ontap.c        |  7 +++----
 libmultipath/prioritizers/path_latency.c |  5 +++--
 libmultipath/prioritizers/rdac.c         |  4 ++--
 11 files changed, 35 insertions(+), 31 deletions(-)
Signature · 6 lines
2.17.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

#7 lore raw
In reply to Benjamin Marzinski
Quoted 7 lines · Benjamin Marzinski

This patchset changes how prioritizers set their timeouts, to make them
match how the checker functions work, and also cleans up some minor timeout issues. I did this to make out timeouts consistent, but if someone has a good reason to object to that, I don't feel strongly that it's necessary, and I can resend just the bugfixes.

I don't object the idea, quite the contrary. But I would prefer a different solution.

IMO we should treat the "io_timeout" as a path property, and add a field in "struct path" for it. It would be initialized from conf->checker_timeout, or if that's unset, from sysfs, and finally, DEF_TIMEOUT. By reading the sysfs value, we'd be able to accomodate different properties for different devices, but we'd not re-read this value repeatedly like we're doing now. IMO that would be more consistent with what we do for other device properties.

We currently pass the timeout value down the call stack all the way from pathinfo() like this (for alua):

pathinfo()
get_prio()

     prio_getprio()
       p->getprio()
         get_alua_info()
            get_target_port_group()
               do_inquiry() (*)
                 do_inquiry_sg()
            get_asymmetric_access_state()
               do_rtpg() (*)

With the exception of the functions marked by (*), all these functions obtain a "struct path" argument, too. IIUC, the main reason we're doing this is to avoid stalled getprio() calls for paths that are down (bb935d4 ("libmultipath: change failed path prio timeout")).

IMO it would make more sense to remove the "timeout" arguments from these functions, and just determine the timeout where it's needed. I don't think that's a layering violation; functions that receive a "struct path" can also handle PATH_DOWN. Thus we could write

int get_prio_timeout_ms(const struct path *pp)

{
      if (pp->state == PATH_DOWN)
            return 10;
      else
            return pp->io_timeout * 1000;
}

and use this function as far down the stack as we can.

Furthermore, to improve code readability and avoid issues like in 3/4 and 4, I think we should call all variables and fields that take millisecond values "timeout_ms".

Thoughts?

Martin

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel

author maintainer
#8 lore raw
Quoted 52 lines · Martin Wilck
Quoted 7 lines · Benjamin Marzinski

This patchset changes how prioritizers set their timeouts, to make them
match how the checker functions work, and also cleans up some minor timeout issues. I did this to make out timeouts consistent, but if someone has a good reason to object to that, I don't feel strongly that it's necessary, and I can resend just the bugfixes.

I don't object the idea, quite the contrary. But I would prefer a different solution.

IMO we should treat the "io_timeout" as a path property, and add a field in "struct path" for it. It would be initialized from conf->checker_timeout, or if that's unset, from sysfs, and finally, DEF_TIMEOUT. By reading the sysfs value, we'd be able to accomodate different properties for different devices, but we'd not re-read this value repeatedly like we're doing now. IMO that would be more consistent with what we do for other device properties.

We currently pass the timeout value down the call stack all the way from pathinfo() like this (for alua):

pathinfo()
get_prio()

     prio_getprio()
       p->getprio()
         get_alua_info()
            get_target_port_group()
               do_inquiry() (*)
                 do_inquiry_sg()
            get_asymmetric_access_state()
               do_rtpg() (*)

With the exception of the functions marked by (*), all these functions obtain a "struct path" argument, too. IIUC, the main reason we're doing this is to avoid stalled getprio() calls for paths that are down (bb935d4 ("libmultipath: change failed path prio timeout")).

IMO it would make more sense to remove the "timeout" arguments from these functions, and just determine the timeout where it's needed. I don't think that's a layering violation; functions that receive a "struct path" can also handle PATH_DOWN. Thus we could write

int get_prio_timeout_ms(const struct path *pp)

{
      if (pp->state == PATH_DOWN)
            return 10;
      else
            return pp->io_timeout * 1000;
}
Quoted 7 lines

and use this function as far down the stack as we can.

Furthermore, to improve code readability and avoid issues like in 3/4 and 4, I think we should call all variables and fields that take millisecond values "timeout_ms".

Thoughts?

Sure. I can rework this.

-Ben

Quoted 2 lines

Martin

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel