linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] loop: Fix missing discard support when using LOOP_CONFIGURE
@ 2021-06-18 11:51 Kristian Klausen
  2021-06-18 14:52 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Kristian Klausen @ 2021-06-18 11:51 UTC (permalink / raw)
  To: linux-block
  Cc: Kristian Klausen, stable, Jens Axboe, Martijn Coenen, open list

Without calling loop_config_discard() the discard flag and parameters
aren't set/updated for the loop device and worst-case they could
indicate discard support when it isn't the case (ex: if the
LOOP_SET_STATUS ioctl was used with a different file prior to
LOOP_CONFIGURE).

Cc: <stable@vger.kernel.org> # 5.8.x-
Fixes: 3448914e8cc5 ("loop: Add LOOP_CONFIGURE ioctl")
Signed-off-by: Kristian Klausen <kristian@klausen.dk>
---
v1 of the patch was tested like so (without the patch):
losetup 2.37<= uses LOOP_CONFIGURE instead of LOOP_SET_STATUS64[1]

# fallocate -l100M disk.img
# rmmod loop
# losetup --version
losetup from util-linux 2.36.2
# losetup --find --show disk.img
/dev/loop0
# grep '' /sys/devices/virtual/block/loop0/queue/*discard*
/sys/devices/virtual/block/loop0/queue/discard_granularity:4096
/sys/devices/virtual/block/loop0/queue/discard_max_bytes:4294966784
/sys/devices/virtual/block/loop0/queue/discard_max_hw_bytes:4294966784
/sys/devices/virtual/block/loop0/queue/discard_zeroes_data:0
/sys/devices/virtual/block/loop0/queue/max_discard_segments:1
# losetup -d /dev/loop0
# [update util-linux]
# losetup --version
losetup from util-linux 2.37
# rmmod loop
# losetup --find --show disk.img
/dev/loop0
# grep '' /sys/devices/virtual/block/loop0/queue/*discard*
/sys/devices/virtual/block/loop0/queue/discard_granularity:0
/sys/devices/virtual/block/loop0/queue/discard_max_bytes:0
/sys/devices/virtual/block/loop0/queue/discard_max_hw_bytes:0
/sys/devices/virtual/block/loop0/queue/discard_zeroes_data:0
/sys/devices/virtual/block/loop0/queue/max_discard_segments:1


With the patch applied:

# losetup --version
losetup from util-linux 2.37
# rmmod loop
# losetup --find --show disk.img
/dev/loop0
# grep '' /sys/devices/virtual/block/loop0/queue/*discard*
/sys/devices/virtual/block/loop0/queue/discard_granularity:4096
/sys/devices/virtual/block/loop0/queue/discard_max_bytes:4294966784
/sys/devices/virtual/block/loop0/queue/discard_max_hw_bytes:4294966784
/sys/devices/virtual/block/loop0/queue/discard_zeroes_data:0
/sys/devices/virtual/block/loop0/queue/max_discard_segments:1

[1] https://github.com/karelzak/util-linux/pull/1152

v2:
Add commit message
Move loop_config_discard() before loop_update_rotational()

 drivers/block/loop.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 76e12f3482a9..8271df125153 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -1154,6 +1154,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
 	blk_queue_physical_block_size(lo->lo_queue, bsize);
 	blk_queue_io_min(lo->lo_queue, bsize);
 
+	loop_config_discard(lo);
 	loop_update_rotational(lo);
 	loop_update_dio(lo);
 	loop_sysfs_init(lo);

base-commit: 70585216fe7730d9fb5453d3e2804e149d0fe201
-- 
2.32.0


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

* Re: [PATCH v2] loop: Fix missing discard support when using LOOP_CONFIGURE
  2021-06-18 11:51 [PATCH v2] loop: Fix missing discard support when using LOOP_CONFIGURE Kristian Klausen
@ 2021-06-18 14:52 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2021-06-18 14:52 UTC (permalink / raw)
  To: Kristian Klausen, linux-block; +Cc: stable, Martijn Coenen, open list

On 6/18/21 5:51 AM, Kristian Klausen wrote:
> Without calling loop_config_discard() the discard flag and parameters
> aren't set/updated for the loop device and worst-case they could
> indicate discard support when it isn't the case (ex: if the
> LOOP_SET_STATUS ioctl was used with a different file prior to
> LOOP_CONFIGURE).

Applied, thanks.

-- 
Jens Axboe


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

end of thread, other threads:[~2021-06-18 14:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-18 11:51 [PATCH v2] loop: Fix missing discard support when using LOOP_CONFIGURE Kristian Klausen
2021-06-18 14:52 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).