Skip to contentSkip to conversation

multipathd: remove nopath flushing code from flush_map()

PATCH Martin Wilck 2 participants 24 messages Dec 14, 2023 – Dec 18, 2023 17 messages not in the archive Device mapper

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

author Reviewed-by
#4 lore raw

Re: [PATCH 02/16] multipathd: make flush_map() delete maps like the multipath command

Quoted 25 lines · Benjamin Marzinski

When the multipath command tries to delete a multipath device, it first
disables queueing and then suspends the device to force the IOs to get
flushed. Then it attempts to delete the device and any kpartx partitions.  multipathd, on the other hand, simply tries to delete the
device and kpartx partitions, without disabling queueing or suspending.
If there are no paths but there is outstanding IO, multipathd will hang
trying to delete the last kpartx device. This is because it must be the
last opener of the multipath device (multipath won't try to delete the
device if it has any openers besides the kpartx devices) and the kernel
will not allow the last opener of a block device to close until all the
outstanding IO is flushed.  This hang can be avoided if multipathd calls
dm_suspend_and_flush_map() like the multipath command does, instead of
dm_flush_map().

Quoted 1 line

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#10 lore raw

Re: [PATCH 03/16] multipathd: disable queueing when removing unknown maps

Quoted 4 lines · Benjamin Marzinski

Make cli_del_maps() call dm_suspend_and_flush_map() for the unknown multipath devices as well.

dm_flush_maps() is now always called with need_suspend=1. We can simplify it.

Regards
Martin

#11 lore raw

Re: [PATCH 03/16] multipathd: disable queueing when removing unknown maps

Quoted 8 lines · Martin Wilck
Quoted 4 lines · Benjamin Marzinski

Make cli_del_maps() call dm_suspend_and_flush_map() for the unknown multipath devices as well.

dm_flush_maps() is now always called with need_suspend=1. We can simplify it.

Yep. I can add that.

-Ben

Quoted 3 lines

Regards
Martin

A message that is not in the archive (sent off-list or not yet received): [email protected]

author Reviewed-by
#13 lore raw

Re: [PATCH 04/16] multipathd: simplify cli_del_map()

Quoted 9 lines · Benjamin Marzinski

cli_del_map() does a lot of unnecessary work to match the arguments of
ev_remove_map(), of which it is the only caller.  Then ev_remove_map()
does more unnecessary work to verify the arguments passed in. remove ev_remove_map() and make cli_del_map() get the mpp like the rest of the client handlers do.

A message that is not in the archive (sent off-list or not yet received): [email protected]

author Reviewed-by
#15 lore raw

Re: [PATCH 09/16] multipathd: handle busy devices in cli_del_maps()

Quoted 6 lines · Benjamin Marzinski

Make cli_del_maps() return -EBUSY like cli_del_map() if it fails because
a device is in use and it doesn't run into any other type of failures.

It's kind of weird that we use both 1 and negative error codes in our cli handlers to indicate failure. Maybe we should get rid of the catch- all error code 1. Anyway, that's not the fault of your patch, so

A message that is not in the archive (sent off-list or not yet received): [email protected]

#17 lore raw

Re: [PATCH 10/16] libmultipath: print error when find_mp_by_str() fails.

Quoted 7 lines · Benjamin Marzinski

None of the callers of find_mp_by_str() print any message if they fail
because the map name is invalid. Print one in find_mp_by_str() to save
the effort of adding it to all the callers.

This will be printed to the journal; clients won't see the message unless they check the journal, too. It's ok to add the message, but I don't think it' a condlog(0), which is normally reserved to fatal multipathd errors. I'd make it a 2; after all, it's most likely just a typo by the user.

Martin

#18 lore raw

Re: [PATCH 10/16] libmultipath: print error when find_mp_by_str() fails.

Quoted 7 lines · Martin Wilck
Quoted 6 lines · Benjamin Marzinski

None of the callers of find_mp_by_str() print any message if they fail
because the map name is invalid. Print one in find_mp_by_str() to save
the effort of adding it to all the callers.

Quoted 7 lines
Quoted 1 line

This will be printed to the journal; clients won't see the message unless they check the journal, too. It's ok to add the message, but I don't think it' a condlog(0), which is normally reserved to fatal multipathd errors. I'd make it a 2; after all, it's most likely just a typo by the user.

Sure.

-Ben

Quoted 2 lines

Martin

A message that is not in the archive (sent off-list or not yet received): [email protected]

author Reviewed-by
#20 lore raw

Re: [PATCH 08/16] multipathd: print extra default reply msg for busy devices

Quoted 7 lines · Benjamin Marzinski

If removing a multipath device fails because the device is in use, return DM_FLUSH_BUSY from remove_functions, which causes cli_del_map()
to return -EBUSY, which will not print extra information in default_reply().

This is slightly unclean, because do_foreach_partmaps() works with generic int return codes and not with the DM_FLUSH_xyz enum. Yet:

A message that is not in the archive (sent off-list or not yet received): [email protected]

#22 lore raw

Re: [PATCH 07/16] multipathd: always start failure replies with "fail\n"

Quoted 51 lines · Benjamin Marzinski

When multipathd interactive commands fail for certain reasons, like timing out or incorrect permissions, they do not reply with "fail\n". Currently, multipath and multipathc expect that a reply other than "fail\n" means success. Instead, prefix all failure replies with "fail\n", and adapt multipath and multipathc to return failure for any
reply starting with "fail\n".

---
 libdmmp/libdmmp.c   |  6 +++---
 multipath/main.c    |  2 +-
 multipathd/uxclnt.c |  2 +-
 multipathd/uxlsnr.c | 12 +++++-------

 4 files changed, 10 insertions(+), 12 deletions(-)
libdmmp/libdmmp.c +0 -0
index 0025e66d..77f8a6a0 100644
@@ -321,7 +321,7 @@ invoke:
  		}
  	}

  if ((*output != NULL) &&

libdmmp/libdmmp.c +1 -1
-	    (strncmp(*output, "timeout", strlen("timeout")) == 0))
+	    (strncmp(*output, "fail\ntimeout",

strlen("fail\ntimeout")) == 0))
  flag_check_tmo = true;

  if (flag_check_tmo == true) {

libdmmp/libdmmp.c +0 -0
@@ -364,8 +364,8 @@ invoke:
  	}


  if ((*output != NULL) &&

libdmmp/libdmmp.c +2 -2
-	    strncmp(*output, "permission deny",
-		    strlen("permission deny")) == 0) {
+	    strncmp(*output, "fail\npermission deny",
+		    strlen("fail\npermission deny")) == 0) {

  _error(ctx, "Permission deny, need to be root"); rc = DMMP_ERR_PERMISSION_DENY;
  goto out;

multipath/main.c +0 -0
index c37befa5..4b399e21 100644
@@ -804,7 +804,7 @@ int delegate_to_multipathd(enum mpath_cmds cmd,
  	}


  if (reply != NULL && *reply != '\0') {

multipath/main.c +1 -1
-		if (strcmp(reply, "fail\n"))
+		if (strncmp(reply, "fail\n", 5))
Quoted 3 lines

  r = DELEGATE_OK;
  if (r != NOT_DELEGATED && strcmp(reply, "ok\n")) printf("%s", reply);

Perhaps here we should check if the reply length is > 5, and if yes, strip the "fail\n" part. That would make the output consistent with what it used to be.

multipathd/uxclnt.c static int process_req(int fd, char * inbuf, · line 34

Quoted 9 lines
multipathd/uxclnt.c +0 -0
index c3ae5db6..2401199d 100644
@@ -31,7 +31,7 @@ static int process_req(int fd, char * inbuf,
 unsigned int timeout)
  		return 1;
  	} else {
  		printf("%s", reply);

Same here.

Quoted 36 lines
multipathd/uxclnt.c +1 -1
-		ret = (strcmp(reply, "fail\n") == 0);
+		ret = (strncmp(reply, "fail\n", 5) == 0);
  		free(reply);
  		return ret;

  }

multipathd/uxlsnr.c +0 -0
index 4d6f258c..4df01666 100644
@@ -392,6 +392,11 @@ static void drain_idle_fd(int fd)


 void default_reply(struct client *c, int r)
 {

multipathd/uxlsnr.c +5 -0
+	if (r == 0) {
+		append_strbuf_str(&c->reply, "ok\n");
+		return;
+	}
+	append_strbuf_str(&c->reply, "fail\n");

  switch(r) {
  case -EINVAL:
  case -ESRCH:

multipathd/uxlsnr.c +0 -0
@@ -406,13 +411,6 @@ void default_reply(struct client *c, int r)

  case -ETIMEDOUT:
  append_strbuf_str(&c->reply, "timeout\n"); break;

multipathd/uxlsnr.c +0 -5
-	case 0:
-		append_strbuf_str(&c->reply, "ok\n");
-		break;
-	default:
-		/* cli_handler functions return 1 on unspecified

error */

multipathd/uxlsnr.c +0 -2
-		append_strbuf_str(&c->reply, "fail\n");
-		break;

  }
 }

#23 lore raw

Re: [PATCH 07/16] multipathd: always start failure replies with "fail\n"

Quoted 61 lines · Martin Wilck
Quoted 51 lines · Benjamin Marzinski

When multipathd interactive commands fail for certain reasons, like timing out or incorrect permissions, they do not reply with "fail\n". Currently, multipath and multipathc expect that a reply other than "fail\n" means success. Instead, prefix all failure replies with "fail\n", and adapt multipath and multipathc to return failure for any
reply starting with "fail\n".

---
 libdmmp/libdmmp.c   |  6 +++---
 multipath/main.c    |  2 +-
 multipathd/uxclnt.c |  2 +-
 multipathd/uxlsnr.c | 12 +++++-------

 4 files changed, 10 insertions(+), 12 deletions(-)
libdmmp/libdmmp.c +0 -0
index 0025e66d..77f8a6a0 100644
@@ -321,7 +321,7 @@ invoke:
  		}
  	}

  if ((*output != NULL) &&

libdmmp/libdmmp.c +1 -1
-	    (strncmp(*output, "timeout", strlen("timeout")) == 0))
+	    (strncmp(*output, "fail\ntimeout",

strlen("fail\ntimeout")) == 0))
  flag_check_tmo = true;

  if (flag_check_tmo == true) {

libdmmp/libdmmp.c +0 -0
@@ -364,8 +364,8 @@ invoke:
  	}


  if ((*output != NULL) &&

libdmmp/libdmmp.c +2 -2
-	    strncmp(*output, "permission deny",
-		    strlen("permission deny")) == 0) {
+	    strncmp(*output, "fail\npermission deny",
+		    strlen("fail\npermission deny")) == 0) {

  _error(ctx, "Permission deny, need to be root"); rc = DMMP_ERR_PERMISSION_DENY;
  goto out;

multipath/main.c +0 -0
index c37befa5..4b399e21 100644
@@ -804,7 +804,7 @@ int delegate_to_multipathd(enum mpath_cmds cmd,
  	}


  if (reply != NULL && *reply != '\0') {

multipath/main.c +1 -1
-		if (strcmp(reply, "fail\n"))
+		if (strncmp(reply, "fail\n", 5))
Quoted 3 lines

  r = DELEGATE_OK;
  if (r != NOT_DELEGATED && strcmp(reply, "ok\n")) printf("%s", reply);

Perhaps here we should check if the reply length is > 5, and if yes, strip the "fail\n" part. That would make the output consistent with what it used to be.

Quoted 11 lines

multipathd/uxclnt.c static int process_req(int fd, char * inbuf, · line 34

Quoted 9 lines
multipathd/uxclnt.c +0 -0
index c3ae5db6..2401199d 100644
@@ -31,7 +31,7 @@ static int process_req(int fd, char * inbuf,
 unsigned int timeout)
  		return 1;
  	} else {
  		printf("%s", reply);

Same here.

Sure.

-Ben

Quoted 37 lines
Quoted 37 lines
multipathd/uxclnt.c +1 -1
-		ret = (strcmp(reply, "fail\n") == 0);
+		ret = (strncmp(reply, "fail\n", 5) == 0);
  		free(reply);
  		return ret;

  }

multipathd/uxlsnr.c +0 -0
index 4d6f258c..4df01666 100644
@@ -392,6 +392,11 @@ static void drain_idle_fd(int fd)


 void default_reply(struct client *c, int r)
 {

multipathd/uxlsnr.c +5 -0
+	if (r == 0) {
+		append_strbuf_str(&c->reply, "ok\n");
+		return;
+	}
+	append_strbuf_str(&c->reply, "fail\n");

  switch(r) {
  case -EINVAL:
  case -ESRCH:

multipathd/uxlsnr.c +0 -0
@@ -406,13 +411,6 @@ void default_reply(struct client *c, int r)

  case -ETIMEDOUT:
  append_strbuf_str(&c->reply, "timeout\n"); break;

multipathd/uxlsnr.c +0 -5
-	case 0:
-		append_strbuf_str(&c->reply, "ok\n");
-		break;
-	default:
-		/* cli_handler functions return 1 on unspecified

error */

multipathd/uxlsnr.c +0 -2
-		append_strbuf_str(&c->reply, "fail\n");
-		break;

  }
 }

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#27 lore raw

Re: [PATCH 12/16] multipathd: make cli_handlers check for paths by dev and devt

Quoted 24 lines · Benjamin Marzinski

Some of the client handlers checked for paths by both dev and devt, but
not all. Also, many of the client handlers don't print anything if they
failed to find a path. Make all the client handlers which work on path
devices use a new function, find_path_by_str(), which will try both methods to find a path, and can print out an error message if none is found.

---
 multipathd/cli_handlers.c | 40 ++++++++++++++++++++----------------- --

 1 file changed, 21 insertions(+), 19 deletions(-)
multipathd/cli_handlers.c +0 -0
index 063a771f..7f550030 100644
@@ -33,6 +33,20 @@
  #include "cli_handlers.h"
  #include "devmapper.h"

multipathd/cli_handlers.c

Quoted 8 lines
multipathd/cli_handlers.c +8 -0
+static struct path *
+find_path_by_str(const struct _vector *pathvec, const char *str,
+		  const char *action_str)
+{
+	struct path *pp;
+
+	if (!(pp = find_path_by_dev(pathvec, str)))
+		pp = find_path_by_devt(pathvec, str);

I wonder if devt should be tried first. It doesn't make a real difference because no real-world devices will have major:minor names, and the callers in the old code did it the other way around, too; but it would feel more correct to me.

Other than that, LGTM.

Regards
Martin

#28 lore raw

Re: [PATCH 12/16] multipathd: make cli_handlers check for paths by dev and devt

Quoted 30 lines · Martin Wilck
Quoted 29 lines · Benjamin Marzinski

Some of the client handlers checked for paths by both dev and devt, but
not all. Also, many of the client handlers don't print anything if they
failed to find a path. Make all the client handlers which work on path
devices use a new function, find_path_by_str(), which will try both methods to find a path, and can print out an error message if none is found.

---
 multipathd/cli_handlers.c | 40 ++++++++++++++++++++----------------- --

 1 file changed, 21 insertions(+), 19 deletions(-)
multipathd/cli_handlers.c +0 -0
index 063a771f..7f550030 100644
@@ -33,6 +33,20 @@
  #include "cli_handlers.h"
  #include "devmapper.h"

multipathd/cli_handlers.c +5 -0
+static struct path *
+find_path_by_str(const struct _vector *pathvec, const char *str,
+		  const char *action_str)
+{
+	struct path *pp;
Quoted 8 lines

multipathd/cli_handlers.c

Quoted 3 lines
multipathd/cli_handlers.c +3 -0
+
+	if (!(pp = find_path_by_dev(pathvec, str)))
+		pp = find_path_by_devt(pathvec, str);

I wonder if devt should be tried first. It doesn't make a real difference because no real-world devices will have major:minor names, and the callers in the old code did it the other way around, too; but it would feel more correct to me.

I'm fine with switching the order. Also, I assume you'd like the log level to be set to 2, right?

-Ben

Quoted 4 lines

Other than that, LGTM.

Regards
Martin

#29 lore raw

Re: [PATCH 12/16] multipathd: make cli_handlers check for paths by dev and devt

Quoted 48 lines · Benjamin Marzinski
Quoted 38 lines · Martin Wilck
Quoted 37 lines · Benjamin Marzinski

Some of the client handlers checked for paths by both dev and devt,
but
not all. Also, many of the client handlers don't print anything if
they
failed to find a path. Make all the client handlers which work on path
devices use a new function, find_path_by_str(), which will try both
methods to find a path, and can print out an error message if none is
found.

---
 multipathd/cli_handlers.c | 40 ++++++++++++++++++++-------------
----
--

 1 file changed, 21 insertions(+), 19 deletions(-)
multipathd/cli_handlers.c +0 -0
index 063a771f..7f550030 100644
@@ -33,6 +33,20 @@
  #include "cli_handlers.h"
  #include "devmapper.h"

multipathd/cli_handlers.c +7 -0
+static struct path *
+find_path_by_str(const struct _vector *pathvec, const char *str,
+		  const char *action_str)
+{
+	struct path *pp;
+
+	if (!(pp = find_path_by_dev(pathvec, str)))
Quoted 8 lines

multipathd/cli_handlers.c

Quoted 1 line
multipathd/cli_handlers.c +1 -0
+		pp = find_path_by_devt(pathvec, str);

I wonder if devt should be tried first. It doesn't make a real difference because no real-world devices will have major:minor names,
and the callers in the old code did it the other way around, too; but
it would feel more correct to me.

Quoted 2 lines

I'm fine with switching the order. Also, I assume you'd like the log level to be set to 2, right?

Yes.

Regards
Martin

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

author Reviewed-by
#33 lore raw

Re: [PATCH 14/16] libdmmp: handle failures in _process_cmd

Quoted 8 lines · Benjamin Marzinski

currently, most of the callers of _process_cmd() do not gracefully handle the case where multipathd returns "fail\n". dmmp_flush_mpath() does, but it does extra work to try to figure out after the fact why the
flush command failed. Instead, handle fail replies in _process_cmd() using the appropriate DMMP error codes.

(should Gris Ge have been cc'd on this perhaps? Is he still at Red Hat?)

#34 lore raw

Re: [PATCH 14/16] libdmmp: handle failures in _process_cmd

Quoted 8 lines · Martin Wilck
Quoted 7 lines · Benjamin Marzinski

currently, most of the callers of _process_cmd() do not gracefully handle the case where multipathd returns "fail\n". dmmp_flush_mpath() does, but it does extra work to try to figure out after the fact why the
flush command failed. Instead, handle fail replies in _process_cmd() using the appropriate DMMP error codes.

Quoted 6 lines
Quoted 1 line

(should Gris Ge have been cc'd on this perhaps? Is he still at Red Hat?)

Yeah. He's still at Red Hat, just working on other things now.

-Ben

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#38 lore raw

Re: [PATCH 16/16] multipath: Don't always retry deletgated remove failures

Quoted 6 lines · Benjamin Marzinski

Now that multipathd is running the same code to remove devices as multipath, multipath doesn't need to automatically retry the remove if
it fails.

If we know that multipathd executes the same commands that multipathd does, why don't we just call delegate_to_multipathd() repeatedly until the retries are exhausted?

Martin

#39 lore raw

Re: [PATCH 16/16] multipath: Don't always retry deletgated remove failures

Quoted 11 lines · Martin Wilck
Quoted 6 lines · Benjamin Marzinski

Now that multipathd is running the same code to remove devices as multipath, multipath doesn't need to automatically retry the remove if
it fails.

If we know that multipathd executes the same commands that multipathd does, why don't we just call delegate_to_multipathd() repeatedly until the retries are exhausted?

We could. The benefit of the multipath command is a more specific error when the device is in use, and it will work even if multipathd is wedged. On the other hand users can always check the logs for the specifics of which device was in use and we could handle ETIMEDOUT or a reply of "fail\ntimeout" specially. We might want to do that even if the user doesn't ask for retries, since it would be useful for all the delegated commands to failback to doing the work in multipath if multipathd is timing out.

-Ben

Quoted 1 line

Martin

#40 lore raw

Re: [PATCH 16/16] multipath: Don't always retry deletgated remove failures

Quoted 16 lines · Benjamin Marzinski
Quoted 7 lines · Martin Wilck
Quoted 6 lines · Benjamin Marzinski

Now that multipathd is running the same code to remove devices as multipath, multipath doesn't need to automatically retry the remove
if
it fails.

Quoted 7 lines
Quoted 1 line

If we know that multipathd executes the same commands that multipathd
does, why don't we just call delegate_to_multipathd() repeatedly until
the retries are exhausted?

Quoted 11 lines

We could. The benefit of the multipath command is a more specific error
when the device is in use, and it will work even if multipathd is wedged. On the other hand users can always check the logs for the specifics of which device was in use and we could handle ETIMEDOUT or a
reply of "fail\ntimeout" specially. We might want to do that even if the
user doesn't ask for retries, since it would be useful for all the delegated commands to failback to doing the work in multipath if multipathd is timing out.

Good point, I agree.

Martin