]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.19.35/btrfs-do-not-allow-trimming-when-a-fs-is-mounted-with-the-nologreplay-option.patch
Linux 4.14.112
[thirdparty/kernel/stable-queue.git] / releases / 4.19.35 / btrfs-do-not-allow-trimming-when-a-fs-is-mounted-with-the-nologreplay-option.patch
1 From f35f06c35560a86e841631f0243b83a984dc11a9 Mon Sep 17 00:00:00 2001
2 From: Filipe Manana <fdmanana@suse.com>
3 Date: Tue, 26 Mar 2019 10:49:56 +0000
4 Subject: Btrfs: do not allow trimming when a fs is mounted with the nologreplay option
5
6 From: Filipe Manana <fdmanana@suse.com>
7
8 commit f35f06c35560a86e841631f0243b83a984dc11a9 upstream.
9
10 Whan a filesystem is mounted with the nologreplay mount option, which
11 requires it to be mounted in RO mode as well, we can not allow discard on
12 free space inside block groups, because log trees refer to extents that
13 are not pinned in a block group's free space cache (pinning the extents is
14 precisely the first phase of replaying a log tree).
15
16 So do not allow the fitrim ioctl to do anything when the filesystem is
17 mounted with the nologreplay option, because later it can be mounted RW
18 without that option, which causes log replay to happen and result in
19 either a failure to replay the log trees (leading to a mount failure), a
20 crash or some silent corruption.
21
22 Reported-by: Darrick J. Wong <darrick.wong@oracle.com>
23 Fixes: 96da09192cda ("btrfs: Introduce new mount option to disable tree log replay")
24 CC: stable@vger.kernel.org # 4.9+
25 Reviewed-by: Nikolay Borisov <nborisov@suse.com>
26 Signed-off-by: Filipe Manana <fdmanana@suse.com>
27 Reviewed-by: David Sterba <dsterba@suse.com>
28 Signed-off-by: David Sterba <dsterba@suse.com>
29 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
30
31 ---
32 fs/btrfs/ioctl.c | 10 ++++++++++
33 1 file changed, 10 insertions(+)
34
35 --- a/fs/btrfs/ioctl.c
36 +++ b/fs/btrfs/ioctl.c
37 @@ -496,6 +496,16 @@ static noinline int btrfs_ioctl_fitrim(s
38 if (!capable(CAP_SYS_ADMIN))
39 return -EPERM;
40
41 + /*
42 + * If the fs is mounted with nologreplay, which requires it to be
43 + * mounted in RO mode as well, we can not allow discard on free space
44 + * inside block groups, because log trees refer to extents that are not
45 + * pinned in a block group's free space cache (pinning the extents is
46 + * precisely the first phase of replaying a log tree).
47 + */
48 + if (btrfs_test_opt(fs_info, NOLOGREPLAY))
49 + return -EROFS;
50 +
51 rcu_read_lock();
52 list_for_each_entry_rcu(device, &fs_info->fs_devices->devices,
53 dev_list) {