aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/bcache/bset.h
diff options
context:
space:
mode:
authorKent Overstreet <kmo@daterainc.com>2013-07-24 20:24:25 -0400
committerKent Overstreet <kmo@daterainc.com>2013-11-11 00:56:00 -0500
commitc2f95ae2ebbe1ab61b1d4437f5923fdf720d4d4d (patch)
tree67da94194f87693f7c280176cfc5a13c6162eea0 /drivers/md/bcache/bset.h
parent4f3d40147b8d0ce7055e241e1d263e0aa2b2b46d (diff)
bcache: Clean up keylist code
More random refactoring. Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Diffstat (limited to 'drivers/md/bcache/bset.h')
-rw-r--r--drivers/md/bcache/bset.h35
1 files changed, 26 insertions, 9 deletions
diff --git a/drivers/md/bcache/bset.h b/drivers/md/bcache/bset.h
index a3627d0cd88b..8a9305685b7e 100644
--- a/drivers/md/bcache/bset.h
+++ b/drivers/md/bcache/bset.h
@@ -227,20 +227,23 @@ static inline struct bkey *bkey_next(const struct bkey *k)
227/* Keylists */ 227/* Keylists */
228 228
229struct keylist { 229struct keylist {
230 struct bkey *top;
231 union { 230 union {
232 uint64_t *list; 231 struct bkey *keys;
233 struct bkey *bottom; 232 uint64_t *keys_p;
233 };
234 union {
235 struct bkey *top;
236 uint64_t *top_p;
234 }; 237 };
235 238
236 /* Enough room for btree_split's keys without realloc */ 239 /* Enough room for btree_split's keys without realloc */
237#define KEYLIST_INLINE 16 240#define KEYLIST_INLINE 16
238 uint64_t d[KEYLIST_INLINE]; 241 uint64_t inline_keys[KEYLIST_INLINE];
239}; 242};
240 243
241static inline void bch_keylist_init(struct keylist *l) 244static inline void bch_keylist_init(struct keylist *l)
242{ 245{
243 l->top = (void *) (l->list = l->d); 246 l->top_p = l->keys_p = l->inline_keys;
244} 247}
245 248
246static inline void bch_keylist_push(struct keylist *l) 249static inline void bch_keylist_push(struct keylist *l)
@@ -256,16 +259,30 @@ static inline void bch_keylist_add(struct keylist *l, struct bkey *k)
256 259
257static inline bool bch_keylist_empty(struct keylist *l) 260static inline bool bch_keylist_empty(struct keylist *l)
258{ 261{
259 return l->top == (void *) l->list; 262 return l->top == l->keys;
263}
264
265static inline void bch_keylist_reset(struct keylist *l)
266{
267 l->top = l->keys;
260} 268}
261 269
262static inline void bch_keylist_free(struct keylist *l) 270static inline void bch_keylist_free(struct keylist *l)
263{ 271{
264 if (l->list != l->d) 272 if (l->keys_p != l->inline_keys)
265 kfree(l->list); 273 kfree(l->keys_p);
274}
275
276static inline size_t bch_keylist_nkeys(struct keylist *l)
277{
278 return l->top_p - l->keys_p;
279}
280
281static inline size_t bch_keylist_bytes(struct keylist *l)
282{
283 return bch_keylist_nkeys(l) * sizeof(uint64_t);
266} 284}
267 285
268void bch_keylist_copy(struct keylist *, struct keylist *);
269struct bkey *bch_keylist_pop(struct keylist *); 286struct bkey *bch_keylist_pop(struct keylist *);
270void bch_keylist_pop_front(struct keylist *); 287void bch_keylist_pop_front(struct keylist *);
271int bch_keylist_realloc(struct keylist *, int, struct cache_set *); 288int bch_keylist_realloc(struct keylist *, int, struct cache_set *);