dm: disable REQ_NOWAIT for flushes
authorMikulas Patocka <mpatocka@redhat.com>
Thu, 9 Jan 2025 13:49:11 +0000 (14:49 +0100)
committerMikulas Patocka <mpatocka@redhat.com>
Fri, 17 Jan 2025 21:05:39 +0000 (22:05 +0100)
REQ_NOWAIT for flushes cannot be easily supported by device mapper
because it may allocate multiple bios and its impossible to undo if one
of those allocations wants to wait. So, this patch disables REQ_NOWAIT
flushes in device mapper and we always return EAGAIN.

Previously, the code accepted REQ_NOWAIT flushes, but the non-blocking
execution was not guaranteed.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
drivers/md/dm.c

index 4817ef1206a909c9d3aa4f34802d86b460e17c4b..ee86cc60d4b861ab9e0b5822901823a2e857864d 100644 (file)
@@ -1968,6 +1968,15 @@ static void dm_split_and_process_bio(struct mapped_device *md,
 
        /* Only support nowait for normal IO */
        if (unlikely(bio->bi_opf & REQ_NOWAIT) && !is_abnormal) {
+               /*
+                * Don't support NOWAIT for FLUSH because it may allocate
+                * multiple bios and there's no easy way how to undo the
+                * allocations.
+                */
+               if (bio->bi_opf & REQ_PREFLUSH) {
+                       bio_wouldblock_error(bio);
+                       return;
+               }
                io = alloc_io(md, bio, GFP_NOWAIT);
                if (unlikely(!io)) {
                        /* Unable to do anything without dm_io. */