33#define _BCACHEFS_BTREE_GC_H
44
55#include "bkey.h"
6+ #include "btree_gc_types.h"
67#include "btree_types.h"
78
89int bch2_check_topology (struct bch_fs * );
@@ -32,36 +33,15 @@ int bch2_check_allocations(struct bch_fs *);
3233/* Position of (the start of) a gc phase: */
3334static inline struct gc_pos gc_phase (enum gc_phase phase )
3435{
35- return (struct gc_pos ) {
36- .phase = phase ,
37- .level = 0 ,
38- .pos = POS_MIN ,
39- };
40- }
41-
42- static inline int gc_pos_cmp (struct gc_pos l , struct gc_pos r )
43- {
44- return cmp_int (l .phase , r .phase ) ?:
45- - cmp_int (l .level , r .level ) ?:
46- bpos_cmp (l .pos , r .pos );
47- }
48-
49- static inline enum gc_phase btree_id_to_gc_phase (enum btree_id id )
50- {
51- switch (id ) {
52- #define x (name , v , ...) case BTREE_ID_##name: return GC_PHASE_BTREE_##name;
53- BCH_BTREE_IDS ()
54- #undef x
55- default :
56- BUG ();
57- }
36+ return (struct gc_pos ) { .phase = phase , };
5837}
5938
6039static inline struct gc_pos gc_pos_btree (enum btree_id btree , unsigned level ,
6140 struct bpos pos )
6241{
6342 return (struct gc_pos ) {
64- .phase = btree_id_to_gc_phase (btree ),
43+ .phase = GC_PHASE_btree ,
44+ .btree = btree ,
6545 .level = level ,
6646 .pos = pos ,
6747 };
@@ -76,6 +56,22 @@ static inline struct gc_pos gc_pos_btree_node(struct btree *b)
7656 return gc_pos_btree (b -> c .btree_id , b -> c .level , b -> key .k .p );
7757}
7858
59+ static inline int gc_btree_order (enum btree_id btree )
60+ {
61+ if (btree == BTREE_ID_stripes )
62+ return -1 ;
63+ return btree ;
64+ }
65+
66+ static inline int gc_pos_cmp (struct gc_pos l , struct gc_pos r )
67+ {
68+ return cmp_int (l .phase , r .phase ) ?:
69+ cmp_int (gc_btree_order (l .btree ),
70+ gc_btree_order (r .btree )) ?:
71+ - cmp_int (l .level , r .level ) ?:
72+ bpos_cmp (l .pos , r .pos );
73+ }
74+
7975static inline bool gc_visited (struct bch_fs * c , struct gc_pos pos )
8076{
8177 unsigned seq ;
0 commit comments