diff mbox series

[v2] btrfs: prevent remounting to v1 space cache for subpage mount

Message ID 141ea1f29543c7eccabc3899f34b691a13841a5a.1652850165.git.wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series [v2] btrfs: prevent remounting to v1 space cache for subpage mount | expand

Commit Message

Qu Wenruo May 18, 2022, 5:03 a.m. UTC
Upstream commit 9f73f1aef98b ("btrfs: force v2 space cache usage for
subpage mount") forces subpage mount to use v2 cache, to avoid
deprecated v1 cache which doesn't support subpage properly.

But there is a loophole that user can still remount to v1 cache.

The existing check will only give users a warning, but not really
prevents the users to do the remount.

Although remounting to v1 will not cause any problems since the v1 cache
will always be marked invalid when mounted with a different page size,
it's still better to prevent v1 cache at all for subpage mounts.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
Changelog:
v2:
- Assigned @ret to -EINVAL before going restore tag.
---
 fs/btrfs/super.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

David Sterba May 25, 2022, 2:45 p.m. UTC | #1
On Wed, May 18, 2022 at 01:03:09PM +0800, Qu Wenruo wrote:
> Upstream commit 9f73f1aef98b ("btrfs: force v2 space cache usage for
> subpage mount") forces subpage mount to use v2 cache, to avoid
> deprecated v1 cache which doesn't support subpage properly.
> 
> But there is a loophole that user can still remount to v1 cache.
> 
> The existing check will only give users a warning, but not really
> prevents the users to do the remount.
> 
> Although remounting to v1 will not cause any problems since the v1 cache
> will always be marked invalid when mounted with a different page size,
> it's still better to prevent v1 cache at all for subpage mounts.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>

Added to misc-next, thanks.
diff mbox series

Patch

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index b1fdc6a26c76..aab8831119d1 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1985,6 +1985,15 @@  static int btrfs_remount(struct super_block *sb, int *flags, char *data)
 	if (ret)
 		goto restore;
 
+	/* V1 cache is not supported for subpage mount. */
+	if (fs_info->sectorsize < PAGE_SIZE &&
+	    btrfs_test_opt(fs_info, SPACE_CACHE)) {
+		btrfs_warn(fs_info,
+	"v1 space cache is not supported for page size %lu with sectorsize %u",
+			   PAGE_SIZE, fs_info->sectorsize);
+		ret = -EINVAL;
+		goto restore;
+	}
 	btrfs_remount_begin(fs_info, old_opts, *flags);
 	btrfs_resize_thread_pool(fs_info,
 		fs_info->thread_pool_size, old_thread_pool_size);