Skip to contentSkip to conversation

multipath: return failure on an invalid remove command

PATCH Superseded Benjamin Marzinski 2 participants 3 messages Mar 30, 2022 Device mapper

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Benjamin Marzinski

author maintainer
#0 lore raw

PATCH 1/1 multipath: return failure on an invalid remove command

When "multipath -f" is run on a device that doesn't exist or isn't a multipath device, the command will not remove any device, but it will still return success. Multiple functions rely on _dm_flush_map() returning success when called with name that doesn't match any multipath device. So before calling _dm_flush_map(), call dm_is_mpath(), to check if the device exists and is a multipath device, and return failure if it's not.

---
 multipath/main.c | 5 +++++
 1 file changed, 5 insertions(+)
multipath/main.c +5 -0
index d09f62db..e865309d 100644
@@ -1060,6 +1060,11 @@ main (int argc, char *argv[])
 	if (retries < 0)
 		retries = conf->remove_retries;
 	if (cmd == CMD_FLUSH_ONE) {
+		if (dm_is_mpath(dev) != 1) {
+			condlog(0, "failed removing \"%s\"", dev);
+			r = RTVL_FAIL;
+			goto out;
+		}
 		r = dm_suspend_and_flush_map(dev, retries) ?
 		    RTVL_FAIL : RTVL_OK;
 		goto out;
Signature · 6 lines
2.17.2

--
dm-devel mailing list
[email protected]
https://listman.redhat.com/mailman/listinfo/dm-devel
#1 lore raw
Quoted 19 lines · Benjamin Marzinski

When "multipath -f" is run on a device that doesn't exist or isn't a multipath device, the command will not remove any device, but it will still return success.  Multiple functions rely on _dm_flush_map() returning success when called with name that doesn't match any multipath device. So before calling _dm_flush_map(), call dm_is_mpath(),
to check if the device exists and is a multipath device, and return failure if it's not.

---
 multipath/main.c | 5 +++++

 1 file changed, 5 insertions(+)
multipath/main.c +0 -0
index d09f62db..e865309d 100644

multipath/main.c main (int argc, char *argv[]) · line 1064

Quoted 5 lines
multipath/main.c +2 -0
@@ -1060,6 +1060,11 @@ main (int argc, char *argv[])
         if (retries < 0)
                 retries = conf->remove_retries;
         if (cmd == CMD_FLUSH_ONE) {
+               if (dm_is_mpath(dev) != 1) {
+                       condlog(0, "failed removing \"%s\"", dev);

Could we provide a more meaningful error message here? (As you're the native speaker - shouldn't it rather be "failed to remove"?)

Otherwise, ack.

Martin

Quoted 6 lines
multipath/main.c +3 -0
+                       r = RTVL_FAIL;
+                       goto out;
+               }

                r = dm_suspend_and_flush_map(dev, retries) ? RTVL_FAIL : RTVL_OK;
                goto out;

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

author maintainer
#2 lore raw
Quoted 15 lines · Martin Wilck
Quoted 14 lines · Benjamin Marzinski

When "multipath -f" is run on a device that doesn't exist or isn't a multipath device, the command will not remove any device, but it will still return success.  Multiple functions rely on _dm_flush_map() returning success when called with name that doesn't match any multipath device. So before calling _dm_flush_map(), call dm_is_mpath(),
to check if the device exists and is a multipath device, and return failure if it's not.

---
 multipath/main.c | 5 +++++

 1 file changed, 5 insertions(+)
Quoted 14 lines

multipath/main.c main (int argc, char *argv[]) · line 1064

Quoted 10 lines
multipath/main.c +2 -0
index d09f62db..e865309d 100644
@@ -1060,6 +1060,11 @@ main (int argc, char *argv[])
         if (retries < 0)
                 retries = conf->remove_retries;
         if (cmd == CMD_FLUSH_ONE) {
+               if (dm_is_mpath(dev) != 1) {
+                       condlog(0, "failed removing \"%s\"", dev);

Could we provide a more meaningful error message here? (As you're the native speaker - shouldn't it rather be "failed to remove"?)

Sure. I'll clean that up.

-Ben

Quoted 12 lines

Otherwise, ack.

Martin

Quoted 6 lines
multipath/main.c +3 -0
+                       r = RTVL_FAIL;
+                       goto out;
+               }

                r = dm_suspend_and_flush_map(dev, retries) ? RTVL_FAIL : RTVL_OK;
                goto out;

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