Blob Blame History Raw
From: David Sterba <dsterba@suse.cz>
Date: Fri, 18 Jan 2013 00:28:40 +0100
Patch-mainline: Never, SLES-specific
References: fate#314697
Subject: [PATCH] btrfs: add allow_unsupported module parameter

Disallow access to filesystem with unsupported features by default but
leave a chance to access the filesystem via module parameter override
(taints kernel).

The status can be toggled during runtime by changing the exported module
parameter in /sys/module/btrfs/parameters/allow_unsupported.

Current:
- mount: inode_cache - deny mount
- mount: raid56 - remount RO
- mount: seeding device - deny mount
- balance: use of raid56 taints kernel

fate#325563 - allow device replace

Signed-off-by: David Sterba <dsterba@suse.cz>
---
 fs/btrfs/ctree.h   |    7 +++++++
 fs/btrfs/disk-io.c |   14 ++++++++++++++
 fs/btrfs/super.c   |   10 ++++++++++
 3 files changed, 31 insertions(+)

--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -28,6 +28,7 @@
 #include <linux/refcount.h>
 #include <linux/crc32c.h>
 #include <linux/iomap.h>
+#include <linux/unsupported-feature.h>
 #include "extent-io-tree.h"
 #include "extent_io.h"
 #include "extent_map.h"
@@ -3781,6 +3782,12 @@ static inline int btrfs_is_testing(struc
 }
 #endif
 
+/*
+ * Module parameter
+ */
+DECLARE_SUSE_UNSUPPORTED_FEATURE(btrfs)
+#define btrfs_allow_unsupported btrfs_allow_unsupported()
+
 static inline bool btrfs_is_zoned(const struct btrfs_fs_info *fs_info)
 {
 	return fs_info->zoned != 0;
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3297,6 +3297,13 @@ int __cold open_ctree(struct super_block
 
 	disk_super = fs_info->super_copy;
 
+	if (btrfs_super_flags(disk_super) & BTRFS_SUPER_FLAG_SEEDING) {
+		if (!btrfs_allow_unsupported) {
+			printk(KERN_WARNING "btrfs: seeding mode is not supported, load module with allow_unsupported=1\n");
+			ret = -EOPNOTSUPP;
+			goto fail_alloc;
+		}
+	}
 
 	features = btrfs_super_flags(disk_super);
 	if (features & BTRFS_SUPER_FLAG_CHANGING_FSID_V2) {
@@ -3391,6 +3398,13 @@ int __cold open_ctree(struct super_block
 		goto fail_alloc;
 	}
 
+	if (features & BTRFS_FEATURE_INCOMPAT_RAID56) {
+		if (!btrfs_allow_unsupported) {
+			printk(KERN_WARNING "btrfs: RAID56 is supported read-only, load module with allow_unsupported=1\n");
+			sb->s_flags |= SB_RDONLY;
+		}
+	}
+
 	/*
 	 * Needn't use the lock because there is no other task which will
 	 * update the flag.
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -27,6 +27,7 @@
 #include <linux/ratelimit.h>
 #include <linux/crc32c.h>
 #include <linux/btrfs.h>
+#include <linux/moduleparam.h>
 #include "delayed-inode.h"
 #include "ctree.h"
 #include "disk-io.h"
@@ -52,6 +53,8 @@
 #define CREATE_TRACE_POINTS
 #include <trace/events/btrfs.h>
 
+DEFINE_SUSE_UNSUPPORTED_FEATURE(btrfs)
+
 static const struct super_operations btrfs_super_ops;
 
 /*
@@ -2069,6 +2072,13 @@ static int btrfs_remount(struct super_bl
 			ret = -EACCES;
 			goto restore;
 		}
+		if ((btrfs_super_incompat_flags(fs_info->super_copy)
+					& BTRFS_FEATURE_INCOMPAT_RAID56)
+				&& !btrfs_allow_unsupported) {
+			printk(KERN_WARNING "btrfs: cannot remount RW, RAID56 is supported read-only, load module with allow_unsupported=1\n");
+			ret = -EINVAL;
+			goto restore;
+		}
 
 		if (btrfs_super_log_root(fs_info->super_copy) != 0) {
 			btrfs_warn(fs_info,