blkdev.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281
  1. #ifndef _LINUX_BLKDEV_H
  2. #define _LINUX_BLKDEV_H
  3. #ifdef CONFIG_BLOCK
  4. #include <linux/sched.h>
  5. #include <linux/major.h>
  6. #include <linux/genhd.h>
  7. #include <linux/list.h>
  8. #include <linux/timer.h>
  9. #include <linux/workqueue.h>
  10. #include <linux/pagemap.h>
  11. #include <linux/backing-dev.h>
  12. #include <linux/wait.h>
  13. #include <linux/mempool.h>
  14. #include <linux/bio.h>
  15. #include <linux/module.h>
  16. #include <linux/stringify.h>
  17. #include <linux/gfp.h>
  18. #include <linux/bsg.h>
  19. #include <linux/smp.h>
  20. #include <asm/scatterlist.h>
  21. struct scsi_ioctl_command;
  22. struct request_queue;
  23. struct elevator_queue;
  24. struct request_pm_state;
  25. struct blk_trace;
  26. struct request;
  27. struct sg_io_hdr;
  28. #define BLKDEV_MIN_RQ 4
  29. #define BLKDEV_MAX_RQ 128 /* Default maximum */
  30. struct request;
  31. typedef void (rq_end_io_fn)(struct request *, int);
  32. struct request_list {
  33. /*
  34. * count[], starved[], and wait[] are indexed by
  35. * BLK_RW_SYNC/BLK_RW_ASYNC
  36. */
  37. int count[2];
  38. int starved[2];
  39. int elvpriv;
  40. mempool_t *rq_pool;
  41. wait_queue_head_t wait[2];
  42. };
  43. /*
  44. * request command types
  45. */
  46. enum rq_cmd_type_bits {
  47. REQ_TYPE_FS = 1, /* fs request */
  48. REQ_TYPE_BLOCK_PC, /* scsi command */
  49. REQ_TYPE_SENSE, /* sense request */
  50. REQ_TYPE_PM_SUSPEND, /* suspend request */
  51. REQ_TYPE_PM_RESUME, /* resume request */
  52. REQ_TYPE_PM_SHUTDOWN, /* shutdown request */
  53. REQ_TYPE_SPECIAL, /* driver defined type */
  54. /*
  55. * for ATA/ATAPI devices. this really doesn't belong here, ide should
  56. * use REQ_TYPE_SPECIAL and use rq->cmd[0] with the range of driver
  57. * private REQ_LB opcodes to differentiate what type of request this is
  58. */
  59. REQ_TYPE_ATA_TASKFILE,
  60. REQ_TYPE_ATA_PC,
  61. };
  62. #define BLK_MAX_CDB 16
  63. /*
  64. * try to put the fields that are referenced together in the same cacheline.
  65. * if you modify this structure, be sure to check block/blk-core.c:rq_init()
  66. * as well!
  67. */
  68. struct request {
  69. struct list_head queuelist;
  70. struct call_single_data csd;
  71. struct request_queue *q;
  72. unsigned int cmd_flags;
  73. enum rq_cmd_type_bits cmd_type;
  74. unsigned long atomic_flags;
  75. int cpu;
  76. /* the following two fields are internal, NEVER access directly */
  77. unsigned int __data_len; /* total data len */
  78. sector_t __sector; /* sector cursor */
  79. struct bio *bio;
  80. struct bio *biotail;
  81. struct hlist_node hash; /* merge hash */
  82. /*
  83. * The rb_node is only used inside the io scheduler, requests
  84. * are pruned when moved to the dispatch queue. So let the
  85. * completion_data share space with the rb_node.
  86. */
  87. union {
  88. struct rb_node rb_node; /* sort/lookup */
  89. void *completion_data;
  90. };
  91. /*
  92. * Three pointers are available for the IO schedulers, if they need
  93. * more they have to dynamically allocate it.
  94. */
  95. void *elevator_private;
  96. void *elevator_private2;
  97. void *elevator_private3;
  98. struct gendisk *rq_disk;
  99. unsigned long start_time;
  100. #ifdef CONFIG_BLK_CGROUP
  101. unsigned long long start_time_ns;
  102. unsigned long long io_start_time_ns; /* when passed to hardware */
  103. #endif
  104. /* Number of scatter-gather DMA addr+len pairs after
  105. * physical address coalescing is performed.
  106. */
  107. unsigned short nr_phys_segments;
  108. unsigned short ioprio;
  109. int ref_count;
  110. void *special; /* opaque pointer available for LLD use */
  111. char *buffer; /* kaddr of the current segment if available */
  112. int tag;
  113. int errors;
  114. /*
  115. * when request is used as a packet command carrier
  116. */
  117. unsigned char __cmd[BLK_MAX_CDB];
  118. unsigned char *cmd;
  119. unsigned short cmd_len;
  120. unsigned int extra_len; /* length of alignment and padding */
  121. unsigned int sense_len;
  122. unsigned int resid_len; /* residual count */
  123. void *sense;
  124. unsigned long deadline;
  125. struct list_head timeout_list;
  126. unsigned int timeout;
  127. int retries;
  128. /*
  129. * completion callback.
  130. */
  131. rq_end_io_fn *end_io;
  132. void *end_io_data;
  133. /* for bidi */
  134. struct request *next_rq;
  135. };
  136. static inline unsigned short req_get_ioprio(struct request *req)
  137. {
  138. return req->ioprio;
  139. }
  140. /*
  141. * State information carried for REQ_TYPE_PM_SUSPEND and REQ_TYPE_PM_RESUME
  142. * requests. Some step values could eventually be made generic.
  143. */
  144. struct request_pm_state
  145. {
  146. /* PM state machine step value, currently driver specific */
  147. int pm_step;
  148. /* requested PM state value (S1, S2, S3, S4, ...) */
  149. u32 pm_state;
  150. void* data; /* for driver use */
  151. };
  152. #include <linux/elevator.h>
  153. typedef void (request_fn_proc) (struct request_queue *q);
  154. typedef int (make_request_fn) (struct request_queue *q, struct bio *bio);
  155. typedef int (prep_rq_fn) (struct request_queue *, struct request *);
  156. typedef void (unprep_rq_fn) (struct request_queue *, struct request *);
  157. typedef void (unplug_fn) (struct request_queue *);
  158. struct bio_vec;
  159. struct bvec_merge_data {
  160. struct block_device *bi_bdev;
  161. sector_t bi_sector;
  162. unsigned bi_size;
  163. unsigned long bi_rw;
  164. };
  165. typedef int (merge_bvec_fn) (struct request_queue *, struct bvec_merge_data *,
  166. struct bio_vec *);
  167. typedef void (softirq_done_fn)(struct request *);
  168. typedef int (dma_drain_needed_fn)(struct request *);
  169. typedef int (lld_busy_fn) (struct request_queue *q);
  170. enum blk_eh_timer_return {
  171. BLK_EH_NOT_HANDLED,
  172. BLK_EH_HANDLED,
  173. BLK_EH_RESET_TIMER,
  174. };
  175. typedef enum blk_eh_timer_return (rq_timed_out_fn)(struct request *);
  176. enum blk_queue_state {
  177. Queue_down,
  178. Queue_up,
  179. };
  180. struct blk_queue_tag {
  181. struct request **tag_index; /* map of busy tags */
  182. unsigned long *tag_map; /* bit map of free/busy tags */
  183. int busy; /* current depth */
  184. int max_depth; /* what we will send to device */
  185. int real_max_depth; /* what the array can hold */
  186. atomic_t refcnt; /* map can be shared */
  187. };
  188. #define BLK_SCSI_MAX_CMDS (256)
  189. #define BLK_SCSI_CMD_PER_LONG (BLK_SCSI_MAX_CMDS / (sizeof(long) * 8))
  190. struct queue_limits {
  191. unsigned long bounce_pfn;
  192. unsigned long seg_boundary_mask;
  193. unsigned int max_hw_sectors;
  194. unsigned int max_sectors;
  195. unsigned int max_segment_size;
  196. unsigned int physical_block_size;
  197. unsigned int alignment_offset;
  198. unsigned int io_min;
  199. unsigned int io_opt;
  200. unsigned int max_discard_sectors;
  201. unsigned int discard_granularity;
  202. unsigned int discard_alignment;
  203. unsigned short logical_block_size;
  204. unsigned short max_segments;
  205. unsigned char misaligned;
  206. unsigned char discard_misaligned;
  207. unsigned char no_cluster;
  208. signed char discard_zeroes_data;
  209. };
  210. struct request_queue
  211. {
  212. /*
  213. * Together with queue_head for cacheline sharing
  214. */
  215. struct list_head queue_head;
  216. struct request *last_merge;
  217. struct elevator_queue *elevator;
  218. /*
  219. * the queue request freelist, one for reads and one for writes
  220. */
  221. struct request_list rq;
  222. request_fn_proc *request_fn;
  223. make_request_fn *make_request_fn;
  224. prep_rq_fn *prep_rq_fn;
  225. unprep_rq_fn *unprep_rq_fn;
  226. unplug_fn *unplug_fn;
  227. merge_bvec_fn *merge_bvec_fn;
  228. softirq_done_fn *softirq_done_fn;
  229. rq_timed_out_fn *rq_timed_out_fn;
  230. dma_drain_needed_fn *dma_drain_needed;
  231. lld_busy_fn *lld_busy_fn;
  232. /*
  233. * Dispatch queue sorting
  234. */
  235. sector_t end_sector;
  236. struct request *boundary_rq;
  237. /*
  238. * Auto-unplugging state
  239. */
  240. struct timer_list unplug_timer;
  241. int unplug_thresh; /* After this many requests */
  242. unsigned long unplug_delay; /* After this many jiffies */
  243. struct work_struct unplug_work;
  244. struct backing_dev_info backing_dev_info;
  245. /*
  246. * The queue owner gets to use this for whatever they like.
  247. * ll_rw_blk doesn't touch it.
  248. */
  249. void *queuedata;
  250. /*
  251. * queue needs bounce pages for pages above this limit
  252. */
  253. gfp_t bounce_gfp;
  254. /*
  255. * various queue flags, see QUEUE_* below
  256. */
  257. unsigned long queue_flags;
  258. /*
  259. * protects queue structures from reentrancy. ->__queue_lock should
  260. * _never_ be used directly, it is queue private. always use
  261. * ->queue_lock.
  262. */
  263. spinlock_t __queue_lock;
  264. spinlock_t *queue_lock;
  265. /*
  266. * queue kobject
  267. */
  268. struct kobject kobj;
  269. /*
  270. * queue settings
  271. */
  272. unsigned long nr_requests; /* Max # of requests */
  273. unsigned int nr_congestion_on;
  274. unsigned int nr_congestion_off;
  275. unsigned int nr_batching;
  276. void *dma_drain_buffer;
  277. unsigned int dma_drain_size;
  278. unsigned int dma_pad_mask;
  279. unsigned int dma_alignment;
  280. struct blk_queue_tag *queue_tags;
  281. struct list_head tag_busy_list;
  282. unsigned int nr_sorted;
  283. unsigned int in_flight[2];
  284. unsigned int rq_timeout;
  285. struct timer_list timeout;
  286. struct list_head timeout_list;
  287. struct queue_limits limits;
  288. /*
  289. * sg stuff
  290. */
  291. unsigned int sg_timeout;
  292. unsigned int sg_reserved_size;
  293. int node;
  294. #ifdef CONFIG_BLK_DEV_IO_TRACE
  295. struct blk_trace *blk_trace;
  296. #endif
  297. /*
  298. * reserved for flush operations
  299. */
  300. unsigned int ordered, next_ordered, ordseq;
  301. int orderr, ordcolor;
  302. struct request pre_flush_rq, bar_rq, post_flush_rq;
  303. struct request *orig_bar_rq;
  304. struct mutex sysfs_lock;
  305. #if defined(CONFIG_BLK_DEV_BSG)
  306. struct bsg_class_device bsg_dev;
  307. #endif
  308. };
  309. #define QUEUE_FLAG_CLUSTER 0 /* cluster several segments into 1 */
  310. #define QUEUE_FLAG_QUEUED 1 /* uses generic tag queueing */
  311. #define QUEUE_FLAG_STOPPED 2 /* queue is stopped */
  312. #define QUEUE_FLAG_SYNCFULL 3 /* read queue has been filled */
  313. #define QUEUE_FLAG_ASYNCFULL 4 /* write queue has been filled */
  314. #define QUEUE_FLAG_DEAD 5 /* queue being torn down */
  315. #define QUEUE_FLAG_REENTER 6 /* Re-entrancy avoidance */
  316. #define QUEUE_FLAG_PLUGGED 7 /* queue is plugged */
  317. #define QUEUE_FLAG_ELVSWITCH 8 /* don't use elevator, just do FIFO */
  318. #define QUEUE_FLAG_BIDI 9 /* queue supports bidi requests */
  319. #define QUEUE_FLAG_NOMERGES 10 /* disable merge attempts */
  320. #define QUEUE_FLAG_SAME_COMP 11 /* force complete on same CPU */
  321. #define QUEUE_FLAG_FAIL_IO 12 /* fake timeout */
  322. #define QUEUE_FLAG_STACKABLE 13 /* supports request stacking */
  323. #define QUEUE_FLAG_NONROT 14 /* non-rotational device (SSD) */
  324. #define QUEUE_FLAG_VIRT QUEUE_FLAG_NONROT /* paravirt device */
  325. #define QUEUE_FLAG_IO_STAT 15 /* do IO stats */
  326. #define QUEUE_FLAG_DISCARD 16 /* supports DISCARD */
  327. #define QUEUE_FLAG_NOXMERGES 17 /* No extended merges */
  328. #define QUEUE_FLAG_ADD_RANDOM 18 /* Contributes to random pool */
  329. #define QUEUE_FLAG_SECDISCARD 19 /* supports SECDISCARD */
  330. #define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \
  331. (1 << QUEUE_FLAG_CLUSTER) | \
  332. (1 << QUEUE_FLAG_STACKABLE) | \
  333. (1 << QUEUE_FLAG_SAME_COMP) | \
  334. (1 << QUEUE_FLAG_ADD_RANDOM))
  335. static inline int queue_is_locked(struct request_queue *q)
  336. {
  337. #ifdef CONFIG_SMP
  338. spinlock_t *lock = q->queue_lock;
  339. return lock && spin_is_locked(lock);
  340. #else
  341. return 1;
  342. #endif
  343. }
  344. static inline void queue_flag_set_unlocked(unsigned int flag,
  345. struct request_queue *q)
  346. {
  347. __set_bit(flag, &q->queue_flags);
  348. }
  349. static inline int queue_flag_test_and_clear(unsigned int flag,
  350. struct request_queue *q)
  351. {
  352. WARN_ON_ONCE(!queue_is_locked(q));
  353. if (test_bit(flag, &q->queue_flags)) {
  354. __clear_bit(flag, &q->queue_flags);
  355. return 1;
  356. }
  357. return 0;
  358. }
  359. static inline int queue_flag_test_and_set(unsigned int flag,
  360. struct request_queue *q)
  361. {
  362. WARN_ON_ONCE(!queue_is_locked(q));
  363. if (!test_bit(flag, &q->queue_flags)) {
  364. __set_bit(flag, &q->queue_flags);
  365. return 0;
  366. }
  367. return 1;
  368. }
  369. static inline void queue_flag_set(unsigned int flag, struct request_queue *q)
  370. {
  371. WARN_ON_ONCE(!queue_is_locked(q));
  372. __set_bit(flag, &q->queue_flags);
  373. }
  374. static inline void queue_flag_clear_unlocked(unsigned int flag,
  375. struct request_queue *q)
  376. {
  377. __clear_bit(flag, &q->queue_flags);
  378. }
  379. static inline int queue_in_flight(struct request_queue *q)
  380. {
  381. return q->in_flight[0] + q->in_flight[1];
  382. }
  383. static inline void queue_flag_clear(unsigned int flag, struct request_queue *q)
  384. {
  385. WARN_ON_ONCE(!queue_is_locked(q));
  386. __clear_bit(flag, &q->queue_flags);
  387. }
  388. enum {
  389. /*
  390. * Hardbarrier is supported with one of the following methods.
  391. *
  392. * NONE : hardbarrier unsupported
  393. * DRAIN : ordering by draining is enough
  394. * DRAIN_FLUSH : ordering by draining w/ pre and post flushes
  395. * DRAIN_FUA : ordering by draining w/ pre flush and FUA write
  396. * TAG : ordering by tag is enough
  397. * TAG_FLUSH : ordering by tag w/ pre and post flushes
  398. * TAG_FUA : ordering by tag w/ pre flush and FUA write
  399. */
  400. QUEUE_ORDERED_BY_DRAIN = 0x01,
  401. QUEUE_ORDERED_BY_TAG = 0x02,
  402. QUEUE_ORDERED_DO_PREFLUSH = 0x10,
  403. QUEUE_ORDERED_DO_BAR = 0x20,
  404. QUEUE_ORDERED_DO_POSTFLUSH = 0x40,
  405. QUEUE_ORDERED_DO_FUA = 0x80,
  406. QUEUE_ORDERED_NONE = 0x00,
  407. QUEUE_ORDERED_DRAIN = QUEUE_ORDERED_BY_DRAIN |
  408. QUEUE_ORDERED_DO_BAR,
  409. QUEUE_ORDERED_DRAIN_FLUSH = QUEUE_ORDERED_DRAIN |
  410. QUEUE_ORDERED_DO_PREFLUSH |
  411. QUEUE_ORDERED_DO_POSTFLUSH,
  412. QUEUE_ORDERED_DRAIN_FUA = QUEUE_ORDERED_DRAIN |
  413. QUEUE_ORDERED_DO_PREFLUSH |
  414. QUEUE_ORDERED_DO_FUA,
  415. QUEUE_ORDERED_TAG = QUEUE_ORDERED_BY_TAG |
  416. QUEUE_ORDERED_DO_BAR,
  417. QUEUE_ORDERED_TAG_FLUSH = QUEUE_ORDERED_TAG |
  418. QUEUE_ORDERED_DO_PREFLUSH |
  419. QUEUE_ORDERED_DO_POSTFLUSH,
  420. QUEUE_ORDERED_TAG_FUA = QUEUE_ORDERED_TAG |
  421. QUEUE_ORDERED_DO_PREFLUSH |
  422. QUEUE_ORDERED_DO_FUA,
  423. /*
  424. * Ordered operation sequence
  425. */
  426. QUEUE_ORDSEQ_STARTED = 0x01, /* flushing in progress */
  427. QUEUE_ORDSEQ_DRAIN = 0x02, /* waiting for the queue to be drained */
  428. QUEUE_ORDSEQ_PREFLUSH = 0x04, /* pre-flushing in progress */
  429. QUEUE_ORDSEQ_BAR = 0x08, /* original barrier req in progress */
  430. QUEUE_ORDSEQ_POSTFLUSH = 0x10, /* post-flushing in progress */
  431. QUEUE_ORDSEQ_DONE = 0x20,
  432. };
  433. #define blk_queue_plugged(q) test_bit(QUEUE_FLAG_PLUGGED, &(q)->queue_flags)
  434. #define blk_queue_tagged(q) test_bit(QUEUE_FLAG_QUEUED, &(q)->queue_flags)
  435. #define blk_queue_stopped(q) test_bit(QUEUE_FLAG_STOPPED, &(q)->queue_flags)
  436. #define blk_queue_nomerges(q) test_bit(QUEUE_FLAG_NOMERGES, &(q)->queue_flags)
  437. #define blk_queue_noxmerges(q) \
  438. test_bit(QUEUE_FLAG_NOXMERGES, &(q)->queue_flags)
  439. #define blk_queue_nonrot(q) test_bit(QUEUE_FLAG_NONROT, &(q)->queue_flags)
  440. #define blk_queue_io_stat(q) test_bit(QUEUE_FLAG_IO_STAT, &(q)->queue_flags)
  441. #define blk_queue_add_random(q) test_bit(QUEUE_FLAG_ADD_RANDOM, &(q)->queue_flags)
  442. #define blk_queue_stackable(q) \
  443. test_bit(QUEUE_FLAG_STACKABLE, &(q)->queue_flags)
  444. #define blk_queue_discard(q) test_bit(QUEUE_FLAG_DISCARD, &(q)->queue_flags)
  445. #define blk_queue_secdiscard(q) (blk_queue_discard(q) && \
  446. test_bit(QUEUE_FLAG_SECDISCARD, &(q)->queue_flags))
  447. #define blk_noretry_request(rq) \
  448. ((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \
  449. REQ_FAILFAST_DRIVER))
  450. #define blk_account_rq(rq) \
  451. (((rq)->cmd_flags & REQ_STARTED) && \
  452. ((rq)->cmd_type == REQ_TYPE_FS || \
  453. ((rq)->cmd_flags & REQ_DISCARD)))
  454. #define blk_pm_request(rq) \
  455. ((rq)->cmd_type == REQ_TYPE_PM_SUSPEND || \
  456. (rq)->cmd_type == REQ_TYPE_PM_RESUME)
  457. #define blk_rq_cpu_valid(rq) ((rq)->cpu != -1)
  458. #define blk_bidi_rq(rq) ((rq)->next_rq != NULL)
  459. /* rq->queuelist of dequeued request must be list_empty() */
  460. #define blk_queued_rq(rq) (!list_empty(&(rq)->queuelist))
  461. #define list_entry_rq(ptr) list_entry((ptr), struct request, queuelist)
  462. #define rq_data_dir(rq) ((rq)->cmd_flags & 1)
  463. /*
  464. * We regard a request as sync, if either a read or a sync write
  465. */
  466. static inline bool rw_is_sync(unsigned int rw_flags)
  467. {
  468. return !(rw_flags & REQ_WRITE) || (rw_flags & REQ_SYNC);
  469. }
  470. static inline bool rq_is_sync(struct request *rq)
  471. {
  472. return rw_is_sync(rq->cmd_flags);
  473. }
  474. static inline int blk_queue_full(struct request_queue *q, int sync)
  475. {
  476. if (sync)
  477. return test_bit(QUEUE_FLAG_SYNCFULL, &q->queue_flags);
  478. return test_bit(QUEUE_FLAG_ASYNCFULL, &q->queue_flags);
  479. }
  480. static inline void blk_set_queue_full(struct request_queue *q, int sync)
  481. {
  482. if (sync)
  483. queue_flag_set(QUEUE_FLAG_SYNCFULL, q);
  484. else
  485. queue_flag_set(QUEUE_FLAG_ASYNCFULL, q);
  486. }
  487. static inline void blk_clear_queue_full(struct request_queue *q, int sync)
  488. {
  489. if (sync)
  490. queue_flag_clear(QUEUE_FLAG_SYNCFULL, q);
  491. else
  492. queue_flag_clear(QUEUE_FLAG_ASYNCFULL, q);
  493. }
  494. /*
  495. * mergeable request must not have _NOMERGE or _BARRIER bit set, nor may
  496. * it already be started by driver.
  497. */
  498. #define RQ_NOMERGE_FLAGS \
  499. (REQ_NOMERGE | REQ_STARTED | REQ_HARDBARRIER | REQ_SOFTBARRIER)
  500. #define rq_mergeable(rq) \
  501. (!((rq)->cmd_flags & RQ_NOMERGE_FLAGS) && \
  502. (((rq)->cmd_flags & REQ_DISCARD) || \
  503. (rq)->cmd_type == REQ_TYPE_FS))
  504. /*
  505. * q->prep_rq_fn return values
  506. */
  507. #define BLKPREP_OK 0 /* serve it */
  508. #define BLKPREP_KILL 1 /* fatal error, kill */
  509. #define BLKPREP_DEFER 2 /* leave on queue */
  510. extern unsigned long blk_max_low_pfn, blk_max_pfn;
  511. /*
  512. * standard bounce addresses:
  513. *
  514. * BLK_BOUNCE_HIGH : bounce all highmem pages
  515. * BLK_BOUNCE_ANY : don't bounce anything
  516. * BLK_BOUNCE_ISA : bounce pages above ISA DMA boundary
  517. */
  518. #if BITS_PER_LONG == 32
  519. #define BLK_BOUNCE_HIGH ((u64)blk_max_low_pfn << PAGE_SHIFT)
  520. #else
  521. #define BLK_BOUNCE_HIGH -1ULL
  522. #endif
  523. #define BLK_BOUNCE_ANY (-1ULL)
  524. #define BLK_BOUNCE_ISA (DMA_BIT_MASK(24))
  525. /*
  526. * default timeout for SG_IO if none specified
  527. */
  528. #define BLK_DEFAULT_SG_TIMEOUT (60 * HZ)
  529. #define BLK_MIN_SG_TIMEOUT (7 * HZ)
  530. #ifdef CONFIG_BOUNCE
  531. extern int init_emergency_isa_pool(void);
  532. extern void blk_queue_bounce(struct request_queue *q, struct bio **bio);
  533. #else
  534. static inline int init_emergency_isa_pool(void)
  535. {
  536. return 0;
  537. }
  538. static inline void blk_queue_bounce(struct request_queue *q, struct bio **bio)
  539. {
  540. }
  541. #endif /* CONFIG_MMU */
  542. struct rq_map_data {
  543. struct page **pages;
  544. int page_order;
  545. int nr_entries;
  546. unsigned long offset;
  547. int null_mapped;
  548. int from_user;
  549. };
  550. struct req_iterator {
  551. int i;
  552. struct bio *bio;
  553. };
  554. /* This should not be used directly - use rq_for_each_segment */
  555. #define for_each_bio(_bio) \
  556. for (; _bio; _bio = _bio->bi_next)
  557. #define __rq_for_each_bio(_bio, rq) \
  558. if ((rq->bio)) \
  559. for (_bio = (rq)->bio; _bio; _bio = _bio->bi_next)
  560. #define rq_for_each_segment(bvl, _rq, _iter) \
  561. __rq_for_each_bio(_iter.bio, _rq) \
  562. bio_for_each_segment(bvl, _iter.bio, _iter.i)
  563. #define rq_iter_last(rq, _iter) \
  564. (_iter.bio->bi_next == NULL && _iter.i == _iter.bio->bi_vcnt-1)
  565. #ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
  566. # error "You should define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE for your platform"
  567. #endif
  568. #if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
  569. extern void rq_flush_dcache_pages(struct request *rq);
  570. #else
  571. static inline void rq_flush_dcache_pages(struct request *rq)
  572. {
  573. }
  574. #endif
  575. extern int blk_register_queue(struct gendisk *disk);
  576. extern void blk_unregister_queue(struct gendisk *disk);
  577. extern void register_disk(struct gendisk *dev);
  578. extern void generic_make_request(struct bio *bio);
  579. extern void blk_rq_init(struct request_queue *q, struct request *rq);
  580. extern void blk_put_request(struct request *);
  581. extern void __blk_put_request(struct request_queue *, struct request *);
  582. extern struct request *blk_get_request(struct request_queue *, int, gfp_t);
  583. extern struct request *blk_make_request(struct request_queue *, struct bio *,
  584. gfp_t);
  585. extern void blk_insert_request(struct request_queue *, struct request *, int, void *);
  586. extern void blk_requeue_request(struct request_queue *, struct request *);
  587. extern void blk_add_request_payload(struct request *rq, struct page *page,
  588. unsigned int len);
  589. extern int blk_rq_check_limits(struct request_queue *q, struct request *rq);
  590. extern int blk_lld_busy(struct request_queue *q);
  591. extern int blk_rq_prep_clone(struct request *rq, struct request *rq_src,
  592. struct bio_set *bs, gfp_t gfp_mask,
  593. int (*bio_ctr)(struct bio *, struct bio *, void *),
  594. void *data);
  595. extern void blk_rq_unprep_clone(struct request *rq);
  596. extern int blk_insert_cloned_request(struct request_queue *q,
  597. struct request *rq);
  598. extern void blk_plug_device(struct request_queue *);
  599. extern void blk_plug_device_unlocked(struct request_queue *);
  600. extern int blk_remove_plug(struct request_queue *);
  601. extern void blk_recount_segments(struct request_queue *, struct bio *);
  602. extern int scsi_cmd_ioctl(struct request_queue *, struct gendisk *, fmode_t,
  603. unsigned int, void __user *);
  604. extern int sg_scsi_ioctl(struct request_queue *, struct gendisk *, fmode_t,
  605. struct scsi_ioctl_command __user *);
  606. /*
  607. * A queue has just exitted congestion. Note this in the global counter of
  608. * congested queues, and wake up anyone who was waiting for requests to be
  609. * put back.
  610. */
  611. static inline void blk_clear_queue_congested(struct request_queue *q, int sync)
  612. {
  613. clear_bdi_congested(&q->backing_dev_info, sync);
  614. }
  615. /*
  616. * A queue has just entered congestion. Flag that in the queue's VM-visible
  617. * state flags and increment the global gounter of congested queues.
  618. */
  619. static inline void blk_set_queue_congested(struct request_queue *q, int sync)
  620. {
  621. set_bdi_congested(&q->backing_dev_info, sync);
  622. }
  623. extern void blk_start_queue(struct request_queue *q);
  624. extern void blk_stop_queue(struct request_queue *q);
  625. extern void blk_sync_queue(struct request_queue *q);
  626. extern void __blk_stop_queue(struct request_queue *q);
  627. extern void __blk_run_queue(struct request_queue *);
  628. extern void blk_run_queue(struct request_queue *);
  629. extern int blk_rq_map_user(struct request_queue *, struct request *,
  630. struct rq_map_data *, void __user *, unsigned long,
  631. gfp_t);
  632. extern int blk_rq_unmap_user(struct bio *);
  633. extern int blk_rq_map_kern(struct request_queue *, struct request *, void *, unsigned int, gfp_t);
  634. extern int blk_rq_map_user_iov(struct request_queue *, struct request *,
  635. struct rq_map_data *, struct sg_iovec *, int,
  636. unsigned int, gfp_t);
  637. extern int blk_execute_rq(struct request_queue *, struct gendisk *,
  638. struct request *, int);
  639. extern void blk_execute_rq_nowait(struct request_queue *, struct gendisk *,
  640. struct request *, int, rq_end_io_fn *);
  641. extern void blk_unplug(struct request_queue *q);
  642. static inline struct request_queue *bdev_get_queue(struct block_device *bdev)
  643. {
  644. return bdev->bd_disk->queue;
  645. }
  646. /*
  647. * blk_rq_pos() : the current sector
  648. * blk_rq_bytes() : bytes left in the entire request
  649. * blk_rq_cur_bytes() : bytes left in the current segment
  650. * blk_rq_err_bytes() : bytes left till the next error boundary
  651. * blk_rq_sectors() : sectors left in the entire request
  652. * blk_rq_cur_sectors() : sectors left in the current segment
  653. */
  654. static inline sector_t blk_rq_pos(const struct request *rq)
  655. {
  656. return rq->__sector;
  657. }
  658. static inline unsigned int blk_rq_bytes(const struct request *rq)
  659. {
  660. return rq->__data_len;
  661. }
  662. static inline int blk_rq_cur_bytes(const struct request *rq)
  663. {
  664. return rq->bio ? bio_cur_bytes(rq->bio) : 0;
  665. }
  666. extern unsigned int blk_rq_err_bytes(const struct request *rq);
  667. static inline unsigned int blk_rq_sectors(const struct request *rq)
  668. {
  669. return blk_rq_bytes(rq) >> 9;
  670. }
  671. static inline unsigned int blk_rq_cur_sectors(const struct request *rq)
  672. {
  673. return blk_rq_cur_bytes(rq) >> 9;
  674. }
  675. /*
  676. * Request issue related functions.
  677. */
  678. extern struct request *blk_peek_request(struct request_queue *q);
  679. extern void blk_start_request(struct request *rq);
  680. extern struct request *blk_fetch_request(struct request_queue *q);
  681. /*
  682. * Request completion related functions.
  683. *
  684. * blk_update_request() completes given number of bytes and updates
  685. * the request without completing it.
  686. *
  687. * blk_end_request() and friends. __blk_end_request() must be called
  688. * with the request queue spinlock acquired.
  689. *
  690. * Several drivers define their own end_request and call
  691. * blk_end_request() for parts of the original function.
  692. * This prevents code duplication in drivers.
  693. */
  694. extern bool blk_update_request(struct request *rq, int error,
  695. unsigned int nr_bytes);
  696. extern bool blk_end_request(struct request *rq, int error,
  697. unsigned int nr_bytes);
  698. extern void blk_end_request_all(struct request *rq, int error);
  699. extern bool blk_end_request_cur(struct request *rq, int error);
  700. extern bool blk_end_request_err(struct request *rq, int error);
  701. extern bool __blk_end_request(struct request *rq, int error,
  702. unsigned int nr_bytes);
  703. extern void __blk_end_request_all(struct request *rq, int error);
  704. extern bool __blk_end_request_cur(struct request *rq, int error);
  705. extern bool __blk_end_request_err(struct request *rq, int error);
  706. extern void blk_complete_request(struct request *);
  707. extern void __blk_complete_request(struct request *);
  708. extern void blk_abort_request(struct request *);
  709. extern void blk_abort_queue(struct request_queue *);
  710. extern void blk_unprep_request(struct request *);
  711. /*
  712. * Access functions for manipulating queue properties
  713. */
  714. extern struct request_queue *blk_init_queue_node(request_fn_proc *rfn,
  715. spinlock_t *lock, int node_id);
  716. extern struct request_queue *blk_init_allocated_queue_node(struct request_queue *,
  717. request_fn_proc *,
  718. spinlock_t *, int node_id);
  719. extern struct request_queue *blk_init_queue(request_fn_proc *, spinlock_t *);
  720. extern struct request_queue *blk_init_allocated_queue(struct request_queue *,
  721. request_fn_proc *, spinlock_t *);
  722. extern void blk_cleanup_queue(struct request_queue *);
  723. extern void blk_queue_make_request(struct request_queue *, make_request_fn *);
  724. extern void blk_queue_bounce_limit(struct request_queue *, u64);
  725. extern void blk_queue_max_hw_sectors(struct request_queue *, unsigned int);
  726. extern void blk_queue_max_segments(struct request_queue *, unsigned short);
  727. extern void blk_queue_max_segment_size(struct request_queue *, unsigned int);
  728. extern void blk_queue_max_discard_sectors(struct request_queue *q,
  729. unsigned int max_discard_sectors);
  730. extern void blk_queue_logical_block_size(struct request_queue *, unsigned short);
  731. extern void blk_queue_physical_block_size(struct request_queue *, unsigned short);
  732. extern void blk_queue_alignment_offset(struct request_queue *q,
  733. unsigned int alignment);
  734. extern void blk_limits_io_min(struct queue_limits *limits, unsigned int min);
  735. extern void blk_queue_io_min(struct request_queue *q, unsigned int min);
  736. extern void blk_limits_io_opt(struct queue_limits *limits, unsigned int opt);
  737. extern void blk_queue_io_opt(struct request_queue *q, unsigned int opt);
  738. extern void blk_set_default_limits(struct queue_limits *lim);
  739. extern int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
  740. sector_t offset);
  741. extern int bdev_stack_limits(struct queue_limits *t, struct block_device *bdev,
  742. sector_t offset);
  743. extern void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
  744. sector_t offset);
  745. extern void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b);
  746. extern void blk_queue_dma_pad(struct request_queue *, unsigned int);
  747. extern void blk_queue_update_dma_pad(struct request_queue *, unsigned int);
  748. extern int blk_queue_dma_drain(struct request_queue *q,
  749. dma_drain_needed_fn *dma_drain_needed,
  750. void *buf, unsigned int size);
  751. extern void blk_queue_lld_busy(struct request_queue *q, lld_busy_fn *fn);
  752. extern void blk_queue_segment_boundary(struct request_queue *, unsigned long);
  753. extern void blk_queue_prep_rq(struct request_queue *, prep_rq_fn *pfn);
  754. extern void blk_queue_unprep_rq(struct request_queue *, unprep_rq_fn *ufn);
  755. extern void blk_queue_merge_bvec(struct request_queue *, merge_bvec_fn *);
  756. extern void blk_queue_dma_alignment(struct request_queue *, int);
  757. extern void blk_queue_update_dma_alignment(struct request_queue *, int);
  758. extern void blk_queue_softirq_done(struct request_queue *, softirq_done_fn *);
  759. extern void blk_queue_rq_timed_out(struct request_queue *, rq_timed_out_fn *);
  760. extern void blk_queue_rq_timeout(struct request_queue *, unsigned int);
  761. extern struct backing_dev_info *blk_get_backing_dev_info(struct block_device *bdev);
  762. extern int blk_queue_ordered(struct request_queue *, unsigned);
  763. extern bool blk_do_ordered(struct request_queue *, struct request **);
  764. extern unsigned blk_ordered_cur_seq(struct request_queue *);
  765. extern unsigned blk_ordered_req_seq(struct request *);
  766. extern bool blk_ordered_complete_seq(struct request_queue *, unsigned, int);
  767. extern int blk_rq_map_sg(struct request_queue *, struct request *, struct scatterlist *);
  768. extern void blk_dump_rq_flags(struct request *, char *);
  769. extern void generic_unplug_device(struct request_queue *);
  770. extern long nr_blockdev_pages(void);
  771. int blk_get_queue(struct request_queue *);
  772. struct request_queue *blk_alloc_queue(gfp_t);
  773. struct request_queue *blk_alloc_queue_node(gfp_t, int);
  774. extern void blk_put_queue(struct request_queue *);
  775. /*
  776. * tag stuff
  777. */
  778. #define blk_rq_tagged(rq) ((rq)->cmd_flags & REQ_QUEUED)
  779. extern int blk_queue_start_tag(struct request_queue *, struct request *);
  780. extern struct request *blk_queue_find_tag(struct request_queue *, int);
  781. extern void blk_queue_end_tag(struct request_queue *, struct request *);
  782. extern int blk_queue_init_tags(struct request_queue *, int, struct blk_queue_tag *);
  783. extern void blk_queue_free_tags(struct request_queue *);
  784. extern int blk_queue_resize_tags(struct request_queue *, int);
  785. extern void blk_queue_invalidate_tags(struct request_queue *);
  786. extern struct blk_queue_tag *blk_init_tags(int);
  787. extern void blk_free_tags(struct blk_queue_tag *);
  788. static inline struct request *blk_map_queue_find_tag(struct blk_queue_tag *bqt,
  789. int tag)
  790. {
  791. if (unlikely(bqt == NULL || tag >= bqt->real_max_depth))
  792. return NULL;
  793. return bqt->tag_index[tag];
  794. }
  795. enum{
  796. BLKDEV_WAIT, /* wait for completion */
  797. BLKDEV_BARRIER, /* issue request with barrier */
  798. BLKDEV_SECURE, /* secure discard */
  799. };
  800. #define BLKDEV_IFL_WAIT (1 << BLKDEV_WAIT)
  801. #define BLKDEV_IFL_BARRIER (1 << BLKDEV_BARRIER)
  802. #define BLKDEV_IFL_SECURE (1 << BLKDEV_SECURE)
  803. extern int blkdev_issue_flush(struct block_device *, gfp_t, sector_t *,
  804. unsigned long);
  805. extern int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
  806. sector_t nr_sects, gfp_t gfp_mask, unsigned long flags);
  807. extern int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
  808. sector_t nr_sects, gfp_t gfp_mask, unsigned long flags);
  809. static inline int sb_issue_discard(struct super_block *sb,
  810. sector_t block, sector_t nr_blocks)
  811. {
  812. block <<= (sb->s_blocksize_bits - 9);
  813. nr_blocks <<= (sb->s_blocksize_bits - 9);
  814. return blkdev_issue_discard(sb->s_bdev, block, nr_blocks, GFP_NOFS,
  815. BLKDEV_IFL_WAIT | BLKDEV_IFL_BARRIER);
  816. }
  817. extern int blk_verify_command(unsigned char *cmd, fmode_t has_write_perm);
  818. enum blk_default_limits {
  819. BLK_MAX_SEGMENTS = 128,
  820. BLK_SAFE_MAX_SECTORS = 255,
  821. BLK_DEF_MAX_SECTORS = 1024,
  822. BLK_MAX_SEGMENT_SIZE = 65536,
  823. BLK_SEG_BOUNDARY_MASK = 0xFFFFFFFFUL,
  824. };
  825. #define blkdev_entry_to_request(entry) list_entry((entry), struct request, queuelist)
  826. static inline unsigned long queue_bounce_pfn(struct request_queue *q)
  827. {
  828. return q->limits.bounce_pfn;
  829. }
  830. static inline unsigned long queue_segment_boundary(struct request_queue *q)
  831. {
  832. return q->limits.seg_boundary_mask;
  833. }
  834. static inline unsigned int queue_max_sectors(struct request_queue *q)
  835. {
  836. return q->limits.max_sectors;
  837. }
  838. static inline unsigned int queue_max_hw_sectors(struct request_queue *q)
  839. {
  840. return q->limits.max_hw_sectors;
  841. }
  842. static inline unsigned short queue_max_segments(struct request_queue *q)
  843. {
  844. return q->limits.max_segments;
  845. }
  846. static inline unsigned int queue_max_segment_size(struct request_queue *q)
  847. {
  848. return q->limits.max_segment_size;
  849. }
  850. static inline unsigned short queue_logical_block_size(struct request_queue *q)
  851. {
  852. int retval = 512;
  853. if (q && q->limits.logical_block_size)
  854. retval = q->limits.logical_block_size;
  855. return retval;
  856. }
  857. static inline unsigned short bdev_logical_block_size(struct block_device *bdev)
  858. {
  859. return queue_logical_block_size(bdev_get_queue(bdev));
  860. }
  861. static inline unsigned int queue_physical_block_size(struct request_queue *q)
  862. {
  863. return q->limits.physical_block_size;
  864. }
  865. static inline int bdev_physical_block_size(struct block_device *bdev)
  866. {
  867. return queue_physical_block_size(bdev_get_queue(bdev));
  868. }
  869. static inline unsigned int queue_io_min(struct request_queue *q)
  870. {
  871. return q->limits.io_min;
  872. }
  873. static inline int bdev_io_min(struct block_device *bdev)
  874. {
  875. return queue_io_min(bdev_get_queue(bdev));
  876. }
  877. static inline unsigned int queue_io_opt(struct request_queue *q)
  878. {
  879. return q->limits.io_opt;
  880. }
  881. static inline int bdev_io_opt(struct block_device *bdev)
  882. {
  883. return queue_io_opt(bdev_get_queue(bdev));
  884. }
  885. static inline int queue_alignment_offset(struct request_queue *q)
  886. {
  887. if (q->limits.misaligned)
  888. return -1;
  889. return q->limits.alignment_offset;
  890. }
  891. static inline int queue_limit_alignment_offset(struct queue_limits *lim, sector_t sector)
  892. {
  893. unsigned int granularity = max(lim->physical_block_size, lim->io_min);
  894. unsigned int alignment = (sector << 9) & (granularity - 1);
  895. return (granularity + lim->alignment_offset - alignment)
  896. & (granularity - 1);
  897. }
  898. static inline int bdev_alignment_offset(struct block_device *bdev)
  899. {
  900. struct request_queue *q = bdev_get_queue(bdev);
  901. if (q->limits.misaligned)
  902. return -1;
  903. if (bdev != bdev->bd_contains)
  904. return bdev->bd_part->alignment_offset;
  905. return q->limits.alignment_offset;
  906. }
  907. static inline int queue_discard_alignment(struct request_queue *q)
  908. {
  909. if (q->limits.discard_misaligned)
  910. return -1;
  911. return q->limits.discard_alignment;
  912. }
  913. static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector_t sector)
  914. {
  915. unsigned int alignment = (sector << 9) & (lim->discard_granularity - 1);
  916. return (lim->discard_granularity + lim->discard_alignment - alignment)
  917. & (lim->discard_granularity - 1);
  918. }
  919. static inline unsigned int queue_discard_zeroes_data(struct request_queue *q)
  920. {
  921. if (q->limits.discard_zeroes_data == 1)
  922. return 1;
  923. return 0;
  924. }
  925. static inline unsigned int bdev_discard_zeroes_data(struct block_device *bdev)
  926. {
  927. return queue_discard_zeroes_data(bdev_get_queue(bdev));
  928. }
  929. static inline int queue_dma_alignment(struct request_queue *q)
  930. {
  931. return q ? q->dma_alignment : 511;
  932. }
  933. static inline int blk_rq_aligned(struct request_queue *q, void *addr,
  934. unsigned int len)
  935. {
  936. unsigned int alignment = queue_dma_alignment(q) | q->dma_pad_mask;
  937. return !((unsigned long)addr & alignment) && !(len & alignment);
  938. }
  939. /* assumes size > 256 */
  940. static inline unsigned int blksize_bits(unsigned int size)
  941. {
  942. unsigned int bits = 8;
  943. do {
  944. bits++;
  945. size >>= 1;
  946. } while (size > 256);
  947. return bits;
  948. }
  949. static inline unsigned int block_size(struct block_device *bdev)
  950. {
  951. return bdev->bd_block_size;
  952. }
  953. typedef struct {struct page *v;} Sector;
  954. unsigned char *read_dev_sector(struct block_device *, sector_t, Sector *);
  955. static inline void put_dev_sector(Sector p)
  956. {
  957. page_cache_release(p.v);
  958. }
  959. struct work_struct;
  960. int kblockd_schedule_work(struct request_queue *q, struct work_struct *work);
  961. #ifdef CONFIG_BLK_CGROUP
  962. /*
  963. * This should not be using sched_clock(). A real patch is in progress
  964. * to fix this up, until that is in place we need to disable preemption
  965. * around sched_clock() in this function and set_io_start_time_ns().
  966. */
  967. static inline void set_start_time_ns(struct request *req)
  968. {
  969. preempt_disable();
  970. req->start_time_ns = sched_clock();
  971. preempt_enable();
  972. }
  973. static inline void set_io_start_time_ns(struct request *req)
  974. {
  975. preempt_disable();
  976. req->io_start_time_ns = sched_clock();
  977. preempt_enable();
  978. }
  979. static inline uint64_t rq_start_time_ns(struct request *req)
  980. {
  981. return req->start_time_ns;
  982. }
  983. static inline uint64_t rq_io_start_time_ns(struct request *req)
  984. {
  985. return req->io_start_time_ns;
  986. }
  987. #else
  988. static inline void set_start_time_ns(struct request *req) {}
  989. static inline void set_io_start_time_ns(struct request *req) {}
  990. static inline uint64_t rq_start_time_ns(struct request *req)
  991. {
  992. return 0;
  993. }
  994. static inline uint64_t rq_io_start_time_ns(struct request *req)
  995. {
  996. return 0;
  997. }
  998. #endif
  999. #define MODULE_ALIAS_BLOCKDEV(major,minor) \
  1000. MODULE_ALIAS("block-major-" __stringify(major) "-" __stringify(minor))
  1001. #define MODULE_ALIAS_BLOCKDEV_MAJOR(major) \
  1002. MODULE_ALIAS("block-major-" __stringify(major) "-*")
  1003. #if defined(CONFIG_BLK_DEV_INTEGRITY)
  1004. #define INTEGRITY_FLAG_READ 2 /* verify data integrity on read */
  1005. #define INTEGRITY_FLAG_WRITE 4 /* generate data integrity on write */
  1006. struct blk_integrity_exchg {
  1007. void *prot_buf;
  1008. void *data_buf;
  1009. sector_t sector;
  1010. unsigned int data_size;
  1011. unsigned short sector_size;
  1012. const char *disk_name;
  1013. };
  1014. typedef void (integrity_gen_fn) (struct blk_integrity_exchg *);
  1015. typedef int (integrity_vrfy_fn) (struct blk_integrity_exchg *);
  1016. typedef void (integrity_set_tag_fn) (void *, void *, unsigned int);
  1017. typedef void (integrity_get_tag_fn) (void *, void *, unsigned int);
  1018. struct blk_integrity {
  1019. integrity_gen_fn *generate_fn;
  1020. integrity_vrfy_fn *verify_fn;
  1021. integrity_set_tag_fn *set_tag_fn;
  1022. integrity_get_tag_fn *get_tag_fn;
  1023. unsigned short flags;
  1024. unsigned short tuple_size;
  1025. unsigned short sector_size;
  1026. unsigned short tag_size;
  1027. const char *name;
  1028. struct kobject kobj;
  1029. };
  1030. extern int blk_integrity_register(struct gendisk *, struct blk_integrity *);
  1031. extern void blk_integrity_unregister(struct gendisk *);
  1032. extern int blk_integrity_compare(struct gendisk *, struct gendisk *);
  1033. extern int blk_rq_map_integrity_sg(struct request *, struct scatterlist *);
  1034. extern int blk_rq_count_integrity_sg(struct request *);
  1035. static inline
  1036. struct blk_integrity *bdev_get_integrity(struct block_device *bdev)
  1037. {
  1038. return bdev->bd_disk->integrity;
  1039. }
  1040. static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk)
  1041. {
  1042. return disk->integrity;
  1043. }
  1044. static inline int blk_integrity_rq(struct request *rq)
  1045. {
  1046. if (rq->bio == NULL)
  1047. return 0;
  1048. return bio_integrity(rq->bio);
  1049. }
  1050. #else /* CONFIG_BLK_DEV_INTEGRITY */
  1051. #define blk_integrity_rq(rq) (0)
  1052. #define blk_rq_count_integrity_sg(a) (0)
  1053. #define blk_rq_map_integrity_sg(a, b) (0)
  1054. #define bdev_get_integrity(a) (0)
  1055. #define blk_get_integrity(a) (0)
  1056. #define blk_integrity_compare(a, b) (0)
  1057. #define blk_integrity_register(a, b) (0)
  1058. #define blk_integrity_unregister(a) do { } while (0);
  1059. #endif /* CONFIG_BLK_DEV_INTEGRITY */
  1060. struct block_device_operations {
  1061. int (*open) (struct block_device *, fmode_t);
  1062. int (*release) (struct gendisk *, fmode_t);
  1063. int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
  1064. int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
  1065. int (*direct_access) (struct block_device *, sector_t,
  1066. void **, unsigned long *);
  1067. int (*media_changed) (struct gendisk *);
  1068. void (*unlock_native_capacity) (struct gendisk *);
  1069. int (*revalidate_disk) (struct gendisk *);
  1070. int (*getgeo)(struct block_device *, struct hd_geometry *);
  1071. /* this callback is with swap_lock and sometimes page table lock held */
  1072. void (*swap_slot_free_notify) (struct block_device *, unsigned long);
  1073. struct module *owner;
  1074. };
  1075. extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
  1076. unsigned long);
  1077. #else /* CONFIG_BLOCK */
  1078. /*
  1079. * stubs for when the block layer is configured out
  1080. */
  1081. #define buffer_heads_over_limit 0
  1082. static inline long nr_blockdev_pages(void)
  1083. {
  1084. return 0;
  1085. }
  1086. #endif /* CONFIG_BLOCK */
  1087. #endif