blkdev.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266
  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. */
  397. QUEUE_ORDERED_DO_PREFLUSH = 0x10,
  398. QUEUE_ORDERED_DO_BAR = 0x20,
  399. QUEUE_ORDERED_DO_POSTFLUSH = 0x40,
  400. QUEUE_ORDERED_DO_FUA = 0x80,
  401. QUEUE_ORDERED_NONE = 0x00,
  402. QUEUE_ORDERED_DRAIN = QUEUE_ORDERED_DO_BAR,
  403. QUEUE_ORDERED_DRAIN_FLUSH = QUEUE_ORDERED_DRAIN |
  404. QUEUE_ORDERED_DO_PREFLUSH |
  405. QUEUE_ORDERED_DO_POSTFLUSH,
  406. QUEUE_ORDERED_DRAIN_FUA = QUEUE_ORDERED_DRAIN |
  407. QUEUE_ORDERED_DO_PREFLUSH |
  408. QUEUE_ORDERED_DO_FUA,
  409. /*
  410. * Ordered operation sequence
  411. */
  412. QUEUE_ORDSEQ_STARTED = 0x01, /* flushing in progress */
  413. QUEUE_ORDSEQ_DRAIN = 0x02, /* waiting for the queue to be drained */
  414. QUEUE_ORDSEQ_PREFLUSH = 0x04, /* pre-flushing in progress */
  415. QUEUE_ORDSEQ_BAR = 0x08, /* original barrier req in progress */
  416. QUEUE_ORDSEQ_POSTFLUSH = 0x10, /* post-flushing in progress */
  417. QUEUE_ORDSEQ_DONE = 0x20,
  418. };
  419. #define blk_queue_plugged(q) test_bit(QUEUE_FLAG_PLUGGED, &(q)->queue_flags)
  420. #define blk_queue_tagged(q) test_bit(QUEUE_FLAG_QUEUED, &(q)->queue_flags)
  421. #define blk_queue_stopped(q) test_bit(QUEUE_FLAG_STOPPED, &(q)->queue_flags)
  422. #define blk_queue_nomerges(q) test_bit(QUEUE_FLAG_NOMERGES, &(q)->queue_flags)
  423. #define blk_queue_noxmerges(q) \
  424. test_bit(QUEUE_FLAG_NOXMERGES, &(q)->queue_flags)
  425. #define blk_queue_nonrot(q) test_bit(QUEUE_FLAG_NONROT, &(q)->queue_flags)
  426. #define blk_queue_io_stat(q) test_bit(QUEUE_FLAG_IO_STAT, &(q)->queue_flags)
  427. #define blk_queue_add_random(q) test_bit(QUEUE_FLAG_ADD_RANDOM, &(q)->queue_flags)
  428. #define blk_queue_stackable(q) \
  429. test_bit(QUEUE_FLAG_STACKABLE, &(q)->queue_flags)
  430. #define blk_queue_discard(q) test_bit(QUEUE_FLAG_DISCARD, &(q)->queue_flags)
  431. #define blk_queue_secdiscard(q) (blk_queue_discard(q) && \
  432. test_bit(QUEUE_FLAG_SECDISCARD, &(q)->queue_flags))
  433. #define blk_noretry_request(rq) \
  434. ((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \
  435. REQ_FAILFAST_DRIVER))
  436. #define blk_account_rq(rq) \
  437. (((rq)->cmd_flags & REQ_STARTED) && \
  438. ((rq)->cmd_type == REQ_TYPE_FS || \
  439. ((rq)->cmd_flags & REQ_DISCARD)))
  440. #define blk_pm_request(rq) \
  441. ((rq)->cmd_type == REQ_TYPE_PM_SUSPEND || \
  442. (rq)->cmd_type == REQ_TYPE_PM_RESUME)
  443. #define blk_rq_cpu_valid(rq) ((rq)->cpu != -1)
  444. #define blk_bidi_rq(rq) ((rq)->next_rq != NULL)
  445. /* rq->queuelist of dequeued request must be list_empty() */
  446. #define blk_queued_rq(rq) (!list_empty(&(rq)->queuelist))
  447. #define list_entry_rq(ptr) list_entry((ptr), struct request, queuelist)
  448. #define rq_data_dir(rq) ((rq)->cmd_flags & 1)
  449. /*
  450. * We regard a request as sync, if either a read or a sync write
  451. */
  452. static inline bool rw_is_sync(unsigned int rw_flags)
  453. {
  454. return !(rw_flags & REQ_WRITE) || (rw_flags & REQ_SYNC);
  455. }
  456. static inline bool rq_is_sync(struct request *rq)
  457. {
  458. return rw_is_sync(rq->cmd_flags);
  459. }
  460. static inline int blk_queue_full(struct request_queue *q, int sync)
  461. {
  462. if (sync)
  463. return test_bit(QUEUE_FLAG_SYNCFULL, &q->queue_flags);
  464. return test_bit(QUEUE_FLAG_ASYNCFULL, &q->queue_flags);
  465. }
  466. static inline void blk_set_queue_full(struct request_queue *q, int sync)
  467. {
  468. if (sync)
  469. queue_flag_set(QUEUE_FLAG_SYNCFULL, q);
  470. else
  471. queue_flag_set(QUEUE_FLAG_ASYNCFULL, q);
  472. }
  473. static inline void blk_clear_queue_full(struct request_queue *q, int sync)
  474. {
  475. if (sync)
  476. queue_flag_clear(QUEUE_FLAG_SYNCFULL, q);
  477. else
  478. queue_flag_clear(QUEUE_FLAG_ASYNCFULL, q);
  479. }
  480. /*
  481. * mergeable request must not have _NOMERGE or _BARRIER bit set, nor may
  482. * it already be started by driver.
  483. */
  484. #define RQ_NOMERGE_FLAGS \
  485. (REQ_NOMERGE | REQ_STARTED | REQ_HARDBARRIER | REQ_SOFTBARRIER)
  486. #define rq_mergeable(rq) \
  487. (!((rq)->cmd_flags & RQ_NOMERGE_FLAGS) && \
  488. (((rq)->cmd_flags & REQ_DISCARD) || \
  489. (rq)->cmd_type == REQ_TYPE_FS))
  490. /*
  491. * q->prep_rq_fn return values
  492. */
  493. #define BLKPREP_OK 0 /* serve it */
  494. #define BLKPREP_KILL 1 /* fatal error, kill */
  495. #define BLKPREP_DEFER 2 /* leave on queue */
  496. extern unsigned long blk_max_low_pfn, blk_max_pfn;
  497. /*
  498. * standard bounce addresses:
  499. *
  500. * BLK_BOUNCE_HIGH : bounce all highmem pages
  501. * BLK_BOUNCE_ANY : don't bounce anything
  502. * BLK_BOUNCE_ISA : bounce pages above ISA DMA boundary
  503. */
  504. #if BITS_PER_LONG == 32
  505. #define BLK_BOUNCE_HIGH ((u64)blk_max_low_pfn << PAGE_SHIFT)
  506. #else
  507. #define BLK_BOUNCE_HIGH -1ULL
  508. #endif
  509. #define BLK_BOUNCE_ANY (-1ULL)
  510. #define BLK_BOUNCE_ISA (DMA_BIT_MASK(24))
  511. /*
  512. * default timeout for SG_IO if none specified
  513. */
  514. #define BLK_DEFAULT_SG_TIMEOUT (60 * HZ)
  515. #define BLK_MIN_SG_TIMEOUT (7 * HZ)
  516. #ifdef CONFIG_BOUNCE
  517. extern int init_emergency_isa_pool(void);
  518. extern void blk_queue_bounce(struct request_queue *q, struct bio **bio);
  519. #else
  520. static inline int init_emergency_isa_pool(void)
  521. {
  522. return 0;
  523. }
  524. static inline void blk_queue_bounce(struct request_queue *q, struct bio **bio)
  525. {
  526. }
  527. #endif /* CONFIG_MMU */
  528. struct rq_map_data {
  529. struct page **pages;
  530. int page_order;
  531. int nr_entries;
  532. unsigned long offset;
  533. int null_mapped;
  534. int from_user;
  535. };
  536. struct req_iterator {
  537. int i;
  538. struct bio *bio;
  539. };
  540. /* This should not be used directly - use rq_for_each_segment */
  541. #define for_each_bio(_bio) \
  542. for (; _bio; _bio = _bio->bi_next)
  543. #define __rq_for_each_bio(_bio, rq) \
  544. if ((rq->bio)) \
  545. for (_bio = (rq)->bio; _bio; _bio = _bio->bi_next)
  546. #define rq_for_each_segment(bvl, _rq, _iter) \
  547. __rq_for_each_bio(_iter.bio, _rq) \
  548. bio_for_each_segment(bvl, _iter.bio, _iter.i)
  549. #define rq_iter_last(rq, _iter) \
  550. (_iter.bio->bi_next == NULL && _iter.i == _iter.bio->bi_vcnt-1)
  551. #ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
  552. # error "You should define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE for your platform"
  553. #endif
  554. #if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
  555. extern void rq_flush_dcache_pages(struct request *rq);
  556. #else
  557. static inline void rq_flush_dcache_pages(struct request *rq)
  558. {
  559. }
  560. #endif
  561. extern int blk_register_queue(struct gendisk *disk);
  562. extern void blk_unregister_queue(struct gendisk *disk);
  563. extern void register_disk(struct gendisk *dev);
  564. extern void generic_make_request(struct bio *bio);
  565. extern void blk_rq_init(struct request_queue *q, struct request *rq);
  566. extern void blk_put_request(struct request *);
  567. extern void __blk_put_request(struct request_queue *, struct request *);
  568. extern struct request *blk_get_request(struct request_queue *, int, gfp_t);
  569. extern struct request *blk_make_request(struct request_queue *, struct bio *,
  570. gfp_t);
  571. extern void blk_insert_request(struct request_queue *, struct request *, int, void *);
  572. extern void blk_requeue_request(struct request_queue *, struct request *);
  573. extern void blk_add_request_payload(struct request *rq, struct page *page,
  574. unsigned int len);
  575. extern int blk_rq_check_limits(struct request_queue *q, struct request *rq);
  576. extern int blk_lld_busy(struct request_queue *q);
  577. extern int blk_rq_prep_clone(struct request *rq, struct request *rq_src,
  578. struct bio_set *bs, gfp_t gfp_mask,
  579. int (*bio_ctr)(struct bio *, struct bio *, void *),
  580. void *data);
  581. extern void blk_rq_unprep_clone(struct request *rq);
  582. extern int blk_insert_cloned_request(struct request_queue *q,
  583. struct request *rq);
  584. extern void blk_plug_device(struct request_queue *);
  585. extern void blk_plug_device_unlocked(struct request_queue *);
  586. extern int blk_remove_plug(struct request_queue *);
  587. extern void blk_recount_segments(struct request_queue *, struct bio *);
  588. extern int scsi_cmd_ioctl(struct request_queue *, struct gendisk *, fmode_t,
  589. unsigned int, void __user *);
  590. extern int sg_scsi_ioctl(struct request_queue *, struct gendisk *, fmode_t,
  591. struct scsi_ioctl_command __user *);
  592. /*
  593. * A queue has just exitted congestion. Note this in the global counter of
  594. * congested queues, and wake up anyone who was waiting for requests to be
  595. * put back.
  596. */
  597. static inline void blk_clear_queue_congested(struct request_queue *q, int sync)
  598. {
  599. clear_bdi_congested(&q->backing_dev_info, sync);
  600. }
  601. /*
  602. * A queue has just entered congestion. Flag that in the queue's VM-visible
  603. * state flags and increment the global gounter of congested queues.
  604. */
  605. static inline void blk_set_queue_congested(struct request_queue *q, int sync)
  606. {
  607. set_bdi_congested(&q->backing_dev_info, sync);
  608. }
  609. extern void blk_start_queue(struct request_queue *q);
  610. extern void blk_stop_queue(struct request_queue *q);
  611. extern void blk_sync_queue(struct request_queue *q);
  612. extern void __blk_stop_queue(struct request_queue *q);
  613. extern void __blk_run_queue(struct request_queue *);
  614. extern void blk_run_queue(struct request_queue *);
  615. extern int blk_rq_map_user(struct request_queue *, struct request *,
  616. struct rq_map_data *, void __user *, unsigned long,
  617. gfp_t);
  618. extern int blk_rq_unmap_user(struct bio *);
  619. extern int blk_rq_map_kern(struct request_queue *, struct request *, void *, unsigned int, gfp_t);
  620. extern int blk_rq_map_user_iov(struct request_queue *, struct request *,
  621. struct rq_map_data *, struct sg_iovec *, int,
  622. unsigned int, gfp_t);
  623. extern int blk_execute_rq(struct request_queue *, struct gendisk *,
  624. struct request *, int);
  625. extern void blk_execute_rq_nowait(struct request_queue *, struct gendisk *,
  626. struct request *, int, rq_end_io_fn *);
  627. extern void blk_unplug(struct request_queue *q);
  628. static inline struct request_queue *bdev_get_queue(struct block_device *bdev)
  629. {
  630. return bdev->bd_disk->queue;
  631. }
  632. /*
  633. * blk_rq_pos() : the current sector
  634. * blk_rq_bytes() : bytes left in the entire request
  635. * blk_rq_cur_bytes() : bytes left in the current segment
  636. * blk_rq_err_bytes() : bytes left till the next error boundary
  637. * blk_rq_sectors() : sectors left in the entire request
  638. * blk_rq_cur_sectors() : sectors left in the current segment
  639. */
  640. static inline sector_t blk_rq_pos(const struct request *rq)
  641. {
  642. return rq->__sector;
  643. }
  644. static inline unsigned int blk_rq_bytes(const struct request *rq)
  645. {
  646. return rq->__data_len;
  647. }
  648. static inline int blk_rq_cur_bytes(const struct request *rq)
  649. {
  650. return rq->bio ? bio_cur_bytes(rq->bio) : 0;
  651. }
  652. extern unsigned int blk_rq_err_bytes(const struct request *rq);
  653. static inline unsigned int blk_rq_sectors(const struct request *rq)
  654. {
  655. return blk_rq_bytes(rq) >> 9;
  656. }
  657. static inline unsigned int blk_rq_cur_sectors(const struct request *rq)
  658. {
  659. return blk_rq_cur_bytes(rq) >> 9;
  660. }
  661. /*
  662. * Request issue related functions.
  663. */
  664. extern struct request *blk_peek_request(struct request_queue *q);
  665. extern void blk_start_request(struct request *rq);
  666. extern struct request *blk_fetch_request(struct request_queue *q);
  667. /*
  668. * Request completion related functions.
  669. *
  670. * blk_update_request() completes given number of bytes and updates
  671. * the request without completing it.
  672. *
  673. * blk_end_request() and friends. __blk_end_request() must be called
  674. * with the request queue spinlock acquired.
  675. *
  676. * Several drivers define their own end_request and call
  677. * blk_end_request() for parts of the original function.
  678. * This prevents code duplication in drivers.
  679. */
  680. extern bool blk_update_request(struct request *rq, int error,
  681. unsigned int nr_bytes);
  682. extern bool blk_end_request(struct request *rq, int error,
  683. unsigned int nr_bytes);
  684. extern void blk_end_request_all(struct request *rq, int error);
  685. extern bool blk_end_request_cur(struct request *rq, int error);
  686. extern bool blk_end_request_err(struct request *rq, int error);
  687. extern bool __blk_end_request(struct request *rq, int error,
  688. unsigned int nr_bytes);
  689. extern void __blk_end_request_all(struct request *rq, int error);
  690. extern bool __blk_end_request_cur(struct request *rq, int error);
  691. extern bool __blk_end_request_err(struct request *rq, int error);
  692. extern void blk_complete_request(struct request *);
  693. extern void __blk_complete_request(struct request *);
  694. extern void blk_abort_request(struct request *);
  695. extern void blk_abort_queue(struct request_queue *);
  696. extern void blk_unprep_request(struct request *);
  697. /*
  698. * Access functions for manipulating queue properties
  699. */
  700. extern struct request_queue *blk_init_queue_node(request_fn_proc *rfn,
  701. spinlock_t *lock, int node_id);
  702. extern struct request_queue *blk_init_allocated_queue_node(struct request_queue *,
  703. request_fn_proc *,
  704. spinlock_t *, int node_id);
  705. extern struct request_queue *blk_init_queue(request_fn_proc *, spinlock_t *);
  706. extern struct request_queue *blk_init_allocated_queue(struct request_queue *,
  707. request_fn_proc *, spinlock_t *);
  708. extern void blk_cleanup_queue(struct request_queue *);
  709. extern void blk_queue_make_request(struct request_queue *, make_request_fn *);
  710. extern void blk_queue_bounce_limit(struct request_queue *, u64);
  711. extern void blk_queue_max_hw_sectors(struct request_queue *, unsigned int);
  712. extern void blk_queue_max_segments(struct request_queue *, unsigned short);
  713. extern void blk_queue_max_segment_size(struct request_queue *, unsigned int);
  714. extern void blk_queue_max_discard_sectors(struct request_queue *q,
  715. unsigned int max_discard_sectors);
  716. extern void blk_queue_logical_block_size(struct request_queue *, unsigned short);
  717. extern void blk_queue_physical_block_size(struct request_queue *, unsigned short);
  718. extern void blk_queue_alignment_offset(struct request_queue *q,
  719. unsigned int alignment);
  720. extern void blk_limits_io_min(struct queue_limits *limits, unsigned int min);
  721. extern void blk_queue_io_min(struct request_queue *q, unsigned int min);
  722. extern void blk_limits_io_opt(struct queue_limits *limits, unsigned int opt);
  723. extern void blk_queue_io_opt(struct request_queue *q, unsigned int opt);
  724. extern void blk_set_default_limits(struct queue_limits *lim);
  725. extern int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
  726. sector_t offset);
  727. extern int bdev_stack_limits(struct queue_limits *t, struct block_device *bdev,
  728. sector_t offset);
  729. extern void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
  730. sector_t offset);
  731. extern void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b);
  732. extern void blk_queue_dma_pad(struct request_queue *, unsigned int);
  733. extern void blk_queue_update_dma_pad(struct request_queue *, unsigned int);
  734. extern int blk_queue_dma_drain(struct request_queue *q,
  735. dma_drain_needed_fn *dma_drain_needed,
  736. void *buf, unsigned int size);
  737. extern void blk_queue_lld_busy(struct request_queue *q, lld_busy_fn *fn);
  738. extern void blk_queue_segment_boundary(struct request_queue *, unsigned long);
  739. extern void blk_queue_prep_rq(struct request_queue *, prep_rq_fn *pfn);
  740. extern void blk_queue_unprep_rq(struct request_queue *, unprep_rq_fn *ufn);
  741. extern void blk_queue_merge_bvec(struct request_queue *, merge_bvec_fn *);
  742. extern void blk_queue_dma_alignment(struct request_queue *, int);
  743. extern void blk_queue_update_dma_alignment(struct request_queue *, int);
  744. extern void blk_queue_softirq_done(struct request_queue *, softirq_done_fn *);
  745. extern void blk_queue_rq_timed_out(struct request_queue *, rq_timed_out_fn *);
  746. extern void blk_queue_rq_timeout(struct request_queue *, unsigned int);
  747. extern struct backing_dev_info *blk_get_backing_dev_info(struct block_device *bdev);
  748. extern int blk_queue_ordered(struct request_queue *, unsigned);
  749. extern bool blk_do_ordered(struct request_queue *, struct request **);
  750. extern unsigned blk_ordered_cur_seq(struct request_queue *);
  751. extern unsigned blk_ordered_req_seq(struct request *);
  752. extern bool blk_ordered_complete_seq(struct request_queue *, unsigned, int);
  753. extern int blk_rq_map_sg(struct request_queue *, struct request *, struct scatterlist *);
  754. extern void blk_dump_rq_flags(struct request *, char *);
  755. extern void generic_unplug_device(struct request_queue *);
  756. extern long nr_blockdev_pages(void);
  757. int blk_get_queue(struct request_queue *);
  758. struct request_queue *blk_alloc_queue(gfp_t);
  759. struct request_queue *blk_alloc_queue_node(gfp_t, int);
  760. extern void blk_put_queue(struct request_queue *);
  761. /*
  762. * tag stuff
  763. */
  764. #define blk_rq_tagged(rq) ((rq)->cmd_flags & REQ_QUEUED)
  765. extern int blk_queue_start_tag(struct request_queue *, struct request *);
  766. extern struct request *blk_queue_find_tag(struct request_queue *, int);
  767. extern void blk_queue_end_tag(struct request_queue *, struct request *);
  768. extern int blk_queue_init_tags(struct request_queue *, int, struct blk_queue_tag *);
  769. extern void blk_queue_free_tags(struct request_queue *);
  770. extern int blk_queue_resize_tags(struct request_queue *, int);
  771. extern void blk_queue_invalidate_tags(struct request_queue *);
  772. extern struct blk_queue_tag *blk_init_tags(int);
  773. extern void blk_free_tags(struct blk_queue_tag *);
  774. static inline struct request *blk_map_queue_find_tag(struct blk_queue_tag *bqt,
  775. int tag)
  776. {
  777. if (unlikely(bqt == NULL || tag >= bqt->real_max_depth))
  778. return NULL;
  779. return bqt->tag_index[tag];
  780. }
  781. enum{
  782. BLKDEV_WAIT, /* wait for completion */
  783. BLKDEV_BARRIER, /* issue request with barrier */
  784. BLKDEV_SECURE, /* secure discard */
  785. };
  786. #define BLKDEV_IFL_WAIT (1 << BLKDEV_WAIT)
  787. #define BLKDEV_IFL_BARRIER (1 << BLKDEV_BARRIER)
  788. #define BLKDEV_IFL_SECURE (1 << BLKDEV_SECURE)
  789. extern int blkdev_issue_flush(struct block_device *, gfp_t, sector_t *,
  790. unsigned long);
  791. extern int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
  792. sector_t nr_sects, gfp_t gfp_mask, unsigned long flags);
  793. extern int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
  794. sector_t nr_sects, gfp_t gfp_mask, unsigned long flags);
  795. static inline int sb_issue_discard(struct super_block *sb,
  796. sector_t block, sector_t nr_blocks)
  797. {
  798. block <<= (sb->s_blocksize_bits - 9);
  799. nr_blocks <<= (sb->s_blocksize_bits - 9);
  800. return blkdev_issue_discard(sb->s_bdev, block, nr_blocks, GFP_NOFS,
  801. BLKDEV_IFL_WAIT | BLKDEV_IFL_BARRIER);
  802. }
  803. extern int blk_verify_command(unsigned char *cmd, fmode_t has_write_perm);
  804. enum blk_default_limits {
  805. BLK_MAX_SEGMENTS = 128,
  806. BLK_SAFE_MAX_SECTORS = 255,
  807. BLK_DEF_MAX_SECTORS = 1024,
  808. BLK_MAX_SEGMENT_SIZE = 65536,
  809. BLK_SEG_BOUNDARY_MASK = 0xFFFFFFFFUL,
  810. };
  811. #define blkdev_entry_to_request(entry) list_entry((entry), struct request, queuelist)
  812. static inline unsigned long queue_bounce_pfn(struct request_queue *q)
  813. {
  814. return q->limits.bounce_pfn;
  815. }
  816. static inline unsigned long queue_segment_boundary(struct request_queue *q)
  817. {
  818. return q->limits.seg_boundary_mask;
  819. }
  820. static inline unsigned int queue_max_sectors(struct request_queue *q)
  821. {
  822. return q->limits.max_sectors;
  823. }
  824. static inline unsigned int queue_max_hw_sectors(struct request_queue *q)
  825. {
  826. return q->limits.max_hw_sectors;
  827. }
  828. static inline unsigned short queue_max_segments(struct request_queue *q)
  829. {
  830. return q->limits.max_segments;
  831. }
  832. static inline unsigned int queue_max_segment_size(struct request_queue *q)
  833. {
  834. return q->limits.max_segment_size;
  835. }
  836. static inline unsigned short queue_logical_block_size(struct request_queue *q)
  837. {
  838. int retval = 512;
  839. if (q && q->limits.logical_block_size)
  840. retval = q->limits.logical_block_size;
  841. return retval;
  842. }
  843. static inline unsigned short bdev_logical_block_size(struct block_device *bdev)
  844. {
  845. return queue_logical_block_size(bdev_get_queue(bdev));
  846. }
  847. static inline unsigned int queue_physical_block_size(struct request_queue *q)
  848. {
  849. return q->limits.physical_block_size;
  850. }
  851. static inline int bdev_physical_block_size(struct block_device *bdev)
  852. {
  853. return queue_physical_block_size(bdev_get_queue(bdev));
  854. }
  855. static inline unsigned int queue_io_min(struct request_queue *q)
  856. {
  857. return q->limits.io_min;
  858. }
  859. static inline int bdev_io_min(struct block_device *bdev)
  860. {
  861. return queue_io_min(bdev_get_queue(bdev));
  862. }
  863. static inline unsigned int queue_io_opt(struct request_queue *q)
  864. {
  865. return q->limits.io_opt;
  866. }
  867. static inline int bdev_io_opt(struct block_device *bdev)
  868. {
  869. return queue_io_opt(bdev_get_queue(bdev));
  870. }
  871. static inline int queue_alignment_offset(struct request_queue *q)
  872. {
  873. if (q->limits.misaligned)
  874. return -1;
  875. return q->limits.alignment_offset;
  876. }
  877. static inline int queue_limit_alignment_offset(struct queue_limits *lim, sector_t sector)
  878. {
  879. unsigned int granularity = max(lim->physical_block_size, lim->io_min);
  880. unsigned int alignment = (sector << 9) & (granularity - 1);
  881. return (granularity + lim->alignment_offset - alignment)
  882. & (granularity - 1);
  883. }
  884. static inline int bdev_alignment_offset(struct block_device *bdev)
  885. {
  886. struct request_queue *q = bdev_get_queue(bdev);
  887. if (q->limits.misaligned)
  888. return -1;
  889. if (bdev != bdev->bd_contains)
  890. return bdev->bd_part->alignment_offset;
  891. return q->limits.alignment_offset;
  892. }
  893. static inline int queue_discard_alignment(struct request_queue *q)
  894. {
  895. if (q->limits.discard_misaligned)
  896. return -1;
  897. return q->limits.discard_alignment;
  898. }
  899. static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector_t sector)
  900. {
  901. unsigned int alignment = (sector << 9) & (lim->discard_granularity - 1);
  902. return (lim->discard_granularity + lim->discard_alignment - alignment)
  903. & (lim->discard_granularity - 1);
  904. }
  905. static inline unsigned int queue_discard_zeroes_data(struct request_queue *q)
  906. {
  907. if (q->limits.discard_zeroes_data == 1)
  908. return 1;
  909. return 0;
  910. }
  911. static inline unsigned int bdev_discard_zeroes_data(struct block_device *bdev)
  912. {
  913. return queue_discard_zeroes_data(bdev_get_queue(bdev));
  914. }
  915. static inline int queue_dma_alignment(struct request_queue *q)
  916. {
  917. return q ? q->dma_alignment : 511;
  918. }
  919. static inline int blk_rq_aligned(struct request_queue *q, void *addr,
  920. unsigned int len)
  921. {
  922. unsigned int alignment = queue_dma_alignment(q) | q->dma_pad_mask;
  923. return !((unsigned long)addr & alignment) && !(len & alignment);
  924. }
  925. /* assumes size > 256 */
  926. static inline unsigned int blksize_bits(unsigned int size)
  927. {
  928. unsigned int bits = 8;
  929. do {
  930. bits++;
  931. size >>= 1;
  932. } while (size > 256);
  933. return bits;
  934. }
  935. static inline unsigned int block_size(struct block_device *bdev)
  936. {
  937. return bdev->bd_block_size;
  938. }
  939. typedef struct {struct page *v;} Sector;
  940. unsigned char *read_dev_sector(struct block_device *, sector_t, Sector *);
  941. static inline void put_dev_sector(Sector p)
  942. {
  943. page_cache_release(p.v);
  944. }
  945. struct work_struct;
  946. int kblockd_schedule_work(struct request_queue *q, struct work_struct *work);
  947. #ifdef CONFIG_BLK_CGROUP
  948. /*
  949. * This should not be using sched_clock(). A real patch is in progress
  950. * to fix this up, until that is in place we need to disable preemption
  951. * around sched_clock() in this function and set_io_start_time_ns().
  952. */
  953. static inline void set_start_time_ns(struct request *req)
  954. {
  955. preempt_disable();
  956. req->start_time_ns = sched_clock();
  957. preempt_enable();
  958. }
  959. static inline void set_io_start_time_ns(struct request *req)
  960. {
  961. preempt_disable();
  962. req->io_start_time_ns = sched_clock();
  963. preempt_enable();
  964. }
  965. static inline uint64_t rq_start_time_ns(struct request *req)
  966. {
  967. return req->start_time_ns;
  968. }
  969. static inline uint64_t rq_io_start_time_ns(struct request *req)
  970. {
  971. return req->io_start_time_ns;
  972. }
  973. #else
  974. static inline void set_start_time_ns(struct request *req) {}
  975. static inline void set_io_start_time_ns(struct request *req) {}
  976. static inline uint64_t rq_start_time_ns(struct request *req)
  977. {
  978. return 0;
  979. }
  980. static inline uint64_t rq_io_start_time_ns(struct request *req)
  981. {
  982. return 0;
  983. }
  984. #endif
  985. #define MODULE_ALIAS_BLOCKDEV(major,minor) \
  986. MODULE_ALIAS("block-major-" __stringify(major) "-" __stringify(minor))
  987. #define MODULE_ALIAS_BLOCKDEV_MAJOR(major) \
  988. MODULE_ALIAS("block-major-" __stringify(major) "-*")
  989. #if defined(CONFIG_BLK_DEV_INTEGRITY)
  990. #define INTEGRITY_FLAG_READ 2 /* verify data integrity on read */
  991. #define INTEGRITY_FLAG_WRITE 4 /* generate data integrity on write */
  992. struct blk_integrity_exchg {
  993. void *prot_buf;
  994. void *data_buf;
  995. sector_t sector;
  996. unsigned int data_size;
  997. unsigned short sector_size;
  998. const char *disk_name;
  999. };
  1000. typedef void (integrity_gen_fn) (struct blk_integrity_exchg *);
  1001. typedef int (integrity_vrfy_fn) (struct blk_integrity_exchg *);
  1002. typedef void (integrity_set_tag_fn) (void *, void *, unsigned int);
  1003. typedef void (integrity_get_tag_fn) (void *, void *, unsigned int);
  1004. struct blk_integrity {
  1005. integrity_gen_fn *generate_fn;
  1006. integrity_vrfy_fn *verify_fn;
  1007. integrity_set_tag_fn *set_tag_fn;
  1008. integrity_get_tag_fn *get_tag_fn;
  1009. unsigned short flags;
  1010. unsigned short tuple_size;
  1011. unsigned short sector_size;
  1012. unsigned short tag_size;
  1013. const char *name;
  1014. struct kobject kobj;
  1015. };
  1016. extern int blk_integrity_register(struct gendisk *, struct blk_integrity *);
  1017. extern void blk_integrity_unregister(struct gendisk *);
  1018. extern int blk_integrity_compare(struct gendisk *, struct gendisk *);
  1019. extern int blk_rq_map_integrity_sg(struct request *, struct scatterlist *);
  1020. extern int blk_rq_count_integrity_sg(struct request *);
  1021. static inline
  1022. struct blk_integrity *bdev_get_integrity(struct block_device *bdev)
  1023. {
  1024. return bdev->bd_disk->integrity;
  1025. }
  1026. static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk)
  1027. {
  1028. return disk->integrity;
  1029. }
  1030. static inline int blk_integrity_rq(struct request *rq)
  1031. {
  1032. if (rq->bio == NULL)
  1033. return 0;
  1034. return bio_integrity(rq->bio);
  1035. }
  1036. #else /* CONFIG_BLK_DEV_INTEGRITY */
  1037. #define blk_integrity_rq(rq) (0)
  1038. #define blk_rq_count_integrity_sg(a) (0)
  1039. #define blk_rq_map_integrity_sg(a, b) (0)
  1040. #define bdev_get_integrity(a) (0)
  1041. #define blk_get_integrity(a) (0)
  1042. #define blk_integrity_compare(a, b) (0)
  1043. #define blk_integrity_register(a, b) (0)
  1044. #define blk_integrity_unregister(a) do { } while (0);
  1045. #endif /* CONFIG_BLK_DEV_INTEGRITY */
  1046. struct block_device_operations {
  1047. int (*open) (struct block_device *, fmode_t);
  1048. int (*release) (struct gendisk *, fmode_t);
  1049. int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
  1050. int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
  1051. int (*direct_access) (struct block_device *, sector_t,
  1052. void **, unsigned long *);
  1053. int (*media_changed) (struct gendisk *);
  1054. void (*unlock_native_capacity) (struct gendisk *);
  1055. int (*revalidate_disk) (struct gendisk *);
  1056. int (*getgeo)(struct block_device *, struct hd_geometry *);
  1057. /* this callback is with swap_lock and sometimes page table lock held */
  1058. void (*swap_slot_free_notify) (struct block_device *, unsigned long);
  1059. struct module *owner;
  1060. };
  1061. extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
  1062. unsigned long);
  1063. #else /* CONFIG_BLOCK */
  1064. /*
  1065. * stubs for when the block layer is configured out
  1066. */
  1067. #define buffer_heads_over_limit 0
  1068. static inline long nr_blockdev_pages(void)
  1069. {
  1070. return 0;
  1071. }
  1072. #endif /* CONFIG_BLOCK */
  1073. #endif