From: "Holger Hoffstätte" <holger.hoffstaette@googlemail.com>
To: LKML <linux-kernel@vger.kernel.org>, Jens Axboe <axboe@fb.com>
Subject: [PATCH] loop: properly observe rotational flag of underlying device
Date: Wed, 11 Nov 2015 16:21:51 +0100 [thread overview]
Message-ID: <56435D0F.80006@googlemail.com> (raw)
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.
Signed-off-by: Holger Hoffstätte <holger.hoffstaette@googlemail.com>
---
drivers/block/loop.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 423f4ca..2984aca 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -843,6 +843,24 @@ static void loop_config_discard(struct loop_device *lo)
queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
}
+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)
+ queue_flag_set_unlocked(QUEUE_FLAG_NONROT, q);
+ else
+ queue_flag_clear_unlocked(QUEUE_FLAG_NONROT, q);
+}
+
static void loop_unprepare_queue(struct loop_device *lo)
{
flush_kthread_worker(&lo->worker);
@@ -939,6 +957,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
if (!(lo_flags & LO_FLAGS_READ_ONLY) && file->f_op->fsync)
blk_queue_flush(lo->lo_queue, REQ_FLUSH);
+ loop_update_rotational(lo);
loop_update_dio(lo);
set_capacity(lo->lo_disk, size);
bd_set_size(bdev, size << 9);
--
2.6.3
next reply other threads:[~2015-11-11 15:21 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-11 15:21 Holger Hoffstätte [this message]
2015-11-11 21:29 ` [PATCH] loop: properly observe rotational flag of underlying device Jens Axboe
2015-11-11 22:08 ` Holger Hoffstätte
2016-01-11 23:20 ` Holger Hoffstätte
2016-05-12 20:28 ` gwendal grignou
2016-05-12 22:30 ` Holger Hoffstätte
2019-02-12 22:54 Benjamin Gordon
2019-03-26 16:55 ` Holger Hoffstätte
[not found] ` <CADaYBq32aM4QpHmOmevFWSkjYqWmBWdhgd7CDWh+Se6q_2byHg@mail.gmail.com>
2019-03-26 17:57 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56435D0F.80006@googlemail.com \
--to=holger.hoffstaette@googlemail.com \
--cc=axboe@fb.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.