Skip to content

Commit 253a99d

Browse files
Coly Liaxboe
authored andcommitted
bcache: move macro btree() and btree_root() into btree.h
In order to accelerate bcache registration speed, the macro btree() and btree_root() will be referenced out of btree.c. This patch moves them from btree.c into btree.h with other relative function declaration in btree.h, for the following changes. Signed-off-by: Coly Li <colyli@suse.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 431d6e3 commit 253a99d

File tree

2 files changed

+67
-59
lines changed

2 files changed

+67
-59
lines changed

drivers/md/bcache/btree.c

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -101,64 +101,6 @@
101101

102102
#define insert_lock(s, b) ((b)->level <= (s)->lock)
103103

104-
/*
105-
* These macros are for recursing down the btree - they handle the details of
106-
* locking and looking up nodes in the cache for you. They're best treated as
107-
* mere syntax when reading code that uses them.
108-
*
109-
* op->lock determines whether we take a read or a write lock at a given depth.
110-
* If you've got a read lock and find that you need a write lock (i.e. you're
111-
* going to have to split), set op->lock and return -EINTR; btree_root() will
112-
* call you again and you'll have the correct lock.
113-
*/
114-
115-
/**
116-
* btree - recurse down the btree on a specified key
117-
* @fn: function to call, which will be passed the child node
118-
* @key: key to recurse on
119-
* @b: parent btree node
120-
* @op: pointer to struct btree_op
121-
*/
122-
#define btree(fn, key, b, op, ...) \
123-
({ \
124-
int _r, l = (b)->level - 1; \
125-
bool _w = l <= (op)->lock; \
126-
struct btree *_child = bch_btree_node_get((b)->c, op, key, l, \
127-
_w, b); \
128-
if (!IS_ERR(_child)) { \
129-
_r = bch_btree_ ## fn(_child, op, ##__VA_ARGS__); \
130-
rw_unlock(_w, _child); \
131-
} else \
132-
_r = PTR_ERR(_child); \
133-
_r; \
134-
})
135-
136-
/**
137-
* btree_root - call a function on the root of the btree
138-
* @fn: function to call, which will be passed the child node
139-
* @c: cache set
140-
* @op: pointer to struct btree_op
141-
*/
142-
#define btree_root(fn, c, op, ...) \
143-
({ \
144-
int _r = -EINTR; \
145-
do { \
146-
struct btree *_b = (c)->root; \
147-
bool _w = insert_lock(op, _b); \
148-
rw_lock(_w, _b, _b->level); \
149-
if (_b == (c)->root && \
150-
_w == insert_lock(op, _b)) { \
151-
_r = bch_btree_ ## fn(_b, op, ##__VA_ARGS__); \
152-
} \
153-
rw_unlock(_w, _b); \
154-
bch_cannibalize_unlock(c); \
155-
if (_r == -EINTR) \
156-
schedule(); \
157-
} while (_r == -EINTR); \
158-
\
159-
finish_wait(&(c)->btree_cache_wait, &(op)->wait); \
160-
_r; \
161-
})
162104

163105
static inline struct bset *write_block(struct btree *b)
164106
{
@@ -2422,7 +2364,7 @@ int __bch_btree_map_nodes(struct btree_op *op, struct cache_set *c,
24222364
return btree_root(map_nodes_recurse, c, op, from, fn, flags);
24232365
}
24242366

2425-
static int bch_btree_map_keys_recurse(struct btree *b, struct btree_op *op,
2367+
int bch_btree_map_keys_recurse(struct btree *b, struct btree_op *op,
24262368
struct bkey *from, btree_map_keys_fn *fn,
24272369
int flags)
24282370
{

drivers/md/bcache/btree.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,13 @@ void bch_initial_gc_finish(struct cache_set *c);
260260
void bch_moving_gc(struct cache_set *c);
261261
int bch_btree_check(struct cache_set *c);
262262
void bch_initial_mark_key(struct cache_set *c, int level, struct bkey *k);
263+
typedef int (btree_map_keys_fn)(struct btree_op *op, struct btree *b,
264+
struct bkey *k);
265+
int bch_btree_map_keys_recurse(struct btree *b, struct btree_op *op,
266+
struct bkey *from, btree_map_keys_fn *fn,
267+
int flags);
268+
int bch_btree_map_keys(struct btree_op *op, struct cache_set *c,
269+
struct bkey *from, btree_map_keys_fn *fn, int flags);
263270

264271
static inline void wake_up_gc(struct cache_set *c)
265272
{
@@ -284,6 +291,65 @@ static inline void force_wake_up_gc(struct cache_set *c)
284291
wake_up_gc(c);
285292
}
286293

294+
/*
295+
* These macros are for recursing down the btree - they handle the details of
296+
* locking and looking up nodes in the cache for you. They're best treated as
297+
* mere syntax when reading code that uses them.
298+
*
299+
* op->lock determines whether we take a read or a write lock at a given depth.
300+
* If you've got a read lock and find that you need a write lock (i.e. you're
301+
* going to have to split), set op->lock and return -EINTR; btree_root() will
302+
* call you again and you'll have the correct lock.
303+
*/
304+
305+
/**
306+
* btree - recurse down the btree on a specified key
307+
* @fn: function to call, which will be passed the child node
308+
* @key: key to recurse on
309+
* @b: parent btree node
310+
* @op: pointer to struct btree_op
311+
*/
312+
#define btree(fn, key, b, op, ...) \
313+
({ \
314+
int _r, l = (b)->level - 1; \
315+
bool _w = l <= (op)->lock; \
316+
struct btree *_child = bch_btree_node_get((b)->c, op, key, l, \
317+
_w, b); \
318+
if (!IS_ERR(_child)) { \
319+
_r = bch_btree_ ## fn(_child, op, ##__VA_ARGS__); \
320+
rw_unlock(_w, _child); \
321+
} else \
322+
_r = PTR_ERR(_child); \
323+
_r; \
324+
})
325+
326+
/**
327+
* btree_root - call a function on the root of the btree
328+
* @fn: function to call, which will be passed the child node
329+
* @c: cache set
330+
* @op: pointer to struct btree_op
331+
*/
332+
#define btree_root(fn, c, op, ...) \
333+
({ \
334+
int _r = -EINTR; \
335+
do { \
336+
struct btree *_b = (c)->root; \
337+
bool _w = insert_lock(op, _b); \
338+
rw_lock(_w, _b, _b->level); \
339+
if (_b == (c)->root && \
340+
_w == insert_lock(op, _b)) { \
341+
_r = bch_btree_ ## fn(_b, op, ##__VA_ARGS__); \
342+
} \
343+
rw_unlock(_w, _b); \
344+
bch_cannibalize_unlock(c); \
345+
if (_r == -EINTR) \
346+
schedule(); \
347+
} while (_r == -EINTR); \
348+
\
349+
finish_wait(&(c)->btree_cache_wait, &(op)->wait); \
350+
_r; \
351+
})
352+
287353
#define MAP_DONE 0
288354
#define MAP_CONTINUE 1
289355

0 commit comments

Comments
 (0)