]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.19.35/btrfs-do-not-allow-trimming-when-a-fs-is-mounted-with-the-nologreplay-option.patch
Linux 4.19.35
[thirdparty/kernel/stable-queue.git] / releases / 4.19.35 / btrfs-do-not-allow-trimming-when-a-fs-is-mounted-with-the-nologreplay-option.patch
CommitLineData
1dabdb6f
GKH
1From f35f06c35560a86e841631f0243b83a984dc11a9 Mon Sep 17 00:00:00 2001
2From: Filipe Manana <fdmanana@suse.com>
3Date: Tue, 26 Mar 2019 10:49:56 +0000
4Subject: Btrfs: do not allow trimming when a fs is mounted with the nologreplay option
5
6From: Filipe Manana <fdmanana@suse.com>
7
8commit f35f06c35560a86e841631f0243b83a984dc11a9 upstream.
9
10Whan a filesystem is mounted with the nologreplay mount option, which
11requires it to be mounted in RO mode as well, we can not allow discard on
12free space inside block groups, because log trees refer to extents that
13are not pinned in a block group's free space cache (pinning the extents is
14precisely the first phase of replaying a log tree).
15
16So do not allow the fitrim ioctl to do anything when the filesystem is
17mounted with the nologreplay option, because later it can be mounted RW
18without that option, which causes log replay to happen and result in
19either a failure to replay the log trees (leading to a mount failure), a
20crash or some silent corruption.
21
22Reported-by: Darrick J. Wong <darrick.wong@oracle.com>
23Fixes: 96da09192cda ("btrfs: Introduce new mount option to disable tree log replay")
24CC: stable@vger.kernel.org # 4.9+
25Reviewed-by: Nikolay Borisov <nborisov@suse.com>
26Signed-off-by: Filipe Manana <fdmanana@suse.com>
27Reviewed-by: David Sterba <dsterba@suse.com>
28Signed-off-by: David Sterba <dsterba@suse.com>
29Signed-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) {