1 #ifndef _BCACHE_BTREE_IO_H
2 #define _BCACHE_BTREE_IO_H
11 struct btree_read_bio {
13 struct extent_pick_ptr pick;
14 struct work_struct work;
18 static inline void btree_node_io_unlock(struct btree *b)
20 EBUG_ON(!btree_node_write_in_flight(b));
21 clear_btree_node_write_in_flight(b);
22 wake_up_bit(&b->flags, BTREE_NODE_write_in_flight);
25 static inline void btree_node_io_lock(struct btree *b)
27 wait_on_bit_lock_io(&b->flags, BTREE_NODE_write_in_flight,
28 TASK_UNINTERRUPTIBLE);
31 static inline void btree_node_wait_on_io(struct btree *b)
33 wait_on_bit_io(&b->flags, BTREE_NODE_write_in_flight,
34 TASK_UNINTERRUPTIBLE);
37 static inline bool btree_node_may_write(struct btree *b)
39 return list_empty_careful(&b->write_blocked) &&
40 !b->will_make_reachable;
46 COMPACT_WRITTEN_NO_WRITE_LOCK,
49 bool __bch2_compact_whiteouts(struct bch_fs *, struct btree *, enum compact_mode);
51 static inline bool bch2_maybe_compact_whiteouts(struct bch_fs *c, struct btree *b)
56 unsigned live_u64s = b->nr.bset_u64s[t - b->set];
57 unsigned bset_u64s = le16_to_cpu(bset(b, t)->u64s);
59 if (live_u64s * 4 < bset_u64s * 3)
65 return __bch2_compact_whiteouts(c, b, COMPACT_LAZY);
68 void bch2_btree_sort_into(struct bch_fs *, struct btree *, struct btree *);
70 void bch2_btree_build_aux_trees(struct btree *);
71 void bch2_btree_init_next(struct bch_fs *, struct btree *,
74 void bch2_btree_node_read_done(struct bch_fs *, struct btree *,
75 struct bch_dev *, const struct bch_extent_ptr *);
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 /* _BCACHE_BTREE_IO_H */