1 #ifndef _BCACHEFS_BTREE_IO_H
2 #define _BCACHEFS_BTREE_IO_H
11 struct btree_read_bio {
14 struct extent_pick_ptr pick;
15 struct work_struct work;
19 static inline void btree_node_io_unlock(struct btree *b)
21 EBUG_ON(!btree_node_write_in_flight(b));
22 clear_btree_node_write_in_flight(b);
23 wake_up_bit(&b->flags, BTREE_NODE_write_in_flight);
26 static inline void btree_node_io_lock(struct btree *b)
28 wait_on_bit_lock_io(&b->flags, BTREE_NODE_write_in_flight,
29 TASK_UNINTERRUPTIBLE);
32 static inline void btree_node_wait_on_io(struct btree *b)
34 wait_on_bit_io(&b->flags, BTREE_NODE_write_in_flight,
35 TASK_UNINTERRUPTIBLE);
38 static inline bool btree_node_may_write(struct btree *b)
40 return list_empty_careful(&b->write_blocked) &&
41 !b->will_make_reachable;
47 COMPACT_WRITTEN_NO_WRITE_LOCK,
50 bool __bch2_compact_whiteouts(struct bch_fs *, struct btree *, enum compact_mode);
52 static inline bool bch2_maybe_compact_whiteouts(struct bch_fs *c, struct btree *b)
57 unsigned live_u64s = b->nr.bset_u64s[t - b->set];
58 unsigned bset_u64s = le16_to_cpu(bset(b, t)->u64s);
60 if (live_u64s * 4 < bset_u64s * 3)
66 return __bch2_compact_whiteouts(c, b, COMPACT_LAZY);
69 void bch2_btree_sort_into(struct bch_fs *, struct btree *, struct btree *);
71 void bch2_btree_build_aux_trees(struct btree *);
72 void bch2_btree_init_next(struct bch_fs *, struct btree *,
75 int bch2_btree_node_read_done(struct bch_fs *, struct btree *);
76 void bch2_btree_node_read(struct bch_fs *, struct btree *, bool);
77 int bch2_btree_root_read(struct bch_fs *, enum btree_id,
78 const struct bkey_i *, unsigned);
80 void bch2_btree_complete_write(struct bch_fs *, struct btree *,
81 struct btree_write *);
82 void bch2_btree_write_error_work(struct work_struct *);
84 void __bch2_btree_node_write(struct bch_fs *, struct btree *,
85 struct closure *, enum six_lock_type);
86 bool bch2_btree_post_write_cleanup(struct bch_fs *, struct btree *);
88 void bch2_btree_node_write(struct bch_fs *, struct btree *,
89 struct closure *, enum six_lock_type);
91 #define bch2_btree_node_write_dirty(_c, _b, _cl, cond) \
93 while ((_b)->written && btree_node_dirty(_b) && (cond)) { \
94 set_btree_node_need_write(_b); \
96 if (!btree_node_may_write(_b)) \
99 if (!btree_node_write_in_flight(_b)) { \
100 bch2_btree_node_write(_c, _b, _cl, SIX_LOCK_read);\
104 six_unlock_read(&(_b)->lock); \
105 btree_node_wait_on_io(_b); \
106 six_lock_read(&(_b)->lock); \
110 void bch2_btree_verify_flushed(struct bch_fs *);
112 #endif /* _BCACHEFS_BTREE_IO_H */