1 #ifndef _BCACHEFS_BTREE_IO_H
2 #define _BCACHEFS_BTREE_IO_H
11 struct btree_read_bio {
13 unsigned submit_time_us;
15 struct extent_pick_ptr pick;
16 struct work_struct work;
20 static inline void btree_node_io_unlock(struct btree *b)
22 EBUG_ON(!btree_node_write_in_flight(b));
23 clear_btree_node_write_in_flight(b);
24 wake_up_bit(&b->flags, BTREE_NODE_write_in_flight);
27 static inline void btree_node_io_lock(struct btree *b)
29 wait_on_bit_lock_io(&b->flags, BTREE_NODE_write_in_flight,
30 TASK_UNINTERRUPTIBLE);
33 static inline void btree_node_wait_on_io(struct btree *b)
35 wait_on_bit_io(&b->flags, BTREE_NODE_write_in_flight,
36 TASK_UNINTERRUPTIBLE);
39 static inline bool btree_node_may_write(struct btree *b)
41 return list_empty_careful(&b->write_blocked) &&
42 !b->will_make_reachable;
48 COMPACT_WRITTEN_NO_WRITE_LOCK,
51 bool __bch2_compact_whiteouts(struct bch_fs *, struct btree *, enum compact_mode);
53 static inline bool bch2_maybe_compact_whiteouts(struct bch_fs *c, struct btree *b)
58 unsigned live_u64s = b->nr.bset_u64s[t - b->set];
59 unsigned bset_u64s = le16_to_cpu(bset(b, t)->u64s);
61 if (live_u64s * 4 < bset_u64s * 3)
67 return __bch2_compact_whiteouts(c, b, COMPACT_LAZY);
70 void bch2_btree_sort_into(struct bch_fs *, struct btree *, struct btree *);
72 void bch2_btree_build_aux_trees(struct btree *);
73 void bch2_btree_init_next(struct bch_fs *, struct btree *,
76 int bch2_btree_node_read_done(struct bch_fs *, struct btree *, bool);
77 void bch2_btree_node_read(struct bch_fs *, struct btree *, bool);
78 int bch2_btree_root_read(struct bch_fs *, enum btree_id,
79 const struct bkey_i *, unsigned);
81 void bch2_btree_complete_write(struct bch_fs *, struct btree *,
82 struct btree_write *);
83 void bch2_btree_write_error_work(struct work_struct *);
85 void __bch2_btree_node_write(struct bch_fs *, struct btree *,
86 struct closure *, enum six_lock_type);
87 bool bch2_btree_post_write_cleanup(struct bch_fs *, struct btree *);
89 void bch2_btree_node_write(struct bch_fs *, struct btree *,
90 struct closure *, enum six_lock_type);
92 #define bch2_btree_node_write_dirty(_c, _b, _cl, cond) \
94 while ((_b)->written && btree_node_dirty(_b) && (cond)) { \
95 set_btree_node_need_write(_b); \
97 if (!btree_node_may_write(_b)) \
100 if (!btree_node_write_in_flight(_b)) { \
101 bch2_btree_node_write(_c, _b, _cl, SIX_LOCK_read);\
105 six_unlock_read(&(_b)->lock); \
106 btree_node_wait_on_io(_b); \
107 six_lock_read(&(_b)->lock); \
111 void bch2_btree_verify_flushed(struct bch_fs *);
113 #endif /* _BCACHEFS_BTREE_IO_H */