]> git.sesse.net Git - bcachefs-tools-debian/blob - include/linux/blk_types.h
bcache in userspace; userspace fsck
[bcachefs-tools-debian] / include / linux / blk_types.h
1 /*
2  * Block data types and constants.  Directly include this file only to
3  * break include dependency loop.
4  */
5 #ifndef __LINUX_BLK_TYPES_H
6 #define __LINUX_BLK_TYPES_H
7
8 #include <linux/atomic.h>
9 #include <linux/types.h>
10 #include <linux/bvec.h>
11
12 struct bio_set;
13 struct bio;
14 struct block_device;
15 typedef void (bio_end_io_t) (struct bio *);
16 typedef void (bio_destructor_t) (struct bio *);
17
18 /*
19  * main unit of I/O for the block layer and lower layers (ie drivers and
20  * stacking drivers)
21  */
22 struct bio {
23         struct bio              *bi_next;       /* request queue link */
24         struct block_device     *bi_bdev;
25         int                     bi_error;
26         unsigned int            bi_opf;         /* bottom bits req flags,
27                                                  * top bits REQ_OP. Use
28                                                  * accessors.
29                                                  */
30         unsigned short          bi_flags;       /* status, command, etc */
31         unsigned short          bi_ioprio;
32
33         struct bvec_iter        bi_iter;
34
35         atomic_t                __bi_remaining;
36
37         bio_end_io_t            *bi_end_io;
38         void                    *bi_private;
39
40         unsigned short          bi_vcnt;        /* how many bio_vec's */
41
42         /*
43          * Everything starting with bi_max_vecs will be preserved by bio_reset()
44          */
45
46         unsigned short          bi_max_vecs;    /* max bvl_vecs we can hold */
47
48         atomic_t                __bi_cnt;       /* pin count */
49
50         struct bio_vec          *bi_io_vec;     /* the actual vec list */
51
52         struct bio_set          *bi_pool;
53
54         /*
55          * We can inline a number of vecs at the end of the bio, to avoid
56          * double allocations for a small number of bio_vecs. This member
57          * MUST obviously be kept at the very end of the bio.
58          */
59         struct bio_vec          bi_inline_vecs[0];
60 };
61
62 #define BIO_OP_SHIFT    (8 * sizeof(unsigned int) - REQ_OP_BITS)
63 #define bio_op(bio)     ((bio)->bi_opf >> BIO_OP_SHIFT)
64
65 #define bio_set_op_attrs(bio, op, op_flags) do {                \
66         WARN_ON(op >= (1 << REQ_OP_BITS));                      \
67         (bio)->bi_opf &= ((1 << BIO_OP_SHIFT) - 1);             \
68         (bio)->bi_opf |= ((unsigned int) (op) << BIO_OP_SHIFT); \
69         (bio)->bi_opf |= op_flags;                              \
70 } while (0)
71
72 #define BIO_RESET_BYTES         offsetof(struct bio, bi_max_vecs)
73
74 /*
75  * bio flags
76  */
77 #define BIO_SEG_VALID   1       /* bi_phys_segments valid */
78 #define BIO_CLONED      2       /* doesn't own data */
79 #define BIO_BOUNCED     3       /* bio is a bounce bio */
80 #define BIO_USER_MAPPED 4       /* contains user pages */
81 #define BIO_NULL_MAPPED 5       /* contains invalid user pages */
82 #define BIO_QUIET       6       /* Make BIO Quiet */
83 #define BIO_CHAIN       7       /* chained bio, ->bi_remaining in effect */
84 #define BIO_REFFED      8       /* bio has elevated ->bi_cnt */
85
86 /*
87  * Flags starting here get preserved by bio_reset() - this includes
88  * BVEC_POOL_IDX()
89  */
90 #define BIO_RESET_BITS  10
91
92 /*
93  * We support 6 different bvec pools, the last one is magic in that it
94  * is backed by a mempool.
95  */
96 #define BVEC_POOL_NR            6
97 #define BVEC_POOL_MAX           (BVEC_POOL_NR - 1)
98
99 /*
100  * Top 4 bits of bio flags indicate the pool the bvecs came from.  We add
101  * 1 to the actual index so that 0 indicates that there are no bvecs to be
102  * freed.
103  */
104 #define BVEC_POOL_BITS          (4)
105 #define BVEC_POOL_OFFSET        (16 - BVEC_POOL_BITS)
106 #define BVEC_POOL_IDX(bio)      ((bio)->bi_flags >> BVEC_POOL_OFFSET)
107
108 /*
109  * Request flags.  For use in the cmd_flags field of struct request, and in
110  * bi_opf of struct bio.  Note that some flags are only valid in either one.
111  */
112 enum rq_flag_bits {
113         __REQ_SYNC,             /* request is sync (sync write or read) */
114         __REQ_META,             /* metadata io request */
115         __REQ_PRIO,             /* boost priority in cfq */
116
117         __REQ_FUA,              /* forced unit access */
118         __REQ_PREFLUSH,         /* request for cache flush */
119 };
120
121 #define REQ_SYNC                (1ULL << __REQ_SYNC)
122 #define REQ_META                (1ULL << __REQ_META)
123 #define REQ_PRIO                (1ULL << __REQ_PRIO)
124
125 #define REQ_NOMERGE_FLAGS       (REQ_PREFLUSH | REQ_FUA)
126
127 #define REQ_RAHEAD              (1ULL << __REQ_RAHEAD)
128 #define REQ_THROTTLED           (1ULL << __REQ_THROTTLED)
129
130 #define REQ_FUA                 (1ULL << __REQ_FUA)
131 #define REQ_PREFLUSH            (1ULL << __REQ_PREFLUSH)
132
133 #define RW_MASK                 REQ_OP_WRITE
134
135 #define READ                    REQ_OP_READ
136 #define WRITE                   REQ_OP_WRITE
137
138 #define READ_SYNC               REQ_SYNC
139 #define WRITE_SYNC              (REQ_SYNC)
140 #define WRITE_ODIRECT           REQ_SYNC
141 #define WRITE_FLUSH             (REQ_SYNC | REQ_PREFLUSH)
142 #define WRITE_FUA               (REQ_SYNC | REQ_FUA)
143 #define WRITE_FLUSH_FUA         (REQ_SYNC | REQ_PREFLUSH | REQ_FUA)
144
145 enum req_op {
146         REQ_OP_READ,
147         REQ_OP_WRITE,
148         REQ_OP_DISCARD,         /* request to discard sectors */
149         REQ_OP_SECURE_ERASE,    /* request to securely erase sectors */
150         REQ_OP_WRITE_SAME,      /* write same block many times */
151         REQ_OP_FLUSH,           /* request for cache flush */
152 };
153
154 #define REQ_OP_BITS 3
155
156 #endif /* __LINUX_BLK_TYPES_H */