diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2018-11-12 18:30:55 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2018-11-12 19:10:54 -0500 |
commit | 424d1848cce0a3d567c3301107324267f4d46318 (patch) | |
tree | 6b7ac7feaa835d7471510346b2cca404572688a8 | |
parent | d7dbddc4504c1bf509f8eb5818b5042342dc9ed1 (diff) |
bcachefs: Check for unsupported features
-rw-r--r-- | fs/bcachefs/bcachefs_format.h | 3 | ||||
-rw-r--r-- | fs/bcachefs/opts.c | 15 | ||||
-rw-r--r-- | fs/bcachefs/opts.h | 1 | ||||
-rw-r--r-- | fs/bcachefs/super-io.c | 6 | ||||
-rw-r--r-- | fs/bcachefs/sysfs.c | 12 | ||||
-rw-r--r-- | fs/bcachefs/xattr.c | 10 |
6 files changed, 29 insertions, 18 deletions
diff --git a/fs/bcachefs/bcachefs_format.h b/fs/bcachefs/bcachefs_format.h index 7ad080bfff31..7842c81639d4 100644 --- a/fs/bcachefs/bcachefs_format.h +++ b/fs/bcachefs/bcachefs_format.h @@ -1227,7 +1227,8 @@ enum bch_sb_features { BCH_FEATURE_LZ4 = 0, BCH_FEATURE_GZIP = 1, BCH_FEATURE_ZSTD = 2, - BCH_FEATURE_ATOMIC_NLINK = 3, + BCH_FEATURE_ATOMIC_NLINK = 3, /* should have gone under compat */ + BCH_FEATURE_NR, }; /* options: */ diff --git a/fs/bcachefs/opts.c b/fs/bcachefs/opts.c index 1dab991bc29b..775d6a667752 100644 --- a/fs/bcachefs/opts.c +++ b/fs/bcachefs/opts.c @@ -2,6 +2,7 @@ #include <linux/kernel.h> #include "bcachefs.h" +#include "compress.h" #include "disk_groups.h" #include "opts.h" #include "super-io.h" @@ -268,6 +269,20 @@ void bch2_opt_to_text(struct printbuf *out, struct bch_fs *c, } } +int bch2_opt_check_may_set(struct bch_fs *c, int id, u64 v) +{ + int ret = 0; + + switch (id) { + case Opt_compression: + case Opt_background_compression: + ret = bch2_check_set_has_compressed_data(c, v); + break; + } + + return ret; +} + int bch2_parse_mount_opts(struct bch_opts *opts, char *options) { char *opt, *name, *val; diff --git a/fs/bcachefs/opts.h b/fs/bcachefs/opts.h index c65a8d13636d..bdf1e4fb606e 100644 --- a/fs/bcachefs/opts.h +++ b/fs/bcachefs/opts.h @@ -265,6 +265,7 @@ int bch2_opt_parse(struct bch_fs *, const struct bch_option *, const char *, u64 void bch2_opt_to_text(struct printbuf *, struct bch_fs *, const struct bch_option *, u64, unsigned); +int bch2_opt_check_may_set(struct bch_fs *, int, u64); int bch2_parse_mount_opts(struct bch_opts *, char *); /* inode opts: */ diff --git a/fs/bcachefs/super-io.c b/fs/bcachefs/super-io.c index d1fca0d649dc..a8d75c6add82 100644 --- a/fs/bcachefs/super-io.c +++ b/fs/bcachefs/super-io.c @@ -222,6 +222,10 @@ const char *bch2_sb_validate(struct bch_sb_handle *disk_sb) le64_to_cpu(sb->version) > BCH_SB_VERSION_MAX) return"Unsupported superblock version"; + if (sb->features[1] || + (le64_to_cpu(sb->features[0]) & (~0ULL << BCH_FEATURE_NR))) + return "Filesystem has incompatible features"; + if (le64_to_cpu(sb->version) < BCH_SB_VERSION_EXTENT_MAX) { SET_BCH_SB_ENCODED_EXTENT_MAX_BITS(sb, 7); SET_BCH_SB_POSIX_ACL(sb, 1); @@ -455,7 +459,7 @@ reread: if (le64_to_cpu(sb->sb->version) < BCH_SB_VERSION_MIN || le64_to_cpu(sb->sb->version) > BCH_SB_VERSION_MAX) - return"Unsupported superblock version"; + return "Unsupported superblock version"; bytes = vstruct_bytes(sb->sb); diff --git a/fs/bcachefs/sysfs.c b/fs/bcachefs/sysfs.c index c6a653ac2012..f90b8a43a82c 100644 --- a/fs/bcachefs/sysfs.c +++ b/fs/bcachefs/sysfs.c @@ -9,7 +9,6 @@ #include "bcachefs.h" #include "alloc_background.h" -#include "compress.h" #include "sysfs.h" #include "btree_cache.h" #include "btree_io.h" @@ -580,14 +579,9 @@ STORE(bch2_fs_opts_dir) if (ret < 0) return ret; - if (id == Opt_compression || - id == Opt_background_compression) { - int ret = bch2_check_set_has_compressed_data(c, v); - if (ret) { - mutex_unlock(&c->sb_lock); - return ret; - } - } + ret = bch2_opt_check_may_set(c, id, v); + if (ret < 0) + return ret; if (opt->set_sb != SET_NO_SB_OPT) { mutex_lock(&c->sb_lock); diff --git a/fs/bcachefs/xattr.c b/fs/bcachefs/xattr.c index ed62668bb155..31f3b981f6c3 100644 --- a/fs/bcachefs/xattr.c +++ b/fs/bcachefs/xattr.c @@ -2,7 +2,6 @@ #include "bcachefs.h" #include "bkey_methods.h" #include "btree_update.h" -#include "compress.h" #include "extents.h" #include "fs.h" #include "rebalance.h" @@ -430,12 +429,9 @@ static int bch2_xattr_bcachefs_set(const struct xattr_handler *handler, if (ret < 0) return ret; - if (s.id == Opt_compression || - s.id == Opt_background_compression) { - ret = bch2_check_set_has_compressed_data(c, s.v); - if (ret) - return ret; - } + ret = bch2_opt_check_may_set(c, s.id, s.v); + if (ret < 0) + return ret; s.defined = true; } else { |