Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 85b1492e authored by Kent Overstreet's avatar Kent Overstreet
Browse files

bcache: Rip out pkey()/pbtree()



Old gcc doesnt like the struct hack, and it is kind of ugly. So finish
off the work to convert pr_debug() statements to tracepoints, and delete
pkey()/pbtree().

Signed-off-by: default avatarKent Overstreet <koverstreet@google.com>
parent c37511b8
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ struct bkey *bch_keylist_pop(struct keylist *l)
bool __bch_ptr_invalid(struct cache_set *c, int level, const struct bkey *k)
{
	unsigned i;
	char buf[80];

	if (level && (!KEY_PTRS(k) || !KEY_SIZE(k) || KEY_DIRTY(k)))
		goto bad;
@@ -102,7 +103,8 @@ bool __bch_ptr_invalid(struct cache_set *c, int level, const struct bkey *k)

	return false;
bad:
	cache_bug(c, "spotted bad key %s: %s", pkey(k), bch_ptr_status(c, k));
	bch_bkey_to_text(buf, sizeof(buf), k);
	cache_bug(c, "spotted bad key %s: %s", buf, bch_ptr_status(c, k));
	return true;
}

@@ -162,10 +164,16 @@ bool bch_ptr_bad(struct btree *b, const struct bkey *k)
#ifdef CONFIG_BCACHE_EDEBUG
bug:
	mutex_unlock(&b->c->bucket_lock);

	{
		char buf[80];

		bch_bkey_to_text(buf, sizeof(buf), k);
		btree_bug(b,
"inconsistent pointer %s: bucket %zu pin %i prio %i gen %i last_gc %i mark %llu gc_gen %i",
		  pkey(k), PTR_BUCKET_NR(b->c, k, i), atomic_read(&g->pin),
			  buf, PTR_BUCKET_NR(b->c, k, i), atomic_read(&g->pin),
			  g->prio, g->gen, g->last_gc, GC_MARK(g), g->gc_gen);
	}
	return true;
#endif
}
+6 −15
Original line number Diff line number Diff line
@@ -1770,7 +1770,7 @@ static bool btree_insert_key(struct btree *b, struct btree_op *op,
{
	struct bset *i = b->sets[b->nsets].data;
	struct bkey *m, *prev;
	const char *status = "insert";
	unsigned status = BTREE_INSERT_STATUS_INSERT;

	BUG_ON(bkey_cmp(k, &b->key) > 0);
	BUG_ON(b->level && !KEY_PTRS(k));
@@ -1803,17 +1803,17 @@ static bool btree_insert_key(struct btree *b, struct btree_op *op,
			goto insert;

		/* prev is in the tree, if we merge we're done */
		status = "back merging";
		status = BTREE_INSERT_STATUS_BACK_MERGE;
		if (prev &&
		    bch_bkey_try_merge(b, prev, k))
			goto merged;

		status = "overwrote front";
		status = BTREE_INSERT_STATUS_OVERWROTE;
		if (m != end(i) &&
		    KEY_PTRS(m) == KEY_PTRS(k) && !KEY_SIZE(m))
			goto copy;

		status = "front merge";
		status = BTREE_INSERT_STATUS_FRONT_MERGE;
		if (m != end(i) &&
		    bch_bkey_try_merge(b, k, m))
			goto copy;
@@ -1823,16 +1823,12 @@ static bool btree_insert_key(struct btree *b, struct btree_op *op,
insert:	shift_keys(b, m, k);
copy:	bkey_copy(m, k);
merged:
	bch_check_keys(b, "%s for %s at %s: %s", status,
		       op_type(op), pbtree(b), pkey(k));
	bch_check_key_order_msg(b, i, "%s for %s at %s: %s", status,
				op_type(op), pbtree(b), pkey(k));
	bch_check_keys(b, "%u for %s", status, op_type(op));

	if (b->level && !KEY_OFFSET(k))
		btree_current_write(b)->prio_blocked++;

	pr_debug("%s for %s at %s: %s", status,
		 op_type(op), pbtree(b), pkey(k));
	trace_bcache_btree_insert_key(b, k, op->type, status);

	return true;
}
@@ -2234,9 +2230,6 @@ int bch_btree_search_recurse(struct btree *b, struct btree_op *op)
	struct btree_iter iter;
	bch_btree_iter_init(b, &iter, &KEY(op->inode, bio->bi_sector, 0));

	pr_debug("at %s searching for %u:%llu", pbtree(b), op->inode,
		 (uint64_t) bio->bi_sector);

	do {
		k = bch_btree_iter_next_filter(&iter, b, bch_ptr_bad);
		if (!k) {
@@ -2302,8 +2295,6 @@ static int bch_btree_refill_keybuf(struct btree *b, struct btree_op *op,
			if (buf->key_predicate(buf, k)) {
				struct keybuf_key *w;

				pr_debug("%s", pkey(k));

				spin_lock(&buf->lock);

				w = array_alloc(&buf->freelist);
+7 −0
Original line number Diff line number Diff line
@@ -271,6 +271,13 @@ struct btree_op {
	BKEY_PADDED(replace);
};

enum {
	BTREE_INSERT_STATUS_INSERT,
	BTREE_INSERT_STATUS_BACK_MERGE,
	BTREE_INSERT_STATUS_OVERWROTE,
	BTREE_INSERT_STATUS_FRONT_MERGE,
};

void bch_btree_op_init_stack(struct btree_op *);

static inline void rw_lock(bool w, struct btree *b, int level)
+25 −15
Original line number Diff line number Diff line
@@ -47,11 +47,10 @@ const char *bch_ptr_status(struct cache_set *c, const struct bkey *k)
	return "";
}

struct keyprint_hack bch_pkey(const struct bkey *k)
int bch_bkey_to_text(char *buf, size_t size, const struct bkey *k)
{
	unsigned i = 0;
	struct keyprint_hack r;
	char *out = r.s, *end = r.s + KEYHACK_SIZE;
	char *out = buf, *end = buf + size;

#define p(...)	(out += scnprintf(out, end - out, __VA_ARGS__))

@@ -75,16 +74,14 @@ struct keyprint_hack bch_pkey(const struct bkey *k)
	if (KEY_CSUM(k))
		p(" cs%llu %llx", KEY_CSUM(k), k->ptr[1]);
#undef p
	return r;
	return out - buf;
}

struct keyprint_hack bch_pbtree(const struct btree *b)
int bch_btree_to_text(char *buf, size_t size, const struct btree *b)
{
	struct keyprint_hack r;

	snprintf(r.s, 40, "%zu level %i/%i", PTR_BUCKET_NR(b->c, &b->key, 0),
	return scnprintf(buf, size, "%zu level %i/%i",
			 PTR_BUCKET_NR(b->c, &b->key, 0),
			 b->level, b->c->root ? b->c->root->level : -1);
	return r;
}

#if defined(CONFIG_BCACHE_DEBUG) || defined(CONFIG_BCACHE_EDEBUG)
@@ -100,10 +97,12 @@ static void dump_bset(struct btree *b, struct bset *i)
{
	struct bkey *k;
	unsigned j;
	char buf[80];

	for (k = i->start; k < end(i); k = bkey_next(k)) {
		bch_bkey_to_text(buf, sizeof(buf), k);
		printk(KERN_ERR "block %zu key %zi/%u: %s", index(i, b),
		       (uint64_t *) k - i->d, i->keys, pkey(k));
		       (uint64_t *) k - i->d, i->keys, buf);

		for (j = 0; j < KEY_PTRS(k); j++) {
			size_t n = PTR_BUCKET_NR(b->c, k, j);
@@ -252,6 +251,7 @@ static void vdump_bucket_and_panic(struct btree *b, const char *fmt,
				   va_list args)
{
	unsigned i;
	char buf[80];

	console_lock();

@@ -262,7 +262,8 @@ static void vdump_bucket_and_panic(struct btree *b, const char *fmt,

	console_unlock();

	panic("at %s\n", pbtree(b));
	bch_btree_to_text(buf, sizeof(buf), b);
	panic("at %s\n", buf);
}

void bch_check_key_order_msg(struct btree *b, struct bset *i,
@@ -337,6 +338,7 @@ static ssize_t bch_dump_read(struct file *file, char __user *buf,
{
	struct dump_iterator *i = file->private_data;
	ssize_t ret = 0;
	char kbuf[80];

	while (size) {
		struct keybuf_key *w;
@@ -359,7 +361,8 @@ static ssize_t bch_dump_read(struct file *file, char __user *buf,
		if (!w)
			break;

		i->bytes = snprintf(i->buf, PAGE_SIZE, "%s\n", pkey(&w->key));
		bch_bkey_to_text(kbuf, sizeof(kbuf), &w->key);
		i->bytes = snprintf(i->buf, PAGE_SIZE, "%s\n", kbuf);
		bch_keybuf_del(&i->keys, w);
	}

@@ -526,10 +529,17 @@ static ssize_t btree_fuzz(struct kobject *k, struct kobj_attribute *a,
			     k < end(i);
			     k = bkey_next(k), l = bkey_next(l))
				if (bkey_cmp(k, l) ||
				    KEY_SIZE(k) != KEY_SIZE(l))
				    KEY_SIZE(k) != KEY_SIZE(l)) {
					char buf1[80];
					char buf2[80];

					bch_bkey_to_text(buf1, sizeof(buf1), k);
					bch_bkey_to_text(buf2, sizeof(buf2), l);

					pr_err("key %zi differs: %s != %s",
					       (uint64_t *) k - i->d,
					       pkey(k), pkey(l));
					       buf1, buf2);
				}

			for (j = 0; j < 3; j++) {
				pr_err("**** Set %i ****", j);
+2 −9
Original line number Diff line number Diff line
@@ -3,15 +3,8 @@

/* Btree/bkey debug printing */

#define KEYHACK_SIZE 80
struct keyprint_hack {
	char s[KEYHACK_SIZE];
};

struct keyprint_hack bch_pkey(const struct bkey *k);
struct keyprint_hack bch_pbtree(const struct btree *b);
#define pkey(k)		(&bch_pkey(k).s[0])
#define pbtree(b)	(&bch_pbtree(b).s[0])
int bch_bkey_to_text(char *buf, size_t size, const struct bkey *k);
int bch_btree_to_text(char *buf, size_t size, const struct btree *b);

#ifdef CONFIG_BCACHE_EDEBUG

Loading