summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kmo@daterainc.com>2013-09-10 19:22:01 -0700
committerKent Overstreet <kmo@daterainc.com>2013-10-03 15:23:43 -0700
commitbede09ee2be090aa9e2d11b6b33d9b95a1203a60 (patch)
treea0bae5cf6b54209ab9a243bdb47c1404f1abed3d
parent9c67cdb8dcaac85645f457dd1c32219e136428c6 (diff)
bcache: Bkey indexing renaming
More refactoring: node() -> bset_bkey_idx() end() -> bset_bkey_last() Signed-off-by: Kent Overstreet <kmo@daterainc.com>
-rw-r--r--drivers/md/bcache/bcache.h11
-rw-r--r--drivers/md/bcache/bset.c28
-rw-r--r--drivers/md/bcache/bset.h30
-rw-r--r--drivers/md/bcache/btree.c33
-rw-r--r--drivers/md/bcache/debug.c4
-rw-r--r--drivers/md/bcache/journal.c6
-rw-r--r--include/uapi/linux/bcache.h2
7 files changed, 62 insertions, 52 deletions
diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
index fa67ff4ff95f..3f50e9e79df4 100644
--- a/drivers/md/bcache/bcache.h
+++ b/drivers/md/bcache/bcache.h
@@ -728,9 +728,6 @@ static inline unsigned local_clock_us(void)
#define __set_blocks(i, k, c) DIV_ROUND_UP(__set_bytes(i, k), block_bytes(c))
#define set_blocks(i, c) __set_blocks(i, (i)->keys, c)
-#define node(i, j) ((struct bkey *) ((i)->d + (j)))
-#define end(i) node(i, (i)->keys)
-
#define index(i, b) \
((size_t) (((void *) i - (void *) (b)->sets[0].data) / \
block_bytes(b->c)))
@@ -799,18 +796,14 @@ static inline bool ptr_available(struct cache_set *c, const struct bkey *k,
/* Btree key macros */
-static inline void bkey_init(struct bkey *k)
-{
- *k = ZERO_KEY;
-}
-
/*
* This is used for various on disk data structures - cache_sb, prio_set, bset,
* jset: The checksum is _always_ the first 8 bytes of these structs
*/
#define csum_set(i) \
bch_crc64(((void *) (i)) + sizeof(uint64_t), \
- ((void *) end(i)) - (((void *) (i)) + sizeof(uint64_t)))
+ ((void *) bset_bkey_last(i)) - \
+ (((void *) (i)) + sizeof(uint64_t)))
/* Error handling macros */
diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c
index 1a60fda4e828..2a7c22b18cfe 100644
--- a/drivers/md/bcache/bset.c
+++ b/drivers/md/bcache/bset.c
@@ -508,7 +508,7 @@ static void make_bfloat(struct bset_tree *t, unsigned j)
: tree_to_prev_bkey(t, j >> ffs(j));
struct bkey *r = is_power_of_2(j + 1)
- ? node(t->data, t->data->keys - bkey_u64s(&t->end))
+ ? bset_bkey_idx(t->data, t->data->keys - bkey_u64s(&t->end))
: tree_to_bkey(t, j >> (ffz(j) + 1));
BUG_ON(m < l || m > r);
@@ -567,7 +567,7 @@ static void bset_build_written_tree(struct btree *b)
bset_alloc_tree(b, t);
t->size = min_t(unsigned,
- bkey_to_cacheline(t, end(t->data)),
+ bkey_to_cacheline(t, bset_bkey_last(t->data)),
b->sets->tree + bset_tree_space(b) - t->tree);
if (t->size < 2) {
@@ -590,7 +590,7 @@ static void bset_build_written_tree(struct btree *b)
t->tree[j].m = bkey_to_cacheline_offset(k);
}
- while (bkey_next(k) != end(t->data))
+ while (bkey_next(k) != bset_bkey_last(t->data))
k = bkey_next(k);
t->end = *k;
@@ -608,7 +608,7 @@ void bch_bset_fix_invalidated_key(struct btree *b, struct bkey *k)
unsigned inorder, j = 1;
for (t = b->sets; t <= &b->sets[b->nsets]; t++)
- if (k < end(t->data))
+ if (k < bset_bkey_last(t->data))
goto found_set;
BUG();
@@ -621,7 +621,7 @@ found_set:
if (k == t->data->start)
goto fix_left;
- if (bkey_next(k) == end(t->data)) {
+ if (bkey_next(k) == bset_bkey_last(t->data)) {
t->end = *k;
goto fix_right;
}
@@ -687,7 +687,7 @@ void bch_bset_fix_lookup_table(struct btree *b, struct bkey *k)
/* Possibly add a new entry to the end of the lookup table */
for (k = table_to_bkey(t, t->size - 1);
- k != end(t->data);
+ k != bset_bkey_last(t->data);
k = bkey_next(k))
if (t->size == bkey_to_cacheline(t, k)) {
t->prev[t->size] = bkey_to_cacheline_offset(k);
@@ -723,7 +723,7 @@ static struct bset_search_iter bset_search_write_set(struct btree *b,
unsigned li = 0, ri = t->size;
BUG_ON(!b->nsets &&
- t->size < bkey_to_cacheline(t, end(t->data)));
+ t->size < bkey_to_cacheline(t, bset_bkey_last(t->data)));
while (li + 1 != ri) {
unsigned m = (li + ri) >> 1;
@@ -736,7 +736,7 @@ static struct bset_search_iter bset_search_write_set(struct btree *b,
return (struct bset_search_iter) {
table_to_bkey(t, li),
- ri < t->size ? table_to_bkey(t, ri) : end(t->data)
+ ri < t->size ? table_to_bkey(t, ri) : bset_bkey_last(t->data)
};
}
@@ -788,7 +788,7 @@ static struct bset_search_iter bset_search_tree(struct btree *b,
f = &t->tree[inorder_next(j, t->size)];
r = cacheline_to_bkey(t, inorder, f->m);
} else
- r = end(t->data);
+ r = bset_bkey_last(t->data);
} else {
r = cacheline_to_bkey(t, inorder, f->m);
@@ -824,7 +824,7 @@ struct bkey *__bch_bset_search(struct btree *b, struct bset_tree *t,
if (unlikely(!t->size)) {
i.l = t->data->start;
- i.r = end(t->data);
+ i.r = bset_bkey_last(t->data);
} else if (bset_written(b, t)) {
/*
* Each node in the auxiliary search tree covers a certain range
@@ -834,7 +834,7 @@ struct bkey *__bch_bset_search(struct btree *b, struct bset_tree *t,
*/
if (unlikely(bkey_cmp(search, &t->end) >= 0))
- return end(t->data);
+ return bset_bkey_last(t->data);
if (unlikely(bkey_cmp(search, t->data->start) < 0))
return t->data->start;
@@ -850,7 +850,7 @@ struct bkey *__bch_bset_search(struct btree *b, struct bset_tree *t,
inorder_to_tree(bkey_to_cacheline(t, i.l), t)),
search) > 0);
- BUG_ON(i.r != end(t->data) &&
+ BUG_ON(i.r != bset_bkey_last(t->data) &&
bkey_cmp(i.r, search) <= 0);
}
@@ -905,7 +905,7 @@ struct bkey *__bch_btree_iter_init(struct btree *b, struct btree_iter *iter,
for (; start <= &b->sets[b->nsets]; start++) {
ret = bch_bset_search(b, start, search);
- bch_btree_iter_push(iter, ret, end(start->data));
+ bch_btree_iter_push(iter, ret, bset_bkey_last(start->data));
}
return ret;
@@ -1059,7 +1059,7 @@ static void __btree_sort(struct btree *b, struct btree_iter *iter,
} else {
b->sets[start].data->keys = out->keys;
memcpy(b->sets[start].data->start, out->start,
- (void *) end(out) - (void *) out->start);
+ (void *) bset_bkey_last(out) - (void *) out->start);
}
if (out == b->c->sort)
diff --git a/drivers/md/bcache/bset.h b/drivers/md/bcache/bset.h
index 4661a71604e1..d35b573733b8 100644
--- a/drivers/md/bcache/bset.h
+++ b/drivers/md/bcache/bset.h
@@ -190,14 +190,6 @@ struct bset_tree {
struct bset *data;
};
-static __always_inline int64_t bkey_cmp(const struct bkey *l,
- const struct bkey *r)
-{
- return unlikely(KEY_INODE(l) != KEY_INODE(r))
- ? (int64_t) KEY_INODE(l) - (int64_t) KEY_INODE(r)
- : (int64_t) KEY_OFFSET(l) - (int64_t) KEY_OFFSET(r);
-}
-
/* Keylists */
struct keylist {
@@ -261,6 +253,28 @@ struct bkey *bch_keylist_pop(struct keylist *);
void bch_keylist_pop_front(struct keylist *);
int bch_keylist_realloc(struct keylist *, int, struct cache_set *);
+/* Bkey utility code */
+
+#define bset_bkey_last(i) bkey_idx((struct bkey *) (i)->d, (i)->keys)
+
+static inline struct bkey *bset_bkey_idx(struct bset *i, unsigned idx)
+{
+ return bkey_idx(i->start, idx);
+}
+
+static inline void bkey_init(struct bkey *k)
+{
+ *k = ZERO_KEY;
+}
+
+static __always_inline int64_t bkey_cmp(const struct bkey *l,
+ const struct bkey *r)
+{
+ return unlikely(KEY_INODE(l) != KEY_INODE(r))
+ ? (int64_t) KEY_INODE(l) - (int64_t) KEY_INODE(r)
+ : (int64_t) KEY_OFFSET(l) - (int64_t) KEY_OFFSET(r);
+}
+
void bch_bkey_copy_single_ptr(struct bkey *, const struct bkey *,
unsigned);
bool __bch_cut_front(const struct bkey *, struct bkey *);
diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c
index 3efacbf758cf..21bfb39446c3 100644
--- a/drivers/md/bcache/btree.c
+++ b/drivers/md/bcache/btree.c
@@ -194,7 +194,7 @@ void bkey_put(struct cache_set *c, struct bkey *k)
static uint64_t btree_csum_set(struct btree *b, struct bset *i)
{
uint64_t crc = b->key.ptr[0];
- void *data = (void *) i + 8, *end = end(i);
+ void *data = (void *) i + 8, *end = bset_bkey_last(i);
crc = bch_crc64_update(crc, data, end - data);
return crc ^ 0xffffffffffffffffULL;
@@ -248,7 +248,7 @@ static void bch_btree_node_read_done(struct btree *b)
if (i != b->sets[0].data && !i->keys)
goto err;
- bch_btree_iter_push(iter, i->start, end(i));
+ bch_btree_iter_push(iter, i->start, bset_bkey_last(i));
b->written += set_blocks(i, b->c);
}
@@ -1244,7 +1244,7 @@ static int btree_gc_coalesce(struct btree *b, struct btree_op *op,
if (i > 1) {
for (k = n2->start;
- k < end(n2);
+ k < bset_bkey_last(n2);
k = bkey_next(k)) {
if (__set_blocks(n1, n1->keys + keys +
bkey_u64s(k), b->c) > blocks)
@@ -1277,16 +1277,17 @@ static int btree_gc_coalesce(struct btree *b, struct btree_op *op,
if (last)
bkey_copy_key(&new_nodes[i]->key, last);
- memcpy(end(n1),
+ memcpy(bset_bkey_last(n1),
n2->start,
- (void *) node(n2, keys) - (void *) n2->start);
+ (void *) bset_bkey_idx(n2, keys) - (void *) n2->start);
n1->keys += keys;
r[i].keys = n1->keys;
memmove(n2->start,
- node(n2, keys),
- (void *) end(n2) - (void *) node(n2, keys));
+ bset_bkey_idx(n2, keys),
+ (void *) bset_bkey_last(n2) -
+ (void *) bset_bkey_idx(n2, keys));
n2->keys -= keys;
@@ -1741,7 +1742,7 @@ static void shift_keys(struct btree *b, struct bkey *where, struct bkey *insert)
memmove((uint64_t *) where + bkey_u64s(insert),
where,
- (void *) end(i) - (void *) where);
+ (void *) bset_bkey_last(i) - (void *) where);
i->keys += bkey_u64s(insert);
bkey_copy(where, insert);
@@ -1917,7 +1918,7 @@ static bool btree_insert_key(struct btree *b, struct btree_op *op,
return false;
}
- while (m != end(i) &&
+ while (m != bset_bkey_last(i) &&
bkey_cmp(k, &START_KEY(m)) > 0)
prev = m, m = bkey_next(m);
@@ -1931,12 +1932,12 @@ static bool btree_insert_key(struct btree *b, struct btree_op *op,
goto merged;
status = BTREE_INSERT_STATUS_OVERWROTE;
- if (m != end(i) &&
+ if (m != bset_bkey_last(i) &&
KEY_PTRS(m) == KEY_PTRS(k) && !KEY_SIZE(m))
goto copy;
status = BTREE_INSERT_STATUS_FRONT_MERGE;
- if (m != end(i) &&
+ if (m != bset_bkey_last(i) &&
bch_bkey_try_merge(b, k, m))
goto copy;
} else {
@@ -2045,16 +2046,18 @@ static int btree_split(struct btree *b, struct btree_op *op,
*/
while (keys < (n1->sets[0].data->keys * 3) / 5)
- keys += bkey_u64s(node(n1->sets[0].data, keys));
+ keys += bkey_u64s(bset_bkey_idx(n1->sets[0].data,
+ keys));
- bkey_copy_key(&n1->key, node(n1->sets[0].data, keys));
- keys += bkey_u64s(node(n1->sets[0].data, keys));
+ bkey_copy_key(&n1->key,
+ bset_bkey_idx(n1->sets[0].data, keys));
+ keys += bkey_u64s(bset_bkey_idx(n1->sets[0].data, keys));
n2->sets[0].data->keys = n1->sets[0].data->keys - keys;
n1->sets[0].data->keys = keys;
memcpy(n2->sets[0].data->start,
- end(n1->sets[0].data),
+ bset_bkey_last(n1->sets[0].data),
n2->sets[0].data->keys * sizeof(uint64_t));
bkey_copy_key(&n2->key, &b->key);
diff --git a/drivers/md/bcache/debug.c b/drivers/md/bcache/debug.c
index 1ed594b08c06..7f576bdf0cc0 100644
--- a/drivers/md/bcache/debug.c
+++ b/drivers/md/bcache/debug.c
@@ -84,7 +84,7 @@ static void dump_bset(struct btree *b, struct bset *i)
unsigned j;
char buf[80];
- for (k = i->start; k < end(i); k = next) {
+ for (k = i->start; k < bset_bkey_last(i); k = next) {
next = bkey_next(k);
bch_bkey_to_text(buf, sizeof(buf), k);
@@ -102,7 +102,7 @@ static void dump_bset(struct btree *b, struct bset *i)
printk(" %s\n", bch_ptr_status(b->c, k));
- if (next < end(i) &&
+ if (next < bset_bkey_last(i) &&
bkey_cmp(k, !b->level ? &START_KEY(next) : next) > 0)
printk(KERN_ERR "Key skipped backwards\n");
}
diff --git a/drivers/md/bcache/journal.c b/drivers/md/bcache/journal.c
index cce82bba665e..a66f48f0e347 100644
--- a/drivers/md/bcache/journal.c
+++ b/drivers/md/bcache/journal.c
@@ -284,7 +284,7 @@ void bch_journal_mark(struct cache_set *c, struct list_head *list)
}
for (k = i->j.start;
- k < end(&i->j);
+ k < bset_bkey_last(&i->j);
k = bkey_next(k)) {
unsigned j;
@@ -322,7 +322,7 @@ int bch_journal_replay(struct cache_set *s, struct list_head *list)
n, i->j.seq - 1, start, end);
for (k = i->j.start;
- k < end(&i->j);
+ k < bset_bkey_last(&i->j);
k = bkey_next(k)) {
trace_bcache_journal_replay_key(k);
@@ -735,7 +735,7 @@ atomic_t *bch_journal(struct cache_set *c,
w = journal_wait_for_write(c, bch_keylist_nkeys(keys));
- memcpy(end(w->data), keys->keys, bch_keylist_bytes(keys));
+ memcpy(bset_bkey_last(w->data), keys->keys, bch_keylist_bytes(keys));
w->data->keys += bch_keylist_nkeys(keys);
w->need_write = true;
diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
index 164a7e263988..ae66311be82f 100644
--- a/include/uapi/linux/bcache.h
+++ b/include/uapi/linux/bcache.h
@@ -118,7 +118,7 @@ static inline struct bkey *bkey_next(const struct bkey *k)
return (struct bkey *) (d + bkey_u64s(k));
}
-static inline struct bkey *bkey_last(const struct bkey *k, unsigned nr_keys)
+static inline struct bkey *bkey_idx(const struct bkey *k, unsigned nr_keys)
{
__u64 *d = (void *) k;
return (struct bkey *) (d + nr_keys);