Patch "loop: properly observe rotational flag of underlying device" has been added to the 4.19-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    loop: properly observe rotational flag of underlying device

to the 4.19-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     loop-properly-observe-rotational-flag-of-underlying-device.patch
and it can be found in the queue-4.19 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.


>From stable+bounces-25712-greg=kroah.com@xxxxxxxxxxxxxxx Fri Mar  1 02:33:17 2024
From: Genjian <zhanggenjian@xxxxxxx>
Date: Fri,  1 Mar 2024 09:30:25 +0800
Subject: loop: properly observe rotational flag of underlying device
To: stable@xxxxxxxxxxxxxxx
Cc: axboe@xxxxxxxxx, stable@xxxxxxxxxx, linux-block@xxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, zhanggenjian123@xxxxxxxxx, "Holger Hoffstätte" <holger.hoffstaette@xxxxxxxxxxxxxx>, holger@xxxxxxxxxxxxxxxxxxxxxx, "Gwendal Grignou" <gwendal@xxxxxxxxxxxx>, "Benjamin Gordon" <bmgordon@xxxxxxxxxxxx>, "Guenter Roeck" <groeck@xxxxxxxxxxxx>, "Genjian Zhang" <zhanggenjian@xxxxxxxxxx>
Message-ID: <20240301013028.2293831-7-zhanggenjian@xxxxxxx>

From: Holger Hoffstätte <holger.hoffstaette@xxxxxxxxxxxxxx>

[ Upstream commit 56a85fd8376ef32458efb6ea97a820754e12f6bb ]

The loop driver always declares the rotational flag of its device as
rotational, even when the device of the mapped file is nonrotational,
as is the case with SSDs or on tmpfs. This can confuse filesystem tools
which are SSD-aware; in my case I frequently forget to tell mkfs.btrfs
that my loop device on tmpfs is nonrotational, and that I really don't
need any automatic metadata redundancy.

The attached patch fixes this by introspecting the rotational flag of the
mapped file's underlying block device, if it exists. If the mapped file's
filesystem has no associated block device - as is the case on e.g. tmpfs -
we assume nonrotational storage. If there is a better way to identify such
non-devices I'd love to hear them.

Cc: Jens Axboe <axboe@xxxxxxxxx>
Cc: linux-block@xxxxxxxxxxxxxxx
Cc: holger@xxxxxxxxxxxxxxxxxxxxxx
Signed-off-by: Holger Hoffstätte <holger.hoffstaette@xxxxxxxxxxxxxx>
Signed-off-by: Gwendal Grignou <gwendal@xxxxxxxxxxxx>
Signed-off-by: Benjamin Gordon <bmgordon@xxxxxxxxxxxx>
Reviewed-by: Guenter Roeck <groeck@xxxxxxxxxxxx>
Signed-off-by: Jens Axboe <axboe@xxxxxxxxx>
Signed-off-by: Genjian Zhang <zhanggenjian@xxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 drivers/block/loop.c |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -940,6 +940,24 @@ static int loop_prepare_queue(struct loo
 	return 0;
 }
 
+static void loop_update_rotational(struct loop_device *lo)
+{
+	struct file *file = lo->lo_backing_file;
+	struct inode *file_inode = file->f_mapping->host;
+	struct block_device *file_bdev = file_inode->i_sb->s_bdev;
+	struct request_queue *q = lo->lo_queue;
+	bool nonrot = true;
+
+	/* not all filesystems (e.g. tmpfs) have a sb->s_bdev */
+	if (file_bdev)
+		nonrot = blk_queue_nonrot(bdev_get_queue(file_bdev));
+
+	if (nonrot)
+		blk_queue_flag_set(QUEUE_FLAG_NONROT, q);
+	else
+		blk_queue_flag_clear(QUEUE_FLAG_NONROT, q);
+}
+
 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
 		       struct block_device *bdev, unsigned int arg)
 {
@@ -1001,6 +1019,7 @@ static int loop_set_fd(struct loop_devic
 	if (!(lo_flags & LO_FLAGS_READ_ONLY) && file->f_op->fsync)
 		blk_queue_write_cache(lo->lo_queue, true, false);
 
+	loop_update_rotational(lo);
 	loop_update_dio(lo);
 	loop_sysfs_init(lo);
 	loop_set_size(lo, size);


Patches currently in stable-queue which might be from kroah.com@xxxxxxxxxxxxxxx are

queue-4.19/loop-factor-out-configuring-loop-from-status.patch
queue-4.19/loop-call-loop_config_discard-only-after-new-config-is-applied.patch
queue-4.19/loop-refactor-loop_set_status-size-calculation.patch
queue-4.19/loop-factor-out-setting-loop-device-size.patch
queue-4.19/loop-check-for-overflow-while-configuring-loop.patch
queue-4.19/loop-properly-observe-rotational-flag-of-underlying-device.patch
queue-4.19/loop-remove-sector_t-truncation-checks.patch
queue-4.19/revert-loop-check-for-overflow-while-configuring-loop.patch
queue-4.19/loop-loop_set_status_from_info-check-before-assignment.patch




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux