summaryrefslogtreecommitdiff
path: root/libbcache/btree_io.h
blob: 866cc6c3008ca4e099eb5c9f3f2ff154ff08163b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef _BCACHE_BTREE_IO_H
#define _BCACHE_BTREE_IO_H

struct cache_set;
struct btree_write;
struct btree;
struct btree_iter;

static inline void btree_node_io_unlock(struct btree *b)
{
	EBUG_ON(!btree_node_write_in_flight(b));
	clear_btree_node_write_in_flight(b);
	wake_up_bit(&b->flags, BTREE_NODE_write_in_flight);
}

static inline void btree_node_io_lock(struct btree *b)
{
	wait_on_bit_lock_io(&b->flags, BTREE_NODE_write_in_flight,
			    TASK_UNINTERRUPTIBLE);
}

enum compact_mode {
	COMPACT_LAZY,
	COMPACT_WRITTEN,
	COMPACT_WRITTEN_NO_WRITE_LOCK,
};

bool __bch_compact_whiteouts(struct cache_set *, struct btree *, enum compact_mode);

static inline bool bch_maybe_compact_whiteouts(struct cache_set *c, struct btree *b)
{
	struct bset_tree *t;

	for_each_bset(b, t) {
		unsigned live_u64s = b->nr.bset_u64s[t - b->set];
		unsigned bset_u64s = le16_to_cpu(bset(b, t)->u64s);

		if (live_u64s * 4 < bset_u64s * 3)
			goto compact;
	}

	return false;
compact:
	return __bch_compact_whiteouts(c, b, COMPACT_LAZY);
}

void bch_btree_sort_into(struct cache_set *, struct btree *, struct btree *);

void bch_btree_build_aux_trees(struct btree *);
void bch_btree_init_next(struct cache_set *, struct btree *,
			 struct btree_iter *);

void bch_btree_node_read_done(struct cache_set *, struct btree *,
			      struct cache *, const struct bch_extent_ptr *);
void bch_btree_node_read(struct cache_set *, struct btree *);
int bch_btree_root_read(struct cache_set *, enum btree_id,
			const struct bkey_i *, unsigned);

void bch_btree_complete_write(struct cache_set *, struct btree *,
			      struct btree_write *);

void __bch_btree_node_write(struct cache_set *, struct btree *,
			    struct closure *, enum six_lock_type, int);
bool bch_btree_post_write_cleanup(struct cache_set *, struct btree *);

void bch_btree_node_write(struct cache_set *, struct btree *,
			  struct closure *, enum six_lock_type, int);

void bch_btree_flush(struct cache_set *);
void bch_btree_node_flush_journal_entries(struct cache_set *, struct btree *,
					  struct closure *);

#endif /* _BCACHE_BTREE_IO_H */