Commit 2f4e9472 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: bch2_open_bucket_to_text()

Factor out a common helper
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 11bb67a4
...@@ -1329,23 +1329,56 @@ void bch2_fs_allocator_foreground_init(struct bch_fs *c) ...@@ -1329,23 +1329,56 @@ void bch2_fs_allocator_foreground_init(struct bch_fs *c)
} }
} }
static void bch2_open_bucket_to_text(struct printbuf *out, struct bch_fs *c, struct open_bucket *ob)
{
struct bch_dev *ca = bch_dev_bkey_exists(c, ob->dev);
unsigned data_type = ob->data_type;
barrier(); /* READ_ONCE() doesn't work on bitfields */
prt_printf(out, "%zu ref %u %s %u:%llu gen %u allocated %u/%u",
ob - c->open_buckets,
atomic_read(&ob->pin),
data_type < BCH_DATA_NR ? bch2_data_types[data_type] : "invalid data type",
ob->dev, ob->bucket, ob->gen,
ca->mi.bucket_size - ob->sectors_free, ca->mi.bucket_size);
if (ob->ec)
prt_printf(out, " ec idx %llu", ob->ec->idx);
if (ob->on_partial_list)
prt_str(out, " partial");
prt_newline(out);
}
void bch2_open_buckets_to_text(struct printbuf *out, struct bch_fs *c) void bch2_open_buckets_to_text(struct printbuf *out, struct bch_fs *c)
{ {
struct open_bucket *ob; struct open_bucket *ob;
out->atomic++;
for (ob = c->open_buckets; for (ob = c->open_buckets;
ob < c->open_buckets + ARRAY_SIZE(c->open_buckets); ob < c->open_buckets + ARRAY_SIZE(c->open_buckets);
ob++) { ob++) {
spin_lock(&ob->lock); spin_lock(&ob->lock);
if (ob->valid && !ob->on_partial_list) { if (ob->valid && !ob->on_partial_list)
prt_printf(out, "%zu ref %u type %s %u:%llu:%u\n", bch2_open_bucket_to_text(out, c, ob);
ob - c->open_buckets,
atomic_read(&ob->pin),
bch2_data_types[ob->data_type],
ob->dev, ob->bucket, ob->gen);
}
spin_unlock(&ob->lock); spin_unlock(&ob->lock);
} }
--out->atomic;
}
void bch2_open_buckets_partial_to_text(struct printbuf *out, struct bch_fs *c)
{
unsigned i;
out->atomic++;
spin_lock(&c->freelist_lock);
for (i = 0; i < c->open_buckets_partial_nr; i++)
bch2_open_bucket_to_text(out, c,
c->open_buckets + c->open_buckets_partial[i]);
spin_unlock(&c->freelist_lock);
--out->atomic;
} }
static const char * const bch2_write_point_states[] = { static const char * const bch2_write_point_states[] = {
......
...@@ -221,6 +221,7 @@ static inline struct write_point_specifier writepoint_ptr(struct write_point *wp ...@@ -221,6 +221,7 @@ static inline struct write_point_specifier writepoint_ptr(struct write_point *wp
void bch2_fs_allocator_foreground_init(struct bch_fs *); void bch2_fs_allocator_foreground_init(struct bch_fs *);
void bch2_open_buckets_to_text(struct printbuf *, struct bch_fs *); void bch2_open_buckets_to_text(struct printbuf *, struct bch_fs *);
void bch2_open_buckets_partial_to_text(struct printbuf *, struct bch_fs *);
void bch2_write_points_to_text(struct printbuf *, struct bch_fs *); void bch2_write_points_to_text(struct printbuf *, struct bch_fs *);
......
...@@ -194,6 +194,7 @@ read_attribute(btree_cache); ...@@ -194,6 +194,7 @@ read_attribute(btree_cache);
read_attribute(btree_key_cache); read_attribute(btree_key_cache);
read_attribute(stripes_heap); read_attribute(stripes_heap);
read_attribute(open_buckets); read_attribute(open_buckets);
read_attribute(open_buckets_partial);
read_attribute(write_points); read_attribute(write_points);
read_attribute(nocow_lock_table); read_attribute(nocow_lock_table);
...@@ -455,6 +456,9 @@ SHOW(bch2_fs) ...@@ -455,6 +456,9 @@ SHOW(bch2_fs)
if (attr == &sysfs_open_buckets) if (attr == &sysfs_open_buckets)
bch2_open_buckets_to_text(out, c); bch2_open_buckets_to_text(out, c);
if (attr == &sysfs_open_buckets_partial)
bch2_open_buckets_partial_to_text(out, c);
if (attr == &sysfs_write_points) if (attr == &sysfs_write_points)
bch2_write_points_to_text(out, c); bch2_write_points_to_text(out, c);
...@@ -663,6 +667,7 @@ struct attribute *bch2_fs_internal_files[] = { ...@@ -663,6 +667,7 @@ struct attribute *bch2_fs_internal_files[] = {
&sysfs_new_stripes, &sysfs_new_stripes,
&sysfs_stripes_heap, &sysfs_stripes_heap,
&sysfs_open_buckets, &sysfs_open_buckets,
&sysfs_open_buckets_partial,
&sysfs_write_points, &sysfs_write_points,
#ifdef BCH_WRITE_REF_DEBUG #ifdef BCH_WRITE_REF_DEBUG
&sysfs_write_refs, &sysfs_write_refs,
......
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