Commit bf0d9e89 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Split apart bch2_target_to_text(), bch2_target_to_text_sb()

Previously we just had bch2_opt_target_to_text() which could be passed
either a filesystem object or just a superblock - depending on if we
have a running filesystem or not.

Split these into two functions for clarity.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 523f33ef
...@@ -493,10 +493,7 @@ int bch2_opt_target_parse(struct bch_fs *c, const char *val, u64 *res, ...@@ -493,10 +493,7 @@ int bch2_opt_target_parse(struct bch_fs *c, const char *val, u64 *res,
return -EINVAL; return -EINVAL;
} }
void bch2_opt_target_to_text(struct printbuf *out, void bch2_target_to_text(struct printbuf *out, struct bch_fs *c, unsigned v)
struct bch_fs *c,
struct bch_sb *sb,
u64 v)
{ {
struct target t = target_decode(v); struct target t = target_decode(v);
...@@ -504,8 +501,7 @@ void bch2_opt_target_to_text(struct printbuf *out, ...@@ -504,8 +501,7 @@ void bch2_opt_target_to_text(struct printbuf *out,
case TARGET_NULL: case TARGET_NULL:
prt_printf(out, "none"); prt_printf(out, "none");
break; break;
case TARGET_DEV: case TARGET_DEV: {
if (c) {
struct bch_dev *ca; struct bch_dev *ca;
rcu_read_lock(); rcu_read_lock();
...@@ -523,7 +519,27 @@ void bch2_opt_target_to_text(struct printbuf *out, ...@@ -523,7 +519,27 @@ void bch2_opt_target_to_text(struct printbuf *out,
} }
rcu_read_unlock(); rcu_read_unlock();
} else { 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;
default:
BUG();
}
}
void bch2_target_to_text_sb(struct printbuf *out, struct bch_sb *sb, unsigned v)
{
struct target t = target_decode(v);
switch (t.type) {
case TARGET_NULL:
prt_printf(out, "none");
break;
case TARGET_DEV: {
struct bch_member m = bch2_sb_member_get(sb, t.dev); struct bch_member m = bch2_sb_member_get(sb, t.dev);
if (bch2_dev_exists(sb, t.dev)) { if (bch2_dev_exists(sb, t.dev)) {
...@@ -533,18 +549,23 @@ void bch2_opt_target_to_text(struct printbuf *out, ...@@ -533,18 +549,23 @@ void bch2_opt_target_to_text(struct printbuf *out,
} else { } else {
prt_printf(out, "Bad device %u", t.dev); prt_printf(out, "Bad device %u", t.dev);
} }
}
break; break;
}
case TARGET_GROUP: case TARGET_GROUP:
if (c) {
mutex_lock(&c->sb_lock);
bch2_disk_path_to_text(out, c->disk_sb.sb, t.group);
mutex_unlock(&c->sb_lock);
} else {
bch2_disk_path_to_text(out, sb, t.group); bch2_disk_path_to_text(out, sb, t.group);
}
break; break;
default: default:
BUG(); BUG();
} }
} }
void bch2_opt_target_to_text(struct printbuf *out,
struct bch_fs *c,
struct bch_sb *sb,
u64 v)
{
if (c)
bch2_target_to_text(out, c, v);
else
bch2_target_to_text_sb(out, sb, v);
}
...@@ -84,6 +84,7 @@ int bch2_disk_path_find(struct bch_sb_handle *, const char *); ...@@ -84,6 +84,7 @@ int bch2_disk_path_find(struct bch_sb_handle *, const char *);
int bch2_disk_path_find_or_create(struct bch_sb_handle *, const char *); 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_target_to_text(struct printbuf *out, struct bch_fs *, unsigned);
int bch2_opt_target_parse(struct bch_fs *, const char *, u64 *, struct printbuf *); int bch2_opt_target_parse(struct bch_fs *, const char *, u64 *, struct printbuf *);
void bch2_opt_target_to_text(struct printbuf *, struct bch_fs *, struct bch_sb *, u64); void bch2_opt_target_to_text(struct printbuf *, struct bch_fs *, struct bch_sb *, u64);
......
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