]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fs: Propagate write hints to the struct block_device inode
authorBart Van Assche <bvanassche@acm.org>
Fri, 2 Feb 2024 20:39:24 +0000 (12:39 -0800)
committerChristian Brauner <brauner@kernel.org>
Tue, 6 Feb 2024 13:30:48 +0000 (14:30 +0100)
Write hints applied with F_SET_RW_HINT on a block device affect the
block device inode only. Propagate these hints to the inode associated
with struct block_device because that is the inode used when writing
back dirty pages.

Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Jeff Layton <jlayton@kernel.org>
Cc: Chuck Lever <chuck.lever@oracle.com>
Cc: Kanchan Joshi <joshi.k@samsung.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Link: https://lore.kernel.org/r/20240202203926.2478590-6-bvanassche@acm.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/fcntl.c

index 00be0a710bbabc882ca46121e73c314345d00c89..8eb6d64a985b0df3dc48cd537e8793a9859eddbc 100644 (file)
@@ -317,6 +317,13 @@ static long fcntl_set_rw_hint(struct file *file, unsigned int cmd,
 
        WRITE_ONCE(inode->i_write_hint, hint);
 
+       /*
+        * file->f_mapping->host may differ from inode. As an example,
+        * blkdev_open() modifies file->f_mapping.
+        */
+       if (file->f_mapping->host != inode)
+               WRITE_ONCE(file->f_mapping->host->i_write_hint, hint);
+
        return 0;
 }