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