1 #ifndef _BCACHE_BTREE_IO_H
2 #define _BCACHE_BTREE_IO_H
9 static inline void btree_node_io_unlock(struct btree *b)
11 EBUG_ON(!btree_node_write_in_flight(b));
12 clear_btree_node_write_in_flight(b);
13 wake_up_bit(&b->flags, BTREE_NODE_write_in_flight);
16 static inline void btree_node_io_lock(struct btree *b)
18 wait_on_bit_lock_io(&b->flags, BTREE_NODE_write_in_flight,
19 TASK_UNINTERRUPTIBLE);
22 static inline void btree_node_wait_on_io(struct btree *b)
24 wait_on_bit_io(&b->flags, BTREE_NODE_write_in_flight,
25 TASK_UNINTERRUPTIBLE);
28 static inline bool btree_node_may_write(struct btree *b)
30 return list_empty_careful(&b->write_blocked) &&
31 list_empty_careful(&b->reachable);
37 COMPACT_WRITTEN_NO_WRITE_LOCK,
40 bool __bch2_compact_whiteouts(struct bch_fs *, struct btree *, enum compact_mode);
42 static inline bool bch2_maybe_compact_whiteouts(struct bch_fs *c, struct btree *b)
47 unsigned live_u64s = b->nr.bset_u64s[t - b->set];
48 unsigned bset_u64s = le16_to_cpu(bset(b, t)->u64s);
50 if (live_u64s * 4 < bset_u64s * 3)
56 return __bch2_compact_whiteouts(c, b, COMPACT_LAZY);
59 void bch2_btree_sort_into(struct bch_fs *, struct btree *, struct btree *);
61 void bch2_btree_build_aux_trees(struct btree *);
62 void bch2_btree_init_next(struct bch_fs *, struct btree *,
65 void bch2_btree_node_read_done(struct bch_fs *, struct btree *,
66 struct bch_dev *, const struct bch_extent_ptr *);
67 void bch2_btree_node_read(struct bch_fs *, struct btree *);
68 int bch2_btree_root_read(struct bch_fs *, enum btree_id,
69 const struct bkey_i *, unsigned);
71 void bch2_btree_complete_write(struct bch_fs *, struct btree *,
72 struct btree_write *);
74 void __bch2_btree_node_write(struct bch_fs *, struct btree *,
75 struct closure *, enum six_lock_type);
76 bool bch2_btree_post_write_cleanup(struct bch_fs *, struct btree *);
78 void bch2_btree_node_write(struct bch_fs *, struct btree *,
79 struct closure *, enum six_lock_type);
81 #define bch2_btree_node_write_dirty(_c, _b, _cl, cond) \
83 while ((_b)->written && btree_node_dirty(_b) && (cond)) { \
84 set_btree_node_need_write(_b); \
86 if (!btree_node_may_write(_b)) \
89 if (!btree_node_write_in_flight(_b)) { \
90 bch2_btree_node_write(_c, _b, _cl, SIX_LOCK_read);\
94 six_unlock_read(&(_b)->lock); \
95 btree_node_wait_on_io(_b); \
96 six_lock_read(&(_b)->lock); \
100 void bch2_btree_verify_flushed(struct bch_fs *);
102 #endif /* _BCACHE_BTREE_IO_H */