diff options
author | Kent Overstreet <kmo@daterainc.com> | 2013-12-18 00:46:35 -0500 |
---|---|---|
committer | Kent Overstreet <kmo@daterainc.com> | 2014-01-08 16:05:10 -0500 |
commit | 88b9f8c426f35e04738220c1bc05dd1ea1b513a3 (patch) | |
tree | b0391209b767145e53d4c0f52d3cb56376e4dc53 /drivers/md/bcache | |
parent | 5c41c8a713da7874bd79196696a275beeb11821e (diff) |
bcache: kill index()
That was a terrible name for a macro, add some better helpers to replace it.
Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Diffstat (limited to 'drivers/md/bcache')
-rw-r--r-- | drivers/md/bcache/bcache.h | 4 | ||||
-rw-r--r-- | drivers/md/bcache/btree.c | 6 | ||||
-rw-r--r-- | drivers/md/bcache/btree.h | 20 | ||||
-rw-r--r-- | drivers/md/bcache/debug.c | 2 |
4 files changed, 24 insertions, 8 deletions
diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h index 94d346e2ea17..d955a4934616 100644 --- a/drivers/md/bcache/bcache.h +++ b/drivers/md/bcache/bcache.h | |||
@@ -736,10 +736,6 @@ static inline unsigned local_clock_us(void) | |||
736 | #define node(i, j) ((struct bkey *) ((i)->d + (j))) | 736 | #define node(i, j) ((struct bkey *) ((i)->d + (j))) |
737 | #define end(i) node(i, (i)->keys) | 737 | #define end(i) node(i, (i)->keys) |
738 | 738 | ||
739 | #define index(i, b) \ | ||
740 | ((size_t) (((void *) i - (void *) (b)->sets[0].data) / \ | ||
741 | block_bytes(b->c))) | ||
742 | |||
743 | #define btree_data_space(b) (PAGE_SIZE << (b)->page_order) | 739 | #define btree_data_space(b) (PAGE_SIZE << (b)->page_order) |
744 | 740 | ||
745 | #define prios_per_bucket(c) \ | 741 | #define prios_per_bucket(c) \ |
diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index 5a6b7522eb20..8e2573a009f9 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c | |||
@@ -258,7 +258,7 @@ static void bch_btree_node_read_done(struct btree *b) | |||
258 | 258 | ||
259 | err = "corrupted btree"; | 259 | err = "corrupted btree"; |
260 | for (i = write_block(b); | 260 | for (i = write_block(b); |
261 | index(i, b) < btree_blocks(b); | 261 | bset_sector_offset(b, i) < KEY_SIZE(&b->key); |
262 | i = ((void *) i) + block_bytes(b->c)) | 262 | i = ((void *) i) + block_bytes(b->c)) |
263 | if (i->seq == b->sets[0].data->seq) | 263 | if (i->seq == b->sets[0].data->seq) |
264 | goto err; | 264 | goto err; |
@@ -278,9 +278,9 @@ out: | |||
278 | return; | 278 | return; |
279 | err: | 279 | err: |
280 | set_btree_node_io_error(b); | 280 | set_btree_node_io_error(b); |
281 | bch_cache_set_error(b->c, "%s at bucket %zu, block %zu, %u keys", | 281 | bch_cache_set_error(b->c, "%s at bucket %zu, block %u, %u keys", |
282 | err, PTR_BUCKET_NR(b->c, &b->key, 0), | 282 | err, PTR_BUCKET_NR(b->c, &b->key, 0), |
283 | index(i, b), i->keys); | 283 | bset_block_offset(b, i), i->keys); |
284 | goto out; | 284 | goto out; |
285 | } | 285 | } |
286 | 286 | ||
diff --git a/drivers/md/bcache/btree.h b/drivers/md/bcache/btree.h index 4f0378ac1f7b..12c99b1a764d 100644 --- a/drivers/md/bcache/btree.h +++ b/drivers/md/bcache/btree.h | |||
@@ -185,6 +185,26 @@ static inline unsigned bset_offset(struct btree *b, struct bset *i) | |||
185 | return (((size_t) i) - ((size_t) b->sets->data)) >> 9; | 185 | return (((size_t) i) - ((size_t) b->sets->data)) >> 9; |
186 | } | 186 | } |
187 | 187 | ||
188 | static inline struct bset *btree_bset_first(struct btree *b) | ||
189 | { | ||
190 | return b->sets->data; | ||
191 | } | ||
192 | |||
193 | static inline unsigned bset_byte_offset(struct btree *b, struct bset *i) | ||
194 | { | ||
195 | return ((size_t) i) - ((size_t) b->sets->data); | ||
196 | } | ||
197 | |||
198 | static inline unsigned bset_sector_offset(struct btree *b, struct bset *i) | ||
199 | { | ||
200 | return (((void *) i) - ((void *) btree_bset_first(b))) >> 9; | ||
201 | } | ||
202 | |||
203 | static inline unsigned bset_block_offset(struct btree *b, struct bset *i) | ||
204 | { | ||
205 | return bset_sector_offset(b, i) >> b->c->block_bits; | ||
206 | } | ||
207 | |||
188 | static inline struct bset *write_block(struct btree *b) | 208 | static inline struct bset *write_block(struct btree *b) |
189 | { | 209 | { |
190 | return ((void *) b->sets[0].data) + b->written * block_bytes(b->c); | 210 | return ((void *) b->sets[0].data) + b->written * block_bytes(b->c); |
diff --git a/drivers/md/bcache/debug.c b/drivers/md/bcache/debug.c index fab3767d6d28..473e8d5a7fe1 100644 --- a/drivers/md/bcache/debug.c +++ b/drivers/md/bcache/debug.c | |||
@@ -88,7 +88,7 @@ static void dump_bset(struct btree *b, struct bset *i) | |||
88 | next = bkey_next(k); | 88 | next = bkey_next(k); |
89 | 89 | ||
90 | bch_bkey_to_text(buf, sizeof(buf), k); | 90 | bch_bkey_to_text(buf, sizeof(buf), k); |
91 | printk(KERN_ERR "block %zu key %zi/%u: %s", index(i, b), | 91 | printk(KERN_ERR "block %u key %zi/%u: %s", bset_block_offset(b, i), |
92 | (uint64_t *) k - i->d, i->keys, buf); | 92 | (uint64_t *) k - i->d, i->keys, buf); |
93 | 93 | ||
94 | for (j = 0; j < KEY_PTRS(k); j++) { | 94 | for (j = 0; j < KEY_PTRS(k); j++) { |