Commit 5521b1df authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: Convert bch2_sb_to_text to master option list

Options no longer have to be manually added to bch2_sb_to_text() - it
now uses the master list of options in opts.h. Also, improve some of the
formatting by converting it to tabstops.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 4eea53de
...@@ -445,7 +445,10 @@ int bch2_opt_target_parse(struct bch_fs *c, const char *buf, u64 *v) ...@@ -445,7 +445,10 @@ int bch2_opt_target_parse(struct bch_fs *c, const char *buf, u64 *v)
return -EINVAL; return -EINVAL;
} }
void bch2_sb_target_to_text(struct printbuf *out, struct bch_sb *sb, u64 v) void bch2_opt_target_to_text(struct printbuf *out,
struct bch_fs *c,
struct bch_sb *sb,
u64 v)
{ {
struct target t = target_decode(v); struct target t = target_decode(v);
...@@ -453,60 +456,46 @@ void bch2_sb_target_to_text(struct printbuf *out, struct bch_sb *sb, u64 v) ...@@ -453,60 +456,46 @@ void bch2_sb_target_to_text(struct printbuf *out, struct bch_sb *sb, u64 v)
case TARGET_NULL: case TARGET_NULL:
pr_buf(out, "none"); pr_buf(out, "none");
break; break;
case TARGET_DEV: { case TARGET_DEV:
struct bch_sb_field_members *mi = bch2_sb_get_members(sb); if (c) {
struct bch_member *m = mi->members + t.dev; struct bch_dev *ca;
if (bch2_dev_exists(sb, mi, t.dev)) { rcu_read_lock();
pr_buf(out, "Device "); ca = t.dev < c->sb.nr_devices
pr_uuid(out, m->uuid.b); ? rcu_dereference(c->devs[t.dev])
pr_buf(out, " (%u)", t.dev); : NULL;
if (ca && percpu_ref_tryget(&ca->io_ref)) {
pr_buf(out, "/dev/%pg", ca->disk_sb.bdev);
percpu_ref_put(&ca->io_ref);
} else if (ca) {
pr_buf(out, "offline device %u", t.dev);
} else {
pr_buf(out, "invalid device %u", t.dev);
}
rcu_read_unlock();
} else { } else {
pr_buf(out, "Bad device %u", t.dev); struct bch_sb_field_members *mi = bch2_sb_get_members(sb);
struct bch_member *m = mi->members + t.dev;
if (bch2_dev_exists(sb, mi, t.dev)) {
pr_buf(out, "Device ");
pr_uuid(out, m->uuid.b);
pr_buf(out, " (%u)", t.dev);
} else {
pr_buf(out, "Bad device %u", t.dev);
}
} }
break; break;
}
case TARGET_GROUP: case TARGET_GROUP:
bch2_disk_path_to_text(out, sb, t.group); if (c) {
break; mutex_lock(&c->sb_lock);
default: bch2_disk_path_to_text(out, c->disk_sb.sb, t.group);
BUG(); mutex_unlock(&c->sb_lock);
}
}
void bch2_opt_target_to_text(struct printbuf *out, struct bch_fs *c, u64 v)
{
struct target t = target_decode(v);
switch (t.type) {
case TARGET_NULL:
pr_buf(out, "none");
break;
case TARGET_DEV: {
struct bch_dev *ca;
rcu_read_lock();
ca = t.dev < c->sb.nr_devices
? rcu_dereference(c->devs[t.dev])
: NULL;
if (ca && percpu_ref_tryget(&ca->io_ref)) {
pr_buf(out, "/dev/%pg", ca->disk_sb.bdev);
percpu_ref_put(&ca->io_ref);
} else if (ca) {
pr_buf(out, "offline device %u", t.dev);
} else { } else {
pr_buf(out, "invalid device %u", t.dev); bch2_disk_path_to_text(out, sb, t.group);
} }
rcu_read_unlock();
break;
}
case TARGET_GROUP:
mutex_lock(&c->sb_lock);
bch2_disk_path_to_text(out, c->disk_sb.sb, t.group);
mutex_unlock(&c->sb_lock);
break; break;
default: default:
BUG(); BUG();
......
...@@ -77,10 +77,8 @@ int bch2_disk_path_find_or_create(struct bch_sb_handle *, const char *); ...@@ -77,10 +77,8 @@ int bch2_disk_path_find_or_create(struct bch_sb_handle *, const char *);
void bch2_disk_path_to_text(struct printbuf *, struct bch_sb *, unsigned); void bch2_disk_path_to_text(struct printbuf *, struct bch_sb *, unsigned);
void bch2_sb_target_to_text(struct printbuf *, struct bch_sb *, u64);
int bch2_opt_target_parse(struct bch_fs *, const char *, u64 *); int bch2_opt_target_parse(struct bch_fs *, const char *, u64 *);
void bch2_opt_target_to_text(struct printbuf *, struct bch_fs *, u64); void bch2_opt_target_to_text(struct printbuf *, struct bch_fs *, struct bch_sb *, u64);
int bch2_sb_disk_groups_to_cpu(struct bch_fs *); int bch2_sb_disk_groups_to_cpu(struct bch_fs *);
......
...@@ -1691,7 +1691,7 @@ static int bch2_show_options(struct seq_file *seq, struct dentry *root) ...@@ -1691,7 +1691,7 @@ static int bch2_show_options(struct seq_file *seq, struct dentry *root)
continue; continue;
printbuf_reset(&buf); printbuf_reset(&buf);
bch2_opt_to_text(&buf, c, opt, v, bch2_opt_to_text(&buf, c, c->disk_sb.sb, opt, v,
OPT_SHOW_MOUNT_STYLE); OPT_SHOW_MOUNT_STYLE);
seq_putc(seq, ','); seq_putc(seq, ',');
seq_puts(seq, buf.buf); seq_puts(seq, buf.buf);
......
...@@ -96,6 +96,16 @@ const char * const bch2_d_types[BCH_DT_MAX] = { ...@@ -96,6 +96,16 @@ const char * const bch2_d_types[BCH_DT_MAX] = {
[DT_SUBVOL] = "subvol", [DT_SUBVOL] = "subvol",
}; };
u64 BCH2_NO_SB_OPT(const struct bch_sb *sb)
{
BUG();
}
void SET_BCH2_NO_SB_OPT(struct bch_sb *sb, u64 v)
{
BUG();
}
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 x(_name, ...) \ #define x(_name, ...) \
...@@ -280,7 +290,8 @@ int bch2_opt_parse(struct bch_fs *c, const char *msg, ...@@ -280,7 +290,8 @@ int bch2_opt_parse(struct bch_fs *c, const char *msg,
return bch2_opt_validate(opt, msg, *res); return bch2_opt_validate(opt, msg, *res);
} }
void bch2_opt_to_text(struct printbuf *out, struct bch_fs *c, void bch2_opt_to_text(struct printbuf *out,
struct bch_fs *c, struct bch_sb *sb,
const struct bch_option *opt, u64 v, const struct bch_option *opt, u64 v,
unsigned flags) unsigned flags)
{ {
...@@ -310,7 +321,7 @@ void bch2_opt_to_text(struct printbuf *out, struct bch_fs *c, ...@@ -310,7 +321,7 @@ void bch2_opt_to_text(struct printbuf *out, struct bch_fs *c,
pr_buf(out, opt->choices[v]); pr_buf(out, opt->choices[v]);
break; break;
case BCH_OPT_FN: case BCH_OPT_FN:
opt->to_text(out, c, v); opt->to_text(out, c, sb, v);
break; break;
default: default:
BUG(); BUG();
...@@ -431,6 +442,22 @@ int bch2_parse_mount_opts(struct bch_fs *c, struct bch_opts *opts, ...@@ -431,6 +442,22 @@ int bch2_parse_mount_opts(struct bch_fs *c, struct bch_opts *opts,
return ret; return ret;
} }
u64 bch2_opt_from_sb(struct bch_sb *sb, enum bch_opt_id id)
{
const struct bch_option *opt = bch2_opt_table + id;
u64 v;
v = opt->get_sb(sb);
if (opt->flags & OPT_SB_FIELD_ILOG2)
v = 1ULL << v;
if (opt->flags & OPT_SB_FIELD_SECTORS)
v <<= 9;
return v;
}
/* /*
* Initial options from superblock - here we don't want any options undefined, * Initial options from superblock - here we don't want any options undefined,
* any options the superblock doesn't specify are set to 0: * any options the superblock doesn't specify are set to 0:
...@@ -444,16 +471,10 @@ int bch2_opts_from_sb(struct bch_opts *opts, struct bch_sb *sb) ...@@ -444,16 +471,10 @@ int bch2_opts_from_sb(struct bch_opts *opts, struct bch_sb *sb)
const struct bch_option *opt = bch2_opt_table + id; const struct bch_option *opt = bch2_opt_table + id;
u64 v; u64 v;
if (opt->get_sb == NO_SB_OPT) if (opt->get_sb == BCH2_NO_SB_OPT)
continue; continue;
v = opt->get_sb(sb); v = bch2_opt_from_sb(sb, id);
if (opt->flags & OPT_SB_FIELD_ILOG2)
v = 1ULL << v;
if (opt->flags & OPT_SB_FIELD_SECTORS)
v <<= 9;
ret = bch2_opt_validate(opt, "superblock option ", v); ret = bch2_opt_validate(opt, "superblock option ", v);
if (ret) if (ret)
...@@ -467,7 +488,7 @@ int bch2_opts_from_sb(struct bch_opts *opts, struct bch_sb *sb) ...@@ -467,7 +488,7 @@ int bch2_opts_from_sb(struct bch_opts *opts, struct bch_sb *sb)
void __bch2_opt_set_sb(struct bch_sb *sb, const struct bch_option *opt, u64 v) void __bch2_opt_set_sb(struct bch_sb *sb, const struct bch_option *opt, u64 v)
{ {
if (opt->set_sb == SET_NO_SB_OPT) if (opt->set_sb == SET_BCH2_NO_SB_OPT)
return; return;
if (opt->flags & OPT_SB_FIELD_SECTORS) if (opt->flags & OPT_SB_FIELD_SECTORS)
...@@ -481,7 +502,7 @@ void __bch2_opt_set_sb(struct bch_sb *sb, const struct bch_option *opt, u64 v) ...@@ -481,7 +502,7 @@ void __bch2_opt_set_sb(struct bch_sb *sb, const struct bch_option *opt, u64 v)
void bch2_opt_set_sb(struct bch_fs *c, const struct bch_option *opt, u64 v) void bch2_opt_set_sb(struct bch_fs *c, const struct bch_option *opt, u64 v)
{ {
if (opt->set_sb == SET_NO_SB_OPT) if (opt->set_sb == SET_BCH2_NO_SB_OPT)
return; return;
mutex_lock(&c->sb_lock); mutex_lock(&c->sb_lock);
......
...@@ -42,7 +42,8 @@ static inline const char *bch2_d_type_str(unsigned d_type) ...@@ -42,7 +42,8 @@ static inline const char *bch2_d_type_str(unsigned d_type)
*/ */
/* 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); u64 BCH2_NO_SB_OPT(const struct bch_sb *);
void SET_BCH2_NO_SB_OPT(struct bch_sb *, u64);
/* When can be set: */ /* When can be set: */
enum opt_flags { enum opt_flags {
...@@ -202,7 +203,7 @@ enum opt_type { ...@@ -202,7 +203,7 @@ enum opt_type {
x(btree_node_mem_ptr_optimization, u8, \ x(btree_node_mem_ptr_optimization, u8, \
OPT_FS|OPT_MOUNT|OPT_RUNTIME, \ OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, true, \ BCH2_NO_SB_OPT, true, \
NULL, "Stash pointer to in memory btree node in btree ptr")\ NULL, "Stash pointer to in memory btree node in btree ptr")\
x(gc_reserve_percent, u8, \ x(gc_reserve_percent, u8, \
OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
...@@ -229,7 +230,7 @@ enum opt_type { ...@@ -229,7 +230,7 @@ enum opt_type {
x(inline_data, u8, \ x(inline_data, u8, \
OPT_FS|OPT_MOUNT|OPT_RUNTIME, \ OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, true, \ BCH2_NO_SB_OPT, true, \
NULL, "Enable inline data extents") \ NULL, "Enable inline data extents") \
x(acl, u8, \ x(acl, u8, \
OPT_FS|OPT_FORMAT|OPT_MOUNT, \ OPT_FS|OPT_FORMAT|OPT_MOUNT, \
...@@ -254,22 +255,22 @@ enum opt_type { ...@@ -254,22 +255,22 @@ enum opt_type {
x(degraded, u8, \ x(degraded, u8, \
OPT_FS|OPT_MOUNT, \ OPT_FS|OPT_MOUNT, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false, \ BCH2_NO_SB_OPT, false, \
NULL, "Allow mounting in degraded mode") \ NULL, "Allow mounting in degraded mode") \
x(very_degraded, u8, \ x(very_degraded, u8, \
OPT_FS|OPT_MOUNT, \ OPT_FS|OPT_MOUNT, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false, \ BCH2_NO_SB_OPT, false, \
NULL, "Allow mounting in when data will be missing") \ NULL, "Allow mounting in when data will be missing") \
x(discard, u8, \ x(discard, u8, \
OPT_FS|OPT_MOUNT|OPT_DEVICE, \ OPT_FS|OPT_MOUNT|OPT_DEVICE, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false, \ BCH2_NO_SB_OPT, false, \
NULL, "Enable discard/TRIM support") \ NULL, "Enable discard/TRIM support") \
x(verbose, u8, \ x(verbose, u8, \
OPT_FS|OPT_MOUNT, \ OPT_FS|OPT_MOUNT, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false, \ BCH2_NO_SB_OPT, false, \
NULL, "Extra debugging information during mount/recovery")\ NULL, "Extra debugging information during mount/recovery")\
x(journal_flush_delay, u32, \ x(journal_flush_delay, u32, \
OPT_FS|OPT_MOUNT|OPT_RUNTIME, \ OPT_FS|OPT_MOUNT|OPT_RUNTIME, \
...@@ -291,48 +292,48 @@ enum opt_type { ...@@ -291,48 +292,48 @@ enum opt_type {
x(fsck, u8, \ x(fsck, u8, \
OPT_FS|OPT_MOUNT, \ OPT_FS|OPT_MOUNT, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false, \ BCH2_NO_SB_OPT, false, \
NULL, "Run fsck on mount") \ NULL, "Run fsck on mount") \
x(fix_errors, u8, \ x(fix_errors, u8, \
OPT_FS|OPT_MOUNT, \ OPT_FS|OPT_MOUNT, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false, \ BCH2_NO_SB_OPT, false, \
NULL, "Fix errors during fsck without asking") \ NULL, "Fix errors during fsck without asking") \
x(ratelimit_errors, u8, \ x(ratelimit_errors, u8, \
OPT_FS|OPT_MOUNT, \ OPT_FS|OPT_MOUNT, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, RATELIMIT_ERRORS_DEFAULT, \ BCH2_NO_SB_OPT, RATELIMIT_ERRORS_DEFAULT, \
NULL, "Ratelimit error messages during fsck") \ NULL, "Ratelimit error messages during fsck") \
x(nochanges, u8, \ x(nochanges, u8, \
OPT_FS|OPT_MOUNT, \ OPT_FS|OPT_MOUNT, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false, \ BCH2_NO_SB_OPT, false, \
NULL, "Super read only mode - no writes at all will be issued,\n"\ NULL, "Super read only mode - no writes at all will be issued,\n"\
"even if we have to replay the journal") \ "even if we have to replay the journal") \
x(norecovery, u8, \ x(norecovery, u8, \
OPT_FS|OPT_MOUNT, \ OPT_FS|OPT_MOUNT, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false, \ BCH2_NO_SB_OPT, false, \
NULL, "Don't replay the journal") \ NULL, "Don't replay the journal") \
x(rebuild_replicas, u8, \ x(rebuild_replicas, u8, \
OPT_FS|OPT_MOUNT, \ OPT_FS|OPT_MOUNT, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false, \ BCH2_NO_SB_OPT, false, \
NULL, "Rebuild the superblock replicas section") \ NULL, "Rebuild the superblock replicas section") \
x(keep_journal, u8, \ x(keep_journal, u8, \
0, \ 0, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false, \ BCH2_NO_SB_OPT, false, \
NULL, "Don't free journal entries/keys after startup")\ NULL, "Don't free journal entries/keys after startup")\
x(read_entire_journal, u8, \ x(read_entire_journal, u8, \
0, \ 0, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false, \ BCH2_NO_SB_OPT, false, \
NULL, "Read all journal entries, not just dirty ones")\ NULL, "Read all journal entries, not just dirty ones")\
x(read_journal_only, u8, \ x(read_journal_only, u8, \
0, \ 0, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false, \ BCH2_NO_SB_OPT, false, \
NULL, "Only read the journal, skip the rest of recovery")\ NULL, "Only read the journal, skip the rest of recovery")\
x(journal_transaction_names, u8, \ x(journal_transaction_names, u8, \
OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \ OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
...@@ -342,64 +343,64 @@ enum opt_type { ...@@ -342,64 +343,64 @@ enum opt_type {
x(noexcl, u8, \ x(noexcl, u8, \
OPT_FS|OPT_MOUNT, \ OPT_FS|OPT_MOUNT, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false, \ BCH2_NO_SB_OPT, false, \
NULL, "Don't open device in exclusive mode") \ NULL, "Don't open device in exclusive mode") \
x(sb, u64, \ x(sb, u64, \
OPT_MOUNT, \ OPT_MOUNT, \
OPT_UINT(0, S64_MAX), \ OPT_UINT(0, S64_MAX), \
NO_SB_OPT, BCH_SB_SECTOR, \ BCH2_NO_SB_OPT, BCH_SB_SECTOR, \
"offset", "Sector offset of superblock") \ "offset", "Sector offset of superblock") \
x(read_only, u8, \ x(read_only, u8, \
OPT_FS, \ OPT_FS, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false, \ BCH2_NO_SB_OPT, false, \
NULL, NULL) \ NULL, NULL) \
x(nostart, u8, \ x(nostart, u8, \
0, \ 0, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false, \ BCH2_NO_SB_OPT, false, \
NULL, "Don\'t start filesystem, only open devices") \ NULL, "Don\'t start filesystem, only open devices") \
x(reconstruct_alloc, u8, \ x(reconstruct_alloc, u8, \
OPT_FS|OPT_MOUNT, \ OPT_FS|OPT_MOUNT, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false, \ BCH2_NO_SB_OPT, false, \
NULL, "Reconstruct alloc btree") \ NULL, "Reconstruct alloc btree") \
x(version_upgrade, u8, \ x(version_upgrade, u8, \
OPT_FS|OPT_MOUNT, \ OPT_FS|OPT_MOUNT, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false, \ BCH2_NO_SB_OPT, false, \
NULL, "Set superblock to latest version,\n" \ NULL, "Set superblock to latest version,\n" \
"allowing any new features to be used") \ "allowing any new features to be used") \
x(buckets_nouse, u8, \ x(buckets_nouse, u8, \
0, \ 0, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false, \ BCH2_NO_SB_OPT, false, \
NULL, "Allocate the buckets_nouse bitmap") \ NULL, "Allocate the buckets_nouse bitmap") \
x(project, u8, \ x(project, u8, \
OPT_INODE, \ OPT_INODE, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false, \ BCH2_NO_SB_OPT, false, \
NULL, NULL) \ NULL, NULL) \
x(no_data_io, u8, \ x(no_data_io, u8, \
OPT_MOUNT, \ OPT_MOUNT, \
OPT_BOOL(), \ OPT_BOOL(), \
NO_SB_OPT, false, \ BCH2_NO_SB_OPT, false, \
NULL, "Skip submit_bio() for data reads and writes, " \ NULL, "Skip submit_bio() for data reads and writes, " \
"for performance testing purposes") \ "for performance testing purposes") \
x(fs_size, u64, \ x(fs_size, u64, \
OPT_DEVICE, \ OPT_DEVICE, \
OPT_UINT(0, S64_MAX), \ OPT_UINT(0, S64_MAX), \
NO_SB_OPT, 0, \ BCH2_NO_SB_OPT, 0, \
"size", "Size of filesystem on device") \ "size", "Size of filesystem on device") \
x(bucket, u32, \ x(bucket, u32, \
OPT_DEVICE, \ OPT_DEVICE, \
OPT_UINT(0, S64_MAX), \ OPT_UINT(0, S64_MAX), \
NO_SB_OPT, 0, \ BCH2_NO_SB_OPT, 0, \
"size", "Size of filesystem on device") \ "size", "Size of filesystem on device") \
x(durability, u8, \ x(durability, u8, \
OPT_DEVICE, \ OPT_DEVICE, \
OPT_UINT(0, BCH_REPLICAS_MAX), \ OPT_UINT(0, BCH_REPLICAS_MAX), \
NO_SB_OPT, 1, \ BCH2_NO_SB_OPT, 1, \
"n", "Data written to this device will be considered\n"\ "n", "Data written to this device will be considered\n"\
"to have already been replicated n times") "to have already been replicated n times")
...@@ -466,7 +467,7 @@ struct bch_option { ...@@ -466,7 +467,7 @@ struct bch_option {
}; };
struct { struct {
int (*parse)(struct bch_fs *, const char *, u64 *); int (*parse)(struct bch_fs *, const char *, u64 *);
void (*to_text)(struct printbuf *, struct bch_fs *, u64); void (*to_text)(struct printbuf *, struct bch_fs *, struct bch_sb *, u64);
}; };
}; };
...@@ -481,6 +482,7 @@ bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id); ...@@ -481,6 +482,7 @@ bool bch2_opt_defined_by_id(const struct bch_opts *, enum bch_opt_id);
u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id); u64 bch2_opt_get_by_id(const struct bch_opts *, enum bch_opt_id);
void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64); void bch2_opt_set_by_id(struct bch_opts *, enum bch_opt_id, u64);
u64 bch2_opt_from_sb(struct bch_sb *, enum bch_opt_id);
int bch2_opts_from_sb(struct bch_opts *, struct bch_sb *); int bch2_opts_from_sb(struct bch_opts *, struct bch_sb *);
void __bch2_opt_set_sb(struct bch_sb *, const struct bch_option *, u64); void __bch2_opt_set_sb(struct bch_sb *, const struct bch_option *, u64);
void bch2_opt_set_sb(struct bch_fs *, const struct bch_option *, u64); void bch2_opt_set_sb(struct bch_fs *, const struct bch_option *, u64);
...@@ -492,7 +494,7 @@ int bch2_opt_parse(struct bch_fs *, const char *, const struct bch_option *, ...@@ -492,7 +494,7 @@ int bch2_opt_parse(struct bch_fs *, const char *, const struct bch_option *,
#define OPT_SHOW_FULL_LIST (1 << 0) #define OPT_SHOW_FULL_LIST (1 << 0)
#define OPT_SHOW_MOUNT_STYLE (1 << 1) #define OPT_SHOW_MOUNT_STYLE (1 << 1)
void bch2_opt_to_text(struct printbuf *, struct bch_fs *, void bch2_opt_to_text(struct printbuf *, struct bch_fs *, struct bch_sb *,
const struct bch_option *, u64, unsigned); const struct bch_option *, u64, unsigned);
int bch2_opt_check_may_set(struct bch_fs *, int, u64); int bch2_opt_check_may_set(struct bch_fs *, int, u64);
......
...@@ -1047,45 +1047,56 @@ static void bch2_sb_members_to_text(struct printbuf *out, struct bch_sb *sb, ...@@ -1047,45 +1047,56 @@ static void bch2_sb_members_to_text(struct printbuf *out, struct bch_sb *sb,
if (!bch2_member_exists(m)) if (!bch2_member_exists(m))
continue; continue;
pr_buf(out, "Device: %u", i); pr_buf(out, "Device:");
pr_tab(out);
pr_buf(out, "%u", i);
pr_newline(out); pr_newline(out);
pr_indent_push(out, 2); pr_indent_push(out, 2);
pr_buf(out, "UUID: "); pr_buf(out, "UUID:");
pr_tab(out);
pr_uuid(out, m->uuid.b); pr_uuid(out, m->uuid.b);
pr_newline(out); pr_newline(out);
pr_buf(out, "Size: "); pr_buf(out, "Size:");
pr_tab(out);
pr_units(out, device_size, device_size << 9); pr_units(out, device_size, device_size << 9);
pr_newline(out); pr_newline(out);
pr_buf(out, "Bucket size: "); pr_buf(out, "Bucket size:");
pr_tab(out);
pr_units(out, bucket_size, bucket_size << 9); pr_units(out, bucket_size, bucket_size << 9);
pr_newline(out); pr_newline(out);
pr_buf(out, "First bucket: %u", pr_buf(out, "First bucket:");
le16_to_cpu(m->first_bucket)); pr_tab(out);
pr_buf(out, "%u", le16_to_cpu(m->first_bucket));
pr_newline(out); pr_newline(out);
pr_buf(out, "Buckets: %llu", pr_buf(out, "Buckets:");
le64_to_cpu(m->nbuckets)); pr_tab(out);
pr_buf(out, "%llu", le64_to_cpu(m->nbuckets));
pr_newline(out); pr_newline(out);
pr_buf(out, "Last mount: "); pr_buf(out, "Last mount:");
pr_tab(out);
if (m->last_mount) if (m->last_mount)
pr_time(out, le64_to_cpu(m->last_mount)); pr_time(out, le64_to_cpu(m->last_mount));
else else
pr_buf(out, "(never)"); pr_buf(out, "(never)");
pr_newline(out); pr_newline(out);
pr_buf(out, "State: %s", pr_buf(out, "State:");
pr_tab(out);
pr_buf(out, "%s",
BCH_MEMBER_STATE(m) < BCH_MEMBER_STATE_NR BCH_MEMBER_STATE(m) < BCH_MEMBER_STATE_NR
? bch2_member_states[BCH_MEMBER_STATE(m)] ? bch2_member_states[BCH_MEMBER_STATE(m)]
: "unknown"); : "unknown");
pr_newline(out); pr_newline(out);
pr_buf(out, "Group: "); pr_buf(out, "Group:");
pr_tab(out);
if (BCH_MEMBER_GROUP(m)) { if (BCH_MEMBER_GROUP(m)) {
unsigned idx = BCH_MEMBER_GROUP(m) - 1; unsigned idx = BCH_MEMBER_GROUP(m) - 1;
...@@ -1099,7 +1110,8 @@ static void bch2_sb_members_to_text(struct printbuf *out, struct bch_sb *sb, ...@@ -1099,7 +1110,8 @@ static void bch2_sb_members_to_text(struct printbuf *out, struct bch_sb *sb,
} }
pr_newline(out); pr_newline(out);
pr_buf(out, "Data allowed: "); pr_buf(out, "Data allowed:");
pr_tab(out);
if (BCH_MEMBER_DATA_ALLOWED(m)) if (BCH_MEMBER_DATA_ALLOWED(m))
bch2_flags_to_text(out, bch2_data_types, bch2_flags_to_text(out, bch2_data_types,
BCH_MEMBER_DATA_ALLOWED(m)); BCH_MEMBER_DATA_ALLOWED(m));
...@@ -1107,15 +1119,17 @@ static void bch2_sb_members_to_text(struct printbuf *out, struct bch_sb *sb, ...@@ -1107,15 +1119,17 @@ static void bch2_sb_members_to_text(struct printbuf *out, struct bch_sb *sb,
pr_buf(out, "(none)"); pr_buf(out, "(none)");
pr_newline(out); pr_newline(out);
pr_buf(out, "Has data: "); pr_buf(out, "Has data:");
pr_tab(out);
if (data_have) if (data_have)
bch2_flags_to_text(out, bch2_data_types, data_have); bch2_flags_to_text(out, bch2_data_types, data_have);
else else
pr_buf(out, "(none)"); pr_buf(out, "(none)");
pr_newline(out); pr_newline(out);
pr_buf(out, "Discard: %llu", pr_buf(out, "Discard:");
BCH_MEMBER_DISCARD(m)); pr_tab(out);
pr_buf(out, "%llu", BCH_MEMBER_DISCARD(m));
pr_newline(out); pr_newline(out);
pr_indent_pop(out, 2); pr_indent_pop(out, 2);
...@@ -1452,6 +1466,9 @@ void bch2_sb_field_to_text(struct printbuf *out, struct bch_sb *sb, ...@@ -1452,6 +1466,9 @@ void bch2_sb_field_to_text(struct printbuf *out, struct bch_sb *sb,
const struct bch_sb_field_ops *ops = type < BCH_SB_FIELD_NR const struct bch_sb_field_ops *ops = type < BCH_SB_FIELD_NR
? bch2_sb_field_ops[type] : NULL; ? bch2_sb_field_ops[type] : NULL;
if (!out->tabstops[0])
out->tabstops[0] = 32;
if (ops) if (ops)
pr_buf(out, "%s", bch2_sb_fields[type]); pr_buf(out, "%s", bch2_sb_fields[type]);
else else
...@@ -1500,6 +1517,9 @@ void bch2_sb_to_text(struct printbuf *out, struct bch_sb *sb, ...@@ -1500,6 +1517,9 @@ void bch2_sb_to_text(struct printbuf *out, struct bch_sb *sb,
u64 fields_have = 0; u64 fields_have = 0;
unsigned nr_devices = 0; unsigned nr_devices = 0;
if (!out->tabstops[0])
out->tabstops[0] = 32;
mi = bch2_sb_get_members(sb); mi = bch2_sb_get_members(sb);
if (mi) { if (mi) {
struct bch_member *m; struct bch_member *m;
...@@ -1510,137 +1530,106 @@ void bch2_sb_to_text(struct printbuf *out, struct bch_sb *sb, ...@@ -1510,137 +1530,106 @@ void bch2_sb_to_text(struct printbuf *out, struct bch_sb *sb,
nr_devices += bch2_member_exists(m); nr_devices += bch2_member_exists(m);
} }
pr_buf(out, "External UUID: "); pr_buf(out, "External UUID:");
pr_tab(out);
pr_uuid(out, sb->user_uuid.b); pr_uuid(out, sb->user_uuid.b);
pr_newline(out); pr_newline(out);
pr_buf(out, "Internal UUID: "); pr_buf(out, "Internal UUID:");
pr_tab(out);
pr_uuid(out, sb->uuid.b); pr_uuid(out, sb->uuid.b);
pr_newline(out); pr_newline(out);
pr_buf(out, "Device index: %u", sb->dev_idx); pr_buf(out, "Device index:");
pr_tab(out);
pr_buf(out, "%u", sb->dev_idx);
pr_newline(out); pr_newline(out);
pr_buf(out, "Label: "); pr_buf(out, "Label:");
pr_tab(out);
pr_buf(out, "%.*s", (int) sizeof(sb->label), sb->label); pr_buf(out, "%.*s", (int) sizeof(sb->label), sb->label);
pr_newline(out); pr_newline(out);
pr_buf(out, "Version: %u", le16_to_cpu(sb->version)); pr_buf(out, "Version:");
pr_tab(out);
pr_buf(out, "%u", le16_to_cpu(sb->version));
pr_newline(out); pr_newline(out);
pr_buf(out, "Oldest version on disk: %u", le16_to_cpu(sb->version_min)); pr_buf(out, "Oldest version on disk:");
pr_tab(out);
pr_buf(out, "%u", le16_to_cpu(sb->version_min));
pr_newline(out); pr_newline(out);
pr_buf(out, "Created: "); pr_buf(out, "Created:");
pr_tab(out);
if (sb->time_base_lo) if (sb->time_base_lo)
pr_time(out, div_u64(le64_to_cpu(sb->time_base_lo), NSEC_PER_SEC)); pr_time(out, div_u64(le64_to_cpu(sb->time_base_lo), NSEC_PER_SEC));
else else
pr_buf(out, "(not set)"); pr_buf(out, "(not set)");
pr_newline(out); pr_newline(out);
pr_buf(out, "Squence number: %llu", le64_to_cpu(sb->seq)); pr_buf(out, "Sequence number:");
pr_tab(out);
pr_buf(out, "%llu", le64_to_cpu(sb->seq));
pr_newline(out); pr_newline(out);
pr_buf(out, "Block_size: "); pr_buf(out, "Superblock size:");
pr_units(out, le16_to_cpu(sb->block_size), pr_tab(out);
(u32) le16_to_cpu(sb->block_size) << 9); pr_buf(out, "%zu", vstruct_bytes(sb));
pr_newline(out); pr_newline(out);
pr_buf(out, "Btree node size: "); pr_buf(out, "Clean:");
pr_units(out, BCH_SB_BTREE_NODE_SIZE(sb), pr_tab(out);
BCH_SB_BTREE_NODE_SIZE(sb) << 9); pr_buf(out, "%llu", BCH_SB_CLEAN(sb));
pr_newline(out); pr_newline(out);
pr_buf(out, "Error action: %s", pr_buf(out, "Devices:");
BCH_SB_ERROR_ACTION(sb) < BCH_ON_ERROR_NR pr_tab(out);
? bch2_error_actions[BCH_SB_ERROR_ACTION(sb)] pr_buf(out, "%u", nr_devices);
: "unknown");
pr_newline(out); pr_newline(out);
pr_buf(out, "Clean: %llu", BCH_SB_CLEAN(sb)); pr_buf(out, "Sections:");
vstruct_for_each(sb, f)
fields_have |= 1 << le32_to_cpu(f->type);
pr_tab(out);
bch2_flags_to_text(out, bch2_sb_fields, fields_have);
pr_newline(out); pr_newline(out);
pr_buf(out, "Features: "); pr_buf(out, "Features:");
pr_tab(out);
bch2_flags_to_text(out, bch2_sb_features, bch2_flags_to_text(out, bch2_sb_features,
le64_to_cpu(sb->features[0])); le64_to_cpu(sb->features[0]));
pr_newline(out); pr_newline(out);
pr_buf(out, "Compat features: "); pr_buf(out, "Compat features:");
pr_tab(out);
bch2_flags_to_text(out, bch2_sb_compat, bch2_flags_to_text(out, bch2_sb_compat,
le64_to_cpu(sb->compat[0])); le64_to_cpu(sb->compat[0]));
pr_newline(out); pr_newline(out);
pr_buf(out, "Metadata replicas: %llu", BCH_SB_META_REPLICAS_WANT(sb));
pr_newline(out); pr_newline(out);
pr_buf(out, "Options:");
pr_buf(out, "Data replicas: %llu", BCH_SB_DATA_REPLICAS_WANT(sb));
pr_newline(out);
pr_buf(out, "Metadata checksum type: %s (%llu)",
BCH_SB_META_CSUM_TYPE(sb) < BCH_CSUM_OPT_NR
? bch2_csum_opts[BCH_SB_META_CSUM_TYPE(sb)]
: "unknown",
BCH_SB_META_CSUM_TYPE(sb));
pr_newline(out);
pr_buf(out, "Data checksum type: %s (%llu)",
BCH_SB_DATA_CSUM_TYPE(sb) < BCH_CSUM_OPT_NR
? bch2_csum_opts[BCH_SB_DATA_CSUM_TYPE(sb)]
: "unknown",
BCH_SB_DATA_CSUM_TYPE(sb));
pr_newline(out);
pr_buf(out, "Compression type: %s (%llu)",
BCH_SB_COMPRESSION_TYPE(sb) < BCH_COMPRESSION_OPT_NR
? bch2_compression_opts[BCH_SB_COMPRESSION_TYPE(sb)]
: "unknown",
BCH_SB_COMPRESSION_TYPE(sb));
pr_newline(out);
pr_buf(out, "Foreground write target: ");
bch2_sb_target_to_text(out, sb, BCH_SB_FOREGROUND_TARGET(sb));
pr_newline(out);
pr_buf(out, "Background write target: ");
bch2_sb_target_to_text(out, sb, BCH_SB_BACKGROUND_TARGET(sb));
pr_newline(out);
pr_buf(out, "Promote target: ");
bch2_sb_target_to_text(out, sb, BCH_SB_PROMOTE_TARGET(sb));
pr_newline(out);
pr_buf(out, "Metadata target: ");
bch2_sb_target_to_text(out, sb, BCH_SB_METADATA_TARGET(sb));
pr_newline(out);
pr_buf(out, "String hash type: %s (%llu)",
BCH_SB_STR_HASH_TYPE(sb) < BCH_STR_HASH_NR
? bch2_str_hash_types[BCH_SB_STR_HASH_TYPE(sb)]
: "unknown",
BCH_SB_STR_HASH_TYPE(sb));
pr_newline(out);
pr_buf(out, "32 bit inodes: %llu", BCH_SB_INODE_32BIT(sb));
pr_newline(out);
pr_buf(out, "GC reserve percentage: %llu%%", BCH_SB_GC_RESERVE(sb));
pr_newline(out); pr_newline(out);
pr_indent_push(out, 2);
{
enum bch_opt_id id;
pr_buf(out, "Root reserve percentage: %llu%%", BCH_SB_ROOT_RESERVE(sb)); for (id = 0; id < bch2_opts_nr; id++) {
pr_newline(out); const struct bch_option *opt = bch2_opt_table + id;
pr_buf(out, "Devices: %u live, %u total", if (opt->get_sb != BCH2_NO_SB_OPT) {
nr_devices, sb->nr_devices); u64 v = bch2_opt_from_sb(sb, id);
pr_newline(out);
pr_buf(out, "Sections: "); pr_buf(out, "%s:", opt->attr.name);
vstruct_for_each(sb, f) pr_tab(out);
fields_have |= 1 << le32_to_cpu(f->type); bch2_opt_to_text(out, NULL, sb, opt, v,
bch2_flags_to_text(out, bch2_sb_fields, fields_have); OPT_HUMAN_READABLE|OPT_SHOW_FULL_LIST);
pr_newline(out); pr_newline(out);
}
}
}
pr_buf(out, "Superblock size: %zu", vstruct_bytes(sb)); pr_indent_pop(out, 2);
pr_newline(out);
if (print_layout) { if (print_layout) {
pr_newline(out); pr_newline(out);
......
...@@ -891,7 +891,7 @@ static void print_mount_opts(struct bch_fs *c) ...@@ -891,7 +891,7 @@ static void print_mount_opts(struct bch_fs *c)
if (!first) if (!first)
pr_buf(&p, ","); pr_buf(&p, ",");
first = false; first = false;
bch2_opt_to_text(&p, c, opt, v, OPT_SHOW_MOUNT_STYLE); bch2_opt_to_text(&p, c, c->disk_sb.sb, opt, v, OPT_SHOW_MOUNT_STYLE);
} }
if (!p.pos) if (!p.pos)
......
...@@ -597,7 +597,7 @@ SHOW(bch2_fs_opts_dir) ...@@ -597,7 +597,7 @@ SHOW(bch2_fs_opts_dir)
int id = opt - bch2_opt_table; int id = opt - bch2_opt_table;
u64 v = bch2_opt_get_by_id(&c->opts, id); u64 v = bch2_opt_get_by_id(&c->opts, id);
bch2_opt_to_text(out, c, opt, v, OPT_SHOW_FULL_LIST); bch2_opt_to_text(out, c, c->disk_sb.sb, opt, v, OPT_SHOW_FULL_LIST);
pr_char(out, '\n'); pr_char(out, '\n');
return 0; return 0;
......
...@@ -448,7 +448,7 @@ static int __bch2_xattr_bcachefs_get(const struct xattr_handler *handler, ...@@ -448,7 +448,7 @@ static int __bch2_xattr_bcachefs_get(const struct xattr_handler *handler,
return -ENODATA; return -ENODATA;
v = bch2_opt_get_by_id(&opts, id); v = bch2_opt_get_by_id(&opts, id);
bch2_opt_to_text(&out, c, opt, v, 0); bch2_opt_to_text(&out, c, c->disk_sb.sb, opt, v, 0);
ret = out.pos; ret = out.pos;
......
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