]> git.sesse.net Git - bcachefs-tools-debian/blob - include/linux/blk_types.h
Update bcachefs sources to b91a514413 bcachefs: Don't try to delete stripes when RO
[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
17 /*
18  * Block error status values.  See block/blk-core:blk_errors for the details.
19  */
20 typedef u8 __bitwise blk_status_t;
21 #define BLK_STS_OK 0
22 #define BLK_STS_NOTSUPP         ((__force blk_status_t)1)
23 #define BLK_STS_TIMEOUT         ((__force blk_status_t)2)
24 #define BLK_STS_NOSPC           ((__force blk_status_t)3)
25 #define BLK_STS_TRANSPORT       ((__force blk_status_t)4)
26 #define BLK_STS_TARGET          ((__force blk_status_t)5)
27 #define BLK_STS_NEXUS           ((__force blk_status_t)6)
28 #define BLK_STS_MEDIUM          ((__force blk_status_t)7)
29 #define BLK_STS_PROTECTION      ((__force blk_status_t)8)
30 #define BLK_STS_RESOURCE        ((__force blk_status_t)9)
31 #define BLK_STS_IOERR           ((__force blk_status_t)10)
32
33 /* hack for device mapper, don't use elsewhere: */
34 #define BLK_STS_DM_REQUEUE    ((__force blk_status_t)11)
35
36 #define BLK_STS_AGAIN           ((__force blk_status_t)12)
37
38 /*
39  * main unit of I/O for the block layer and lower layers (ie drivers and
40  * stacking drivers)
41  */
42 struct bio {
43         struct bio              *bi_next;       /* request queue link */
44         struct block_device     *bi_bdev;
45         blk_status_t            bi_status;
46         unsigned int            bi_opf;         /* bottom bits req flags,
47                                                  * top bits REQ_OP. Use
48                                                  * accessors.
49                                                  */
50         unsigned short          bi_flags;       /* status, command, etc */
51         unsigned short          bi_ioprio;
52
53         struct bvec_iter        bi_iter;
54
55         atomic_t                __bi_remaining;
56
57         bio_end_io_t            *bi_end_io;
58         void                    *bi_private;
59
60         unsigned short          bi_vcnt;        /* how many bio_vec's */
61
62         /*
63          * Everything starting with bi_max_vecs will be preserved by bio_reset()
64          */
65
66         unsigned short          bi_max_vecs;    /* max bvl_vecs we can hold */
67
68         atomic_t                __bi_cnt;       /* pin count */
69
70         struct bio_vec          *bi_io_vec;     /* the actual vec list */
71
72         struct bio_set          *bi_pool;
73
74         /*
75          * We can inline a number of vecs at the end of the bio, to avoid
76          * double allocations for a small number of bio_vecs. This member
77          * MUST obviously be kept at the very end of the bio.
78          */
79         struct bio_vec          bi_inline_vecs[0];
80 };
81
82 #define BIO_RESET_BYTES         offsetof(struct bio, bi_max_vecs)
83
84 /*
85  * bio flags
86  */
87 #define BIO_SEG_VALID   1       /* bi_phys_segments valid */
88 #define BIO_CLONED      2       /* doesn't own data */
89 #define BIO_BOUNCED     3       /* bio is a bounce bio */
90 #define BIO_USER_MAPPED 4       /* contains user pages */
91 #define BIO_NULL_MAPPED 5       /* contains invalid user pages */
92 #define BIO_QUIET       6       /* Make BIO Quiet */
93 #define BIO_CHAIN       7       /* chained bio, ->bi_remaining in effect */
94 #define BIO_REFFED      8       /* bio has elevated ->bi_cnt */
95
96 /*
97  * Flags starting here get preserved by bio_reset() - this includes
98  * BVEC_POOL_IDX()
99  */
100 #define BIO_RESET_BITS  10
101
102 /*
103  * We support 6 different bvec pools, the last one is magic in that it
104  * is backed by a mempool.
105  */
106 #define BVEC_POOL_NR            6
107 #define BVEC_POOL_MAX           (BVEC_POOL_NR - 1)
108
109 /*
110  * Top 4 bits of bio flags indicate the pool the bvecs came from.  We add
111  * 1 to the actual index so that 0 indicates that there are no bvecs to be
112  * freed.
113  */
114 #define BVEC_POOL_BITS          (4)
115 #define BVEC_POOL_OFFSET        (16 - BVEC_POOL_BITS)
116 #define BVEC_POOL_IDX(bio)      ((bio)->bi_flags >> BVEC_POOL_OFFSET)
117
118 /*
119  * Operations and flags common to the bio and request structures.
120  * We use 8 bits for encoding the operation, and the remaining 24 for flags.
121  *
122  * The least significant bit of the operation number indicates the data
123  * transfer direction:
124  *
125  *   - if the least significant bit is set transfers are TO the device
126  *   - if the least significant bit is not set transfers are FROM the device
127  *
128  * If a operation does not transfer data the least significant bit has no
129  * meaning.
130  */
131 #define REQ_OP_BITS     8
132 #define REQ_OP_MASK     ((1 << REQ_OP_BITS) - 1)
133 #define REQ_FLAG_BITS   24
134
135 enum req_opf {
136         /* read sectors from the device */
137         REQ_OP_READ             = 0,
138         /* write sectors to the device */
139         REQ_OP_WRITE            = 1,
140         /* flush the volatile write cache */
141         REQ_OP_FLUSH            = 2,
142         /* discard sectors */
143         REQ_OP_DISCARD          = 3,
144         /* get zone information */
145         REQ_OP_ZONE_REPORT      = 4,
146         /* securely erase sectors */
147         REQ_OP_SECURE_ERASE     = 5,
148         /* seset a zone write pointer */
149         REQ_OP_ZONE_RESET       = 6,
150         /* write the same sector many times */
151         REQ_OP_WRITE_SAME       = 7,
152         /* write the zero filled sector many times */
153         REQ_OP_WRITE_ZEROES     = 8,
154
155         /* SCSI passthrough using struct scsi_request */
156         REQ_OP_SCSI_IN          = 32,
157         REQ_OP_SCSI_OUT         = 33,
158         /* Driver private requests */
159         REQ_OP_DRV_IN           = 34,
160         REQ_OP_DRV_OUT          = 35,
161
162         REQ_OP_LAST,
163 };
164
165 enum req_flag_bits {
166         __REQ_FAILFAST_DEV =    /* no driver retries of device errors */
167                 REQ_OP_BITS,
168         __REQ_FAILFAST_TRANSPORT, /* no driver retries of transport errors */
169         __REQ_FAILFAST_DRIVER,  /* no driver retries of driver errors */
170         __REQ_SYNC,             /* request is sync (sync write or read) */
171         __REQ_META,             /* metadata io request */
172         __REQ_PRIO,             /* boost priority in cfq */
173         __REQ_NOMERGE,          /* don't touch this for merging */
174         __REQ_IDLE,             /* anticipate more IO after this one */
175         __REQ_INTEGRITY,        /* I/O includes block integrity payload */
176         __REQ_FUA,              /* forced unit access */
177         __REQ_PREFLUSH,         /* request for cache flush */
178         __REQ_RAHEAD,           /* read ahead, can fail anytime */
179         __REQ_BACKGROUND,       /* background IO */
180         __REQ_NR_BITS,          /* stops here */
181 };
182
183 #define REQ_SYNC                (1ULL << __REQ_SYNC)
184 #define REQ_META                (1ULL << __REQ_META)
185 #define REQ_PRIO                (1ULL << __REQ_PRIO)
186
187 #define REQ_NOMERGE_FLAGS       (REQ_PREFLUSH | REQ_FUA)
188
189 #define bio_op(bio) \
190         ((bio)->bi_opf & REQ_OP_MASK)
191
192 static inline void bio_set_op_attrs(struct bio *bio, unsigned op,
193                 unsigned op_flags)
194 {
195         bio->bi_opf = op | op_flags;
196 }
197
198 #define REQ_RAHEAD              (1ULL << __REQ_RAHEAD)
199 #define REQ_THROTTLED           (1ULL << __REQ_THROTTLED)
200
201 #define REQ_FUA                 (1ULL << __REQ_FUA)
202 #define REQ_PREFLUSH            (1ULL << __REQ_PREFLUSH)
203
204 #define RW_MASK                 REQ_OP_WRITE
205
206 #define READ                    REQ_OP_READ
207 #define WRITE                   REQ_OP_WRITE
208
209 #define READ_SYNC               REQ_SYNC
210 #define WRITE_SYNC              (REQ_SYNC)
211 #define WRITE_ODIRECT           REQ_SYNC
212 #define WRITE_FLUSH             (REQ_SYNC | REQ_PREFLUSH)
213 #define WRITE_FUA               (REQ_SYNC | REQ_FUA)
214 #define WRITE_FLUSH_FUA         (REQ_SYNC | REQ_PREFLUSH | REQ_FUA)
215
216 #endif /* __LINUX_BLK_TYPES_H */