]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcache/btree_io.h
bcache in userspace; userspace fsck
[bcachefs-tools-debian] / libbcache / btree_io.h
1 #ifndef _BCACHE_BTREE_IO_H
2 #define _BCACHE_BTREE_IO_H
3
4 struct cache_set;
5 struct btree_write;
6 struct btree;
7 struct btree_iter;
8
9 static inline void btree_node_io_unlock(struct btree *b)
10 {
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);
14 }
15
16 static inline void btree_node_io_lock(struct btree *b)
17 {
18         wait_on_bit_lock_io(&b->flags, BTREE_NODE_write_in_flight,
19                             TASK_UNINTERRUPTIBLE);
20 }
21
22 enum compact_mode {
23         COMPACT_LAZY,
24         COMPACT_WRITTEN,
25         COMPACT_WRITTEN_NO_WRITE_LOCK,
26 };
27
28 bool __bch_compact_whiteouts(struct cache_set *, struct btree *, enum compact_mode);
29
30 static inline bool bch_maybe_compact_whiteouts(struct cache_set *c, struct btree *b)
31 {
32         struct bset_tree *t;
33
34         for_each_bset(b, t) {
35                 unsigned live_u64s = b->nr.bset_u64s[t - b->set];
36                 unsigned bset_u64s = le16_to_cpu(bset(b, t)->u64s);
37
38                 if (live_u64s * 4 < bset_u64s * 3)
39                         goto compact;
40         }
41
42         return false;
43 compact:
44         return __bch_compact_whiteouts(c, b, COMPACT_LAZY);
45 }
46
47 void bch_btree_sort_into(struct cache_set *, struct btree *, struct btree *);
48
49 void bch_btree_build_aux_trees(struct btree *);
50 void bch_btree_init_next(struct cache_set *, struct btree *,
51                          struct btree_iter *);
52
53 void bch_btree_node_read_done(struct cache_set *, struct btree *,
54                               struct cache *, const struct bch_extent_ptr *);
55 void bch_btree_node_read(struct cache_set *, struct btree *);
56 int bch_btree_root_read(struct cache_set *, enum btree_id,
57                         const struct bkey_i *, unsigned);
58
59 void bch_btree_complete_write(struct cache_set *, struct btree *,
60                               struct btree_write *);
61
62 void __bch_btree_node_write(struct cache_set *, struct btree *,
63                             struct closure *, enum six_lock_type, int);
64 bool bch_btree_post_write_cleanup(struct cache_set *, struct btree *);
65
66 void bch_btree_node_write(struct cache_set *, struct btree *,
67                           struct closure *, enum six_lock_type, int);
68
69 void bch_btree_flush(struct cache_set *);
70 void bch_btree_node_flush_journal_entries(struct cache_set *, struct btree *,
71                                           struct closure *);
72
73 #endif /* _BCACHE_BTREE_IO_H */