Skip to content

Commit b722e40

Browse files
josefbacikjankara
authored andcommitted
btrfs: disable defrag on pre-content watched files
We queue up inodes to be defrag'ed asynchronously, which means we do not have their original file for readahead. This means that the code to skip readahead on pre-content watched files will not run, and we could potentially read in empty pages. Handle this corner case by disabling defrag on files that are currently being watched for pre-content events. Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: Jan Kara <[email protected]> Link: https://patch.msgid.link/4cc5bcea13db7904174353d08e85157356282a59.1731684329.git.josef@toxicpanda.com
1 parent 7f4796a commit b722e40

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

fs/btrfs/ioctl.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2635,6 +2635,15 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp)
26352635
goto out;
26362636
}
26372637

2638+
/*
2639+
* Don't allow defrag on pre-content watched files, as it could
2640+
* populate the page cache with 0's via readahead.
2641+
*/
2642+
if (unlikely(FMODE_FSNOTIFY_HSM(file->f_mode))) {
2643+
ret = -EINVAL;
2644+
goto out;
2645+
}
2646+
26382647
if (argp) {
26392648
if (copy_from_user(&range, argp, sizeof(range))) {
26402649
ret = -EFAULT;

0 commit comments

Comments
 (0)