]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
block: ensure discard_granularity is zero when discard is not supported
authorChristoph Hellwig <hch@lst.de>
Thu, 31 Jul 2025 15:22:28 +0000 (08:22 -0700)
committerJens Axboe <axboe@kernel.dk>
Thu, 31 Jul 2025 21:01:35 +0000 (15:01 -0600)
Documentation/ABI/stable/sysfs-block states:

  What: /sys/block/<disk>/queue/discard_granularity
  [...]
  A discard_granularity of 0 means that the device does not support
  discard functionality.

but this got broken when sorting out the block limits updates.  Fix this
by setting the discard_granularity limit to zero when the combined
max_discard_sectors is zero.

Fixes: 3c407dc723bb ("block: default the discard granularity to sector size")
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Link: https://lore.kernel.org/r/20250731152228.873923-1-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-settings.c

index a7a794baba72dc171800bdd3e4926719057da99b..07874e9b609f6fe6f6f6a417ebefe632cefd87e7 100644 (file)
@@ -400,12 +400,19 @@ int blk_validate_limits(struct queue_limits *lim)
        lim->max_discard_sectors =
                min(lim->max_hw_discard_sectors, lim->max_user_discard_sectors);
 
+       /*
+        * When discard is not supported, discard_granularity should be reported
+        * as 0 to userspace.
+        */
+       if (lim->max_discard_sectors)
+               lim->discard_granularity =
+                       max(lim->discard_granularity, lim->physical_block_size);
+       else
+               lim->discard_granularity = 0;
+
        if (!lim->max_discard_segments)
                lim->max_discard_segments = 1;
 
-       if (lim->discard_granularity < lim->physical_block_size)
-               lim->discard_granularity = lim->physical_block_size;
-
        /*
         * By default there is no limit on the segment boundary alignment,
         * but if there is one it can't be smaller than the page size as