summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2017-02-02 22:26:24 -0900
committerKent Overstreet <kent.overstreet@gmail.com>2017-02-06 20:43:39 -0900
commitb1f945ee785fdec1bc953efe7d2edd6262d2f322 (patch)
treea7851581a25f7ff51eae095bc9543b3c6d9b7bc5
parent53cbdcd2d4b1eaa205ff76b91204049d4c314342 (diff)
bcache: more bcache-in-userspace stuff
-rw-r--r--drivers/md/bcache/btree_cache.c48
-rw-r--r--drivers/md/bcache/btree_cache.h10
-rw-r--r--drivers/md/bcache/btree_update.h7
-rw-r--r--drivers/md/bcache/debug.c57
-rw-r--r--drivers/md/bcache/super.c1
5 files changed, 65 insertions, 58 deletions
diff --git a/drivers/md/bcache/btree_cache.c b/drivers/md/bcache/btree_cache.c
index 342b53a8cb4b..7b75c1db6388 100644
--- a/drivers/md/bcache/btree_cache.c
+++ b/drivers/md/bcache/btree_cache.c
@@ -700,3 +700,51 @@ retry:
return b;
}
+
+int bch_print_btree_node(struct cache_set *c, struct btree *b,
+ char *buf, size_t len)
+{
+ const struct bkey_format *f = &b->format;
+ struct bset_stats stats;
+
+ memset(&stats, 0, sizeof(stats));
+
+ bch_btree_keys_stats(b, &stats);
+
+ return scnprintf(buf, len,
+ "l %u %llu:%llu - %llu:%llu:\n"
+ " format: u64s %u fields %u %u %u %u %u\n"
+ " unpack fn len: %u\n"
+ " bytes used %zu/%zu (%zu%% full)\n"
+ " sib u64s: %u, %u (merge threshold %zu)\n"
+ " nr packed keys %u\n"
+ " nr unpacked keys %u\n"
+ " floats %zu\n"
+ " failed unpacked %zu\n"
+ " failed prev %zu\n"
+ " failed overflow %zu\n",
+ b->level,
+ b->data->min_key.inode,
+ b->data->min_key.offset,
+ b->data->max_key.inode,
+ b->data->max_key.offset,
+ f->key_u64s,
+ f->bits_per_field[0],
+ f->bits_per_field[1],
+ f->bits_per_field[2],
+ f->bits_per_field[3],
+ f->bits_per_field[4],
+ b->unpack_fn_len,
+ b->nr.live_u64s * sizeof(u64),
+ btree_bytes(c) - sizeof(struct btree_node),
+ b->nr.live_u64s * 100 / btree_max_u64s(c),
+ b->sib_u64s[0],
+ b->sib_u64s[1],
+ BTREE_FOREGROUND_MERGE_THRESHOLD(c),
+ b->nr.packed_keys,
+ b->nr.unpacked_keys,
+ stats.floats,
+ stats.failed_unpacked,
+ stats.failed_prev,
+ stats.failed_overflow);
+}
diff --git a/drivers/md/bcache/btree_cache.h b/drivers/md/bcache/btree_cache.h
index e745abbe9219..c26489d129cd 100644
--- a/drivers/md/bcache/btree_cache.h
+++ b/drivers/md/bcache/btree_cache.h
@@ -56,6 +56,16 @@ static inline unsigned btree_blocks(struct cache_set *c)
return c->sb.btree_node_size >> c->block_bits;
}
+#define BTREE_SPLIT_THRESHOLD(c) (btree_blocks(c) * 3 / 4)
+
+#define BTREE_FOREGROUND_MERGE_THRESHOLD(c) (btree_max_u64s(c) * 1 / 3)
+#define BTREE_FOREGROUND_MERGE_HYSTERESIS(c) \
+ (BTREE_FOREGROUND_MERGE_THRESHOLD(c) + \
+ (BTREE_FOREGROUND_MERGE_THRESHOLD(c) << 2))
+
#define btree_node_root(_c, _b) ((_c)->btree_roots[(_b)->btree_id].b)
+int bch_print_btree_node(struct cache_set *, struct btree *,
+ char *, size_t);
+
#endif /* _BCACHE_BTREE_CACHE_H */
diff --git a/drivers/md/bcache/btree_update.h b/drivers/md/bcache/btree_update.h
index 015444109984..5fc1b1aaf069 100644
--- a/drivers/md/bcache/btree_update.h
+++ b/drivers/md/bcache/btree_update.h
@@ -11,13 +11,6 @@ struct bkey_format_state;
struct bkey_format;
struct btree;
-#define BTREE_SPLIT_THRESHOLD(c) (btree_blocks(c) * 3 / 4)
-
-#define BTREE_FOREGROUND_MERGE_THRESHOLD(c) (btree_max_u64s(c) * 1 / 3)
-#define BTREE_FOREGROUND_MERGE_HYSTERESIS(c) \
- (BTREE_FOREGROUND_MERGE_THRESHOLD(c) + \
- (BTREE_FOREGROUND_MERGE_THRESHOLD(c) << 2))
-
static inline void btree_node_reset_sib_u64s(struct btree *b)
{
b->sib_u64s[0] = b->nr.live_u64s;
diff --git a/drivers/md/bcache/debug.c b/drivers/md/bcache/debug.c
index 11c64b52068b..39f5550e887c 100644
--- a/drivers/md/bcache/debug.c
+++ b/drivers/md/bcache/debug.c
@@ -299,55 +299,6 @@ static const struct file_operations btree_debug_ops = {
.read = bch_read_btree,
};
-static int print_btree_node(struct dump_iter *i, struct btree *b)
-{
- const struct bkey_format *f = &b->format;
- struct bset_stats stats;
-
- memset(&stats, 0, sizeof(stats));
-
- bch_btree_keys_stats(b, &stats);
-
- i->bytes = scnprintf(i->buf, sizeof(i->buf),
- "l %u %llu:%llu - %llu:%llu:\n"
- " format: u64s %u fields %u %u %u %u %u\n"
- " unpack fn len: %u\n"
- " bytes used %zu/%zu (%zu%% full)\n"
- " sib u64s: %u, %u (merge threshold %zu)\n"
- " nr packed keys %u\n"
- " nr unpacked keys %u\n"
- " floats %zu\n"
- " failed unpacked %zu\n"
- " failed prev %zu\n"
- " failed overflow %zu\n",
- b->level,
- b->data->min_key.inode,
- b->data->min_key.offset,
- b->data->max_key.inode,
- b->data->max_key.offset,
- f->key_u64s,
- f->bits_per_field[0],
- f->bits_per_field[1],
- f->bits_per_field[2],
- f->bits_per_field[3],
- f->bits_per_field[4],
- b->unpack_fn_len,
- b->nr.live_u64s * sizeof(u64),
- btree_bytes(i->c) - sizeof(struct btree_node),
- b->nr.live_u64s * 100 / btree_max_u64s(i->c),
- b->sib_u64s[0],
- b->sib_u64s[1],
- BTREE_FOREGROUND_MERGE_THRESHOLD(i->c),
- b->nr.packed_keys,
- b->nr.unpacked_keys,
- stats.floats,
- stats.failed_unpacked,
- stats.failed_prev,
- stats.failed_overflow);
-
- return flush_buf(i);
-}
-
static ssize_t bch_read_btree_formats(struct file *file, char __user *buf,
size_t size, loff_t *ppos)
{
@@ -368,7 +319,9 @@ static ssize_t bch_read_btree_formats(struct file *file, char __user *buf,
return i->ret;
for_each_btree_node(&iter, i->c, i->id, i->from, 0, b) {
- err = print_btree_node(i, b);
+ i->bytes = bch_print_btree_node(i->c, b, i->buf,
+ sizeof(i->buf));
+ err = flush_buf(i);
if (err)
break;
@@ -424,7 +377,9 @@ static ssize_t bch_read_bfloat_failed(struct file *file, char __user *buf,
struct bkey_packed *_k = bch_btree_node_iter_peek(node_iter, b);
if (iter.nodes[0] != prev_node) {
- err = print_btree_node(i, iter.nodes[0]);
+ i->bytes = bch_print_btree_node(i->c, b, i->buf,
+ sizeof(i->buf));
+ err = flush_buf(i);
if (err)
break;
}
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 3f64e1075b43..bdbdfe92325a 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -2315,6 +2315,7 @@ const char *bch_register_cache_set(char * const *devices, unsigned nr_devices,
out:
kfree(sb);
module_put(THIS_MODULE);
+ BUG_ON(!err == !c);
return err;
err_unlock:
if (c)