]> git.sesse.net Git - bcachefs-tools-debian/commitdiff
Update bcachefs sources to 2724e115d2 bcachefs: Lots of option handling improvements
authorKent Overstreet <kent.overstreet@gmail.com>
Wed, 19 Dec 2018 20:20:44 +0000 (15:20 -0500)
committerKent Overstreet <kent.overstreet@gmail.com>
Wed, 19 Dec 2018 20:21:54 +0000 (15:21 -0500)
19 files changed:
.bcachefs_revision
cmd_debug.c
cmd_fsck.c
libbcachefs/bcachefs.h
libbcachefs/fs-ioctl.c
libbcachefs/fs.c
libbcachefs/fs.h
libbcachefs/io.c
libbcachefs/journal_io.c
libbcachefs/opts.c
libbcachefs/opts.h
libbcachefs/quota.h
libbcachefs/rebalance.c
libbcachefs/super.c
libbcachefs/sysfs.c
libbcachefs/tests.c
libbcachefs/util.c
libbcachefs/util.h
libbcachefs/xattr.c

index d41e3b03d22ef1cc9536f4784814bdff8452f73d..66897e5c0e044c7dd5d2e1fce19a3f4bfd84e459 100644 (file)
@@ -1 +1 @@
-57ea7773cb4368dc98ec68385c3d0941c246ad70
+2724e115d243043ee62d78883bec4035651d74ab
index a9d597741e1f629b33c60a630eaaf18f83ff9ad2..72eccd8048853ef7bdd727ac45179d269243848a 100644 (file)
@@ -292,7 +292,7 @@ int cmd_list(int argc, char *argv[])
                        opt_set(opts, norecovery, false);
                        break;
                case 'v':
-                       opt_set(opts, verbose_recovery, true);
+                       opt_set(opts, verbose, true);
                        break;
                case 'h':
                        list_keys_usage();
index d16760acfd3b363b54485f973e73d183fd5d6462..617cf25270253aeb1efdad128234f30d2e87bbb0 100644 (file)
@@ -45,7 +45,7 @@ int cmd_fsck(int argc, char *argv[])
                        /* force check, even if filesystem marked clean: */
                        break;
                case 'v':
-                       opt_set(opts, verbose_recovery, true);
+                       opt_set(opts, verbose, true);
                        break;
                case 'h':
                        usage();
index 5149e6eaf49e1518c6fa1ef0fcc1fc083b0e8bf0..3056f3bf4a4bf9fcd7355ec5d00c28fe4a9ce8f5 100644 (file)
 
 #define bch_verbose(c, fmt, ...)                                       \
 do {                                                                   \
-       if ((c)->opts.verbose_recovery)                                 \
+       if ((c)->opts.verbose)                                          \
                bch_info(c, fmt, ##__VA_ARGS__);                        \
 } while (0)
 
 #define pr_verbose_init(opts, fmt, ...)                                        \
 do {                                                                   \
-       if (opt_get(opts, verbose_init))                                \
+       if (opt_get(opts, verbose))                                     \
                pr_info(fmt, ##__VA_ARGS__);                            \
 } while (0)
 
index 7b9acafb949194c1444bebec6333c92f110dda56..d6cb21d690732b030442788866c7caca22f33d26 100644 (file)
@@ -103,19 +103,6 @@ static int bch2_ioc_fsgetxattr(struct bch_inode_info *inode,
        return copy_to_user(arg, &fa, sizeof(fa));
 }
 
-static int bch2_set_projid(struct bch_fs *c,
-                          struct bch_inode_info *inode,
-                          u32 projid)
-{
-       struct bch_qid qid = inode->ei_qid;
-
-       qid.q[QTYP_PRJ] = projid;
-
-       return bch2_fs_quota_transfer(c, inode, qid,
-                                     1 << QTYP_PRJ,
-                                     KEY_TYPE_QUOTA_PREALLOC);
-}
-
 static int fssetxattr_inode_update_fn(struct bch_inode_info *inode,
                                      struct bch_inode_unpacked *bi,
                                      void *p)
@@ -123,11 +110,7 @@ static int fssetxattr_inode_update_fn(struct bch_inode_info *inode,
        struct flags_set *s = p;
 
        if (s->projid != bi->bi_project) {
-               if (s->projid)
-                       bi->bi_fields_set |= 1U << Inode_opt_project;
-               else
-                       bi->bi_fields_set &= ~(1U << Inode_opt_project);
-
+               bi->bi_fields_set |= 1U << Inode_opt_project;
                bi->bi_project = s->projid;
        }
 
@@ -150,7 +133,10 @@ static int bch2_ioc_fssetxattr(struct bch_fs *c,
        if (fa.fsx_xflags)
                return -EOPNOTSUPP;
 
-       s.projid = fa.fsx_projid;
+       if (fa.fsx_projid >= U32_MAX)
+               return -EINVAL;
+
+       s.projid = fa.fsx_projid + 1;
 
        ret = mnt_want_write_file(file);
        if (ret)
@@ -163,7 +149,7 @@ static int bch2_ioc_fssetxattr(struct bch_fs *c,
        }
 
        mutex_lock(&inode->ei_update_lock);
-       ret = bch2_set_projid(c, inode, fa.fsx_projid);
+       ret = bch2_set_projid(c, inode, s.projid);
        if (ret)
                goto err_unlock;
 
index 300348b6648b59d46ae10f7176d518711bb19901..c7797338fe919c1d0d370a6747d8e9c1afa46c1d 100644 (file)
@@ -1604,7 +1604,7 @@ static int bch2_show_options(struct seq_file *seq, struct dentry *root)
                const struct bch_option *opt = &bch2_opt_table[i];
                u64 v = bch2_opt_get_by_id(&c->opts, i);
 
-               if (opt->mode < OPT_MOUNT)
+               if (!(opt->mode & OPT_MOUNT))
                        continue;
 
                if (v == bch2_opt_get_by_id(&bch2_opts_default, i))
index 7dc0453af2db42277a478562689ad52554006bff..9ac6fc87f69a22316577a833a4ec1ffefa12b325 100644 (file)
@@ -104,6 +104,19 @@ int bch2_fs_quota_transfer(struct bch_fs *,
                           unsigned,
                           enum quota_acct_mode);
 
+static inline int bch2_set_projid(struct bch_fs *c,
+                                 struct bch_inode_info *inode,
+                                 u32 projid)
+{
+       struct bch_qid qid = inode->ei_qid;
+
+       qid.q[QTYP_PRJ] = projid;
+
+       return bch2_fs_quota_transfer(c, inode, qid,
+                                     1 << QTYP_PRJ,
+                                     KEY_TYPE_QUOTA_PREALLOC);
+}
+
 struct inode *bch2_vfs_inode_get(struct bch_fs *, u64);
 
 /* returns 0 if we want to do the update, or error is passed up */
index ede1ac1b62d183b9a17001abab6bb56012a7b485..64637687bf40d860a40e46666440cab2a302dc40 100644 (file)
@@ -946,6 +946,7 @@ void bch2_write(struct closure *cl)
 
 struct promote_op {
        struct closure          cl;
+       struct rcu_head         rcu;
        u64                     start_time;
 
        struct rhash_head       hash;
@@ -999,7 +1000,7 @@ static void promote_free(struct bch_fs *c, struct promote_op *op)
                                     bch_promote_params);
        BUG_ON(ret);
        percpu_ref_put(&c->writes);
-       kfree(op);
+       kfree_rcu(op, rcu);
 }
 
 static void promote_done(struct closure *cl)
index 6c16aabf7096e77098884e2d27bad59bcfb3506f..52498627f70e4dbcf36eb53a63c1d1fe365a50af 100644 (file)
@@ -584,7 +584,7 @@ static void bch2_journal_read_device(struct closure *cl)
        while (ja->bucket_seq[ja->cur_idx] > min_seq &&
               ja->bucket_seq[ja->cur_idx] >
               ja->bucket_seq[(ja->cur_idx + 1) % ja->nr])
-               ja->cur_idx++;
+               ja->cur_idx = (ja->cur_idx + 1) % ja->nr;
 
        ja->sectors_free = 0;
 
index 4739f78262da4a69e818d4a76604da204952057f..7bf0f84cb69284bc0aaf38513800035819cb5110 100644 (file)
@@ -74,22 +74,22 @@ const char * const bch2_dev_state[] = {
 
 void bch2_opts_apply(struct bch_opts *dst, struct bch_opts src)
 {
-#define BCH_OPT(_name, ...)                                            \
+#define x(_name, ...)                                          \
        if (opt_defined(src, _name))                                    \
                opt_set(*dst, _name, src._name);
 
        BCH_OPTS()
-#undef BCH_OPT
+#undef x
 }
 
 bool bch2_opt_defined_by_id(const struct bch_opts *opts, enum bch_opt_id id)
 {
        switch (id) {
-#define BCH_OPT(_name, ...)                                            \
+#define x(_name, ...)                                          \
        case Opt_##_name:                                               \
                return opt_defined(*opts, _name);
        BCH_OPTS()
-#undef BCH_OPT
+#undef x
        default:
                BUG();
        }
@@ -98,11 +98,11 @@ bool bch2_opt_defined_by_id(const struct bch_opts *opts, enum bch_opt_id id)
 u64 bch2_opt_get_by_id(const struct bch_opts *opts, enum bch_opt_id id)
 {
        switch (id) {
-#define BCH_OPT(_name, ...)                                            \
+#define x(_name, ...)                                          \
        case Opt_##_name:                                               \
                return opts->_name;
        BCH_OPTS()
-#undef BCH_OPT
+#undef x
        default:
                BUG();
        }
@@ -111,12 +111,12 @@ u64 bch2_opt_get_by_id(const struct bch_opts *opts, enum bch_opt_id id)
 void bch2_opt_set_by_id(struct bch_opts *opts, enum bch_opt_id id, u64 v)
 {
        switch (id) {
-#define BCH_OPT(_name, ...)                                            \
+#define x(_name, ...)                                          \
        case Opt_##_name:                                               \
                opt_set(*opts, _name, v);                               \
                break;
        BCH_OPTS()
-#undef BCH_OPT
+#undef x
        default:
                BUG();
        }
@@ -130,11 +130,11 @@ struct bch_opts bch2_opts_from_sb(struct bch_sb *sb)
 {
        struct bch_opts opts = bch2_opts_empty();
 
-#define BCH_OPT(_name, _bits, _mode, _type, _sb_opt, _default)         \
+#define x(_name, _bits, _mode, _type, _sb_opt, ...)                    \
        if (_sb_opt != NO_SB_OPT)                                       \
                opt_set(opts, _name, _sb_opt(sb));
        BCH_OPTS()
-#undef BCH_OPT
+#undef x
 
        return opts;
 }
@@ -142,24 +142,27 @@ struct bch_opts bch2_opts_from_sb(struct bch_sb *sb)
 const struct bch_option bch2_opt_table[] = {
 #define OPT_BOOL()             .type = BCH_OPT_BOOL
 #define OPT_UINT(_min, _max)   .type = BCH_OPT_UINT, .min = _min, .max = _max
+#define OPT_SECTORS(_min, _max)        .type = BCH_OPT_SECTORS, .min = _min, .max = _max
 #define OPT_STR(_choices)      .type = BCH_OPT_STR, .choices = _choices
 #define OPT_FN(_fn)            .type = BCH_OPT_FN,                     \
                                .parse = _fn##_parse,                   \
                                .to_text = _fn##_to_text
 
-#define BCH_OPT(_name, _bits, _mode, _type, _sb_opt, _default)         \
+#define x(_name, _bits, _mode, _type, _sb_opt, _default, _hint, _help) \
        [Opt_##_name] = {                                               \
                .attr   = {                                             \
                        .name   = #_name,                               \
-                       .mode = _mode == OPT_RUNTIME ? 0644 : 0444,     \
+                       .mode = (_mode) & OPT_RUNTIME ? 0644 : 0444,    \
                },                                                      \
                .mode   = _mode,                                        \
+               .hint   = _hint,                                        \
+               .help   = _help,                                        \
                .set_sb = SET_##_sb_opt,                                \
                _type                                                   \
        },
 
        BCH_OPTS()
-#undef BCH_OPT
+#undef x
 };
 
 int bch2_opt_lookup(const char *name)
@@ -215,6 +218,19 @@ int bch2_opt_parse(struct bch_fs *c, const struct bch_option *opt,
                if (ret < 0)
                        return ret;
 
+               if (*res < opt->min || *res >= opt->max)
+                       return -ERANGE;
+               break;
+       case BCH_OPT_SECTORS:
+               ret = bch2_strtou64_h(val, res);
+               if (ret < 0)
+                       return ret;
+
+               if (*res & 511)
+                       return -EINVAL;
+
+               *res >>= 9;
+
                if (*res < opt->min || *res >= opt->max)
                        return -ERANGE;
                break;
@@ -255,6 +271,9 @@ void bch2_opt_to_text(struct printbuf *out, struct bch_fs *c,
        case BCH_OPT_UINT:
                pr_buf(out, "%lli", v);
                break;
+       case BCH_OPT_SECTORS:
+               bch2_hprint(out, v);
+               break;
        case BCH_OPT_STR:
                if (flags & OPT_SHOW_FULL_LIST)
                        bch2_string_opt_to_text(out, opt->choices, v);
@@ -344,7 +363,7 @@ int bch2_parse_mount_opts(struct bch_opts *opts, char *options)
                                goto no_val;
                }
 
-               if (bch2_opt_table[id].mode < OPT_MOUNT)
+               if (!(bch2_opt_table[id].mode & OPT_MOUNT))
                        goto bad_opt;
 
                if (id == Opt_acl &&
index 8a4e2e5072b07cb2c3f28bb14e08971de276067d..f2ce0e5fa8254158919fd79af2df569ae5c40060 100644 (file)
@@ -31,22 +31,25 @@ extern const char * const bch2_dev_state[];
 /* dummy option, for options that aren't stored in the superblock */
 LE64_BITMASK(NO_SB_OPT,                struct bch_sb, flags[0], 0, 0);
 
+/* When can be set: */
 enum opt_mode {
-       OPT_INTERNAL,
-       OPT_FORMAT,
-       OPT_MOUNT,
-       OPT_RUNTIME,
+       OPT_FORMAT      = (1 << 0),
+       OPT_MOUNT       = (1 << 1),
+       OPT_RUNTIME     = (1 << 2),
+       OPT_INODE       = (1 << 3),
+       OPT_DEVICE      = (1 << 4),
 };
 
 enum opt_type {
        BCH_OPT_BOOL,
        BCH_OPT_UINT,
+       BCH_OPT_SECTORS,
        BCH_OPT_STR,
        BCH_OPT_FN,
 };
 
 /**
- * BCH_OPT(name, type, in mem type, mode, sb_opt)
+ * x(name, shortopt, type, in mem type, mode, sb_opt)
  *
  * @name       - name of mount option, sysfs attribute, and struct bch_opts
  *               member
@@ -65,147 +68,246 @@ enum opt_type {
  */
 
 #define BCH_OPTS()                                                     \
-       BCH_OPT(block_size,             u16,    OPT_FORMAT,             \
-               OPT_UINT(1, 128),                                       \
-               BCH_SB_BLOCK_SIZE,              8)                      \
-       BCH_OPT(btree_node_size,        u16,    OPT_FORMAT,             \
-               OPT_UINT(1, 128),                                       \
-               BCH_SB_BTREE_NODE_SIZE,         512)                    \
-       BCH_OPT(errors,                 u8,     OPT_RUNTIME,            \
-               OPT_STR(bch2_error_actions),                            \
-               BCH_SB_ERROR_ACTION,            BCH_ON_ERROR_RO)        \
-       BCH_OPT(metadata_replicas,      u8,     OPT_RUNTIME,            \
-               OPT_UINT(1, BCH_REPLICAS_MAX),                          \
-               BCH_SB_META_REPLICAS_WANT,      1)                      \
-       BCH_OPT(data_replicas,          u8,     OPT_RUNTIME,            \
-               OPT_UINT(1, BCH_REPLICAS_MAX),                          \
-               BCH_SB_DATA_REPLICAS_WANT,      1)                      \
-       BCH_OPT(metadata_replicas_required, u8, OPT_MOUNT,              \
-               OPT_UINT(1, BCH_REPLICAS_MAX),                          \
-               BCH_SB_META_REPLICAS_REQ,       1)                      \
-       BCH_OPT(data_replicas_required, u8,     OPT_MOUNT,              \
-               OPT_UINT(1, BCH_REPLICAS_MAX),                          \
-               BCH_SB_DATA_REPLICAS_REQ,       1)                      \
-       BCH_OPT(metadata_checksum,      u8,     OPT_RUNTIME,            \
-               OPT_STR(bch2_csum_types),                               \
-               BCH_SB_META_CSUM_TYPE,          BCH_CSUM_OPT_CRC32C)    \
-       BCH_OPT(data_checksum,          u8,     OPT_RUNTIME,            \
-               OPT_STR(bch2_csum_types),                               \
-               BCH_SB_DATA_CSUM_TYPE,          BCH_CSUM_OPT_CRC32C)    \
-       BCH_OPT(compression,            u8,     OPT_RUNTIME,            \
-               OPT_STR(bch2_compression_types),                        \
-               BCH_SB_COMPRESSION_TYPE,        BCH_COMPRESSION_OPT_NONE)\
-       BCH_OPT(background_compression, u8,     OPT_RUNTIME,            \
-               OPT_STR(bch2_compression_types),                        \
-               BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_NONE)\
-       BCH_OPT(str_hash,               u8,     OPT_RUNTIME,            \
-               OPT_STR(bch2_str_hash_types),                           \
-               BCH_SB_STR_HASH_TYPE,           BCH_STR_HASH_SIPHASH)   \
-       BCH_OPT(foreground_target,      u16,    OPT_RUNTIME,            \
-               OPT_FN(bch2_opt_target),                                \
-               BCH_SB_FOREGROUND_TARGET,       0)                      \
-       BCH_OPT(background_target,      u16,    OPT_RUNTIME,            \
-               OPT_FN(bch2_opt_target),                                \
-               BCH_SB_BACKGROUND_TARGET,       0)                      \
-       BCH_OPT(promote_target,         u16,    OPT_RUNTIME,            \
-               OPT_FN(bch2_opt_target),                                \
-               BCH_SB_PROMOTE_TARGET,  0)                              \
-       BCH_OPT(erasure_code,           u16,    OPT_RUNTIME,            \
-               OPT_BOOL(),                                             \
-               BCH_SB_ERASURE_CODE,            false)                  \
-       BCH_OPT(inodes_32bit,           u8,     OPT_RUNTIME,            \
-               OPT_BOOL(),                                             \
-               BCH_SB_INODE_32BIT,             false)                  \
-       BCH_OPT(gc_reserve_percent,     u8,     OPT_RUNTIME,            \
-               OPT_UINT(5, 21),                                        \
-               BCH_SB_GC_RESERVE,              8)                      \
-       BCH_OPT(gc_reserve_bytes,       u64,    OPT_RUNTIME,            \
-               OPT_UINT(0, U64_MAX),                                   \
-               BCH_SB_GC_RESERVE_BYTES,        0)                      \
-       BCH_OPT(root_reserve_percent,   u8,     OPT_MOUNT,              \
-               OPT_UINT(0, 100),                                       \
-               BCH_SB_ROOT_RESERVE,            0)                      \
-       BCH_OPT(wide_macs,              u8,     OPT_RUNTIME,            \
-               OPT_BOOL(),                                             \
-               BCH_SB_128_BIT_MACS,            false)                  \
-       BCH_OPT(acl,                    u8,     OPT_MOUNT,              \
-               OPT_BOOL(),                                             \
-               BCH_SB_POSIX_ACL,               true)                   \
-       BCH_OPT(usrquota,               u8,     OPT_MOUNT,              \
-               OPT_BOOL(),                                             \
-               BCH_SB_USRQUOTA,                false)                  \
-       BCH_OPT(grpquota,               u8,     OPT_MOUNT,              \
-               OPT_BOOL(),                                             \
-               BCH_SB_GRPQUOTA,                false)                  \
-       BCH_OPT(prjquota,               u8,     OPT_MOUNT,              \
-               OPT_BOOL(),                                             \
-               BCH_SB_PRJQUOTA,                false)                  \
-       BCH_OPT(degraded,               u8,     OPT_MOUNT,              \
-               OPT_BOOL(),                                             \
-               NO_SB_OPT,                      false)                  \
-       BCH_OPT(discard,                u8,     OPT_MOUNT,              \
-               OPT_BOOL(),                                             \
-               NO_SB_OPT,                      false)                  \
-       BCH_OPT(verbose_recovery,       u8,     OPT_MOUNT,              \
-               OPT_BOOL(),                                             \
-               NO_SB_OPT,                      false)                  \
-       BCH_OPT(verbose_init,           u8,     OPT_MOUNT,              \
-               OPT_BOOL(),                                             \
-               NO_SB_OPT,                      false)                  \
-       BCH_OPT(journal_flush_disabled, u8,     OPT_RUNTIME,            \
-               OPT_BOOL(),                                             \
-               NO_SB_OPT,                      false)                  \
-       BCH_OPT(fsck,                   u8,     OPT_MOUNT,              \
-               OPT_BOOL(),                                             \
-               NO_SB_OPT,                      true)                   \
-       BCH_OPT(fix_errors,             u8,     OPT_MOUNT,              \
-               OPT_BOOL(),                                             \
-               NO_SB_OPT,                      false)                  \
-       BCH_OPT(nochanges,              u8,     OPT_MOUNT,              \
-               OPT_BOOL(),                                             \
-               NO_SB_OPT,                      false)                  \
-       BCH_OPT(noreplay,               u8,     OPT_MOUNT,              \
-               OPT_BOOL(),                                             \
-               NO_SB_OPT,                      false)                  \
-       BCH_OPT(norecovery,             u8,     OPT_MOUNT,              \
-               OPT_BOOL(),                                             \
-               NO_SB_OPT,                      false)                  \
-       BCH_OPT(noexcl,                 u8,     OPT_MOUNT,              \
-               OPT_BOOL(),                                             \
-               NO_SB_OPT,                      false)                  \
-       BCH_OPT(sb,                     u64,    OPT_MOUNT,              \
-               OPT_UINT(0, S64_MAX),                                   \
-               NO_SB_OPT,                      BCH_SB_SECTOR)          \
-       BCH_OPT(read_only,              u8,     OPT_INTERNAL,           \
-               OPT_BOOL(),                                             \
-               NO_SB_OPT,                      false)                  \
-       BCH_OPT(nostart,                u8,     OPT_INTERNAL,           \
-               OPT_BOOL(),                                             \
-               NO_SB_OPT,                      false)                  \
-       BCH_OPT(version_upgrade,        u8,     OPT_MOUNT,              \
-               OPT_BOOL(),                                             \
-               NO_SB_OPT,                      false)                  \
-       BCH_OPT(project,                u8,     OPT_INTERNAL,           \
-               OPT_BOOL(),                                             \
-               NO_SB_OPT,                      false)                  \
+       x(block_size,                   u16,                            \
+         OPT_FORMAT,                                                   \
+         OPT_SECTORS(1, 128),                                          \
+         BCH_SB_BLOCK_SIZE,            8,                              \
+         "size",       NULL)                                           \
+       x(btree_node_size,              u16,                            \
+         OPT_FORMAT,                                                   \
+         OPT_SECTORS(1, 128),                                          \
+         BCH_SB_BTREE_NODE_SIZE,       512,                            \
+         "size",       "Btree node size, default 256k")                \
+       x(errors,                       u8,                             \
+         OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                             \
+         OPT_STR(bch2_error_actions),                                  \
+         BCH_SB_ERROR_ACTION,          BCH_ON_ERROR_RO,                \
+         NULL,         "Action to take on filesystem error")           \
+       x(metadata_replicas,            u8,                             \
+         OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                             \
+         OPT_UINT(1, BCH_REPLICAS_MAX),                                \
+         BCH_SB_META_REPLICAS_WANT,    1,                              \
+         "#",          "Number of metadata replicas")                  \
+       x(data_replicas,                u8,                             \
+         OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE,                   \
+         OPT_UINT(1, BCH_REPLICAS_MAX),                                \
+         BCH_SB_DATA_REPLICAS_WANT,    1,                              \
+         "#",          "Number of data replicas")                      \
+       x(metadata_replicas_required, u8,                               \
+         OPT_FORMAT|OPT_MOUNT,                                         \
+         OPT_UINT(1, BCH_REPLICAS_MAX),                                \
+         BCH_SB_META_REPLICAS_REQ,     1,                              \
+         "#",          NULL)                                           \
+       x(data_replicas_required,       u8,                             \
+         OPT_FORMAT|OPT_MOUNT,                                         \
+         OPT_UINT(1, BCH_REPLICAS_MAX),                                \
+         BCH_SB_DATA_REPLICAS_REQ,     1,                              \
+         "#",          NULL)                                           \
+       x(metadata_checksum,            u8,                             \
+         OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                             \
+         OPT_STR(bch2_csum_types),                                     \
+         BCH_SB_META_CSUM_TYPE,        BCH_CSUM_OPT_CRC32C,            \
+         NULL,         NULL)                                           \
+       x(data_checksum,                u8,                             \
+         OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE,                   \
+         OPT_STR(bch2_csum_types),                                     \
+         BCH_SB_DATA_CSUM_TYPE,        BCH_CSUM_OPT_CRC32C,            \
+         NULL,         NULL)                                           \
+       x(compression,                  u8,                             \
+         OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE,                   \
+         OPT_STR(bch2_compression_types),                              \
+         BCH_SB_COMPRESSION_TYPE,      BCH_COMPRESSION_OPT_NONE,       \
+         NULL,         NULL)                                           \
+       x(background_compression,       u8,                             \
+         OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE,                   \
+         OPT_STR(bch2_compression_types),                              \
+         BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_NONE,  \
+         NULL,         NULL)                                           \
+       x(str_hash,                     u8,                             \
+         OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                             \
+         OPT_STR(bch2_str_hash_types),                                 \
+         BCH_SB_STR_HASH_TYPE,         BCH_STR_HASH_SIPHASH,           \
+         NULL,         "Hash function for directory entries and xattrs")\
+       x(foreground_target,            u16,                            \
+         OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE,                   \
+         OPT_FN(bch2_opt_target),                                      \
+         BCH_SB_FOREGROUND_TARGET,     0,                              \
+         "(target)",   "Device or disk group for foreground writes")   \
+       x(background_target,            u16,                            \
+         OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE,                   \
+         OPT_FN(bch2_opt_target),                                      \
+         BCH_SB_BACKGROUND_TARGET,     0,                              \
+         "(target)",   "Device or disk group to move data to in the background")\
+       x(promote_target,               u16,                            \
+         OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE,                   \
+         OPT_FN(bch2_opt_target),                                      \
+         BCH_SB_PROMOTE_TARGET,        0,                              \
+         "(target)",   "Device or disk group to promote data to on read")\
+       x(erasure_code,                 u16,                            \
+         OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE,                   \
+         OPT_BOOL(),                                                   \
+         BCH_SB_ERASURE_CODE,          false,                          \
+         NULL,         "Enable erasure coding (DO NOT USE YET)")       \
+       x(inodes_32bit,                 u8,                             \
+         OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                             \
+         OPT_BOOL(),                                                   \
+         BCH_SB_INODE_32BIT,           false,                          \
+         NULL,         "Constrain inode numbers to 32 bits")           \
+       x(gc_reserve_percent,           u8,                             \
+         OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                             \
+         OPT_UINT(5, 21),                                              \
+         BCH_SB_GC_RESERVE,            8,                              \
+         "%",          "Percentage of disk space to reserve for copygc")\
+       x(gc_reserve_bytes,             u64,                            \
+         OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                             \
+         OPT_SECTORS(0, U64_MAX),                                      \
+         BCH_SB_GC_RESERVE_BYTES,      0,                              \
+         "%",          "Amount of disk space to reserve for copygc\n"  \
+                       "Takes precedence over gc_reserve_percent if set")\
+       x(root_reserve_percent,         u8,                             \
+         OPT_FORMAT|OPT_MOUNT,                                         \
+         OPT_UINT(0, 100),                                             \
+         BCH_SB_ROOT_RESERVE,          0,                              \
+         "%",          "Percentage of disk space to reserve for superuser")\
+       x(wide_macs,                    u8,                             \
+         OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                             \
+         OPT_BOOL(),                                                   \
+         BCH_SB_128_BIT_MACS,          false,                          \
+         NULL,         "Store full 128 bits of cryptographic MACs, instead of 80")\
+       x(acl,                          u8,                             \
+         OPT_FORMAT|OPT_MOUNT,                                         \
+         OPT_BOOL(),                                                   \
+         BCH_SB_POSIX_ACL,             true,                           \
+         NULL,         "Enable POSIX acls")                            \
+       x(usrquota,                     u8,                             \
+         OPT_FORMAT|OPT_MOUNT,                                         \
+         OPT_BOOL(),                                                   \
+         BCH_SB_USRQUOTA,              false,                          \
+         NULL,         "Enable user quotas")                           \
+       x(grpquota,                     u8,                             \
+         OPT_FORMAT|OPT_MOUNT,                                         \
+         OPT_BOOL(),                                                   \
+         BCH_SB_GRPQUOTA,              false,                          \
+         NULL,         "Enable group quotas")                          \
+       x(prjquota,                     u8,                             \
+         OPT_FORMAT|OPT_MOUNT,                                         \
+         OPT_BOOL(),                                                   \
+         BCH_SB_PRJQUOTA,              false,                          \
+         NULL,         "Enable project quotas")                        \
+       x(degraded,                     u8,                             \
+         OPT_MOUNT,                                                    \
+         OPT_BOOL(),                                                   \
+         NO_SB_OPT,                    false,                          \
+         NULL,         "Allow mounting in degraded mode")              \
+       x(discard,                      u8,                             \
+         OPT_MOUNT|OPT_DEVICE,                                         \
+         OPT_BOOL(),                                                   \
+         NO_SB_OPT,                    false,                          \
+         NULL,         "Enable discard/TRIM support")                  \
+       x(verbose,                      u8,                             \
+         OPT_MOUNT,                                                    \
+         OPT_BOOL(),                                                   \
+         NO_SB_OPT,                    false,                          \
+         NULL,         "Extra debugging information during mount/recovery")\
+       x(journal_flush_disabled,       u8,                             \
+         OPT_MOUNT|OPT_RUNTIME,                                        \
+         OPT_BOOL(),                                                   \
+         NO_SB_OPT,                    false,                          \
+         NULL,         "Disable journal flush on sync/fsync\n"         \
+                       "If enabled, writes can be lost, but only since the\n"\
+                       "last journal write (default 1 second)")        \
+       x(fsck,                         u8,                             \
+         OPT_MOUNT,                                                    \
+         OPT_BOOL(),                                                   \
+         NO_SB_OPT,                    true,                           \
+         NULL,         "Run fsck on mount")                            \
+       x(fix_errors,                   u8,                             \
+         OPT_MOUNT,                                                    \
+         OPT_BOOL(),                                                   \
+         NO_SB_OPT,                    false,                          \
+         NULL,         "Fix errors during fsck without asking")        \
+       x(nochanges,                    u8,                             \
+         OPT_MOUNT,                                                    \
+         OPT_BOOL(),                                                   \
+         NO_SB_OPT,                    false,                          \
+         NULL,         "Super read only mode - no writes at all will be issued,\n"\
+                       "even if we have to replay the journal")        \
+       x(noreplay,                     u8,                             \
+         OPT_MOUNT,                                                    \
+         OPT_BOOL(),                                                   \
+         NO_SB_OPT,                    false,                          \
+         NULL,         "Don't replay the journal (only for internal tools)")\
+       x(norecovery,                   u8,                             \
+         OPT_MOUNT,                                                    \
+         OPT_BOOL(),                                                   \
+         NO_SB_OPT,                    false,                          \
+         NULL,         NULL)                                           \
+       x(noexcl,                       u8,                             \
+         OPT_MOUNT,                                                    \
+         OPT_BOOL(),                                                   \
+         NO_SB_OPT,                    false,                          \
+         NULL,         "Don't open device in exclusive mode")          \
+       x(sb,                           u64,                            \
+         OPT_MOUNT,                                                    \
+         OPT_UINT(0, S64_MAX),                                         \
+         NO_SB_OPT,                    BCH_SB_SECTOR,                  \
+         "offset",     "Sector offset of superblock")                  \
+       x(read_only,                    u8,                             \
+         0,                                                            \
+         OPT_BOOL(),                                                   \
+         NO_SB_OPT,                    false,                          \
+         NULL,         NULL)                                           \
+       x(nostart,                      u8,                             \
+         0,                                                            \
+         OPT_BOOL(),                                                   \
+         NO_SB_OPT,                    false,                          \
+         NULL,         "Don\'t start filesystem, only open devices")   \
+       x(version_upgrade,              u8,                             \
+         OPT_MOUNT,                                                    \
+         OPT_BOOL(),                                                   \
+         NO_SB_OPT,                    false,                          \
+         NULL,         "Set superblock to latest version,\n"           \
+                       "allowing any new features to be used")         \
+       x(project,                      u8,                             \
+         OPT_INODE,                                                    \
+         OPT_BOOL(),                                                   \
+         NO_SB_OPT,                    false,                          \
+         NULL,         NULL)                                           \
+       x(fs_size,                      u64,                            \
+         OPT_DEVICE,                                                   \
+         OPT_SECTORS(0, S64_MAX),                                      \
+         NO_SB_OPT,                    0,                              \
+         "size",       "Size of filesystem on device")                 \
+       x(bucket,                       u32,                            \
+         OPT_DEVICE,                                                   \
+         OPT_SECTORS(0, S64_MAX),                                      \
+         NO_SB_OPT,                    0,                              \
+         "size",       "Size of filesystem on device")                 \
+       x(durability,                   u8,                             \
+         OPT_DEVICE,                                                   \
+         OPT_UINT(0, BCH_REPLICAS_MAX),                                \
+         NO_SB_OPT,                    1,                              \
+         "n",          "Data written to this device will be considered\n"\
+                       "to have already been replicated n times")
+
 
 struct bch_opts {
-#define BCH_OPT(_name, _bits, ...)     unsigned _name##_defined:1;
+#define x(_name, _bits, ...)   unsigned _name##_defined:1;
        BCH_OPTS()
-#undef BCH_OPT
+#undef x
 
-#define BCH_OPT(_name, _bits, ...)     _bits   _name;
+#define x(_name, _bits, ...)   _bits   _name;
        BCH_OPTS()
-#undef BCH_OPT
+#undef x
 };
 
 static const struct bch_opts bch2_opts_default = {
-#define BCH_OPT(_name, _bits, _mode, _type, _sb_opt, _default)         \
+#define x(_name, _bits, _mode, _type, _sb_opt, _default, ...)          \
        ._name##_defined = true,                                        \
        ._name = _default,                                              \
 
        BCH_OPTS()
-#undef BCH_OPT
+#undef x
 };
 
 #define opt_defined(_opts, _name)      ((_opts)._name##_defined)
@@ -227,9 +329,9 @@ static inline struct bch_opts bch2_opts_empty(void)
 void bch2_opts_apply(struct bch_opts *, struct bch_opts);
 
 enum bch_opt_id {
-#define BCH_OPT(_name, ...)    Opt_##_name,
+#define x(_name, ...)  Opt_##_name,
        BCH_OPTS()
-#undef BCH_OPT
+#undef x
        bch2_opts_nr
 };
 
@@ -255,6 +357,9 @@ struct bch_option {
        };
        };
 
+       const char              *hint;
+       const char              *help;
+
 };
 
 extern const struct bch_option bch2_opt_table[];
index eabb94c143a8457e04af7de6bd9583018a6bf412..34b4a0f0ae77ca94001402b5b0d4d6bd996a28c2 100644 (file)
@@ -19,7 +19,7 @@ static inline struct bch_qid bch_qid(struct bch_inode_unpacked *u)
        return (struct bch_qid) {
                .q[QTYP_USR] = u->bi_uid,
                .q[QTYP_GRP] = u->bi_gid,
-               .q[QTYP_PRJ] = u->bi_project,
+               .q[QTYP_PRJ] = u->bi_project ? u->bi_project - 1 : 0,
        };
 }
 
@@ -55,7 +55,8 @@ static inline int bch2_quota_acct(struct bch_fs *c, struct bch_qid qid,
 
 static inline int bch2_quota_transfer(struct bch_fs *c, unsigned qtypes,
                                      struct bch_qid dst,
-                                     struct bch_qid src, u64 space)
+                                     struct bch_qid src, u64 space,
+                                     enum quota_acct_mode mode)
 {
        return 0;
 }
index dc6ca94dc556ef63d1ca39b8c03319a0a13dcd74..768c02845daf8311b5a7eeb7492087d394201d17 100644 (file)
@@ -262,13 +262,13 @@ ssize_t bch2_rebalance_work_show(struct bch_fs *c, char *buf)
        struct rebalance_work w = rebalance_work(c);
        char h1[21], h2[21];
 
-       bch2_hprint(h1, w.dev_most_full_work << 9);
-       bch2_hprint(h2, w.dev_most_full_capacity << 9);
+       bch2_hprint(&PBUF(h1), w.dev_most_full_work << 9);
+       bch2_hprint(&PBUF(h2), w.dev_most_full_capacity << 9);
        pr_buf(&out, "fullest_dev (%i):\t%s/%s\n",
               w.dev_most_full_idx, h1, h2);
 
-       bch2_hprint(h1, w.total_work << 9);
-       bch2_hprint(h2, c->capacity << 9);
+       bch2_hprint(&PBUF(h1), w.total_work << 9);
+       bch2_hprint(&PBUF(h2), c->capacity << 9);
        pr_buf(&out, "total work:\t\t%s/%s\n", h1, h2);
 
        pr_buf(&out, "rate:\t\t\t%u\n", r->pd.rate.rate);
@@ -278,7 +278,7 @@ ssize_t bch2_rebalance_work_show(struct bch_fs *c, char *buf)
                pr_buf(&out, "waiting\n");
                break;
        case REBALANCE_THROTTLED:
-               bch2_hprint(h1,
+               bch2_hprint(&PBUF(h1),
                            (r->throttled_until_iotime -
                             atomic_long_read(&c->io_clock[WRITE].now)) << 9);
                pr_buf(&out, "throttled for %lu sec or %s io\n",
index 0212832a7e8a6e9be0c93abdd3a8aed8f4c1f62f..82a0bf0729b92de8303989ace335778b6547fdc0 100644 (file)
@@ -1344,7 +1344,8 @@ int bch2_dev_remove(struct bch_fs *c, struct bch_dev *ca, int flags)
        mutex_unlock(&c->state_lock);
        return 0;
 err:
-       if (ca->mi.state == BCH_MEMBER_STATE_RW)
+       if (ca->mi.state == BCH_MEMBER_STATE_RW &&
+           !percpu_ref_is_zero(&ca->io_ref))
                __bch2_dev_read_write(c, ca);
        mutex_unlock(&c->state_lock);
        return ret;
index 883165196833ec698ae630aa6362c7bfba5b0308..316f827fa4907a4ff7fd771062b14638e807e6be 100644 (file)
@@ -72,9 +72,10 @@ do {                                                                 \
 #define sysfs_hprint(file, val)                                                \
 do {                                                                   \
        if (attr == &sysfs_ ## file) {                                  \
-               ssize_t ret = bch2_hprint(buf, val);                    \
-               strcat(buf, "\n");                                      \
-               return ret + 1;                                         \
+               struct printbuf out = _PBUF(buf, PAGE_SIZE);            \
+               bch2_hprint(&out, val);                                 \
+               pr_buf(&out, "\n");                                     \
+               return out.pos - buf;                                   \
        }                                                               \
 } while (0)
 
@@ -657,7 +658,7 @@ int bch2_opts_create_sysfs_files(struct kobject *kobj)
        for (i = bch2_opt_table;
             i < bch2_opt_table + bch2_opts_nr;
             i++) {
-               if (i->mode == OPT_INTERNAL)
+               if (!(i->mode & (OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME)))
                        continue;
 
                ret = sysfs_create_file(kobj, &i->attr);
index 24de979bdfb67484a67d26983c547e36563f7182..0b4a114390c8b13eb98328904d0204eccf248c1a 100644 (file)
@@ -618,8 +618,8 @@ void bch2_btree_perf_test(struct bch_fs *c, const char *testname,
        time = j.finish - j.start;
 
        scnprintf(name_buf, sizeof(name_buf), "%s:", testname);
-       bch2_hprint(nr_buf, nr);
-       bch2_hprint(per_sec_buf, nr * NSEC_PER_SEC / time);
+       bch2_hprint(&PBUF(nr_buf), nr);
+       bch2_hprint(&PBUF(per_sec_buf), nr * NSEC_PER_SEC / time);
        printk(KERN_INFO "%-12s %s with %u threads in %5llu sec, %5llu nsec per iter, %5s per sec\n",
                name_buf, nr_buf, nr_threads,
                time / NSEC_PER_SEC,
index bd0247cb68f62a23abc5ad377d019972ac3b5d5b..80d081861387fce850775422e33338571d9a9145 100644 (file)
@@ -99,10 +99,10 @@ STRTO_H(strtoint, int)
 STRTO_H(strtouint, unsigned int)
 STRTO_H(strtoll, long long)
 STRTO_H(strtoull, unsigned long long)
+STRTO_H(strtou64, u64)
 
-ssize_t bch2_hprint(char *buf, s64 v)
+void bch2_hprint(struct printbuf *buf, s64 v)
 {
-       char dec[4] = "";
        int u, t = 0;
 
        for (u = 0; v >= 1024 || v <= -1024; u++) {
@@ -110,17 +110,16 @@ ssize_t bch2_hprint(char *buf, s64 v)
                v >>= 10;
        }
 
-       if (!u)
-               return sprintf(buf, "%lli", v);
+       pr_buf(buf, "%lli", v);
 
        /*
         * 103 is magic: t is in the range [-1023, 1023] and we want
         * to turn it into [-9, 9]
         */
-       if (v < 100 && v > -100)
-               scnprintf(dec, sizeof(dec), ".%i", t / 103);
-
-       return sprintf(buf, "%lli%s%c", v, dec, si_units[u]);
+       if (u && v < 100 && v > -100)
+               pr_buf(buf, ".%i", t / 103);
+       if (u)
+               pr_buf(buf, "%c", si_units[u]);
 }
 
 void bch2_string_opt_to_text(struct printbuf *out,
@@ -480,12 +479,12 @@ size_t bch2_pd_controller_print_debug(struct bch_pd_controller *pd, char *buf)
        char change[21];
        s64 next_io;
 
-       bch2_hprint(rate,       pd->rate.rate);
-       bch2_hprint(actual,     pd->last_actual);
-       bch2_hprint(target,     pd->last_target);
-       bch2_hprint(proportional, pd->last_proportional);
-       bch2_hprint(derivative, pd->last_derivative);
-       bch2_hprint(change,     pd->last_change);
+       bch2_hprint(&PBUF(rate),        pd->rate.rate);
+       bch2_hprint(&PBUF(actual),      pd->last_actual);
+       bch2_hprint(&PBUF(target),      pd->last_target);
+       bch2_hprint(&PBUF(proportional), pd->last_proportional);
+       bch2_hprint(&PBUF(derivative),  pd->last_derivative);
+       bch2_hprint(&PBUF(change),      pd->last_change);
 
        next_io = div64_s64(pd->rate.next - local_clock(), NSEC_PER_MSEC);
 
index 54392957381bb431f233d3e9b9284a5d4b3c716b..905b24f29d1d1ab3b52320eaab0b2b8de8ca074a 100644 (file)
@@ -283,6 +283,7 @@ int bch2_strtoint_h(const char *, int *);
 int bch2_strtouint_h(const char *, unsigned int *);
 int bch2_strtoll_h(const char *, long long *);
 int bch2_strtoull_h(const char *, unsigned long long *);
+int bch2_strtou64_h(const char *, u64 *);
 
 static inline int bch2_strtol_h(const char *cp, long *res)
 {
@@ -351,7 +352,7 @@ static inline int bch2_strtoul_h(const char *cp, long *res)
                 : type_is(var, char *)         ? "%s\n"                \
                 : "%i\n", var)
 
-ssize_t bch2_hprint(char *buf, s64 v);
+void bch2_hprint(struct printbuf *, s64);
 
 bool bch2_is_zero(const void *, size_t);
 
index 407177b25e242ebb3f6ceb32a30f477c1c782486..4a4dba7256894522bd14220d7931cb8279fca335 100644 (file)
@@ -512,7 +512,14 @@ static int bch2_xattr_bcachefs_set(const struct xattr_handler *handler,
        }
 
        mutex_lock(&inode->ei_update_lock);
+       if (inode_opt_id == Inode_opt_project) {
+               ret = bch2_set_projid(c, inode, s.v);
+               if (ret)
+                       goto err;
+       }
+
        ret = bch2_write_inode(c, inode, inode_opt_set_fn, &s, 0);
+err:
        mutex_unlock(&inode->ei_update_lock);
 
        if (value &&