1 #ifndef _BCACHEFS_BTREE_IO_H
2 #define _BCACHEFS_BTREE_IO_H
12 struct btree_read_bio {
14 unsigned submit_time_us;
16 struct extent_pick_ptr pick;
17 struct work_struct work;
21 struct btree_write_bio {
24 struct work_struct work;
25 struct bch_write_bio wbio;
28 static inline void btree_node_io_unlock(struct btree *b)
30 EBUG_ON(!btree_node_write_in_flight(b));
31 clear_btree_node_write_in_flight(b);
32 wake_up_bit(&b->flags, BTREE_NODE_write_in_flight);
35 static inline void btree_node_io_lock(struct btree *b)
37 wait_on_bit_lock_io(&b->flags, BTREE_NODE_write_in_flight,
38 TASK_UNINTERRUPTIBLE);
41 static inline void btree_node_wait_on_io(struct btree *b)
43 wait_on_bit_io(&b->flags, BTREE_NODE_write_in_flight,
44 TASK_UNINTERRUPTIBLE);
47 static inline bool btree_node_may_write(struct btree *b)
49 return list_empty_careful(&b->write_blocked) &&
50 !b->will_make_reachable;
56 COMPACT_WRITTEN_NO_WRITE_LOCK,
59 bool __bch2_compact_whiteouts(struct bch_fs *, struct btree *, enum compact_mode);
61 static inline bool bch2_maybe_compact_whiteouts(struct bch_fs *c, struct btree *b)
66 unsigned live_u64s = b->nr.bset_u64s[t - b->set];
67 unsigned bset_u64s = le16_to_cpu(bset(b, t)->u64s);
69 if (live_u64s * 4 < bset_u64s * 3)
75 return __bch2_compact_whiteouts(c, b, COMPACT_LAZY);
78 void bch2_btree_sort_into(struct bch_fs *, struct btree *, struct btree *);
80 void bch2_btree_build_aux_trees(struct btree *);
81 void bch2_btree_init_next(struct bch_fs *, struct btree *,
84 int bch2_btree_node_read_done(struct bch_fs *, struct btree *, bool);
85 void bch2_btree_node_read(struct bch_fs *, struct btree *, bool);
86 int bch2_btree_root_read(struct bch_fs *, enum btree_id,
87 const struct bkey_i *, unsigned);
89 void bch2_btree_complete_write(struct bch_fs *, struct btree *,
90 struct btree_write *);
91 void bch2_btree_write_error_work(struct work_struct *);
93 void __bch2_btree_node_write(struct bch_fs *, struct btree *,
94 struct closure *, enum six_lock_type);
95 bool bch2_btree_post_write_cleanup(struct bch_fs *, struct btree *);
97 void bch2_btree_node_write(struct bch_fs *, struct btree *,
98 struct closure *, enum six_lock_type);
100 #define bch2_btree_node_write_dirty(_c, _b, _cl, cond) \
102 while ((_b)->written && btree_node_dirty(_b) && (cond)) { \
103 set_btree_node_need_write(_b); \
105 if (!btree_node_may_write(_b)) \
108 if (!btree_node_write_in_flight(_b)) { \
109 bch2_btree_node_write(_c, _b, _cl, SIX_LOCK_read);\
113 six_unlock_read(&(_b)->lock); \
114 btree_node_wait_on_io(_b); \
115 six_lock_read(&(_b)->lock); \
119 void bch2_btree_verify_flushed(struct bch_fs *);
121 #endif /* _BCACHEFS_BTREE_IO_H */