Skip to content

Commit f35f06c

Browse files
fdmananakdave
authored andcommitted
Btrfs: do not allow trimming when a fs is mounted with the nologreplay option
Whan a filesystem is mounted with the nologreplay mount option, which requires it to be mounted in RO mode as well, we can not allow discard on free space inside block groups, because log trees refer to extents that are not pinned in a block group's free space cache (pinning the extents is precisely the first phase of replaying a log tree). So do not allow the fitrim ioctl to do anything when the filesystem is mounted with the nologreplay option, because later it can be mounted RW without that option, which causes log replay to happen and result in either a failure to replay the log trees (leading to a mount failure), a crash or some silent corruption. Reported-by: Darrick J. Wong <[email protected]> Fixes: 96da091 ("btrfs: Introduce new mount option to disable tree log replay") CC: [email protected] # 4.9+ Reviewed-by: Nikolay Borisov <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 0ccc387 commit f35f06c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

fs/btrfs/ioctl.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,16 @@ static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg)
501501
if (!capable(CAP_SYS_ADMIN))
502502
return -EPERM;
503503

504+
/*
505+
* If the fs is mounted with nologreplay, which requires it to be
506+
* mounted in RO mode as well, we can not allow discard on free space
507+
* inside block groups, because log trees refer to extents that are not
508+
* pinned in a block group's free space cache (pinning the extents is
509+
* precisely the first phase of replaying a log tree).
510+
*/
511+
if (btrfs_test_opt(fs_info, NOLOGREPLAY))
512+
return -EROFS;
513+
504514
rcu_read_lock();
505515
list_for_each_entry_rcu(device, &fs_info->fs_devices->devices,
506516
dev_list) {

0 commit comments

Comments
 (0)