On Mon, 16 Mar 2026, Bart Van Assche wrote:

> 
> On 3/16/26 8:55 AM, Mikulas Patocka wrote:
> >   {
> > -   dm_hash_remove_all(false, false, false);
> > +   dm_hash_remove_all(false, false, false, false);
> >   }
> 
> Three boolean arguments in a row make dm_hash_remove_all() calls much harder
> to read than necessary. Has it been considered to combine the
> three boolean arguments into a single flags argument?
> 
> Thanks,
> 
> Bart.

OK - I can change it to flags.


From: Mikulas Patocka <[email protected]>

The command "dmsetup remove_all" may take a long time (a minute for
removing 1000 devices), so make it interruptible with fatal signals.

For better readability, the bool arguments were changed to flags.

Signed-off-by: Mikulas Patocka <[email protected]>

---
 drivers/md/dm-ioctl.c |   31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

Index: linux-2.6/drivers/md/dm-ioctl.c
===================================================================
--- linux-2.6.orig/drivers/md/dm-ioctl.c        2026-03-16 14:37:37.000000000 
+0100
+++ linux-2.6/drivers/md/dm-ioctl.c     2026-03-16 17:31:24.000000000 +0100
@@ -64,7 +64,11 @@ struct vers_iter {
 static struct rb_root name_rb_tree = RB_ROOT;
 static struct rb_root uuid_rb_tree = RB_ROOT;
 
-static void dm_hash_remove_all(bool keep_open_devices, bool mark_deferred, 
bool only_deferred);
+#define KEEP_OPEN_DEVICES      1
+#define MARK_DEFERRED          2
+#define ONLY_DEFERRED          4
+#define INTERRUPTIBLE          8
+static int dm_hash_remove_all(unsigned flags);
 
 /*
  * Guards access to both hash tables.
@@ -78,7 +82,7 @@ static DEFINE_MUTEX(dm_hash_cells_mutex)
 
 static void dm_hash_exit(void)
 {
-       dm_hash_remove_all(false, false, false);
+       dm_hash_remove_all(0);
 }
 
 /*
@@ -333,7 +337,7 @@ static struct dm_table *__hash_remove(st
        return table;
 }
 
-static void dm_hash_remove_all(bool keep_open_devices, bool mark_deferred, 
bool only_deferred)
+static int dm_hash_remove_all(unsigned flags)
 {
        int dev_skipped;
        struct rb_node *n;
@@ -347,12 +351,17 @@ retry:
        down_write(&_hash_lock);
 
        for (n = rb_first(&name_rb_tree); n; n = rb_next(n)) {
+               if (flags & INTERRUPTIBLE && fatal_signal_pending(current)) {
+                       up_write(&_hash_lock);
+                       return -EINTR;
+               }
+
                hc = container_of(n, struct hash_cell, name_node);
                md = hc->md;
                dm_get(md);
 
-               if (keep_open_devices &&
-                   dm_lock_for_deletion(md, mark_deferred, only_deferred)) {
+               if (flags & KEEP_OPEN_DEVICES &&
+                   dm_lock_for_deletion(md, !!(flags & MARK_DEFERRED), 
!!(flags & ONLY_DEFERRED))) {
                        dm_put(md);
                        dev_skipped++;
                        continue;
@@ -368,7 +377,7 @@ retry:
                }
                dm_ima_measure_on_device_remove(md, true);
                dm_put(md);
-               if (likely(keep_open_devices))
+               if (likely(flags & KEEP_OPEN_DEVICES))
                        dm_destroy(md);
                else
                        dm_destroy_immediate(md);
@@ -384,8 +393,10 @@ retry:
 
        up_write(&_hash_lock);
 
-       if (dev_skipped && !only_deferred)
+       if (dev_skipped && !(flags & ONLY_DEFERRED))
                DMWARN("remove_all left %d open device(s)", dev_skipped);
+
+       return 0;
 }
 
 /*
@@ -513,7 +524,7 @@ static struct mapped_device *dm_hash_ren
 
 void dm_deferred_remove(void)
 {
-       dm_hash_remove_all(true, false, true);
+       dm_hash_remove_all(KEEP_OPEN_DEVICES | ONLY_DEFERRED);
 }
 
 /*
@@ -529,9 +540,9 @@ typedef int (*ioctl_fn)(struct file *fil
 
 static int remove_all(struct file *filp, struct dm_ioctl *param, size_t 
param_size)
 {
-       dm_hash_remove_all(true, !!(param->flags & DM_DEFERRED_REMOVE), false);
+       int r = dm_hash_remove_all(KEEP_OPEN_DEVICES | (param->flags & 
DM_DEFERRED_REMOVE ? MARK_DEFERRED : 0) | INTERRUPTIBLE);
        param->data_size = 0;
-       return 0;
+       return r;
 }
 
 /*


Reply via email to