blkdev.h 38 KB

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