2017-01-08 12:13:18 +03:00
|
|
|
#ifndef _BCACHE_BTREE_IO_H
|
|
|
|
#define _BCACHE_BTREE_IO_H
|
|
|
|
|
2017-04-24 08:56:57 +03:00
|
|
|
#include "extents.h"
|
|
|
|
|
2017-03-11 00:40:01 +03:00
|
|
|
struct bch_fs;
|
2017-01-08 12:13:18 +03:00
|
|
|
struct btree_write;
|
|
|
|
struct btree;
|
|
|
|
struct btree_iter;
|
|
|
|
|
2017-04-24 08:56:57 +03:00
|
|
|
struct btree_read_bio {
|
|
|
|
struct bch_fs *c;
|
2017-06-14 04:06:05 +03:00
|
|
|
u64 start_time;
|
2017-04-24 08:56:57 +03:00
|
|
|
struct extent_pick_ptr pick;
|
|
|
|
struct work_struct work;
|
|
|
|
struct bio bio;
|
|
|
|
};
|
|
|
|
|
2017-01-08 12:13:18 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-04-10 07:11:10 +03:00
|
|
|
static inline void btree_node_wait_on_io(struct btree *b)
|
|
|
|
{
|
|
|
|
wait_on_bit_io(&b->flags, BTREE_NODE_write_in_flight,
|
|
|
|
TASK_UNINTERRUPTIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool btree_node_may_write(struct btree *b)
|
|
|
|
{
|
2017-04-15 07:38:49 +03:00
|
|
|
return list_empty_careful(&b->write_blocked) &&
|
2017-05-13 05:45:15 +03:00
|
|
|
!b->will_make_reachable;
|
2017-04-10 07:11:10 +03:00
|
|
|
}
|
|
|
|
|
2017-01-08 12:13:18 +03:00
|
|
|
enum compact_mode {
|
|
|
|
COMPACT_LAZY,
|
|
|
|
COMPACT_WRITTEN,
|
|
|
|
COMPACT_WRITTEN_NO_WRITE_LOCK,
|
|
|
|
};
|
|
|
|
|
2017-03-20 02:56:34 +03:00
|
|
|
bool __bch2_compact_whiteouts(struct bch_fs *, struct btree *, enum compact_mode);
|
2017-01-08 12:13:18 +03:00
|
|
|
|
2017-03-20 02:56:34 +03:00
|
|
|
static inline bool bch2_maybe_compact_whiteouts(struct bch_fs *c, struct btree *b)
|
2017-01-08 12:13:18 +03:00
|
|
|
{
|
|
|
|
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:
|
2017-03-20 02:56:34 +03:00
|
|
|
return __bch2_compact_whiteouts(c, b, COMPACT_LAZY);
|
2017-01-08 12:13:18 +03:00
|
|
|
}
|
|
|
|
|
2017-03-20 02:56:34 +03:00
|
|
|
void bch2_btree_sort_into(struct bch_fs *, struct btree *, struct btree *);
|
2017-01-08 12:13:18 +03:00
|
|
|
|
2017-03-20 02:56:34 +03:00
|
|
|
void bch2_btree_build_aux_trees(struct btree *);
|
|
|
|
void bch2_btree_init_next(struct bch_fs *, struct btree *,
|
2017-01-08 12:13:18 +03:00
|
|
|
struct btree_iter *);
|
|
|
|
|
2017-06-14 04:06:05 +03:00
|
|
|
int bch2_btree_node_read_done(struct bch_fs *, struct btree *);
|
2017-04-24 08:56:57 +03:00
|
|
|
void bch2_btree_node_read(struct bch_fs *, struct btree *, bool);
|
2017-03-20 02:56:34 +03:00
|
|
|
int bch2_btree_root_read(struct bch_fs *, enum btree_id,
|
2017-06-14 04:06:05 +03:00
|
|
|
const struct bkey_i *, unsigned);
|
2017-01-08 12:13:18 +03:00
|
|
|
|
2017-03-20 02:56:34 +03:00
|
|
|
void bch2_btree_complete_write(struct bch_fs *, struct btree *,
|
2017-01-08 12:13:18 +03:00
|
|
|
struct btree_write *);
|
2017-05-13 05:45:15 +03:00
|
|
|
void bch2_btree_write_error_work(struct work_struct *);
|
2017-01-08 12:13:18 +03:00
|
|
|
|
2017-03-20 02:56:34 +03:00
|
|
|
void __bch2_btree_node_write(struct bch_fs *, struct btree *,
|
2017-04-10 07:11:10 +03:00
|
|
|
struct closure *, enum six_lock_type);
|
2017-03-20 02:56:34 +03:00
|
|
|
bool bch2_btree_post_write_cleanup(struct bch_fs *, struct btree *);
|
2017-01-08 12:13:18 +03:00
|
|
|
|
2017-03-20 02:56:34 +03:00
|
|
|
void bch2_btree_node_write(struct bch_fs *, struct btree *,
|
2017-04-10 07:11:10 +03:00
|
|
|
struct closure *, enum six_lock_type);
|
|
|
|
|
|
|
|
#define bch2_btree_node_write_dirty(_c, _b, _cl, cond) \
|
|
|
|
do { \
|
|
|
|
while ((_b)->written && btree_node_dirty(_b) && (cond)) { \
|
2017-04-15 07:38:49 +03:00
|
|
|
set_btree_node_need_write(_b); \
|
|
|
|
\
|
2017-04-10 07:11:10 +03:00
|
|
|
if (!btree_node_may_write(_b)) \
|
|
|
|
break; \
|
|
|
|
\
|
|
|
|
if (!btree_node_write_in_flight(_b)) { \
|
|
|
|
bch2_btree_node_write(_c, _b, _cl, SIX_LOCK_read);\
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
six_unlock_read(&(_b)->lock); \
|
|
|
|
btree_node_wait_on_io(_b); \
|
|
|
|
six_lock_read(&(_b)->lock); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2017-01-08 12:13:18 +03:00
|
|
|
|
2017-04-11 08:19:15 +03:00
|
|
|
void bch2_btree_verify_flushed(struct bch_fs *);
|
2017-01-08 12:13:18 +03:00
|
|
|
|
|
|
|
#endif /* _BCACHE_BTREE_IO_H */
|