]> git.sesse.net Git - bcachefs-tools-debian/blob - libbcache/blockdev_types.h
bcache in userspace; userspace fsck
[bcachefs-tools-debian] / libbcache / blockdev_types.h
1 #ifndef _BCACHE_BLOCKDEV_TYPES_H
2 #define _BCACHE_BLOCKDEV_TYPES_H
3
4 #include "keybuf_types.h"
5 #include "stats_types.h"
6 #include "super_types.h"
7 #include "util.h"
8
9 struct bcache_device {
10         struct closure          cl;
11
12         struct kobject          kobj;
13
14         struct cache_set        *c;
15
16         struct rb_node          node;
17         struct bkey_i_inode_blockdev inode;
18         struct mutex            inode_lock;
19
20 #define BCACHEDEVNAME_SIZE      12
21         char                    name[BCACHEDEVNAME_SIZE];
22
23         struct gendisk          *disk;
24
25         unsigned long           flags;
26 #define BCACHE_DEV_CLOSING      0
27 #define BCACHE_DEV_DETACHING    1
28 #define BCACHE_DEV_UNLINK_DONE  2
29
30         unsigned                nr_stripes;
31         unsigned                stripe_size;
32         atomic_t                *stripe_sectors_dirty;
33         unsigned long           *full_dirty_stripes;
34
35         struct bio_set          bio_split;
36
37         unsigned                data_csum:1;
38
39         int (*ioctl)(struct bcache_device *, fmode_t, unsigned, unsigned long);
40 };
41
42 struct io {
43         /* Used to track sequential IO so it can be skipped */
44         struct hlist_node       hash;
45         struct list_head        lru;
46
47         unsigned long           last_io;
48         unsigned                sequential;
49         sector_t                last;
50 };
51
52 struct cached_dev {
53         struct list_head        list;
54         struct bcache_device    disk;
55
56         //struct backingdev_sb          sb;
57
58         struct {
59                 struct backingdev_sb    *sb;
60                 struct block_device     *bdev;
61                 struct bio              *bio;
62                 unsigned                page_order;
63         } disk_sb;
64         struct closure          sb_write;
65         struct semaphore        sb_write_mutex;
66
67         /* Refcount on the cache set. Always nonzero when we're caching. */
68         atomic_t                count;
69         struct work_struct      detach;
70
71         /*
72          * Device might not be running if it's dirty and the cache set hasn't
73          * showed up yet.
74          */
75         atomic_t                running;
76
77         /*
78          * Writes take a shared lock from start to finish; scanning for dirty
79          * data to refill the rb tree requires an exclusive lock.
80          */
81         struct rw_semaphore     writeback_lock;
82
83         /*
84          * Nonzero, and writeback has a refcount (d->count), iff there is dirty
85          * data in the cache. Protected by writeback_lock; must have an
86          * shared lock to set and exclusive lock to clear.
87          */
88         atomic_t                has_dirty;
89
90         /* for dynamic rate control of writeback */
91         struct bch_pd_controller writeback_pd;
92         struct delayed_work     writeback_pd_update;
93         unsigned                writeback_pd_update_seconds;
94
95         struct task_struct      *writeback_thread;
96         struct keybuf           writeback_keys;
97         mempool_t               writeback_io_pool;
98         mempool_t               writeback_page_pool;
99
100         /* For tracking sequential IO */
101 #define RECENT_IO_BITS  7
102 #define RECENT_IO       (1 << RECENT_IO_BITS)
103         struct io               io[RECENT_IO];
104         struct hlist_head       io_hash[RECENT_IO + 1];
105         struct list_head        io_lru;
106         spinlock_t              io_lock;
107
108         struct cache_accounting accounting;
109
110         /* The rest of this all shows up in sysfs */
111         unsigned                sequential_cutoff;
112         unsigned                readahead;
113
114         unsigned                verify:1;
115         unsigned                bypass_torture_test:1;
116
117         unsigned                partial_stripes_expensive:1;
118         unsigned                writeback_metadata:1;
119         unsigned                writeback_running:1;
120         unsigned char           writeback_percent;
121 };
122
123 #endif /* _BCACHE_BLOCKDEV_TYPES_H */