0001
0002
0003
0004
0005
0006 #ifndef __LINUX_BLK_TYPES_H
0007 #define __LINUX_BLK_TYPES_H
0008
0009 #include <linux/types.h>
0010 #include <linux/bvec.h>
0011 #include <linux/device.h>
0012 #include <linux/ktime.h>
0013
0014 struct bio_set;
0015 struct bio;
0016 struct bio_integrity_payload;
0017 struct page;
0018 struct io_context;
0019 struct cgroup_subsys_state;
0020 typedef void (bio_end_io_t) (struct bio *);
0021 struct bio_crypt_ctx;
0022
0023
0024
0025
0026
0027
0028
0029 #ifndef SECTOR_SHIFT
0030 #define SECTOR_SHIFT 9
0031 #endif
0032 #ifndef SECTOR_SIZE
0033 #define SECTOR_SIZE (1 << SECTOR_SHIFT)
0034 #endif
0035
0036 #define PAGE_SECTORS_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
0037 #define PAGE_SECTORS (1 << PAGE_SECTORS_SHIFT)
0038 #define SECTOR_MASK (PAGE_SECTORS - 1)
0039
0040 struct block_device {
0041 sector_t bd_start_sect;
0042 sector_t bd_nr_sectors;
0043 struct disk_stats __percpu *bd_stats;
0044 unsigned long bd_stamp;
0045 bool bd_read_only;
0046 dev_t bd_dev;
0047 atomic_t bd_openers;
0048 struct inode * bd_inode;
0049 struct super_block * bd_super;
0050 void * bd_claiming;
0051 struct device bd_device;
0052 void * bd_holder;
0053 int bd_holders;
0054 bool bd_write_holder;
0055 struct kobject *bd_holder_dir;
0056 u8 bd_partno;
0057 spinlock_t bd_size_lock;
0058 struct gendisk * bd_disk;
0059 struct request_queue * bd_queue;
0060
0061
0062 int bd_fsfreeze_count;
0063
0064 struct mutex bd_fsfreeze_mutex;
0065 struct super_block *bd_fsfreeze_sb;
0066
0067 struct partition_meta_info *bd_meta_info;
0068 #ifdef CONFIG_FAIL_MAKE_REQUEST
0069 bool bd_make_it_fail;
0070 #endif
0071 } __randomize_layout;
0072
0073 #define bdev_whole(_bdev) \
0074 ((_bdev)->bd_disk->part0)
0075
0076 #define dev_to_bdev(device) \
0077 container_of((device), struct block_device, bd_device)
0078
0079 #define bdev_kobj(_bdev) \
0080 (&((_bdev)->bd_device.kobj))
0081
0082
0083
0084
0085
0086 #if defined(CONFIG_ALPHA) && !defined(__alpha_bwx__)
0087 typedef u32 __bitwise blk_status_t;
0088 typedef u32 blk_short_t;
0089 #else
0090 typedef u8 __bitwise blk_status_t;
0091 typedef u16 blk_short_t;
0092 #endif
0093 #define BLK_STS_OK 0
0094 #define BLK_STS_NOTSUPP ((__force blk_status_t)1)
0095 #define BLK_STS_TIMEOUT ((__force blk_status_t)2)
0096 #define BLK_STS_NOSPC ((__force blk_status_t)3)
0097 #define BLK_STS_TRANSPORT ((__force blk_status_t)4)
0098 #define BLK_STS_TARGET ((__force blk_status_t)5)
0099 #define BLK_STS_NEXUS ((__force blk_status_t)6)
0100 #define BLK_STS_MEDIUM ((__force blk_status_t)7)
0101 #define BLK_STS_PROTECTION ((__force blk_status_t)8)
0102 #define BLK_STS_RESOURCE ((__force blk_status_t)9)
0103 #define BLK_STS_IOERR ((__force blk_status_t)10)
0104
0105
0106 #define BLK_STS_DM_REQUEUE ((__force blk_status_t)11)
0107
0108
0109
0110
0111
0112 #define BLK_STS_AGAIN ((__force blk_status_t)12)
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130 #define BLK_STS_DEV_RESOURCE ((__force blk_status_t)13)
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142 #define BLK_STS_ZONE_RESOURCE ((__force blk_status_t)14)
0143
0144
0145
0146
0147
0148
0149
0150
0151 #define BLK_STS_ZONE_OPEN_RESOURCE ((__force blk_status_t)15)
0152
0153
0154
0155
0156
0157
0158
0159
0160 #define BLK_STS_ZONE_ACTIVE_RESOURCE ((__force blk_status_t)16)
0161
0162
0163
0164
0165
0166
0167 #define BLK_STS_OFFLINE ((__force blk_status_t)17)
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181 static inline bool blk_path_error(blk_status_t error)
0182 {
0183 switch (error) {
0184 case BLK_STS_NOTSUPP:
0185 case BLK_STS_NOSPC:
0186 case BLK_STS_TARGET:
0187 case BLK_STS_NEXUS:
0188 case BLK_STS_MEDIUM:
0189 case BLK_STS_PROTECTION:
0190 return false;
0191 }
0192
0193
0194 return true;
0195 }
0196
0197
0198
0199
0200
0201
0202
0203 #define BIO_ISSUE_RES_BITS 1
0204 #define BIO_ISSUE_SIZE_BITS 12
0205 #define BIO_ISSUE_RES_SHIFT (64 - BIO_ISSUE_RES_BITS)
0206 #define BIO_ISSUE_SIZE_SHIFT (BIO_ISSUE_RES_SHIFT - BIO_ISSUE_SIZE_BITS)
0207 #define BIO_ISSUE_TIME_MASK ((1ULL << BIO_ISSUE_SIZE_SHIFT) - 1)
0208 #define BIO_ISSUE_SIZE_MASK \
0209 (((1ULL << BIO_ISSUE_SIZE_BITS) - 1) << BIO_ISSUE_SIZE_SHIFT)
0210 #define BIO_ISSUE_RES_MASK (~((1ULL << BIO_ISSUE_RES_SHIFT) - 1))
0211
0212
0213 #define BIO_ISSUE_THROTL_SKIP_LATENCY (1ULL << 63)
0214
0215 struct bio_issue {
0216 u64 value;
0217 };
0218
0219 static inline u64 __bio_issue_time(u64 time)
0220 {
0221 return time & BIO_ISSUE_TIME_MASK;
0222 }
0223
0224 static inline u64 bio_issue_time(struct bio_issue *issue)
0225 {
0226 return __bio_issue_time(issue->value);
0227 }
0228
0229 static inline sector_t bio_issue_size(struct bio_issue *issue)
0230 {
0231 return ((issue->value & BIO_ISSUE_SIZE_MASK) >> BIO_ISSUE_SIZE_SHIFT);
0232 }
0233
0234 static inline void bio_issue_init(struct bio_issue *issue,
0235 sector_t size)
0236 {
0237 size &= (1ULL << BIO_ISSUE_SIZE_BITS) - 1;
0238 issue->value = ((issue->value & BIO_ISSUE_RES_MASK) |
0239 (ktime_get_ns() & BIO_ISSUE_TIME_MASK) |
0240 ((u64)size << BIO_ISSUE_SIZE_SHIFT));
0241 }
0242
0243 typedef __u32 __bitwise blk_opf_t;
0244
0245 typedef unsigned int blk_qc_t;
0246 #define BLK_QC_T_NONE -1U
0247
0248
0249
0250
0251
0252 struct bio {
0253 struct bio *bi_next;
0254 struct block_device *bi_bdev;
0255 blk_opf_t bi_opf;
0256
0257
0258 unsigned short bi_flags;
0259 unsigned short bi_ioprio;
0260 blk_status_t bi_status;
0261 atomic_t __bi_remaining;
0262
0263 struct bvec_iter bi_iter;
0264
0265 blk_qc_t bi_cookie;
0266 bio_end_io_t *bi_end_io;
0267 void *bi_private;
0268 #ifdef CONFIG_BLK_CGROUP
0269
0270
0271
0272
0273
0274
0275 struct blkcg_gq *bi_blkg;
0276 struct bio_issue bi_issue;
0277 #ifdef CONFIG_BLK_CGROUP_IOCOST
0278 u64 bi_iocost_cost;
0279 #endif
0280 #endif
0281
0282 #ifdef CONFIG_BLK_INLINE_ENCRYPTION
0283 struct bio_crypt_ctx *bi_crypt_context;
0284 #endif
0285
0286 union {
0287 #if defined(CONFIG_BLK_DEV_INTEGRITY)
0288 struct bio_integrity_payload *bi_integrity;
0289 #endif
0290 };
0291
0292 unsigned short bi_vcnt;
0293
0294
0295
0296
0297
0298 unsigned short bi_max_vecs;
0299
0300 atomic_t __bi_cnt;
0301
0302 struct bio_vec *bi_io_vec;
0303
0304 struct bio_set *bi_pool;
0305
0306
0307
0308
0309
0310
0311 struct bio_vec bi_inline_vecs[];
0312 };
0313
0314 #define BIO_RESET_BYTES offsetof(struct bio, bi_max_vecs)
0315 #define BIO_MAX_SECTORS (UINT_MAX >> SECTOR_SHIFT)
0316
0317
0318
0319
0320 enum {
0321 BIO_NO_PAGE_REF,
0322 BIO_CLONED,
0323 BIO_BOUNCED,
0324 BIO_WORKINGSET,
0325 BIO_QUIET,
0326 BIO_CHAIN,
0327 BIO_REFFED,
0328 BIO_THROTTLED,
0329
0330 BIO_TRACE_COMPLETION,
0331
0332 BIO_CGROUP_ACCT,
0333 BIO_QOS_THROTTLED,
0334 BIO_QOS_MERGED,
0335 BIO_REMAPPED,
0336 BIO_ZONE_WRITE_LOCKED,
0337 BIO_FLAG_LAST
0338 };
0339
0340 typedef __u32 __bitwise blk_mq_req_flags_t;
0341
0342 #define REQ_OP_BITS 8
0343 #define REQ_OP_MASK (__force blk_opf_t)((1 << REQ_OP_BITS) - 1)
0344 #define REQ_FLAG_BITS 24
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359 enum req_op {
0360
0361 REQ_OP_READ = (__force blk_opf_t)0,
0362
0363 REQ_OP_WRITE = (__force blk_opf_t)1,
0364
0365 REQ_OP_FLUSH = (__force blk_opf_t)2,
0366
0367 REQ_OP_DISCARD = (__force blk_opf_t)3,
0368
0369 REQ_OP_SECURE_ERASE = (__force blk_opf_t)5,
0370
0371 REQ_OP_WRITE_ZEROES = (__force blk_opf_t)9,
0372
0373 REQ_OP_ZONE_OPEN = (__force blk_opf_t)10,
0374
0375 REQ_OP_ZONE_CLOSE = (__force blk_opf_t)11,
0376
0377 REQ_OP_ZONE_FINISH = (__force blk_opf_t)12,
0378
0379 REQ_OP_ZONE_APPEND = (__force blk_opf_t)13,
0380
0381 REQ_OP_ZONE_RESET = (__force blk_opf_t)15,
0382
0383 REQ_OP_ZONE_RESET_ALL = (__force blk_opf_t)17,
0384
0385
0386 REQ_OP_DRV_IN = (__force blk_opf_t)34,
0387 REQ_OP_DRV_OUT = (__force blk_opf_t)35,
0388
0389 REQ_OP_LAST = (__force blk_opf_t)36,
0390 };
0391
0392 enum req_flag_bits {
0393 __REQ_FAILFAST_DEV =
0394 REQ_OP_BITS,
0395 __REQ_FAILFAST_TRANSPORT,
0396 __REQ_FAILFAST_DRIVER,
0397 __REQ_SYNC,
0398 __REQ_META,
0399 __REQ_PRIO,
0400 __REQ_NOMERGE,
0401 __REQ_IDLE,
0402 __REQ_INTEGRITY,
0403 __REQ_FUA,
0404 __REQ_PREFLUSH,
0405 __REQ_RAHEAD,
0406 __REQ_BACKGROUND,
0407 __REQ_NOWAIT,
0408
0409
0410
0411
0412
0413
0414
0415 __REQ_CGROUP_PUNT,
0416 __REQ_POLLED,
0417 __REQ_ALLOC_CACHE,
0418 __REQ_SWAP,
0419 __REQ_DRV,
0420
0421
0422
0423
0424
0425 __REQ_NOUNMAP,
0426
0427 __REQ_NR_BITS,
0428 };
0429
0430 #define REQ_FAILFAST_DEV \
0431 (__force blk_opf_t)(1ULL << __REQ_FAILFAST_DEV)
0432 #define REQ_FAILFAST_TRANSPORT \
0433 (__force blk_opf_t)(1ULL << __REQ_FAILFAST_TRANSPORT)
0434 #define REQ_FAILFAST_DRIVER \
0435 (__force blk_opf_t)(1ULL << __REQ_FAILFAST_DRIVER)
0436 #define REQ_SYNC (__force blk_opf_t)(1ULL << __REQ_SYNC)
0437 #define REQ_META (__force blk_opf_t)(1ULL << __REQ_META)
0438 #define REQ_PRIO (__force blk_opf_t)(1ULL << __REQ_PRIO)
0439 #define REQ_NOMERGE (__force blk_opf_t)(1ULL << __REQ_NOMERGE)
0440 #define REQ_IDLE (__force blk_opf_t)(1ULL << __REQ_IDLE)
0441 #define REQ_INTEGRITY (__force blk_opf_t)(1ULL << __REQ_INTEGRITY)
0442 #define REQ_FUA (__force blk_opf_t)(1ULL << __REQ_FUA)
0443 #define REQ_PREFLUSH (__force blk_opf_t)(1ULL << __REQ_PREFLUSH)
0444 #define REQ_RAHEAD (__force blk_opf_t)(1ULL << __REQ_RAHEAD)
0445 #define REQ_BACKGROUND (__force blk_opf_t)(1ULL << __REQ_BACKGROUND)
0446 #define REQ_NOWAIT (__force blk_opf_t)(1ULL << __REQ_NOWAIT)
0447 #define REQ_CGROUP_PUNT (__force blk_opf_t)(1ULL << __REQ_CGROUP_PUNT)
0448
0449 #define REQ_NOUNMAP (__force blk_opf_t)(1ULL << __REQ_NOUNMAP)
0450 #define REQ_POLLED (__force blk_opf_t)(1ULL << __REQ_POLLED)
0451 #define REQ_ALLOC_CACHE (__force blk_opf_t)(1ULL << __REQ_ALLOC_CACHE)
0452
0453 #define REQ_DRV (__force blk_opf_t)(1ULL << __REQ_DRV)
0454 #define REQ_SWAP (__force blk_opf_t)(1ULL << __REQ_SWAP)
0455
0456 #define REQ_FAILFAST_MASK \
0457 (REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_DRIVER)
0458
0459 #define REQ_NOMERGE_FLAGS \
0460 (REQ_NOMERGE | REQ_PREFLUSH | REQ_FUA)
0461
0462 enum stat_group {
0463 STAT_READ,
0464 STAT_WRITE,
0465 STAT_DISCARD,
0466 STAT_FLUSH,
0467
0468 NR_STAT_GROUPS
0469 };
0470
0471 static inline enum req_op bio_op(const struct bio *bio)
0472 {
0473 return bio->bi_opf & REQ_OP_MASK;
0474 }
0475
0476
0477 static inline void bio_set_op_attrs(struct bio *bio, enum req_op op,
0478 blk_opf_t op_flags)
0479 {
0480 bio->bi_opf = op | op_flags;
0481 }
0482
0483 static inline bool op_is_write(blk_opf_t op)
0484 {
0485 return !!(op & (__force blk_opf_t)1);
0486 }
0487
0488
0489
0490
0491
0492 static inline bool op_is_flush(blk_opf_t op)
0493 {
0494 return op & (REQ_FUA | REQ_PREFLUSH);
0495 }
0496
0497
0498
0499
0500
0501
0502 static inline bool op_is_sync(blk_opf_t op)
0503 {
0504 return (op & REQ_OP_MASK) == REQ_OP_READ ||
0505 (op & (REQ_SYNC | REQ_FUA | REQ_PREFLUSH));
0506 }
0507
0508 static inline bool op_is_discard(blk_opf_t op)
0509 {
0510 return (op & REQ_OP_MASK) == REQ_OP_DISCARD;
0511 }
0512
0513
0514
0515
0516
0517
0518
0519 static inline bool op_is_zone_mgmt(enum req_op op)
0520 {
0521 switch (op & REQ_OP_MASK) {
0522 case REQ_OP_ZONE_RESET:
0523 case REQ_OP_ZONE_OPEN:
0524 case REQ_OP_ZONE_CLOSE:
0525 case REQ_OP_ZONE_FINISH:
0526 return true;
0527 default:
0528 return false;
0529 }
0530 }
0531
0532 static inline int op_stat_group(enum req_op op)
0533 {
0534 if (op_is_discard(op))
0535 return STAT_DISCARD;
0536 return op_is_write(op);
0537 }
0538
0539 struct blk_rq_stat {
0540 u64 mean;
0541 u64 min;
0542 u64 max;
0543 u32 nr_samples;
0544 u64 batch;
0545 };
0546
0547 #endif