blkdev.h 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897
  1. #ifndef _LINUX_BLKDEV_H
  2. #define _LINUX_BLKDEV_H
  3. #include <linux/sched.h>
  4. #ifdef CONFIG_BLOCK
  5. #include <linux/major.h>
  6. #include <linux/genhd.h>
  7. #include <linux/list.h>
  8. #include <linux/llist.h>
  9. #include <linux/timer.h>
  10. #include <linux/workqueue.h>
  11. #include <linux/pagemap.h>
  12. #include <linux/backing-dev-defs.h>
  13. #include <linux/wait.h>
  14. #include <linux/mempool.h>
  15. #include <linux/pfn.h>
  16. #include <linux/bio.h>
  17. #include <linux/stringify.h>
  18. #include <linux/gfp.h>
  19. #include <linux/bsg.h>
  20. #include <linux/smp.h>
  21. #include <linux/rcupdate.h>
  22. #include <linux/percpu-refcount.h>
  23. #include <linux/scatterlist.h>
  24. #include <linux/blkzoned.h>
  25. struct module;
  26. struct scsi_ioctl_command;
  27. struct request_queue;
  28. struct elevator_queue;
  29. struct blk_trace;
  30. struct request;
  31. struct sg_io_hdr;
  32. struct bsg_job;
  33. struct blkcg_gq;
  34. struct blk_flush_queue;
  35. struct pr_ops;
  36. struct rq_wb;
  37. #define BLKDEV_MIN_RQ 4
  38. #define BLKDEV_MAX_RQ 128 /* Default maximum */
  39. /*
  40. * Maximum number of blkcg policies allowed to be registered concurrently.
  41. * Defined here to simplify include dependency.
  42. */
  43. #define BLKCG_MAX_POLS 2
  44. typedef void (rq_end_io_fn)(struct request *, int);
  45. #define BLK_RL_SYNCFULL (1U << 0)
  46. #define BLK_RL_ASYNCFULL (1U << 1)
  47. struct request_list {
  48. struct request_queue *q; /* the queue this rl belongs to */
  49. #ifdef CONFIG_BLK_CGROUP
  50. struct blkcg_gq *blkg; /* blkg this request pool belongs to */
  51. #endif
  52. /*
  53. * count[], starved[], and wait[] are indexed by
  54. * BLK_RW_SYNC/BLK_RW_ASYNC
  55. */
  56. int count[2];
  57. int starved[2];
  58. mempool_t *rq_pool;
  59. wait_queue_head_t wait[2];
  60. unsigned int flags;
  61. };
  62. /*
  63. * request command types
  64. */
  65. enum rq_cmd_type_bits {
  66. REQ_TYPE_FS = 1, /* fs request */
  67. REQ_TYPE_BLOCK_PC, /* scsi command */
  68. REQ_TYPE_DRV_PRIV, /* driver defined types from here */
  69. };
  70. /*
  71. * request flags */
  72. typedef __u32 __bitwise req_flags_t;
  73. /* elevator knows about this request */
  74. #define RQF_SORTED ((__force req_flags_t)(1 << 0))
  75. /* drive already may have started this one */
  76. #define RQF_STARTED ((__force req_flags_t)(1 << 1))
  77. /* uses tagged queueing */
  78. #define RQF_QUEUED ((__force req_flags_t)(1 << 2))
  79. /* may not be passed by ioscheduler */
  80. #define RQF_SOFTBARRIER ((__force req_flags_t)(1 << 3))
  81. /* request for flush sequence */
  82. #define RQF_FLUSH_SEQ ((__force req_flags_t)(1 << 4))
  83. /* merge of different types, fail separately */
  84. #define RQF_MIXED_MERGE ((__force req_flags_t)(1 << 5))
  85. /* track inflight for MQ */
  86. #define RQF_MQ_INFLIGHT ((__force req_flags_t)(1 << 6))
  87. /* don't call prep for this one */
  88. #define RQF_DONTPREP ((__force req_flags_t)(1 << 7))
  89. /* set for "ide_preempt" requests and also for requests for which the SCSI
  90. "quiesce" state must be ignored. */
  91. #define RQF_PREEMPT ((__force req_flags_t)(1 << 8))
  92. /* contains copies of user pages */
  93. #define RQF_COPY_USER ((__force req_flags_t)(1 << 9))
  94. /* vaguely specified driver internal error. Ignored by the block layer */
  95. #define RQF_FAILED ((__force req_flags_t)(1 << 10))
  96. /* don't warn about errors */
  97. #define RQF_QUIET ((__force req_flags_t)(1 << 11))
  98. /* elevator private data attached */
  99. #define RQF_ELVPRIV ((__force req_flags_t)(1 << 12))
  100. /* account I/O stat */
  101. #define RQF_IO_STAT ((__force req_flags_t)(1 << 13))
  102. /* request came from our alloc pool */
  103. #define RQF_ALLOCED ((__force req_flags_t)(1 << 14))
  104. /* runtime pm request */
  105. #define RQF_PM ((__force req_flags_t)(1 << 15))
  106. /* on IO scheduler merge hash */
  107. #define RQF_HASHED ((__force req_flags_t)(1 << 16))
  108. /* IO stats tracking on */
  109. #define RQF_STATS ((__force req_flags_t)(1 << 17))
  110. /* flags that prevent us from merging requests: */
  111. #define RQF_NOMERGE_FLAGS \
  112. (RQF_STARTED | RQF_SOFTBARRIER | RQF_FLUSH_SEQ)
  113. #define BLK_MAX_CDB 16
  114. /*
  115. * Try to put the fields that are referenced together in the same cacheline.
  116. *
  117. * If you modify this structure, make sure to update blk_rq_init() and
  118. * especially blk_mq_rq_ctx_init() to take care of the added fields.
  119. */
  120. struct request {
  121. struct list_head queuelist;
  122. union {
  123. struct call_single_data csd;
  124. u64 fifo_time;
  125. };
  126. struct request_queue *q;
  127. struct blk_mq_ctx *mq_ctx;
  128. int cpu;
  129. unsigned cmd_type;
  130. unsigned int cmd_flags; /* op and common flags */
  131. req_flags_t rq_flags;
  132. unsigned long atomic_flags;
  133. /* the following two fields are internal, NEVER access directly */
  134. unsigned int __data_len; /* total data len */
  135. sector_t __sector; /* sector cursor */
  136. struct bio *bio;
  137. struct bio *biotail;
  138. /*
  139. * The hash is used inside the scheduler, and killed once the
  140. * request reaches the dispatch list. The ipi_list is only used
  141. * to queue the request for softirq completion, which is long
  142. * after the request has been unhashed (and even removed from
  143. * the dispatch list).
  144. */
  145. union {
  146. struct hlist_node hash; /* merge hash */
  147. struct list_head ipi_list;
  148. };
  149. /*
  150. * The rb_node is only used inside the io scheduler, requests
  151. * are pruned when moved to the dispatch queue. So let the
  152. * completion_data share space with the rb_node.
  153. */
  154. union {
  155. struct rb_node rb_node; /* sort/lookup */
  156. void *completion_data;
  157. };
  158. /*
  159. * Three pointers are available for the IO schedulers, if they need
  160. * more they have to dynamically allocate it. Flush requests are
  161. * never put on the IO scheduler. So let the flush fields share
  162. * space with the elevator data.
  163. */
  164. union {
  165. struct {
  166. struct io_cq *icq;
  167. void *priv[2];
  168. } elv;
  169. struct {
  170. unsigned int seq;
  171. struct list_head list;
  172. rq_end_io_fn *saved_end_io;
  173. } flush;
  174. };
  175. struct gendisk *rq_disk;
  176. struct hd_struct *part;
  177. unsigned long start_time;
  178. struct blk_issue_stat issue_stat;
  179. #ifdef CONFIG_BLK_CGROUP
  180. struct request_list *rl; /* rl this rq is alloced from */
  181. unsigned long long start_time_ns;
  182. unsigned long long io_start_time_ns; /* when passed to hardware */
  183. #endif
  184. /* Number of scatter-gather DMA addr+len pairs after
  185. * physical address coalescing is performed.
  186. */
  187. unsigned short nr_phys_segments;
  188. #if defined(CONFIG_BLK_DEV_INTEGRITY)
  189. unsigned short nr_integrity_segments;
  190. #endif
  191. unsigned short ioprio;
  192. void *special; /* opaque pointer available for LLD use */
  193. int tag;
  194. int errors;
  195. /*
  196. * when request is used as a packet command carrier
  197. */
  198. unsigned char __cmd[BLK_MAX_CDB];
  199. unsigned char *cmd;
  200. unsigned short cmd_len;
  201. unsigned int extra_len; /* length of alignment and padding */
  202. unsigned int sense_len;
  203. unsigned int resid_len; /* residual count */
  204. void *sense;
  205. unsigned long deadline;
  206. struct list_head timeout_list;
  207. unsigned int timeout;
  208. int retries;
  209. /*
  210. * completion callback.
  211. */
  212. rq_end_io_fn *end_io;
  213. void *end_io_data;
  214. /* for bidi */
  215. struct request *next_rq;
  216. };
  217. static inline unsigned short req_get_ioprio(struct request *req)
  218. {
  219. return req->ioprio;
  220. }
  221. #include <linux/elevator.h>
  222. struct blk_queue_ctx;
  223. typedef void (request_fn_proc) (struct request_queue *q);
  224. typedef blk_qc_t (make_request_fn) (struct request_queue *q, struct bio *bio);
  225. typedef int (prep_rq_fn) (struct request_queue *, struct request *);
  226. typedef void (unprep_rq_fn) (struct request_queue *, struct request *);
  227. struct bio_vec;
  228. typedef void (softirq_done_fn)(struct request *);
  229. typedef int (dma_drain_needed_fn)(struct request *);
  230. typedef int (lld_busy_fn) (struct request_queue *q);
  231. typedef int (bsg_job_fn) (struct bsg_job *);
  232. enum blk_eh_timer_return {
  233. BLK_EH_NOT_HANDLED,
  234. BLK_EH_HANDLED,
  235. BLK_EH_RESET_TIMER,
  236. };
  237. typedef enum blk_eh_timer_return (rq_timed_out_fn)(struct request *);
  238. enum blk_queue_state {
  239. Queue_down,
  240. Queue_up,
  241. };
  242. struct blk_queue_tag {
  243. struct request **tag_index; /* map of busy tags */
  244. unsigned long *tag_map; /* bit map of free/busy tags */
  245. int busy; /* current depth */
  246. int max_depth; /* what we will send to device */
  247. int real_max_depth; /* what the array can hold */
  248. atomic_t refcnt; /* map can be shared */
  249. int alloc_policy; /* tag allocation policy */
  250. int next_tag; /* next tag */
  251. };
  252. #define BLK_TAG_ALLOC_FIFO 0 /* allocate starting from 0 */
  253. #define BLK_TAG_ALLOC_RR 1 /* allocate starting from last allocated tag */
  254. #define BLK_SCSI_MAX_CMDS (256)
  255. #define BLK_SCSI_CMD_PER_LONG (BLK_SCSI_MAX_CMDS / (sizeof(long) * 8))
  256. /*
  257. * Zoned block device models (zoned limit).
  258. */
  259. enum blk_zoned_model {
  260. BLK_ZONED_NONE, /* Regular block device */
  261. BLK_ZONED_HA, /* Host-aware zoned block device */
  262. BLK_ZONED_HM, /* Host-managed zoned block device */
  263. };
  264. struct queue_limits {
  265. unsigned long bounce_pfn;
  266. unsigned long seg_boundary_mask;
  267. unsigned long virt_boundary_mask;
  268. unsigned int max_hw_sectors;
  269. unsigned int max_dev_sectors;
  270. unsigned int chunk_sectors;
  271. unsigned int max_sectors;
  272. unsigned int max_segment_size;
  273. unsigned int physical_block_size;
  274. unsigned int alignment_offset;
  275. unsigned int io_min;
  276. unsigned int io_opt;
  277. unsigned int max_discard_sectors;
  278. unsigned int max_hw_discard_sectors;
  279. unsigned int max_write_same_sectors;
  280. unsigned int discard_granularity;
  281. unsigned int discard_alignment;
  282. unsigned short logical_block_size;
  283. unsigned short max_segments;
  284. unsigned short max_integrity_segments;
  285. unsigned char misaligned;
  286. unsigned char discard_misaligned;
  287. unsigned char cluster;
  288. unsigned char discard_zeroes_data;
  289. unsigned char raid_partial_stripes_expensive;
  290. enum blk_zoned_model zoned;
  291. };
  292. #ifdef CONFIG_BLK_DEV_ZONED
  293. struct blk_zone_report_hdr {
  294. unsigned int nr_zones;
  295. u8 padding[60];
  296. };
  297. extern int blkdev_report_zones(struct block_device *bdev,
  298. sector_t sector, struct blk_zone *zones,
  299. unsigned int *nr_zones, gfp_t gfp_mask);
  300. extern int blkdev_reset_zones(struct block_device *bdev, sector_t sectors,
  301. sector_t nr_sectors, gfp_t gfp_mask);
  302. extern int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode,
  303. unsigned int cmd, unsigned long arg);
  304. extern int blkdev_reset_zones_ioctl(struct block_device *bdev, fmode_t mode,
  305. unsigned int cmd, unsigned long arg);
  306. #else /* CONFIG_BLK_DEV_ZONED */
  307. static inline int blkdev_report_zones_ioctl(struct block_device *bdev,
  308. fmode_t mode, unsigned int cmd,
  309. unsigned long arg)
  310. {
  311. return -ENOTTY;
  312. }
  313. static inline int blkdev_reset_zones_ioctl(struct block_device *bdev,
  314. fmode_t mode, unsigned int cmd,
  315. unsigned long arg)
  316. {
  317. return -ENOTTY;
  318. }
  319. #endif /* CONFIG_BLK_DEV_ZONED */
  320. struct request_queue {
  321. /*
  322. * Together with queue_head for cacheline sharing
  323. */
  324. struct list_head queue_head;
  325. struct request *last_merge;
  326. struct elevator_queue *elevator;
  327. int nr_rqs[2]; /* # allocated [a]sync rqs */
  328. int nr_rqs_elvpriv; /* # allocated rqs w/ elvpriv */
  329. struct rq_wb *rq_wb;
  330. /*
  331. * If blkcg is not used, @q->root_rl serves all requests. If blkcg
  332. * is used, root blkg allocates from @q->root_rl and all other
  333. * blkgs from their own blkg->rl. Which one to use should be
  334. * determined using bio_request_list().
  335. */
  336. struct request_list root_rl;
  337. request_fn_proc *request_fn;
  338. make_request_fn *make_request_fn;
  339. prep_rq_fn *prep_rq_fn;
  340. unprep_rq_fn *unprep_rq_fn;
  341. softirq_done_fn *softirq_done_fn;
  342. rq_timed_out_fn *rq_timed_out_fn;
  343. dma_drain_needed_fn *dma_drain_needed;
  344. lld_busy_fn *lld_busy_fn;
  345. struct blk_mq_ops *mq_ops;
  346. unsigned int *mq_map;
  347. /* sw queues */
  348. struct blk_mq_ctx __percpu *queue_ctx;
  349. unsigned int nr_queues;
  350. unsigned int queue_depth;
  351. /* hw dispatch queues */
  352. struct blk_mq_hw_ctx **queue_hw_ctx;
  353. unsigned int nr_hw_queues;
  354. /*
  355. * Dispatch queue sorting
  356. */
  357. sector_t end_sector;
  358. struct request *boundary_rq;
  359. /*
  360. * Delayed queue handling
  361. */
  362. struct delayed_work delay_work;
  363. struct backing_dev_info backing_dev_info;
  364. /*
  365. * The queue owner gets to use this for whatever they like.
  366. * ll_rw_blk doesn't touch it.
  367. */
  368. void *queuedata;
  369. /*
  370. * various queue flags, see QUEUE_* below
  371. */
  372. unsigned long queue_flags;
  373. /*
  374. * ida allocated id for this queue. Used to index queues from
  375. * ioctx.
  376. */
  377. int id;
  378. /*
  379. * queue needs bounce pages for pages above this limit
  380. */
  381. gfp_t bounce_gfp;
  382. /*
  383. * protects queue structures from reentrancy. ->__queue_lock should
  384. * _never_ be used directly, it is queue private. always use
  385. * ->queue_lock.
  386. */
  387. spinlock_t __queue_lock;
  388. spinlock_t *queue_lock;
  389. /*
  390. * queue kobject
  391. */
  392. struct kobject kobj;
  393. /*
  394. * mq queue kobject
  395. */
  396. struct kobject mq_kobj;
  397. #ifdef CONFIG_BLK_DEV_INTEGRITY
  398. struct blk_integrity integrity;
  399. #endif /* CONFIG_BLK_DEV_INTEGRITY */
  400. #ifdef CONFIG_PM
  401. struct device *dev;
  402. int rpm_status;
  403. unsigned int nr_pending;
  404. #endif
  405. /*
  406. * queue settings
  407. */
  408. unsigned long nr_requests; /* Max # of requests */
  409. unsigned int nr_congestion_on;
  410. unsigned int nr_congestion_off;
  411. unsigned int nr_batching;
  412. unsigned int dma_drain_size;
  413. void *dma_drain_buffer;
  414. unsigned int dma_pad_mask;
  415. unsigned int dma_alignment;
  416. struct blk_queue_tag *queue_tags;
  417. struct list_head tag_busy_list;
  418. unsigned int nr_sorted;
  419. unsigned int in_flight[2];
  420. struct blk_rq_stat rq_stats[2];
  421. /*
  422. * Number of active block driver functions for which blk_drain_queue()
  423. * must wait. Must be incremented around functions that unlock the
  424. * queue_lock internally, e.g. scsi_request_fn().
  425. */
  426. unsigned int request_fn_active;
  427. unsigned int rq_timeout;
  428. struct timer_list timeout;
  429. struct work_struct timeout_work;
  430. struct list_head timeout_list;
  431. struct list_head icq_list;
  432. #ifdef CONFIG_BLK_CGROUP
  433. DECLARE_BITMAP (blkcg_pols, BLKCG_MAX_POLS);
  434. struct blkcg_gq *root_blkg;
  435. struct list_head blkg_list;
  436. #endif
  437. struct queue_limits limits;
  438. /*
  439. * sg stuff
  440. */
  441. unsigned int sg_timeout;
  442. unsigned int sg_reserved_size;
  443. int node;
  444. #ifdef CONFIG_BLK_DEV_IO_TRACE
  445. struct blk_trace *blk_trace;
  446. #endif
  447. /*
  448. * for flush operations
  449. */
  450. struct blk_flush_queue *fq;
  451. struct list_head requeue_list;
  452. spinlock_t requeue_lock;
  453. struct delayed_work requeue_work;
  454. struct mutex sysfs_lock;
  455. int bypass_depth;
  456. atomic_t mq_freeze_depth;
  457. #if defined(CONFIG_BLK_DEV_BSG)
  458. bsg_job_fn *bsg_job_fn;
  459. int bsg_job_size;
  460. struct bsg_class_device bsg_dev;
  461. #endif
  462. #ifdef CONFIG_BLK_DEV_THROTTLING
  463. /* Throttle data */
  464. struct throtl_data *td;
  465. #endif
  466. struct rcu_head rcu_head;
  467. wait_queue_head_t mq_freeze_wq;
  468. struct percpu_ref q_usage_counter;
  469. struct list_head all_q_node;
  470. struct blk_mq_tag_set *tag_set;
  471. struct list_head tag_set_list;
  472. struct bio_set *bio_split;
  473. bool mq_sysfs_init_done;
  474. };
  475. #define QUEUE_FLAG_QUEUED 1 /* uses generic tag queueing */
  476. #define QUEUE_FLAG_STOPPED 2 /* queue is stopped */
  477. #define QUEUE_FLAG_SYNCFULL 3 /* read queue has been filled */
  478. #define QUEUE_FLAG_ASYNCFULL 4 /* write queue has been filled */
  479. #define QUEUE_FLAG_DYING 5 /* queue being torn down */
  480. #define QUEUE_FLAG_BYPASS 6 /* act as dumb FIFO queue */
  481. #define QUEUE_FLAG_BIDI 7 /* queue supports bidi requests */
  482. #define QUEUE_FLAG_NOMERGES 8 /* disable merge attempts */
  483. #define QUEUE_FLAG_SAME_COMP 9 /* complete on same CPU-group */
  484. #define QUEUE_FLAG_FAIL_IO 10 /* fake timeout */
  485. #define QUEUE_FLAG_STACKABLE 11 /* supports request stacking */
  486. #define QUEUE_FLAG_NONROT 12 /* non-rotational device (SSD) */
  487. #define QUEUE_FLAG_VIRT QUEUE_FLAG_NONROT /* paravirt device */
  488. #define QUEUE_FLAG_IO_STAT 13 /* do IO stats */
  489. #define QUEUE_FLAG_DISCARD 14 /* supports DISCARD */
  490. #define QUEUE_FLAG_NOXMERGES 15 /* No extended merges */
  491. #define QUEUE_FLAG_ADD_RANDOM 16 /* Contributes to random pool */
  492. #define QUEUE_FLAG_SECERASE 17 /* supports secure erase */
  493. #define QUEUE_FLAG_SAME_FORCE 18 /* force complete on same CPU */
  494. #define QUEUE_FLAG_DEAD 19 /* queue tear-down finished */
  495. #define QUEUE_FLAG_INIT_DONE 20 /* queue is initialized */
  496. #define QUEUE_FLAG_NO_SG_MERGE 21 /* don't attempt to merge SG segments*/
  497. #define QUEUE_FLAG_POLL 22 /* IO polling enabled if set */
  498. #define QUEUE_FLAG_WC 23 /* Write back caching */
  499. #define QUEUE_FLAG_FUA 24 /* device supports FUA writes */
  500. #define QUEUE_FLAG_FLUSH_NQ 25 /* flush not queueuable */
  501. #define QUEUE_FLAG_DAX 26 /* device supports DAX */
  502. #define QUEUE_FLAG_STATS 27 /* track rq completion times */
  503. #define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \
  504. (1 << QUEUE_FLAG_STACKABLE) | \
  505. (1 << QUEUE_FLAG_SAME_COMP) | \
  506. (1 << QUEUE_FLAG_ADD_RANDOM))
  507. #define QUEUE_FLAG_MQ_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \
  508. (1 << QUEUE_FLAG_STACKABLE) | \
  509. (1 << QUEUE_FLAG_SAME_COMP) | \
  510. (1 << QUEUE_FLAG_POLL))
  511. static inline void queue_lockdep_assert_held(struct request_queue *q)
  512. {
  513. if (q->queue_lock)
  514. lockdep_assert_held(q->queue_lock);
  515. }
  516. static inline void queue_flag_set_unlocked(unsigned int flag,
  517. struct request_queue *q)
  518. {
  519. __set_bit(flag, &q->queue_flags);
  520. }
  521. static inline int queue_flag_test_and_clear(unsigned int flag,
  522. struct request_queue *q)
  523. {
  524. queue_lockdep_assert_held(q);
  525. if (test_bit(flag, &q->queue_flags)) {
  526. __clear_bit(flag, &q->queue_flags);
  527. return 1;
  528. }
  529. return 0;
  530. }
  531. static inline int queue_flag_test_and_set(unsigned int flag,
  532. struct request_queue *q)
  533. {
  534. queue_lockdep_assert_held(q);
  535. if (!test_bit(flag, &q->queue_flags)) {
  536. __set_bit(flag, &q->queue_flags);
  537. return 0;
  538. }
  539. return 1;
  540. }
  541. static inline void queue_flag_set(unsigned int flag, struct request_queue *q)
  542. {
  543. queue_lockdep_assert_held(q);
  544. __set_bit(flag, &q->queue_flags);
  545. }
  546. static inline void queue_flag_clear_unlocked(unsigned int flag,
  547. struct request_queue *q)
  548. {
  549. __clear_bit(flag, &q->queue_flags);
  550. }
  551. static inline int queue_in_flight(struct request_queue *q)
  552. {
  553. return q->in_flight[0] + q->in_flight[1];
  554. }
  555. static inline void queue_flag_clear(unsigned int flag, struct request_queue *q)
  556. {
  557. queue_lockdep_assert_held(q);
  558. __clear_bit(flag, &q->queue_flags);
  559. }
  560. #define blk_queue_tagged(q) test_bit(QUEUE_FLAG_QUEUED, &(q)->queue_flags)
  561. #define blk_queue_stopped(q) test_bit(QUEUE_FLAG_STOPPED, &(q)->queue_flags)
  562. #define blk_queue_dying(q) test_bit(QUEUE_FLAG_DYING, &(q)->queue_flags)
  563. #define blk_queue_dead(q) test_bit(QUEUE_FLAG_DEAD, &(q)->queue_flags)
  564. #define blk_queue_bypass(q) test_bit(QUEUE_FLAG_BYPASS, &(q)->queue_flags)
  565. #define blk_queue_init_done(q) test_bit(QUEUE_FLAG_INIT_DONE, &(q)->queue_flags)
  566. #define blk_queue_nomerges(q) test_bit(QUEUE_FLAG_NOMERGES, &(q)->queue_flags)
  567. #define blk_queue_noxmerges(q) \
  568. test_bit(QUEUE_FLAG_NOXMERGES, &(q)->queue_flags)
  569. #define blk_queue_nonrot(q) test_bit(QUEUE_FLAG_NONROT, &(q)->queue_flags)
  570. #define blk_queue_io_stat(q) test_bit(QUEUE_FLAG_IO_STAT, &(q)->queue_flags)
  571. #define blk_queue_add_random(q) test_bit(QUEUE_FLAG_ADD_RANDOM, &(q)->queue_flags)
  572. #define blk_queue_stackable(q) \
  573. test_bit(QUEUE_FLAG_STACKABLE, &(q)->queue_flags)
  574. #define blk_queue_discard(q) test_bit(QUEUE_FLAG_DISCARD, &(q)->queue_flags)
  575. #define blk_queue_secure_erase(q) \
  576. (test_bit(QUEUE_FLAG_SECERASE, &(q)->queue_flags))
  577. #define blk_queue_dax(q) test_bit(QUEUE_FLAG_DAX, &(q)->queue_flags)
  578. #define blk_noretry_request(rq) \
  579. ((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \
  580. REQ_FAILFAST_DRIVER))
  581. #define blk_account_rq(rq) \
  582. (((rq)->rq_flags & RQF_STARTED) && \
  583. ((rq)->cmd_type == REQ_TYPE_FS))
  584. #define blk_rq_cpu_valid(rq) ((rq)->cpu != -1)
  585. #define blk_bidi_rq(rq) ((rq)->next_rq != NULL)
  586. /* rq->queuelist of dequeued request must be list_empty() */
  587. #define blk_queued_rq(rq) (!list_empty(&(rq)->queuelist))
  588. #define list_entry_rq(ptr) list_entry((ptr), struct request, queuelist)
  589. #define rq_data_dir(rq) (op_is_write(req_op(rq)) ? WRITE : READ)
  590. /*
  591. * Driver can handle struct request, if it either has an old style
  592. * request_fn defined, or is blk-mq based.
  593. */
  594. static inline bool queue_is_rq_based(struct request_queue *q)
  595. {
  596. return q->request_fn || q->mq_ops;
  597. }
  598. static inline unsigned int blk_queue_cluster(struct request_queue *q)
  599. {
  600. return q->limits.cluster;
  601. }
  602. static inline enum blk_zoned_model
  603. blk_queue_zoned_model(struct request_queue *q)
  604. {
  605. return q->limits.zoned;
  606. }
  607. static inline bool blk_queue_is_zoned(struct request_queue *q)
  608. {
  609. switch (blk_queue_zoned_model(q)) {
  610. case BLK_ZONED_HA:
  611. case BLK_ZONED_HM:
  612. return true;
  613. default:
  614. return false;
  615. }
  616. }
  617. static inline unsigned int blk_queue_zone_size(struct request_queue *q)
  618. {
  619. return blk_queue_is_zoned(q) ? q->limits.chunk_sectors : 0;
  620. }
  621. static inline bool rq_is_sync(struct request *rq)
  622. {
  623. return op_is_sync(rq->cmd_flags);
  624. }
  625. static inline bool blk_rl_full(struct request_list *rl, bool sync)
  626. {
  627. unsigned int flag = sync ? BLK_RL_SYNCFULL : BLK_RL_ASYNCFULL;
  628. return rl->flags & flag;
  629. }
  630. static inline void blk_set_rl_full(struct request_list *rl, bool sync)
  631. {
  632. unsigned int flag = sync ? BLK_RL_SYNCFULL : BLK_RL_ASYNCFULL;
  633. rl->flags |= flag;
  634. }
  635. static inline void blk_clear_rl_full(struct request_list *rl, bool sync)
  636. {
  637. unsigned int flag = sync ? BLK_RL_SYNCFULL : BLK_RL_ASYNCFULL;
  638. rl->flags &= ~flag;
  639. }
  640. static inline bool rq_mergeable(struct request *rq)
  641. {
  642. if (rq->cmd_type != REQ_TYPE_FS)
  643. return false;
  644. if (req_op(rq) == REQ_OP_FLUSH)
  645. return false;
  646. if (rq->cmd_flags & REQ_NOMERGE_FLAGS)
  647. return false;
  648. if (rq->rq_flags & RQF_NOMERGE_FLAGS)
  649. return false;
  650. return true;
  651. }
  652. static inline bool blk_write_same_mergeable(struct bio *a, struct bio *b)
  653. {
  654. if (bio_data(a) == bio_data(b))
  655. return true;
  656. return false;
  657. }
  658. static inline unsigned int blk_queue_depth(struct request_queue *q)
  659. {
  660. if (q->queue_depth)
  661. return q->queue_depth;
  662. return q->nr_requests;
  663. }
  664. /*
  665. * q->prep_rq_fn return values
  666. */
  667. enum {
  668. BLKPREP_OK, /* serve it */
  669. BLKPREP_KILL, /* fatal error, kill, return -EIO */
  670. BLKPREP_DEFER, /* leave on queue */
  671. BLKPREP_INVALID, /* invalid command, kill, return -EREMOTEIO */
  672. };
  673. extern unsigned long blk_max_low_pfn, blk_max_pfn;
  674. /*
  675. * standard bounce addresses:
  676. *
  677. * BLK_BOUNCE_HIGH : bounce all highmem pages
  678. * BLK_BOUNCE_ANY : don't bounce anything
  679. * BLK_BOUNCE_ISA : bounce pages above ISA DMA boundary
  680. */
  681. #if BITS_PER_LONG == 32
  682. #define BLK_BOUNCE_HIGH ((u64)blk_max_low_pfn << PAGE_SHIFT)
  683. #else
  684. #define BLK_BOUNCE_HIGH -1ULL
  685. #endif
  686. #define BLK_BOUNCE_ANY (-1ULL)
  687. #define BLK_BOUNCE_ISA (DMA_BIT_MASK(24))
  688. /*
  689. * default timeout for SG_IO if none specified
  690. */
  691. #define BLK_DEFAULT_SG_TIMEOUT (60 * HZ)
  692. #define BLK_MIN_SG_TIMEOUT (7 * HZ)
  693. #ifdef CONFIG_BOUNCE
  694. extern int init_emergency_isa_pool(void);
  695. extern void blk_queue_bounce(struct request_queue *q, struct bio **bio);
  696. #else
  697. static inline int init_emergency_isa_pool(void)
  698. {
  699. return 0;
  700. }
  701. static inline void blk_queue_bounce(struct request_queue *q, struct bio **bio)
  702. {
  703. }
  704. #endif /* CONFIG_MMU */
  705. struct rq_map_data {
  706. struct page **pages;
  707. int page_order;
  708. int nr_entries;
  709. unsigned long offset;
  710. int null_mapped;
  711. int from_user;
  712. };
  713. struct req_iterator {
  714. struct bvec_iter iter;
  715. struct bio *bio;
  716. };
  717. /* This should not be used directly - use rq_for_each_segment */
  718. #define for_each_bio(_bio) \
  719. for (; _bio; _bio = _bio->bi_next)
  720. #define __rq_for_each_bio(_bio, rq) \
  721. if ((rq->bio)) \
  722. for (_bio = (rq)->bio; _bio; _bio = _bio->bi_next)
  723. #define rq_for_each_segment(bvl, _rq, _iter) \
  724. __rq_for_each_bio(_iter.bio, _rq) \
  725. bio_for_each_segment(bvl, _iter.bio, _iter.iter)
  726. #define rq_iter_last(bvec, _iter) \
  727. (_iter.bio->bi_next == NULL && \
  728. bio_iter_last(bvec, _iter.iter))
  729. #ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
  730. # error "You should define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE for your platform"
  731. #endif
  732. #if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
  733. extern void rq_flush_dcache_pages(struct request *rq);
  734. #else
  735. static inline void rq_flush_dcache_pages(struct request *rq)
  736. {
  737. }
  738. #endif
  739. #ifdef CONFIG_PRINTK
  740. #define vfs_msg(sb, level, fmt, ...) \
  741. __vfs_msg(sb, level, fmt, ##__VA_ARGS__)
  742. #else
  743. #define vfs_msg(sb, level, fmt, ...) \
  744. do { \
  745. no_printk(fmt, ##__VA_ARGS__); \
  746. __vfs_msg(sb, "", " "); \
  747. } while (0)
  748. #endif
  749. extern int blk_register_queue(struct gendisk *disk);
  750. extern void blk_unregister_queue(struct gendisk *disk);
  751. extern blk_qc_t generic_make_request(struct bio *bio);
  752. extern void blk_rq_init(struct request_queue *q, struct request *rq);
  753. extern void blk_put_request(struct request *);
  754. extern void __blk_put_request(struct request_queue *, struct request *);
  755. extern struct request *blk_get_request(struct request_queue *, int, gfp_t);
  756. extern void blk_rq_set_block_pc(struct request *);
  757. extern void blk_requeue_request(struct request_queue *, struct request *);
  758. extern void blk_add_request_payload(struct request *rq, struct page *page,
  759. int offset, unsigned int len);
  760. extern int blk_lld_busy(struct request_queue *q);
  761. extern int blk_rq_prep_clone(struct request *rq, struct request *rq_src,
  762. struct bio_set *bs, gfp_t gfp_mask,
  763. int (*bio_ctr)(struct bio *, struct bio *, void *),
  764. void *data);
  765. extern void blk_rq_unprep_clone(struct request *rq);
  766. extern int blk_insert_cloned_request(struct request_queue *q,
  767. struct request *rq);
  768. extern int blk_rq_append_bio(struct request *rq, struct bio *bio);
  769. extern void blk_delay_queue(struct request_queue *, unsigned long);
  770. extern void blk_queue_split(struct request_queue *, struct bio **,
  771. struct bio_set *);
  772. extern void blk_recount_segments(struct request_queue *, struct bio *);
  773. extern int scsi_verify_blk_ioctl(struct block_device *, unsigned int);
  774. extern int scsi_cmd_blk_ioctl(struct block_device *, fmode_t,
  775. unsigned int, void __user *);
  776. extern int scsi_cmd_ioctl(struct request_queue *, struct gendisk *, fmode_t,
  777. unsigned int, void __user *);
  778. extern int sg_scsi_ioctl(struct request_queue *, struct gendisk *, fmode_t,
  779. struct scsi_ioctl_command __user *);
  780. extern int blk_queue_enter(struct request_queue *q, bool nowait);
  781. extern void blk_queue_exit(struct request_queue *q);
  782. extern void blk_start_queue(struct request_queue *q);
  783. extern void blk_start_queue_async(struct request_queue *q);
  784. extern void blk_stop_queue(struct request_queue *q);
  785. extern void blk_sync_queue(struct request_queue *q);
  786. extern void __blk_stop_queue(struct request_queue *q);
  787. extern void __blk_run_queue(struct request_queue *q);
  788. extern void __blk_run_queue_uncond(struct request_queue *q);
  789. extern void blk_run_queue(struct request_queue *);
  790. extern void blk_run_queue_async(struct request_queue *q);
  791. extern void blk_mq_quiesce_queue(struct request_queue *q);
  792. extern int blk_rq_map_user(struct request_queue *, struct request *,
  793. struct rq_map_data *, void __user *, unsigned long,
  794. gfp_t);
  795. extern int blk_rq_unmap_user(struct bio *);
  796. extern int blk_rq_map_kern(struct request_queue *, struct request *, void *, unsigned int, gfp_t);
  797. extern int blk_rq_map_user_iov(struct request_queue *, struct request *,
  798. struct rq_map_data *, const struct iov_iter *,
  799. gfp_t);
  800. extern int blk_execute_rq(struct request_queue *, struct gendisk *,
  801. struct request *, int);
  802. extern void blk_execute_rq_nowait(struct request_queue *, struct gendisk *,
  803. struct request *, int, rq_end_io_fn *);
  804. bool blk_mq_poll(struct request_queue *q, blk_qc_t cookie);
  805. static inline struct request_queue *bdev_get_queue(struct block_device *bdev)
  806. {
  807. return bdev->bd_disk->queue; /* this is never NULL */
  808. }
  809. /*
  810. * blk_rq_pos() : the current sector
  811. * blk_rq_bytes() : bytes left in the entire request
  812. * blk_rq_cur_bytes() : bytes left in the current segment
  813. * blk_rq_err_bytes() : bytes left till the next error boundary
  814. * blk_rq_sectors() : sectors left in the entire request
  815. * blk_rq_cur_sectors() : sectors left in the current segment
  816. */
  817. static inline sector_t blk_rq_pos(const struct request *rq)
  818. {
  819. return rq->__sector;
  820. }
  821. static inline unsigned int blk_rq_bytes(const struct request *rq)
  822. {
  823. return rq->__data_len;
  824. }
  825. static inline int blk_rq_cur_bytes(const struct request *rq)
  826. {
  827. return rq->bio ? bio_cur_bytes(rq->bio) : 0;
  828. }
  829. extern unsigned int blk_rq_err_bytes(const struct request *rq);
  830. static inline unsigned int blk_rq_sectors(const struct request *rq)
  831. {
  832. return blk_rq_bytes(rq) >> 9;
  833. }
  834. static inline unsigned int blk_rq_cur_sectors(const struct request *rq)
  835. {
  836. return blk_rq_cur_bytes(rq) >> 9;
  837. }
  838. static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,
  839. int op)
  840. {
  841. if (unlikely(op == REQ_OP_DISCARD || op == REQ_OP_SECURE_ERASE))
  842. return min(q->limits.max_discard_sectors, UINT_MAX >> 9);
  843. if (unlikely(op == REQ_OP_WRITE_SAME))
  844. return q->limits.max_write_same_sectors;
  845. return q->limits.max_sectors;
  846. }
  847. /*
  848. * Return maximum size of a request at given offset. Only valid for
  849. * file system requests.
  850. */
  851. static inline unsigned int blk_max_size_offset(struct request_queue *q,
  852. sector_t offset)
  853. {
  854. if (!q->limits.chunk_sectors)
  855. return q->limits.max_sectors;
  856. return q->limits.chunk_sectors -
  857. (offset & (q->limits.chunk_sectors - 1));
  858. }
  859. static inline unsigned int blk_rq_get_max_sectors(struct request *rq,
  860. sector_t offset)
  861. {
  862. struct request_queue *q = rq->q;
  863. if (unlikely(rq->cmd_type != REQ_TYPE_FS))
  864. return q->limits.max_hw_sectors;
  865. if (!q->limits.chunk_sectors ||
  866. req_op(rq) == REQ_OP_DISCARD ||
  867. req_op(rq) == REQ_OP_SECURE_ERASE)
  868. return blk_queue_get_max_sectors(q, req_op(rq));
  869. return min(blk_max_size_offset(q, offset),
  870. blk_queue_get_max_sectors(q, req_op(rq)));
  871. }
  872. static inline unsigned int blk_rq_count_bios(struct request *rq)
  873. {
  874. unsigned int nr_bios = 0;
  875. struct bio *bio;
  876. __rq_for_each_bio(bio, rq)
  877. nr_bios++;
  878. return nr_bios;
  879. }
  880. /*
  881. * Request issue related functions.
  882. */
  883. extern struct request *blk_peek_request(struct request_queue *q);
  884. extern void blk_start_request(struct request *rq);
  885. extern struct request *blk_fetch_request(struct request_queue *q);
  886. /*
  887. * Request completion related functions.
  888. *
  889. * blk_update_request() completes given number of bytes and updates
  890. * the request without completing it.
  891. *
  892. * blk_end_request() and friends. __blk_end_request() must be called
  893. * with the request queue spinlock acquired.
  894. *
  895. * Several drivers define their own end_request and call
  896. * blk_end_request() for parts of the original function.
  897. * This prevents code duplication in drivers.
  898. */
  899. extern bool blk_update_request(struct request *rq, int error,
  900. unsigned int nr_bytes);
  901. extern void blk_finish_request(struct request *rq, int error);
  902. extern bool blk_end_request(struct request *rq, int error,
  903. unsigned int nr_bytes);
  904. extern void blk_end_request_all(struct request *rq, int error);
  905. extern bool blk_end_request_cur(struct request *rq, int error);
  906. extern bool blk_end_request_err(struct request *rq, int error);
  907. extern bool __blk_end_request(struct request *rq, int error,
  908. unsigned int nr_bytes);
  909. extern void __blk_end_request_all(struct request *rq, int error);
  910. extern bool __blk_end_request_cur(struct request *rq, int error);
  911. extern bool __blk_end_request_err(struct request *rq, int error);
  912. extern void blk_complete_request(struct request *);
  913. extern void __blk_complete_request(struct request *);
  914. extern void blk_abort_request(struct request *);
  915. extern void blk_unprep_request(struct request *);
  916. /*
  917. * Access functions for manipulating queue properties
  918. */
  919. extern struct request_queue *blk_init_queue_node(request_fn_proc *rfn,
  920. spinlock_t *lock, int node_id);
  921. extern struct request_queue *blk_init_queue(request_fn_proc *, spinlock_t *);
  922. extern struct request_queue *blk_init_allocated_queue(struct request_queue *,
  923. request_fn_proc *, spinlock_t *);
  924. extern void blk_cleanup_queue(struct request_queue *);
  925. extern void blk_queue_make_request(struct request_queue *, make_request_fn *);
  926. extern void blk_queue_bounce_limit(struct request_queue *, u64);
  927. extern void blk_queue_max_hw_sectors(struct request_queue *, unsigned int);
  928. extern void blk_queue_chunk_sectors(struct request_queue *, unsigned int);
  929. extern void blk_queue_max_segments(struct request_queue *, unsigned short);
  930. extern void blk_queue_max_segment_size(struct request_queue *, unsigned int);
  931. extern void blk_queue_max_discard_sectors(struct request_queue *q,
  932. unsigned int max_discard_sectors);
  933. extern void blk_queue_max_write_same_sectors(struct request_queue *q,
  934. unsigned int max_write_same_sectors);
  935. extern void blk_queue_logical_block_size(struct request_queue *, unsigned short);
  936. extern void blk_queue_physical_block_size(struct request_queue *, unsigned int);
  937. extern void blk_queue_alignment_offset(struct request_queue *q,
  938. unsigned int alignment);
  939. extern void blk_limits_io_min(struct queue_limits *limits, unsigned int min);
  940. extern void blk_queue_io_min(struct request_queue *q, unsigned int min);
  941. extern void blk_limits_io_opt(struct queue_limits *limits, unsigned int opt);
  942. extern void blk_queue_io_opt(struct request_queue *q, unsigned int opt);
  943. extern void blk_set_queue_depth(struct request_queue *q, unsigned int depth);
  944. extern void blk_set_default_limits(struct queue_limits *lim);
  945. extern void blk_set_stacking_limits(struct queue_limits *lim);
  946. extern int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
  947. sector_t offset);
  948. extern int bdev_stack_limits(struct queue_limits *t, struct block_device *bdev,
  949. sector_t offset);
  950. extern void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
  951. sector_t offset);
  952. extern void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b);
  953. extern void blk_queue_dma_pad(struct request_queue *, unsigned int);
  954. extern void blk_queue_update_dma_pad(struct request_queue *, unsigned int);
  955. extern int blk_queue_dma_drain(struct request_queue *q,
  956. dma_drain_needed_fn *dma_drain_needed,
  957. void *buf, unsigned int size);
  958. extern void blk_queue_lld_busy(struct request_queue *q, lld_busy_fn *fn);
  959. extern void blk_queue_segment_boundary(struct request_queue *, unsigned long);
  960. extern void blk_queue_virt_boundary(struct request_queue *, unsigned long);
  961. extern void blk_queue_prep_rq(struct request_queue *, prep_rq_fn *pfn);
  962. extern void blk_queue_unprep_rq(struct request_queue *, unprep_rq_fn *ufn);
  963. extern void blk_queue_dma_alignment(struct request_queue *, int);
  964. extern void blk_queue_update_dma_alignment(struct request_queue *, int);
  965. extern void blk_queue_softirq_done(struct request_queue *, softirq_done_fn *);
  966. extern void blk_queue_rq_timed_out(struct request_queue *, rq_timed_out_fn *);
  967. extern void blk_queue_rq_timeout(struct request_queue *, unsigned int);
  968. extern void blk_queue_flush_queueable(struct request_queue *q, bool queueable);
  969. extern void blk_queue_write_cache(struct request_queue *q, bool enabled, bool fua);
  970. extern struct backing_dev_info *blk_get_backing_dev_info(struct block_device *bdev);
  971. extern int blk_rq_map_sg(struct request_queue *, struct request *, struct scatterlist *);
  972. extern void blk_dump_rq_flags(struct request *, char *);
  973. extern long nr_blockdev_pages(void);
  974. bool __must_check blk_get_queue(struct request_queue *);
  975. struct request_queue *blk_alloc_queue(gfp_t);
  976. struct request_queue *blk_alloc_queue_node(gfp_t, int);
  977. extern void blk_put_queue(struct request_queue *);
  978. extern void blk_set_queue_dying(struct request_queue *);
  979. /*
  980. * block layer runtime pm functions
  981. */
  982. #ifdef CONFIG_PM
  983. extern void blk_pm_runtime_init(struct request_queue *q, struct device *dev);
  984. extern int blk_pre_runtime_suspend(struct request_queue *q);
  985. extern void blk_post_runtime_suspend(struct request_queue *q, int err);
  986. extern void blk_pre_runtime_resume(struct request_queue *q);
  987. extern void blk_post_runtime_resume(struct request_queue *q, int err);
  988. extern void blk_set_runtime_active(struct request_queue *q);
  989. #else
  990. static inline void blk_pm_runtime_init(struct request_queue *q,
  991. struct device *dev) {}
  992. static inline int blk_pre_runtime_suspend(struct request_queue *q)
  993. {
  994. return -ENOSYS;
  995. }
  996. static inline void blk_post_runtime_suspend(struct request_queue *q, int err) {}
  997. static inline void blk_pre_runtime_resume(struct request_queue *q) {}
  998. static inline void blk_post_runtime_resume(struct request_queue *q, int err) {}
  999. extern inline void blk_set_runtime_active(struct request_queue *q) {}
  1000. #endif
  1001. /*
  1002. * blk_plug permits building a queue of related requests by holding the I/O
  1003. * fragments for a short period. This allows merging of sequential requests
  1004. * into single larger request. As the requests are moved from a per-task list to
  1005. * the device's request_queue in a batch, this results in improved scalability
  1006. * as the lock contention for request_queue lock is reduced.
  1007. *
  1008. * It is ok not to disable preemption when adding the request to the plug list
  1009. * or when attempting a merge, because blk_schedule_flush_list() will only flush
  1010. * the plug list when the task sleeps by itself. For details, please see
  1011. * schedule() where blk_schedule_flush_plug() is called.
  1012. */
  1013. struct blk_plug {
  1014. struct list_head list; /* requests */
  1015. struct list_head mq_list; /* blk-mq requests */
  1016. struct list_head cb_list; /* md requires an unplug callback */
  1017. };
  1018. #define BLK_MAX_REQUEST_COUNT 16
  1019. #define BLK_PLUG_FLUSH_SIZE (128 * 1024)
  1020. struct blk_plug_cb;
  1021. typedef void (*blk_plug_cb_fn)(struct blk_plug_cb *, bool);
  1022. struct blk_plug_cb {
  1023. struct list_head list;
  1024. blk_plug_cb_fn callback;
  1025. void *data;
  1026. };
  1027. extern struct blk_plug_cb *blk_check_plugged(blk_plug_cb_fn unplug,
  1028. void *data, int size);
  1029. extern void blk_start_plug(struct blk_plug *);
  1030. extern void blk_finish_plug(struct blk_plug *);
  1031. extern void blk_flush_plug_list(struct blk_plug *, bool);
  1032. static inline void blk_flush_plug(struct task_struct *tsk)
  1033. {
  1034. struct blk_plug *plug = tsk->plug;
  1035. if (plug)
  1036. blk_flush_plug_list(plug, false);
  1037. }
  1038. static inline void blk_schedule_flush_plug(struct task_struct *tsk)
  1039. {
  1040. struct blk_plug *plug = tsk->plug;
  1041. if (plug)
  1042. blk_flush_plug_list(plug, true);
  1043. }
  1044. static inline bool blk_needs_flush_plug(struct task_struct *tsk)
  1045. {
  1046. struct blk_plug *plug = tsk->plug;
  1047. return plug &&
  1048. (!list_empty(&plug->list) ||
  1049. !list_empty(&plug->mq_list) ||
  1050. !list_empty(&plug->cb_list));
  1051. }
  1052. /*
  1053. * tag stuff
  1054. */
  1055. extern int blk_queue_start_tag(struct request_queue *, struct request *);
  1056. extern struct request *blk_queue_find_tag(struct request_queue *, int);
  1057. extern void blk_queue_end_tag(struct request_queue *, struct request *);
  1058. extern int blk_queue_init_tags(struct request_queue *, int, struct blk_queue_tag *, int);
  1059. extern void blk_queue_free_tags(struct request_queue *);
  1060. extern int blk_queue_resize_tags(struct request_queue *, int);
  1061. extern void blk_queue_invalidate_tags(struct request_queue *);
  1062. extern struct blk_queue_tag *blk_init_tags(int, int);
  1063. extern void blk_free_tags(struct blk_queue_tag *);
  1064. static inline struct request *blk_map_queue_find_tag(struct blk_queue_tag *bqt,
  1065. int tag)
  1066. {
  1067. if (unlikely(bqt == NULL || tag >= bqt->real_max_depth))
  1068. return NULL;
  1069. return bqt->tag_index[tag];
  1070. }
  1071. #define BLKDEV_DISCARD_SECURE (1 << 0) /* issue a secure erase */
  1072. #define BLKDEV_DISCARD_ZERO (1 << 1) /* must reliably zero data */
  1073. extern int blkdev_issue_flush(struct block_device *, gfp_t, sector_t *);
  1074. extern int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
  1075. sector_t nr_sects, gfp_t gfp_mask, unsigned long flags);
  1076. extern int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
  1077. sector_t nr_sects, gfp_t gfp_mask, int flags,
  1078. struct bio **biop);
  1079. extern int blkdev_issue_write_same(struct block_device *bdev, sector_t sector,
  1080. sector_t nr_sects, gfp_t gfp_mask, struct page *page);
  1081. extern int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
  1082. sector_t nr_sects, gfp_t gfp_mask, bool discard);
  1083. static inline int sb_issue_discard(struct super_block *sb, sector_t block,
  1084. sector_t nr_blocks, gfp_t gfp_mask, unsigned long flags)
  1085. {
  1086. return blkdev_issue_discard(sb->s_bdev, block << (sb->s_blocksize_bits - 9),
  1087. nr_blocks << (sb->s_blocksize_bits - 9),
  1088. gfp_mask, flags);
  1089. }
  1090. static inline int sb_issue_zeroout(struct super_block *sb, sector_t block,
  1091. sector_t nr_blocks, gfp_t gfp_mask)
  1092. {
  1093. return blkdev_issue_zeroout(sb->s_bdev,
  1094. block << (sb->s_blocksize_bits - 9),
  1095. nr_blocks << (sb->s_blocksize_bits - 9),
  1096. gfp_mask, true);
  1097. }
  1098. extern int blk_verify_command(unsigned char *cmd, fmode_t has_write_perm);
  1099. enum blk_default_limits {
  1100. BLK_MAX_SEGMENTS = 128,
  1101. BLK_SAFE_MAX_SECTORS = 255,
  1102. BLK_DEF_MAX_SECTORS = 2560,
  1103. BLK_MAX_SEGMENT_SIZE = 65536,
  1104. BLK_SEG_BOUNDARY_MASK = 0xFFFFFFFFUL,
  1105. };
  1106. #define blkdev_entry_to_request(entry) list_entry((entry), struct request, queuelist)
  1107. static inline unsigned long queue_bounce_pfn(struct request_queue *q)
  1108. {
  1109. return q->limits.bounce_pfn;
  1110. }
  1111. static inline unsigned long queue_segment_boundary(struct request_queue *q)
  1112. {
  1113. return q->limits.seg_boundary_mask;
  1114. }
  1115. static inline unsigned long queue_virt_boundary(struct request_queue *q)
  1116. {
  1117. return q->limits.virt_boundary_mask;
  1118. }
  1119. static inline unsigned int queue_max_sectors(struct request_queue *q)
  1120. {
  1121. return q->limits.max_sectors;
  1122. }
  1123. static inline unsigned int queue_max_hw_sectors(struct request_queue *q)
  1124. {
  1125. return q->limits.max_hw_sectors;
  1126. }
  1127. static inline unsigned short queue_max_segments(struct request_queue *q)
  1128. {
  1129. return q->limits.max_segments;
  1130. }
  1131. static inline unsigned int queue_max_segment_size(struct request_queue *q)
  1132. {
  1133. return q->limits.max_segment_size;
  1134. }
  1135. static inline unsigned short queue_logical_block_size(struct request_queue *q)
  1136. {
  1137. int retval = 512;
  1138. if (q && q->limits.logical_block_size)
  1139. retval = q->limits.logical_block_size;
  1140. return retval;
  1141. }
  1142. static inline unsigned short bdev_logical_block_size(struct block_device *bdev)
  1143. {
  1144. return queue_logical_block_size(bdev_get_queue(bdev));
  1145. }
  1146. static inline unsigned int queue_physical_block_size(struct request_queue *q)
  1147. {
  1148. return q->limits.physical_block_size;
  1149. }
  1150. static inline unsigned int bdev_physical_block_size(struct block_device *bdev)
  1151. {
  1152. return queue_physical_block_size(bdev_get_queue(bdev));
  1153. }
  1154. static inline unsigned int queue_io_min(struct request_queue *q)
  1155. {
  1156. return q->limits.io_min;
  1157. }
  1158. static inline int bdev_io_min(struct block_device *bdev)
  1159. {
  1160. return queue_io_min(bdev_get_queue(bdev));
  1161. }
  1162. static inline unsigned int queue_io_opt(struct request_queue *q)
  1163. {
  1164. return q->limits.io_opt;
  1165. }
  1166. static inline int bdev_io_opt(struct block_device *bdev)
  1167. {
  1168. return queue_io_opt(bdev_get_queue(bdev));
  1169. }
  1170. static inline int queue_alignment_offset(struct request_queue *q)
  1171. {
  1172. if (q->limits.misaligned)
  1173. return -1;
  1174. return q->limits.alignment_offset;
  1175. }
  1176. static inline int queue_limit_alignment_offset(struct queue_limits *lim, sector_t sector)
  1177. {
  1178. unsigned int granularity = max(lim->physical_block_size, lim->io_min);
  1179. unsigned int alignment = sector_div(sector, granularity >> 9) << 9;
  1180. return (granularity + lim->alignment_offset - alignment) % granularity;
  1181. }
  1182. static inline int bdev_alignment_offset(struct block_device *bdev)
  1183. {
  1184. struct request_queue *q = bdev_get_queue(bdev);
  1185. if (q->limits.misaligned)
  1186. return -1;
  1187. if (bdev != bdev->bd_contains)
  1188. return bdev->bd_part->alignment_offset;
  1189. return q->limits.alignment_offset;
  1190. }
  1191. static inline int queue_discard_alignment(struct request_queue *q)
  1192. {
  1193. if (q->limits.discard_misaligned)
  1194. return -1;
  1195. return q->limits.discard_alignment;
  1196. }
  1197. static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector_t sector)
  1198. {
  1199. unsigned int alignment, granularity, offset;
  1200. if (!lim->max_discard_sectors)
  1201. return 0;
  1202. /* Why are these in bytes, not sectors? */
  1203. alignment = lim->discard_alignment >> 9;
  1204. granularity = lim->discard_granularity >> 9;
  1205. if (!granularity)
  1206. return 0;
  1207. /* Offset of the partition start in 'granularity' sectors */
  1208. offset = sector_div(sector, granularity);
  1209. /* And why do we do this modulus *again* in blkdev_issue_discard()? */
  1210. offset = (granularity + alignment - offset) % granularity;
  1211. /* Turn it back into bytes, gaah */
  1212. return offset << 9;
  1213. }
  1214. static inline int bdev_discard_alignment(struct block_device *bdev)
  1215. {
  1216. struct request_queue *q = bdev_get_queue(bdev);
  1217. if (bdev != bdev->bd_contains)
  1218. return bdev->bd_part->discard_alignment;
  1219. return q->limits.discard_alignment;
  1220. }
  1221. static inline unsigned int queue_discard_zeroes_data(struct request_queue *q)
  1222. {
  1223. if (q->limits.max_discard_sectors && q->limits.discard_zeroes_data == 1)
  1224. return 1;
  1225. return 0;
  1226. }
  1227. static inline unsigned int bdev_discard_zeroes_data(struct block_device *bdev)
  1228. {
  1229. return queue_discard_zeroes_data(bdev_get_queue(bdev));
  1230. }
  1231. static inline unsigned int bdev_write_same(struct block_device *bdev)
  1232. {
  1233. struct request_queue *q = bdev_get_queue(bdev);
  1234. if (q)
  1235. return q->limits.max_write_same_sectors;
  1236. return 0;
  1237. }
  1238. static inline enum blk_zoned_model bdev_zoned_model(struct block_device *bdev)
  1239. {
  1240. struct request_queue *q = bdev_get_queue(bdev);
  1241. if (q)
  1242. return blk_queue_zoned_model(q);
  1243. return BLK_ZONED_NONE;
  1244. }
  1245. static inline bool bdev_is_zoned(struct block_device *bdev)
  1246. {
  1247. struct request_queue *q = bdev_get_queue(bdev);
  1248. if (q)
  1249. return blk_queue_is_zoned(q);
  1250. return false;
  1251. }
  1252. static inline unsigned int bdev_zone_size(struct block_device *bdev)
  1253. {
  1254. struct request_queue *q = bdev_get_queue(bdev);
  1255. if (q)
  1256. return blk_queue_zone_size(q);
  1257. return 0;
  1258. }
  1259. static inline int queue_dma_alignment(struct request_queue *q)
  1260. {
  1261. return q ? q->dma_alignment : 511;
  1262. }
  1263. static inline int blk_rq_aligned(struct request_queue *q, unsigned long addr,
  1264. unsigned int len)
  1265. {
  1266. unsigned int alignment = queue_dma_alignment(q) | q->dma_pad_mask;
  1267. return !(addr & alignment) && !(len & alignment);
  1268. }
  1269. /* assumes size > 256 */
  1270. static inline unsigned int blksize_bits(unsigned int size)
  1271. {
  1272. unsigned int bits = 8;
  1273. do {
  1274. bits++;
  1275. size >>= 1;
  1276. } while (size > 256);
  1277. return bits;
  1278. }
  1279. static inline unsigned int block_size(struct block_device *bdev)
  1280. {
  1281. return bdev->bd_block_size;
  1282. }
  1283. static inline bool queue_flush_queueable(struct request_queue *q)
  1284. {
  1285. return !test_bit(QUEUE_FLAG_FLUSH_NQ, &q->queue_flags);
  1286. }
  1287. typedef struct {struct page *v;} Sector;
  1288. unsigned char *read_dev_sector(struct block_device *, sector_t, Sector *);
  1289. static inline void put_dev_sector(Sector p)
  1290. {
  1291. put_page(p.v);
  1292. }
  1293. static inline bool __bvec_gap_to_prev(struct request_queue *q,
  1294. struct bio_vec *bprv, unsigned int offset)
  1295. {
  1296. return offset ||
  1297. ((bprv->bv_offset + bprv->bv_len) & queue_virt_boundary(q));
  1298. }
  1299. /*
  1300. * Check if adding a bio_vec after bprv with offset would create a gap in
  1301. * the SG list. Most drivers don't care about this, but some do.
  1302. */
  1303. static inline bool bvec_gap_to_prev(struct request_queue *q,
  1304. struct bio_vec *bprv, unsigned int offset)
  1305. {
  1306. if (!queue_virt_boundary(q))
  1307. return false;
  1308. return __bvec_gap_to_prev(q, bprv, offset);
  1309. }
  1310. static inline bool bio_will_gap(struct request_queue *q, struct bio *prev,
  1311. struct bio *next)
  1312. {
  1313. if (bio_has_data(prev) && queue_virt_boundary(q)) {
  1314. struct bio_vec pb, nb;
  1315. bio_get_last_bvec(prev, &pb);
  1316. bio_get_first_bvec(next, &nb);
  1317. return __bvec_gap_to_prev(q, &pb, nb.bv_offset);
  1318. }
  1319. return false;
  1320. }
  1321. static inline bool req_gap_back_merge(struct request *req, struct bio *bio)
  1322. {
  1323. return bio_will_gap(req->q, req->biotail, bio);
  1324. }
  1325. static inline bool req_gap_front_merge(struct request *req, struct bio *bio)
  1326. {
  1327. return bio_will_gap(req->q, bio, req->bio);
  1328. }
  1329. int kblockd_schedule_work(struct work_struct *work);
  1330. int kblockd_schedule_work_on(int cpu, struct work_struct *work);
  1331. int kblockd_schedule_delayed_work(struct delayed_work *dwork, unsigned long delay);
  1332. int kblockd_schedule_delayed_work_on(int cpu, struct delayed_work *dwork, unsigned long delay);
  1333. #ifdef CONFIG_BLK_CGROUP
  1334. /*
  1335. * This should not be using sched_clock(). A real patch is in progress
  1336. * to fix this up, until that is in place we need to disable preemption
  1337. * around sched_clock() in this function and set_io_start_time_ns().
  1338. */
  1339. static inline void set_start_time_ns(struct request *req)
  1340. {
  1341. preempt_disable();
  1342. req->start_time_ns = sched_clock();
  1343. preempt_enable();
  1344. }
  1345. static inline void set_io_start_time_ns(struct request *req)
  1346. {
  1347. preempt_disable();
  1348. req->io_start_time_ns = sched_clock();
  1349. preempt_enable();
  1350. }
  1351. static inline uint64_t rq_start_time_ns(struct request *req)
  1352. {
  1353. return req->start_time_ns;
  1354. }
  1355. static inline uint64_t rq_io_start_time_ns(struct request *req)
  1356. {
  1357. return req->io_start_time_ns;
  1358. }
  1359. #else
  1360. static inline void set_start_time_ns(struct request *req) {}
  1361. static inline void set_io_start_time_ns(struct request *req) {}
  1362. static inline uint64_t rq_start_time_ns(struct request *req)
  1363. {
  1364. return 0;
  1365. }
  1366. static inline uint64_t rq_io_start_time_ns(struct request *req)
  1367. {
  1368. return 0;
  1369. }
  1370. #endif
  1371. #define MODULE_ALIAS_BLOCKDEV(major,minor) \
  1372. MODULE_ALIAS("block-major-" __stringify(major) "-" __stringify(minor))
  1373. #define MODULE_ALIAS_BLOCKDEV_MAJOR(major) \
  1374. MODULE_ALIAS("block-major-" __stringify(major) "-*")
  1375. #if defined(CONFIG_BLK_DEV_INTEGRITY)
  1376. enum blk_integrity_flags {
  1377. BLK_INTEGRITY_VERIFY = 1 << 0,
  1378. BLK_INTEGRITY_GENERATE = 1 << 1,
  1379. BLK_INTEGRITY_DEVICE_CAPABLE = 1 << 2,
  1380. BLK_INTEGRITY_IP_CHECKSUM = 1 << 3,
  1381. };
  1382. struct blk_integrity_iter {
  1383. void *prot_buf;
  1384. void *data_buf;
  1385. sector_t seed;
  1386. unsigned int data_size;
  1387. unsigned short interval;
  1388. const char *disk_name;
  1389. };
  1390. typedef int (integrity_processing_fn) (struct blk_integrity_iter *);
  1391. struct blk_integrity_profile {
  1392. integrity_processing_fn *generate_fn;
  1393. integrity_processing_fn *verify_fn;
  1394. const char *name;
  1395. };
  1396. extern void blk_integrity_register(struct gendisk *, struct blk_integrity *);
  1397. extern void blk_integrity_unregister(struct gendisk *);
  1398. extern int blk_integrity_compare(struct gendisk *, struct gendisk *);
  1399. extern int blk_rq_map_integrity_sg(struct request_queue *, struct bio *,
  1400. struct scatterlist *);
  1401. extern int blk_rq_count_integrity_sg(struct request_queue *, struct bio *);
  1402. extern bool blk_integrity_merge_rq(struct request_queue *, struct request *,
  1403. struct request *);
  1404. extern bool blk_integrity_merge_bio(struct request_queue *, struct request *,
  1405. struct bio *);
  1406. static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk)
  1407. {
  1408. struct blk_integrity *bi = &disk->queue->integrity;
  1409. if (!bi->profile)
  1410. return NULL;
  1411. return bi;
  1412. }
  1413. static inline
  1414. struct blk_integrity *bdev_get_integrity(struct block_device *bdev)
  1415. {
  1416. return blk_get_integrity(bdev->bd_disk);
  1417. }
  1418. static inline bool blk_integrity_rq(struct request *rq)
  1419. {
  1420. return rq->cmd_flags & REQ_INTEGRITY;
  1421. }
  1422. static inline void blk_queue_max_integrity_segments(struct request_queue *q,
  1423. unsigned int segs)
  1424. {
  1425. q->limits.max_integrity_segments = segs;
  1426. }
  1427. static inline unsigned short
  1428. queue_max_integrity_segments(struct request_queue *q)
  1429. {
  1430. return q->limits.max_integrity_segments;
  1431. }
  1432. static inline bool integrity_req_gap_back_merge(struct request *req,
  1433. struct bio *next)
  1434. {
  1435. struct bio_integrity_payload *bip = bio_integrity(req->bio);
  1436. struct bio_integrity_payload *bip_next = bio_integrity(next);
  1437. return bvec_gap_to_prev(req->q, &bip->bip_vec[bip->bip_vcnt - 1],
  1438. bip_next->bip_vec[0].bv_offset);
  1439. }
  1440. static inline bool integrity_req_gap_front_merge(struct request *req,
  1441. struct bio *bio)
  1442. {
  1443. struct bio_integrity_payload *bip = bio_integrity(bio);
  1444. struct bio_integrity_payload *bip_next = bio_integrity(req->bio);
  1445. return bvec_gap_to_prev(req->q, &bip->bip_vec[bip->bip_vcnt - 1],
  1446. bip_next->bip_vec[0].bv_offset);
  1447. }
  1448. #else /* CONFIG_BLK_DEV_INTEGRITY */
  1449. struct bio;
  1450. struct block_device;
  1451. struct gendisk;
  1452. struct blk_integrity;
  1453. static inline int blk_integrity_rq(struct request *rq)
  1454. {
  1455. return 0;
  1456. }
  1457. static inline int blk_rq_count_integrity_sg(struct request_queue *q,
  1458. struct bio *b)
  1459. {
  1460. return 0;
  1461. }
  1462. static inline int blk_rq_map_integrity_sg(struct request_queue *q,
  1463. struct bio *b,
  1464. struct scatterlist *s)
  1465. {
  1466. return 0;
  1467. }
  1468. static inline struct blk_integrity *bdev_get_integrity(struct block_device *b)
  1469. {
  1470. return NULL;
  1471. }
  1472. static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk)
  1473. {
  1474. return NULL;
  1475. }
  1476. static inline int blk_integrity_compare(struct gendisk *a, struct gendisk *b)
  1477. {
  1478. return 0;
  1479. }
  1480. static inline void blk_integrity_register(struct gendisk *d,
  1481. struct blk_integrity *b)
  1482. {
  1483. }
  1484. static inline void blk_integrity_unregister(struct gendisk *d)
  1485. {
  1486. }
  1487. static inline void blk_queue_max_integrity_segments(struct request_queue *q,
  1488. unsigned int segs)
  1489. {
  1490. }
  1491. static inline unsigned short queue_max_integrity_segments(struct request_queue *q)
  1492. {
  1493. return 0;
  1494. }
  1495. static inline bool blk_integrity_merge_rq(struct request_queue *rq,
  1496. struct request *r1,
  1497. struct request *r2)
  1498. {
  1499. return true;
  1500. }
  1501. static inline bool blk_integrity_merge_bio(struct request_queue *rq,
  1502. struct request *r,
  1503. struct bio *b)
  1504. {
  1505. return true;
  1506. }
  1507. static inline bool integrity_req_gap_back_merge(struct request *req,
  1508. struct bio *next)
  1509. {
  1510. return false;
  1511. }
  1512. static inline bool integrity_req_gap_front_merge(struct request *req,
  1513. struct bio *bio)
  1514. {
  1515. return false;
  1516. }
  1517. #endif /* CONFIG_BLK_DEV_INTEGRITY */
  1518. /**
  1519. * struct blk_dax_ctl - control and output parameters for ->direct_access
  1520. * @sector: (input) offset relative to a block_device
  1521. * @addr: (output) kernel virtual address for @sector populated by driver
  1522. * @pfn: (output) page frame number for @addr populated by driver
  1523. * @size: (input) number of bytes requested
  1524. */
  1525. struct blk_dax_ctl {
  1526. sector_t sector;
  1527. void *addr;
  1528. long size;
  1529. pfn_t pfn;
  1530. };
  1531. struct block_device_operations {
  1532. int (*open) (struct block_device *, fmode_t);
  1533. void (*release) (struct gendisk *, fmode_t);
  1534. int (*rw_page)(struct block_device *, sector_t, struct page *, bool);
  1535. int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
  1536. int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
  1537. long (*direct_access)(struct block_device *, sector_t, void **, pfn_t *,
  1538. long);
  1539. unsigned int (*check_events) (struct gendisk *disk,
  1540. unsigned int clearing);
  1541. /* ->media_changed() is DEPRECATED, use ->check_events() instead */
  1542. int (*media_changed) (struct gendisk *);
  1543. void (*unlock_native_capacity) (struct gendisk *);
  1544. int (*revalidate_disk) (struct gendisk *);
  1545. int (*getgeo)(struct block_device *, struct hd_geometry *);
  1546. /* this callback is with swap_lock and sometimes page table lock held */
  1547. void (*swap_slot_free_notify) (struct block_device *, unsigned long);
  1548. struct module *owner;
  1549. const struct pr_ops *pr_ops;
  1550. };
  1551. extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
  1552. unsigned long);
  1553. extern int bdev_read_page(struct block_device *, sector_t, struct page *);
  1554. extern int bdev_write_page(struct block_device *, sector_t, struct page *,
  1555. struct writeback_control *);
  1556. extern long bdev_direct_access(struct block_device *, struct blk_dax_ctl *);
  1557. extern int bdev_dax_supported(struct super_block *, int);
  1558. extern bool bdev_dax_capable(struct block_device *);
  1559. #else /* CONFIG_BLOCK */
  1560. struct block_device;
  1561. /*
  1562. * stubs for when the block layer is configured out
  1563. */
  1564. #define buffer_heads_over_limit 0
  1565. static inline long nr_blockdev_pages(void)
  1566. {
  1567. return 0;
  1568. }
  1569. struct blk_plug {
  1570. };
  1571. static inline void blk_start_plug(struct blk_plug *plug)
  1572. {
  1573. }
  1574. static inline void blk_finish_plug(struct blk_plug *plug)
  1575. {
  1576. }
  1577. static inline void blk_flush_plug(struct task_struct *task)
  1578. {
  1579. }
  1580. static inline void blk_schedule_flush_plug(struct task_struct *task)
  1581. {
  1582. }
  1583. static inline bool blk_needs_flush_plug(struct task_struct *tsk)
  1584. {
  1585. return false;
  1586. }
  1587. static inline int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
  1588. sector_t *error_sector)
  1589. {
  1590. return 0;
  1591. }
  1592. #endif /* CONFIG_BLOCK */
  1593. #endif