vfs: fix readahead(2) on block devices
authorReuben Hawkins <reubenhwk@gmail.com>
Tue, 3 Oct 2023 01:57:04 +0000 (20:57 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 20 Nov 2023 10:58:52 +0000 (11:58 +0100)
[ Upstream commit 7116c0af4b8414b2f19fdb366eea213cbd9d91c2 ]

Readahead was factored to call generic_fadvise.  That refactor added an
S_ISREG restriction which broke readahead on block devices.

In addition to S_ISREG, this change checks S_ISBLK to fix block device
readahead.  There is no change in behavior with any file type besides block
devices in this change.

Fixes: 3d8f7615319b ("vfs: implement readahead(2) using POSIX_FADV_WILLNEED")
Signed-off-by: Reuben Hawkins <reubenhwk@gmail.com>
Link: https://lore.kernel.org/r/20231003015704.2415-1-reubenhwk@gmail.com
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
mm/readahead.c

index e815c11..6925e69 100644 (file)
@@ -735,7 +735,8 @@ ssize_t ksys_readahead(int fd, loff_t offset, size_t count)
         */
        ret = -EINVAL;
        if (!f.file->f_mapping || !f.file->f_mapping->a_ops ||
-           !S_ISREG(file_inode(f.file)->i_mode))
+           (!S_ISREG(file_inode(f.file)->i_mode) &&
+           !S_ISBLK(file_inode(f.file)->i_mode)))
                goto out;
 
        ret = vfs_fadvise(f.file, offset, count, POSIX_FADV_WILLNEED);