]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcache/blockdev.h
bcache in userspace; userspace fsck
[bcachefs-tools-debian] / libbcache / blockdev.h
1 #ifndef _BCACHE_BLOCKDEV_H
2 #define _BCACHE_BLOCKDEV_H
3
4 #include "blockdev_types.h"
5 #include "io_types.h"
6
7 void bch_write_bdev_super(struct cached_dev *, struct closure *);
8
9 void bch_cached_dev_release(struct kobject *);
10 void bch_blockdev_volume_release(struct kobject *);
11
12 int bch_cached_dev_attach(struct cached_dev *, struct cache_set *);
13 void bch_attach_backing_devs(struct cache_set *);
14
15 void bch_cached_dev_detach(struct cached_dev *);
16 void bch_cached_dev_run(struct cached_dev *);
17 void bch_blockdev_stop(struct bcache_device *);
18
19 bool bch_is_open_backing_dev(struct block_device *);
20 const char *bch_backing_dev_register(struct bcache_superblock *);
21
22 int bch_blockdev_volume_create(struct cache_set *, u64);
23 int bch_blockdev_volumes_start(struct cache_set *);
24
25 void bch_blockdevs_stop(struct cache_set *);
26
27 void bch_blockdev_exit(void);
28 int bch_blockdev_init(void);
29
30 static inline void cached_dev_put(struct cached_dev *dc)
31 {
32         if (atomic_dec_and_test(&dc->count))
33                 schedule_work(&dc->detach);
34 }
35
36 static inline bool cached_dev_get(struct cached_dev *dc)
37 {
38         if (!atomic_inc_not_zero(&dc->count))
39                 return false;
40
41         /* Paired with the mb in cached_dev_attach */
42         smp_mb__after_atomic();
43         return true;
44 }
45
46 static inline u64 bcache_dev_inum(struct bcache_device *d)
47 {
48         return d->inode.k.p.inode;
49 }
50
51 static inline struct bcache_device *bch_dev_find(struct cache_set *c, u64 inode)
52 {
53         return radix_tree_lookup(&c->devices, inode);
54 }
55
56 struct search {
57         /* Stack frame for bio_complete */
58         struct closure          cl;
59
60         union {
61         struct bch_read_bio     rbio;
62         struct bch_write_bio    wbio;
63         };
64         /* Not modified */
65         struct bio              *orig_bio;
66         struct bcache_device    *d;
67
68         unsigned                inode;
69         unsigned                write:1;
70
71         /* Flags only used for reads */
72         unsigned                recoverable:1;
73         unsigned                read_dirty_data:1;
74         unsigned                cache_miss:1;
75
76         /*
77          * For reads:  bypass read from cache and insertion into cache
78          * For writes: discard key range from cache, sending the write to
79          *             the backing device (if there is a backing device)
80          */
81         unsigned                bypass:1;
82
83         unsigned long           start_time;
84
85         /*
86          * Mostly only used for writes. For reads, we still make use of
87          * some trivial fields:
88          * - c
89          * - error
90          */
91         struct bch_write_op     iop;
92 };
93
94 extern struct kmem_cache *bch_search_cache;
95
96 extern struct kobj_type bch_cached_dev_ktype;
97 extern struct kobj_type bch_blockdev_volume_ktype;
98
99 #endif /* _BCACHE_BLOCKDEV_H */