2 * Block data types and constants. Directly include this file only to
3 * break include dependency loop.
5 #ifndef __LINUX_BLK_TYPES_H
6 #define __LINUX_BLK_TYPES_H
8 #include <linux/atomic.h>
9 #include <linux/types.h>
10 #include <linux/bvec.h>
15 typedef void (bio_end_io_t) (struct bio *);
16 typedef void (bio_destructor_t) (struct bio *);
19 * main unit of I/O for the block layer and lower layers (ie drivers and
23 struct bio *bi_next; /* request queue link */
24 struct block_device *bi_bdev;
26 unsigned int bi_opf; /* bottom bits req flags,
27 * top bits REQ_OP. Use
30 unsigned short bi_flags; /* status, command, etc */
31 unsigned short bi_ioprio;
33 struct bvec_iter bi_iter;
35 atomic_t __bi_remaining;
37 bio_end_io_t *bi_end_io;
40 unsigned short bi_vcnt; /* how many bio_vec's */
43 * Everything starting with bi_max_vecs will be preserved by bio_reset()
46 unsigned short bi_max_vecs; /* max bvl_vecs we can hold */
48 atomic_t __bi_cnt; /* pin count */
50 struct bio_vec *bi_io_vec; /* the actual vec list */
52 struct bio_set *bi_pool;
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.
59 struct bio_vec bi_inline_vecs[0];
62 #define BIO_OP_SHIFT (8 * sizeof(unsigned int) - REQ_OP_BITS)
63 #define bio_op(bio) ((bio)->bi_opf >> BIO_OP_SHIFT)
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; \
72 #define BIO_RESET_BYTES offsetof(struct bio, bi_max_vecs)
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 */
87 * Flags starting here get preserved by bio_reset() - this includes
90 #define BIO_RESET_BITS 10
93 * We support 6 different bvec pools, the last one is magic in that it
94 * is backed by a mempool.
96 #define BVEC_POOL_NR 6
97 #define BVEC_POOL_MAX (BVEC_POOL_NR - 1)
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
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)
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.
113 __REQ_SYNC, /* request is sync (sync write or read) */
114 __REQ_META, /* metadata io request */
115 __REQ_PRIO, /* boost priority in cfq */
117 __REQ_FUA, /* forced unit access */
118 __REQ_PREFLUSH, /* request for cache flush */
121 #define REQ_SYNC (1ULL << __REQ_SYNC)
122 #define REQ_META (1ULL << __REQ_META)
123 #define REQ_PRIO (1ULL << __REQ_PRIO)
125 #define REQ_NOMERGE_FLAGS (REQ_PREFLUSH | REQ_FUA)
127 #define REQ_RAHEAD (1ULL << __REQ_RAHEAD)
128 #define REQ_THROTTLED (1ULL << __REQ_THROTTLED)
130 #define REQ_FUA (1ULL << __REQ_FUA)
131 #define REQ_PREFLUSH (1ULL << __REQ_PREFLUSH)
133 #define RW_MASK REQ_OP_WRITE
135 #define READ REQ_OP_READ
136 #define WRITE REQ_OP_WRITE
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)
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 */
154 #define REQ_OP_BITS 3
156 #endif /* __LINUX_BLK_TYPES_H */