Skip to content

Commit 3621ecc

Browse files
author
Kent Overstreet
committed
bcachefs: bch2_opts_to_text()
Factor out bch2_show_options() into a generic helper, for debugging option passing issues. Signed-off-by: Kent Overstreet <[email protected]>
1 parent bf61156 commit 3621ecc

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed

fs/bcachefs/fs.c

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,30 +1930,14 @@ static int bch2_show_devname(struct seq_file *seq, struct dentry *root)
19301930
static int bch2_show_options(struct seq_file *seq, struct dentry *root)
19311931
{
19321932
struct bch_fs *c = root->d_sb->s_fs_info;
1933-
enum bch_opt_id i;
19341933
struct printbuf buf = PRINTBUF;
1935-
int ret = 0;
1936-
1937-
for (i = 0; i < bch2_opts_nr; i++) {
1938-
const struct bch_option *opt = &bch2_opt_table[i];
1939-
u64 v = bch2_opt_get_by_id(&c->opts, i);
1940-
1941-
if ((opt->flags & OPT_HIDDEN) ||
1942-
!(opt->flags & OPT_MOUNT))
1943-
continue;
19441934

1945-
if (v == bch2_opt_get_by_id(&bch2_opts_default, i))
1946-
continue;
1947-
1948-
printbuf_reset(&buf);
1949-
bch2_opt_to_text(&buf, c, c->disk_sb.sb, opt, v,
1950-
OPT_SHOW_MOUNT_STYLE);
1951-
seq_putc(seq, ',');
1952-
seq_puts(seq, buf.buf);
1953-
}
1935+
bch2_opts_to_text(&buf, c->opts, c, c->disk_sb.sb,
1936+
OPT_MOUNT, OPT_HIDDEN, OPT_SHOW_MOUNT_STYLE);
1937+
printbuf_nul_terminate(&buf);
1938+
seq_puts(seq, buf.buf);
19541939

1955-
if (buf.allocation_failure)
1956-
ret = -ENOMEM;
1940+
int ret = buf.allocation_failure ? -ENOMEM : 0;
19571941
printbuf_exit(&buf);
19581942
return ret;
19591943
}

fs/bcachefs/opts.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,32 @@ void bch2_opt_to_text(struct printbuf *out,
443443
}
444444
}
445445

446+
void bch2_opts_to_text(struct printbuf *out,
447+
struct bch_opts opts,
448+
struct bch_fs *c, struct bch_sb *sb,
449+
unsigned show_mask, unsigned hide_mask,
450+
unsigned flags)
451+
{
452+
bool first = true;
453+
454+
for (enum bch_opt_id i = 0; i < bch2_opts_nr; i++) {
455+
const struct bch_option *opt = &bch2_opt_table[i];
456+
457+
if ((opt->flags & hide_mask) || !(opt->flags & show_mask))
458+
continue;
459+
460+
u64 v = bch2_opt_get_by_id(&opts, i);
461+
if (v == bch2_opt_get_by_id(&bch2_opts_default, i))
462+
continue;
463+
464+
if (!first)
465+
prt_char(out, ',');
466+
first = false;
467+
468+
bch2_opt_to_text(out, c, sb, opt, v, flags);
469+
}
470+
}
471+
446472
int bch2_opt_check_may_set(struct bch_fs *c, int id, u64 v)
447473
{
448474
int ret = 0;

fs/bcachefs/opts.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,10 @@ int bch2_opt_parse(struct bch_fs *, const struct bch_option *,
605605

606606
void bch2_opt_to_text(struct printbuf *, struct bch_fs *, struct bch_sb *,
607607
const struct bch_option *, u64, unsigned);
608+
void bch2_opts_to_text(struct printbuf *,
609+
struct bch_opts,
610+
struct bch_fs *, struct bch_sb *,
611+
unsigned, unsigned, unsigned);
608612

609613
int bch2_opt_check_may_set(struct bch_fs *, int, u64);
610614
int bch2_opts_check_may_set(struct bch_fs *);

0 commit comments

Comments
 (0)