All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dmsetup: Set exit code to 1 if remove_all fails to remove all devices
@ 2014-12-02 17:58 Lukas Wunner
  2014-12-02 19:16 ` Zdenek Kabelac
  0 siblings, 1 reply; 5+ messages in thread
From: Lukas Wunner @ 2014-12-02 17:58 UTC (permalink / raw)
  To: lvm-devel

There are scripts out there which expect "dmsetup remove_all" to
not exit with 0 if some devices couldn't be removed, e.g. dracut:
https://git.kernel.org/cgit/boot/dracut/dracut.git/tree/modules.d/90dm/dm-shutdown.sh

Up until now the exit code of "dmsetup remove_all" is only non-zero
if the call to ioctl() fails, causing _do_dm_ioctl() to return NULL
instead of a struct dm_ioctl*.

Fix this by counting the remaining devices after the call to
_simple() even if --force is not used, and by returning success
only if the call to simple() was succesful AND no devices remain.

Signed-off-by: Lukas Wunner <lukas@wunner.de>
---
 tools/dmsetup.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index 4202dbb..77d7cf6 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -1528,27 +1528,23 @@ static int _remove_all(CMD_ARGS)
 	/* Remove all closed devices */
 	r =  _simple(DM_DEVICE_REMOVE_ALL, "", 0, 0) | dm_mknodes(NULL);
 
-	if (!_switches[FORCE_ARG])
-		return r;
-
 	_num_devices = 0;
-	r |= _process_all(cmd, argc, argv, 1, _count_devices);
+	r &= _process_all(cmd, argc, argv, 1, _count_devices);
 
-	/* No devices left? */
-	if (!_num_devices)
-		return r;
+	if ((r && !_num_devices) || !_switches[FORCE_ARG])
+		goto out;
 
 	r |= _process_all(cmd, argc, argv, 1, _error_device);
 	r |= _simple(DM_DEVICE_REMOVE_ALL, "", 0, 0) | dm_mknodes(NULL);
 
 	_num_devices = 0;
-	r |= _process_all(cmd, argc, argv, 1, _count_devices);
-	if (!_num_devices)
-		return r;
+	r &= _process_all(cmd, argc, argv, 1, _count_devices);
 
-	fprintf(stderr, "Unable to remove %d device(s).\n", _num_devices);
+out:
+	if (_num_devices)
+		fprintf(stderr, "Unable to remove %d device(s).\n", _num_devices);
 
-	return r;
+	return r && !_num_devices;
 }
 
 static void _display_dev(struct dm_task *dmt, const char *name)
-- 
1.8.5.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-12-06 21:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-02 17:58 [PATCH] dmsetup: Set exit code to 1 if remove_all fails to remove all devices Lukas Wunner
2014-12-02 19:16 ` Zdenek Kabelac
2014-12-02 21:00   ` Lukas Wunner
2014-12-02 21:12     ` Zdenek Kabelac
2014-12-06 21:25       ` Lukas Wunner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.