Commit 0b847a19 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Lots of option handling improvements

Add helptext to option definitions - so  we can unify the option
handling with the format command
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 2fab25cd
...@@ -230,13 +230,13 @@ ...@@ -230,13 +230,13 @@
#define bch_verbose(c, fmt, ...) \ #define bch_verbose(c, fmt, ...) \
do { \ do { \
if ((c)->opts.verbose_recovery) \ if ((c)->opts.verbose) \
bch_info(c, fmt, ##__VA_ARGS__); \ bch_info(c, fmt, ##__VA_ARGS__); \
} while (0) } while (0)
#define pr_verbose_init(opts, fmt, ...) \ #define pr_verbose_init(opts, fmt, ...) \
do { \ do { \
if (opt_get(opts, verbose_init)) \ if (opt_get(opts, verbose)) \
pr_info(fmt, ##__VA_ARGS__); \ pr_info(fmt, ##__VA_ARGS__); \
} while (0) } while (0)
......
...@@ -1690,7 +1690,7 @@ static int bch2_show_options(struct seq_file *seq, struct dentry *root) ...@@ -1690,7 +1690,7 @@ static int bch2_show_options(struct seq_file *seq, struct dentry *root)
const struct bch_option *opt = &bch2_opt_table[i]; const struct bch_option *opt = &bch2_opt_table[i];
u64 v = bch2_opt_get_by_id(&c->opts, i); u64 v = bch2_opt_get_by_id(&c->opts, i);
if (opt->mode < OPT_MOUNT) if (!(opt->mode & OPT_MOUNT))
continue; continue;
if (v == bch2_opt_get_by_id(&bch2_opts_default, i)) if (v == bch2_opt_get_by_id(&bch2_opts_default, i))
......
...@@ -75,22 +75,22 @@ const char * const bch2_dev_state[] = { ...@@ -75,22 +75,22 @@ const char * const bch2_dev_state[] = {
void bch2_opts_apply(struct bch_opts *dst, struct bch_opts src) void bch2_opts_apply(struct bch_opts *dst, struct bch_opts src)
{ {
#define BCH_OPT(_name, ...) \ #define x(_name, ...) \
if (opt_defined(src, _name)) \ if (opt_defined(src, _name)) \
opt_set(*dst, _name, src._name); opt_set(*dst, _name, src._name);
BCH_OPTS() BCH_OPTS()
#undef BCH_OPT #undef x
} }
bool bch2_opt_defined_by_id(const struct bch_opts *opts, enum bch_opt_id id) bool bch2_opt_defined_by_id(const struct bch_opts *opts, enum bch_opt_id id)
{ {
switch (id) { switch (id) {
#define BCH_OPT(_name, ...) \ #define x(_name, ...) \
case Opt_##_name: \ case Opt_##_name: \
return opt_defined(*opts, _name); return opt_defined(*opts, _name);
BCH_OPTS() BCH_OPTS()
#undef BCH_OPT #undef x
default: default:
BUG(); BUG();
} }
...@@ -99,11 +99,11 @@ bool bch2_opt_defined_by_id(const struct bch_opts *opts, enum bch_opt_id id) ...@@ -99,11 +99,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) u64 bch2_opt_get_by_id(const struct bch_opts *opts, enum bch_opt_id id)
{ {
switch (id) { switch (id) {
#define BCH_OPT(_name, ...) \ #define x(_name, ...) \
case Opt_##_name: \ case Opt_##_name: \
return opts->_name; return opts->_name;
BCH_OPTS() BCH_OPTS()
#undef BCH_OPT #undef x
default: default:
BUG(); BUG();
} }
...@@ -112,12 +112,12 @@ u64 bch2_opt_get_by_id(const struct bch_opts *opts, enum bch_opt_id id) ...@@ -112,12 +112,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) void bch2_opt_set_by_id(struct bch_opts *opts, enum bch_opt_id id, u64 v)
{ {
switch (id) { switch (id) {
#define BCH_OPT(_name, ...) \ #define x(_name, ...) \
case Opt_##_name: \ case Opt_##_name: \
opt_set(*opts, _name, v); \ opt_set(*opts, _name, v); \
break; break;
BCH_OPTS() BCH_OPTS()
#undef BCH_OPT #undef x
default: default:
BUG(); BUG();
} }
...@@ -131,11 +131,11 @@ struct bch_opts bch2_opts_from_sb(struct bch_sb *sb) ...@@ -131,11 +131,11 @@ struct bch_opts bch2_opts_from_sb(struct bch_sb *sb)
{ {
struct bch_opts opts = bch2_opts_empty(); 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) \ if (_sb_opt != NO_SB_OPT) \
opt_set(opts, _name, _sb_opt(sb)); opt_set(opts, _name, _sb_opt(sb));
BCH_OPTS() BCH_OPTS()
#undef BCH_OPT #undef x
return opts; return opts;
} }
...@@ -143,24 +143,27 @@ struct bch_opts bch2_opts_from_sb(struct bch_sb *sb) ...@@ -143,24 +143,27 @@ struct bch_opts bch2_opts_from_sb(struct bch_sb *sb)
const struct bch_option bch2_opt_table[] = { const struct bch_option bch2_opt_table[] = {
#define OPT_BOOL() .type = BCH_OPT_BOOL #define OPT_BOOL() .type = BCH_OPT_BOOL
#define OPT_UINT(_min, _max) .type = BCH_OPT_UINT, .min = _min, .max = _max #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_STR(_choices) .type = BCH_OPT_STR, .choices = _choices
#define OPT_FN(_fn) .type = BCH_OPT_FN, \ #define OPT_FN(_fn) .type = BCH_OPT_FN, \
.parse = _fn##_parse, \ .parse = _fn##_parse, \
.to_text = _fn##_to_text .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] = { \ [Opt_##_name] = { \
.attr = { \ .attr = { \
.name = #_name, \ .name = #_name, \
.mode = _mode == OPT_RUNTIME ? 0644 : 0444, \ .mode = (_mode) & OPT_RUNTIME ? 0644 : 0444, \
}, \ }, \
.mode = _mode, \ .mode = _mode, \
.hint = _hint, \
.help = _help, \
.set_sb = SET_##_sb_opt, \ .set_sb = SET_##_sb_opt, \
_type \ _type \
}, },
BCH_OPTS() BCH_OPTS()
#undef BCH_OPT #undef x
}; };
int bch2_opt_lookup(const char *name) int bch2_opt_lookup(const char *name)
...@@ -216,6 +219,19 @@ int bch2_opt_parse(struct bch_fs *c, const struct bch_option *opt, ...@@ -216,6 +219,19 @@ int bch2_opt_parse(struct bch_fs *c, const struct bch_option *opt,
if (ret < 0) if (ret < 0)
return ret; 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) if (*res < opt->min || *res >= opt->max)
return -ERANGE; return -ERANGE;
break; break;
...@@ -256,6 +272,9 @@ void bch2_opt_to_text(struct printbuf *out, struct bch_fs *c, ...@@ -256,6 +272,9 @@ void bch2_opt_to_text(struct printbuf *out, struct bch_fs *c,
case BCH_OPT_UINT: case BCH_OPT_UINT:
pr_buf(out, "%lli", v); pr_buf(out, "%lli", v);
break; break;
case BCH_OPT_SECTORS:
bch2_hprint(out, v);
break;
case BCH_OPT_STR: case BCH_OPT_STR:
if (flags & OPT_SHOW_FULL_LIST) if (flags & OPT_SHOW_FULL_LIST)
bch2_string_opt_to_text(out, opt->choices, v); bch2_string_opt_to_text(out, opt->choices, v);
...@@ -345,7 +364,7 @@ int bch2_parse_mount_opts(struct bch_opts *opts, char *options) ...@@ -345,7 +364,7 @@ int bch2_parse_mount_opts(struct bch_opts *opts, char *options)
goto no_val; goto no_val;
} }
if (bch2_opt_table[id].mode < OPT_MOUNT) if (!(bch2_opt_table[id].mode & OPT_MOUNT))
goto bad_opt; goto bad_opt;
if (id == Opt_acl && if (id == Opt_acl &&
......
...@@ -32,22 +32,25 @@ extern const char * const bch2_dev_state[]; ...@@ -32,22 +32,25 @@ extern const char * const bch2_dev_state[];
/* dummy option, for options that aren't stored in the superblock */ /* dummy option, for options that aren't stored in the superblock */
LE64_BITMASK(NO_SB_OPT, struct bch_sb, flags[0], 0, 0); LE64_BITMASK(NO_SB_OPT, struct bch_sb, flags[0], 0, 0);
/* When can be set: */
enum opt_mode { enum opt_mode {
OPT_INTERNAL, OPT_FORMAT = (1 << 0),
OPT_FORMAT, OPT_MOUNT = (1 << 1),
OPT_MOUNT, OPT_RUNTIME = (1 << 2),
OPT_RUNTIME, OPT_INODE = (1 << 3),
OPT_DEVICE = (1 << 4),
}; };
enum opt_type { enum opt_type {
BCH_OPT_BOOL, BCH_OPT_BOOL,
BCH_OPT_UINT, BCH_OPT_UINT,
BCH_OPT_SECTORS,
BCH_OPT_STR, BCH_OPT_STR,
BCH_OPT_FN, 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 * @name - name of mount option, sysfs attribute, and struct bch_opts
* member * member
...@@ -66,150 +69,252 @@ enum opt_type { ...@@ -66,150 +69,252 @@ enum opt_type {
*/ */
#define BCH_OPTS() \ #define BCH_OPTS() \
BCH_OPT(block_size, u16, OPT_FORMAT, \ x(block_size, u16, \
OPT_UINT(1, 128), \ OPT_FORMAT, \
BCH_SB_BLOCK_SIZE, 8) \ OPT_SECTORS(1, 128), \
BCH_OPT(btree_node_size, u16, OPT_FORMAT, \ BCH_SB_BLOCK_SIZE, 8, \
OPT_UINT(1, 128), \ "size", NULL) \
BCH_SB_BTREE_NODE_SIZE, 512) \ x(btree_node_size, u16, \
BCH_OPT(errors, u8, OPT_RUNTIME, \ OPT_FORMAT, \
OPT_STR(bch2_error_actions), \ OPT_SECTORS(1, 128), \
BCH_SB_ERROR_ACTION, BCH_ON_ERROR_RO) \ BCH_SB_BTREE_NODE_SIZE, 512, \
BCH_OPT(metadata_replicas, u8, OPT_RUNTIME, \ "size", "Btree node size, default 256k") \
OPT_UINT(1, BCH_REPLICAS_MAX), \ x(errors, u8, \
BCH_SB_META_REPLICAS_WANT, 1) \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
BCH_OPT(data_replicas, u8, OPT_RUNTIME, \ OPT_STR(bch2_error_actions), \
OPT_UINT(1, BCH_REPLICAS_MAX), \ BCH_SB_ERROR_ACTION, BCH_ON_ERROR_RO, \
BCH_SB_DATA_REPLICAS_WANT, 1) \ NULL, "Action to take on filesystem error") \
BCH_OPT(metadata_replicas_required, u8, OPT_MOUNT, \ x(metadata_replicas, u8, \
OPT_UINT(1, BCH_REPLICAS_MAX), \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
BCH_SB_META_REPLICAS_REQ, 1) \ OPT_UINT(1, BCH_REPLICAS_MAX), \
BCH_OPT(data_replicas_required, u8, OPT_MOUNT, \ BCH_SB_META_REPLICAS_WANT, 1, \
OPT_UINT(1, BCH_REPLICAS_MAX), \ "#", "Number of metadata replicas") \
BCH_SB_DATA_REPLICAS_REQ, 1) \ x(data_replicas, u8, \
BCH_OPT(metadata_checksum, u8, OPT_RUNTIME, \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
OPT_STR(bch2_csum_types), \ OPT_UINT(1, BCH_REPLICAS_MAX), \
BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_CRC32C) \ BCH_SB_DATA_REPLICAS_WANT, 1, \
BCH_OPT(data_checksum, u8, OPT_RUNTIME, \ "#", "Number of data replicas") \
OPT_STR(bch2_csum_types), \ x(metadata_replicas_required, u8, \
BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_CRC32C) \ OPT_FORMAT|OPT_MOUNT, \
BCH_OPT(compression, u8, OPT_RUNTIME, \ OPT_UINT(1, BCH_REPLICAS_MAX), \
OPT_STR(bch2_compression_types), \ BCH_SB_META_REPLICAS_REQ, 1, \
BCH_SB_COMPRESSION_TYPE, BCH_COMPRESSION_OPT_NONE)\ "#", NULL) \
BCH_OPT(background_compression, u8, OPT_RUNTIME, \ x(data_replicas_required, u8, \
OPT_STR(bch2_compression_types), \ OPT_FORMAT|OPT_MOUNT, \
BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_NONE)\ OPT_UINT(1, BCH_REPLICAS_MAX), \
BCH_OPT(str_hash, u8, OPT_RUNTIME, \ BCH_SB_DATA_REPLICAS_REQ, 1, \
OPT_STR(bch2_str_hash_types), \ "#", NULL) \
BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_SIPHASH) \ x(metadata_checksum, u8, \
BCH_OPT(foreground_target, u16, OPT_RUNTIME, \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
OPT_FN(bch2_opt_target), \ OPT_STR(bch2_csum_types), \
BCH_SB_FOREGROUND_TARGET, 0) \ BCH_SB_META_CSUM_TYPE, BCH_CSUM_OPT_CRC32C, \
BCH_OPT(background_target, u16, OPT_RUNTIME, \ NULL, NULL) \
OPT_FN(bch2_opt_target), \ x(data_checksum, u8, \
BCH_SB_BACKGROUND_TARGET, 0) \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
BCH_OPT(promote_target, u16, OPT_RUNTIME, \ OPT_STR(bch2_csum_types), \
OPT_FN(bch2_opt_target), \ BCH_SB_DATA_CSUM_TYPE, BCH_CSUM_OPT_CRC32C, \
BCH_SB_PROMOTE_TARGET, 0) \ NULL, NULL) \
BCH_OPT(erasure_code, u16, OPT_RUNTIME, \ x(compression, u8, \
OPT_BOOL(), \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
BCH_SB_ERASURE_CODE, false) \ OPT_STR(bch2_compression_types), \
BCH_OPT(inodes_32bit, u8, OPT_RUNTIME, \ BCH_SB_COMPRESSION_TYPE, BCH_COMPRESSION_OPT_NONE, \
OPT_BOOL(), \ NULL, NULL) \
BCH_SB_INODE_32BIT, false) \ x(background_compression, u8, \
BCH_OPT(gc_reserve_percent, u8, OPT_RUNTIME, \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
OPT_UINT(5, 21), \ OPT_STR(bch2_compression_types), \
BCH_SB_GC_RESERVE, 8) \ BCH_SB_BACKGROUND_COMPRESSION_TYPE,BCH_COMPRESSION_OPT_NONE, \
BCH_OPT(gc_reserve_bytes, u64, OPT_RUNTIME, \ NULL, NULL) \
OPT_UINT(0, U64_MAX), \ x(str_hash, u8, \
BCH_SB_GC_RESERVE_BYTES, 0) \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
BCH_OPT(root_reserve_percent, u8, OPT_MOUNT, \ OPT_STR(bch2_str_hash_types), \
OPT_UINT(0, 100), \ BCH_SB_STR_HASH_TYPE, BCH_STR_HASH_SIPHASH, \
BCH_SB_ROOT_RESERVE, 0) \ NULL, "Hash function for directory entries and xattrs")\
BCH_OPT(wide_macs, u8, OPT_RUNTIME, \ x(foreground_target, u16, \
OPT_BOOL(), \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
BCH_SB_128_BIT_MACS, false) \ OPT_FN(bch2_opt_target), \
BCH_OPT(acl, u8, OPT_MOUNT, \ BCH_SB_FOREGROUND_TARGET, 0, \
OPT_BOOL(), \ "(target)", "Device or disk group for foreground writes") \
BCH_SB_POSIX_ACL, true) \ x(background_target, u16, \
BCH_OPT(usrquota, u8, OPT_MOUNT, \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
OPT_BOOL(), \ OPT_FN(bch2_opt_target), \
BCH_SB_USRQUOTA, false) \ BCH_SB_BACKGROUND_TARGET, 0, \
BCH_OPT(grpquota, u8, OPT_MOUNT, \ "(target)", "Device or disk group to move data to in the background")\
OPT_BOOL(), \ x(promote_target, u16, \
BCH_SB_GRPQUOTA, false) \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
BCH_OPT(prjquota, u8, OPT_MOUNT, \ OPT_FN(bch2_opt_target), \
OPT_BOOL(), \ BCH_SB_PROMOTE_TARGET, 0, \
BCH_SB_PRJQUOTA, false) \ "(target)", "Device or disk group to promote data to on read")\
BCH_OPT(degraded, u8, OPT_MOUNT, \ x(erasure_code, u16, \
OPT_BOOL(), \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME|OPT_INODE, \
NO_SB_OPT, false) \ OPT_BOOL(), \
BCH_OPT(discard, u8, OPT_MOUNT, \ BCH_SB_ERASURE_CODE, false, \
OPT_BOOL(), \ NULL, "Enable erasure coding (DO NOT USE YET)") \
NO_SB_OPT, false) \ x(inodes_32bit, u8, \
BCH_OPT(verbose_recovery, u8, OPT_MOUNT, \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false) \ BCH_SB_INODE_32BIT, false, \
BCH_OPT(verbose_init, u8, OPT_MOUNT, \ NULL, "Constrain inode numbers to 32 bits") \
OPT_BOOL(), \ x(gc_reserve_percent, u8, \
NO_SB_OPT, false) \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
BCH_OPT(journal_flush_disabled, u8, OPT_RUNTIME, \ OPT_UINT(5, 21), \
OPT_BOOL(), \ BCH_SB_GC_RESERVE, 8, \
NO_SB_OPT, false) \ "%", "Percentage of disk space to reserve for copygc")\
BCH_OPT(fsck, u8, OPT_MOUNT, \ x(gc_reserve_bytes, u64, \
OPT_BOOL(), \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
NO_SB_OPT, true) \ OPT_SECTORS(0, U64_MAX), \
BCH_OPT(fix_errors, u8, OPT_MOUNT, \ BCH_SB_GC_RESERVE_BYTES, 0, \
OPT_BOOL(), \ "%", "Amount of disk space to reserve for copygc\n" \
NO_SB_OPT, false) \ "Takes precedence over gc_reserve_percent if set")\
BCH_OPT(nochanges, u8, OPT_MOUNT, \ x(root_reserve_percent, u8, \
OPT_BOOL(), \ OPT_FORMAT|OPT_MOUNT, \
NO_SB_OPT, false) \ OPT_UINT(0, 100), \
BCH_OPT(noreplay, u8, OPT_MOUNT, \ BCH_SB_ROOT_RESERVE, 0, \
OPT_BOOL(), \ "%", "Percentage of disk space to reserve for superuser")\
NO_SB_OPT, false) \ x(wide_macs, u8, \
BCH_OPT(norecovery, u8, OPT_MOUNT, \ OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false) \ BCH_SB_128_BIT_MACS, false, \
BCH_OPT(noexcl, u8, OPT_MOUNT, \ NULL, "Store full 128 bits of cryptographic MACs, instead of 80")\
OPT_BOOL(), \ x(acl, u8, \
NO_SB_OPT, false) \ OPT_FORMAT|OPT_MOUNT, \
BCH_OPT(sb, u64, OPT_MOUNT, \ OPT_BOOL(), \
OPT_UINT(0, S64_MAX), \ BCH_SB_POSIX_ACL, true, \
NO_SB_OPT, BCH_SB_SECTOR) \ NULL, "Enable POSIX acls") \
BCH_OPT(read_only, u8, OPT_INTERNAL, \ x(usrquota, u8, \
OPT_BOOL(), \ OPT_FORMAT|OPT_MOUNT, \
NO_SB_OPT, false) \ OPT_BOOL(), \
BCH_OPT(nostart, u8, OPT_INTERNAL, \ BCH_SB_USRQUOTA, false, \
OPT_BOOL(), \ NULL, "Enable user quotas") \
NO_SB_OPT, false) \ x(grpquota, u8, \
BCH_OPT(no_data_io, u8, OPT_MOUNT, \ OPT_FORMAT|OPT_MOUNT, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false) \ BCH_SB_GRPQUOTA, false, \
BCH_OPT(version_upgrade, u8, OPT_MOUNT, \ NULL, "Enable group quotas") \
OPT_BOOL(), \ x(prjquota, u8, \
NO_SB_OPT, false) \ OPT_FORMAT|OPT_MOUNT, \
BCH_OPT(project, u8, OPT_INTERNAL, \ OPT_BOOL(), \
OPT_BOOL(), \ BCH_SB_PRJQUOTA, false, \
NO_SB_OPT, 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(no_data_io, u8, \
OPT_MOUNT, \
OPT_BOOL(), \
NO_SB_OPT, false, \
NULL, "Skip submit_bio() for data reads and writes, " \
"for performance testing purposes") \
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 { struct bch_opts {
#define BCH_OPT(_name, _bits, ...) unsigned _name##_defined:1; #define x(_name, _bits, ...) unsigned _name##_defined:1;
BCH_OPTS() BCH_OPTS()
#undef BCH_OPT #undef x
#define BCH_OPT(_name, _bits, ...) _bits _name; #define x(_name, _bits, ...) _bits _name;
BCH_OPTS() BCH_OPTS()
#undef BCH_OPT #undef x
}; };
static const struct bch_opts bch2_opts_default = { 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##_defined = true, \
._name = _default, \ ._name = _default, \
BCH_OPTS() BCH_OPTS()
#undef BCH_OPT #undef x
}; };
#define opt_defined(_opts, _name) ((_opts)._name##_defined) #define opt_defined(_opts, _name) ((_opts)._name##_defined)
...@@ -231,9 +336,9 @@ static inline struct bch_opts bch2_opts_empty(void) ...@@ -231,9 +336,9 @@ static inline struct bch_opts bch2_opts_empty(void)
void bch2_opts_apply(struct bch_opts *, struct bch_opts); void bch2_opts_apply(struct bch_opts *, struct bch_opts);
enum bch_opt_id { enum bch_opt_id {
#define BCH_OPT(_name, ...) Opt_##_name, #define x(_name, ...) Opt_##_name,
BCH_OPTS() BCH_OPTS()
#undef BCH_OPT #undef x
bch2_opts_nr bch2_opts_nr
}; };
...@@ -259,6 +364,9 @@ struct bch_option { ...@@ -259,6 +364,9 @@ struct bch_option {
}; };
}; };
const char *hint;
const char *help;
}; };
extern const struct bch_option bch2_opt_table[]; extern const struct bch_option bch2_opt_table[];
......
...@@ -263,13 +263,13 @@ ssize_t bch2_rebalance_work_show(struct bch_fs *c, char *buf) ...@@ -263,13 +263,13 @@ ssize_t bch2_rebalance_work_show(struct bch_fs *c, char *buf)
struct rebalance_work w = rebalance_work(c); struct rebalance_work w = rebalance_work(c);
char h1[21], h2[21]; char h1[21], h2[21];
bch2_hprint(h1, w.dev_most_full_work << 9); bch2_hprint(&PBUF(h1), w.dev_most_full_work << 9);
bch2_hprint(h2, w.dev_most_full_capacity << 9); bch2_hprint(&PBUF(h2), w.dev_most_full_capacity << 9);
pr_buf(&out, "fullest_dev (%i):\t%s/%s\n", pr_buf(&out, "fullest_dev (%i):\t%s/%s\n",
w.dev_most_full_idx, h1, h2); w.dev_most_full_idx, h1, h2);
bch2_hprint(h1, w.total_work << 9); bch2_hprint(&PBUF(h1), w.total_work << 9);
bch2_hprint(h2, c->capacity << 9); bch2_hprint(&PBUF(h2), c->capacity << 9);
pr_buf(&out, "total work:\t\t%s/%s\n", h1, h2); 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); pr_buf(&out, "rate:\t\t\t%u\n", r->pd.rate.rate);
...@@ -279,7 +279,7 @@ ssize_t bch2_rebalance_work_show(struct bch_fs *c, char *buf) ...@@ -279,7 +279,7 @@ ssize_t bch2_rebalance_work_show(struct bch_fs *c, char *buf)
pr_buf(&out, "waiting\n"); pr_buf(&out, "waiting\n");
break; break;
case REBALANCE_THROTTLED: case REBALANCE_THROTTLED:
bch2_hprint(h1, bch2_hprint(&PBUF(h1),
(r->throttled_until_iotime - (r->throttled_until_iotime -
atomic_long_read(&c->io_clock[WRITE].now)) << 9); atomic_long_read(&c->io_clock[WRITE].now)) << 9);
pr_buf(&out, "throttled for %lu sec or %s io\n", pr_buf(&out, "throttled for %lu sec or %s io\n",
......
...@@ -73,9 +73,10 @@ do { \ ...@@ -73,9 +73,10 @@ do { \
#define sysfs_hprint(file, val) \ #define sysfs_hprint(file, val) \
do { \ do { \
if (attr == &sysfs_ ## file) { \ if (attr == &sysfs_ ## file) { \
ssize_t ret = bch2_hprint(buf, val); \ struct printbuf out = _PBUF(buf, PAGE_SIZE); \
strcat(buf, "\n"); \ bch2_hprint(&out, val); \
return ret + 1; \ pr_buf(&out, "\n"); \
return out.pos - buf; \
} \ } \
} while (0) } while (0)
...@@ -658,7 +659,7 @@ int bch2_opts_create_sysfs_files(struct kobject *kobj) ...@@ -658,7 +659,7 @@ int bch2_opts_create_sysfs_files(struct kobject *kobj)
for (i = bch2_opt_table; for (i = bch2_opt_table;
i < bch2_opt_table + bch2_opts_nr; i < bch2_opt_table + bch2_opts_nr;
i++) { i++) {
if (i->mode == OPT_INTERNAL) if (!(i->mode & (OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME)))
continue; continue;
ret = sysfs_create_file(kobj, &i->attr); ret = sysfs_create_file(kobj, &i->attr);
......
...@@ -619,8 +619,8 @@ void bch2_btree_perf_test(struct bch_fs *c, const char *testname, ...@@ -619,8 +619,8 @@ void bch2_btree_perf_test(struct bch_fs *c, const char *testname,
time = j.finish - j.start; time = j.finish - j.start;
scnprintf(name_buf, sizeof(name_buf), "%s:", testname); scnprintf(name_buf, sizeof(name_buf), "%s:", testname);
bch2_hprint(nr_buf, nr); bch2_hprint(&PBUF(nr_buf), nr);
bch2_hprint(per_sec_buf, nr * NSEC_PER_SEC / time); 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", 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, name_buf, nr_buf, nr_threads,
time / NSEC_PER_SEC, time / NSEC_PER_SEC,
......
...@@ -100,10 +100,10 @@ STRTO_H(strtoint, int) ...@@ -100,10 +100,10 @@ STRTO_H(strtoint, int)
STRTO_H(strtouint, unsigned int) STRTO_H(strtouint, unsigned int)
STRTO_H(strtoll, long long) STRTO_H(strtoll, long long)
STRTO_H(strtoull, unsigned 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; int u, t = 0;
for (u = 0; v >= 1024 || v <= -1024; u++) { for (u = 0; v >= 1024 || v <= -1024; u++) {
...@@ -111,17 +111,16 @@ ssize_t bch2_hprint(char *buf, s64 v) ...@@ -111,17 +111,16 @@ ssize_t bch2_hprint(char *buf, s64 v)
v >>= 10; v >>= 10;
} }
if (!u) pr_buf(buf, "%lli", v);
return sprintf(buf, "%lli", v);
/* /*
* 103 is magic: t is in the range [-1023, 1023] and we want * 103 is magic: t is in the range [-1023, 1023] and we want
* to turn it into [-9, 9] * to turn it into [-9, 9]
*/ */
if (v < 100 && v > -100) if (u && v < 100 && v > -100)
scnprintf(dec, sizeof(dec), ".%i", t / 103); pr_buf(buf, ".%i", t / 103);
if (u)
return sprintf(buf, "%lli%s%c", v, dec, si_units[u]); pr_buf(buf, "%c", si_units[u]);
} }
void bch2_string_opt_to_text(struct printbuf *out, void bch2_string_opt_to_text(struct printbuf *out,
...@@ -483,12 +482,12 @@ size_t bch2_pd_controller_print_debug(struct bch_pd_controller *pd, char *buf) ...@@ -483,12 +482,12 @@ size_t bch2_pd_controller_print_debug(struct bch_pd_controller *pd, char *buf)
char change[21]; char change[21];
s64 next_io; s64 next_io;
bch2_hprint(rate, pd->rate.rate); bch2_hprint(&PBUF(rate), pd->rate.rate);
bch2_hprint(actual, pd->last_actual); bch2_hprint(&PBUF(actual), pd->last_actual);
bch2_hprint(target, pd->last_target); bch2_hprint(&PBUF(target), pd->last_target);
bch2_hprint(proportional, pd->last_proportional); bch2_hprint(&PBUF(proportional), pd->last_proportional);
bch2_hprint(derivative, pd->last_derivative); bch2_hprint(&PBUF(derivative), pd->last_derivative);
bch2_hprint(change, pd->last_change); bch2_hprint(&PBUF(change), pd->last_change);
next_io = div64_s64(pd->rate.next - local_clock(), NSEC_PER_MSEC); next_io = div64_s64(pd->rate.next - local_clock(), NSEC_PER_MSEC);
......
...@@ -265,6 +265,7 @@ int bch2_strtoint_h(const char *, int *); ...@@ -265,6 +265,7 @@ int bch2_strtoint_h(const char *, int *);
int bch2_strtouint_h(const char *, unsigned int *); int bch2_strtouint_h(const char *, unsigned int *);
int bch2_strtoll_h(const char *, long long *); int bch2_strtoll_h(const char *, long long *);
int bch2_strtoull_h(const char *, unsigned 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) static inline int bch2_strtol_h(const char *cp, long *res)
{ {
...@@ -333,7 +334,7 @@ static inline int bch2_strtoul_h(const char *cp, long *res) ...@@ -333,7 +334,7 @@ static inline int bch2_strtoul_h(const char *cp, long *res)
: type_is(var, char *) ? "%s\n" \ : type_is(var, char *) ? "%s\n" \
: "%i\n", var) : "%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); bool bch2_is_zero(const void *, size_t);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment