request.h 2.4 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
K
Kent Overstreet 已提交
2 3
#ifndef _BCACHE_REQUEST_H_
#define _BCACHE_REQUEST_H_
4 5
#include "btree.h"
#include "acache.h"
K
Kent Overstreet 已提交
6

K
Kent Overstreet 已提交
7
struct data_insert_op {
K
Kent Overstreet 已提交
8
	struct closure		cl;
K
Kent Overstreet 已提交
9
	struct cache_set	*c;
K
Kent Overstreet 已提交
10
	struct bio		*bio;
11
	struct workqueue_struct *wq;
K
Kent Overstreet 已提交
12

13
	unsigned int		inode;
14
	uint16_t		write_point;
K
Kent Overstreet 已提交
15
	uint16_t		write_prio;
16
	blk_status_t		status;
K
Kent Overstreet 已提交
17

K
Kent Overstreet 已提交
18 19
	union {
		uint16_t	flags;
K
Kent Overstreet 已提交
20

K
Kent Overstreet 已提交
21
	struct {
22 23 24 25
		unsigned int	bypass:1;
		unsigned int	writeback:1;
		unsigned int	flush_journal:1;
		unsigned int	csum:1;
K
Kent Overstreet 已提交
26

27 28
		unsigned int	replace:1;
		unsigned int	replace_collision:1;
K
Kent Overstreet 已提交
29

30
		unsigned int	insert_data_done:1;
K
Kent Overstreet 已提交
31 32
	};
	};
33 34

	struct keylist		insert_keys;
K
Kent Overstreet 已提交
35
	BKEY_PADDED(replace_key);
K
Kent Overstreet 已提交
36 37
};

38
unsigned int bch_get_congested(const struct cache_set *c);
39
void bch_data_insert(struct closure *cl);
K
Kent Overstreet 已提交
40 41

void bch_cached_dev_request_init(struct cached_dev *dc);
42
blk_qc_t cached_dev_submit_bio(struct bio *bio);
43

K
Kent Overstreet 已提交
44
void bch_flash_dev_request_init(struct bcache_device *d);
45
blk_qc_t flash_dev_submit_bio(struct bio *bio);
K
Kent Overstreet 已提交
46

47
extern struct kmem_cache *bch_search_cache;
K
Kent Overstreet 已提交
48

49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
struct search {
	/* Stack frame for bio_complete */
	struct closure		cl;

	struct bbio		bio;
	struct bio		*orig_bio;
	struct bio		*cache_miss;
	struct bcache_device	*d;

	unsigned int		insert_bio_sectors;
	unsigned int		recoverable:1;
	unsigned int		write:1;
	unsigned int		read_dirty_data:1;
	unsigned int		cache_missed:1;

	struct hd_struct	*part;
	unsigned long		start_time;
	/* for prefetch, we do not need copy data to bio */
	bool			prefetch;
68 69 70 71 72 73 74 75 76 77 78 79 80
	/*
	 * The function bch_data_insert() is invoked asynchronously as the bio
	 * subbmited to backend block device, therefore there may be a read
	 * request subbmited after the bch_data_insert() done and ended before
	 * the backend bio is end. This read request will read data from the
	 * backend block device, and insert dirty data to cache device. However
	 * by writearound cache mode, bcache will not invalidate data again,
	 * so that read request after will read dirty data from the cache,
	 * causing a data corruption.
	 * So that we should put off this invalidation. This switch is for this
	 * put off.
	 */
	bool			write_inval_data_putoff;
81 82 83 84 85 86 87 88 89 90 91
	struct list_head	list_node;
	wait_queue_head_t	wqh;
	struct acache_info	smp;

	struct btree_op		op;
	struct data_insert_op	iop;
};

void search_free(struct closure *cl);
struct search *search_alloc(struct bio *bio, struct bcache_device *d, bool prefetch);
void cached_dev_read(struct cached_dev *dc, struct search *s);
K
Kent Overstreet 已提交
92
#endif /* _BCACHE_REQUEST_H_ */