bio.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. /*
  2. * 2.5 block I/O model
  3. *
  4. * Copyright (C) 2001 Jens Axboe <axboe@suse.de>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. *
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public Licens
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-
  19. */
  20. #ifndef __LINUX_BIO_H
  21. #define __LINUX_BIO_H
  22. #include <linux/highmem.h>
  23. #include <linux/mempool.h>
  24. #include <linux/ioprio.h>
  25. #include <linux/bug.h>
  26. #ifdef CONFIG_BLOCK
  27. #include <asm/io.h>
  28. /* struct bio, bio_vec and BIO_* flags are defined in blk_types.h */
  29. #include <linux/blk_types.h>
  30. #define BIO_DEBUG
  31. #ifdef BIO_DEBUG
  32. #define BIO_BUG_ON BUG_ON
  33. #else
  34. #define BIO_BUG_ON
  35. #endif
  36. #define BIO_MAX_PAGES 256
  37. #define BIO_MAX_SIZE (BIO_MAX_PAGES << PAGE_CACHE_SHIFT)
  38. #define BIO_MAX_SECTORS (BIO_MAX_SIZE >> 9)
  39. /*
  40. * upper 16 bits of bi_rw define the io priority of this bio
  41. */
  42. #define BIO_PRIO_SHIFT (8 * sizeof(unsigned long) - IOPRIO_BITS)
  43. #define bio_prio(bio) ((bio)->bi_rw >> BIO_PRIO_SHIFT)
  44. #define bio_prio_valid(bio) ioprio_valid(bio_prio(bio))
  45. #define bio_set_prio(bio, prio) do { \
  46. WARN_ON(prio >= (1 << IOPRIO_BITS)); \
  47. (bio)->bi_rw &= ((1UL << BIO_PRIO_SHIFT) - 1); \
  48. (bio)->bi_rw |= ((unsigned long) (prio) << BIO_PRIO_SHIFT); \
  49. } while (0)
  50. /*
  51. * various member access, note that bio_data should of course not be used
  52. * on highmem page vectors
  53. */
  54. #define bio_iovec_idx(bio, idx) (&((bio)->bi_io_vec[(idx)]))
  55. #define __bio_iovec(bio) bio_iovec_idx((bio), (bio)->bi_iter.bi_idx)
  56. #define __bvec_iter_bvec(bvec, iter) (&(bvec)[(iter).bi_idx])
  57. #define bvec_iter_page(bvec, iter) \
  58. (__bvec_iter_bvec((bvec), (iter))->bv_page)
  59. #define bvec_iter_len(bvec, iter) \
  60. min((iter).bi_size, \
  61. __bvec_iter_bvec((bvec), (iter))->bv_len - (iter).bi_bvec_done)
  62. #define bvec_iter_offset(bvec, iter) \
  63. (__bvec_iter_bvec((bvec), (iter))->bv_offset + (iter).bi_bvec_done)
  64. #define bvec_iter_bvec(bvec, iter) \
  65. ((struct bio_vec) { \
  66. .bv_page = bvec_iter_page((bvec), (iter)), \
  67. .bv_len = bvec_iter_len((bvec), (iter)), \
  68. .bv_offset = bvec_iter_offset((bvec), (iter)), \
  69. })
  70. #define bio_iter_iovec(bio, iter) \
  71. bvec_iter_bvec((bio)->bi_io_vec, (iter))
  72. #define bio_iter_page(bio, iter) \
  73. bvec_iter_page((bio)->bi_io_vec, (iter))
  74. #define bio_iter_len(bio, iter) \
  75. bvec_iter_len((bio)->bi_io_vec, (iter))
  76. #define bio_iter_offset(bio, iter) \
  77. bvec_iter_offset((bio)->bi_io_vec, (iter))
  78. #define bio_page(bio) bio_iter_page((bio), (bio)->bi_iter)
  79. #define bio_offset(bio) bio_iter_offset((bio), (bio)->bi_iter)
  80. #define bio_iovec(bio) bio_iter_iovec((bio), (bio)->bi_iter)
  81. #define bio_segments(bio) ((bio)->bi_vcnt - (bio)->bi_iter.bi_idx)
  82. #define bio_sectors(bio) ((bio)->bi_iter.bi_size >> 9)
  83. #define bio_end_sector(bio) ((bio)->bi_iter.bi_sector + bio_sectors((bio)))
  84. static inline unsigned int bio_cur_bytes(struct bio *bio)
  85. {
  86. if (bio->bi_vcnt)
  87. return bio_iovec(bio).bv_len;
  88. else /* dataless requests such as discard */
  89. return bio->bi_iter.bi_size;
  90. }
  91. static inline void *bio_data(struct bio *bio)
  92. {
  93. if (bio->bi_vcnt)
  94. return page_address(bio_page(bio)) + bio_offset(bio);
  95. return NULL;
  96. }
  97. /*
  98. * will die
  99. */
  100. #define bio_to_phys(bio) (page_to_phys(bio_page((bio))) + (unsigned long) bio_offset((bio)))
  101. #define bvec_to_phys(bv) (page_to_phys((bv)->bv_page) + (unsigned long) (bv)->bv_offset)
  102. /*
  103. * queues that have highmem support enabled may still need to revert to
  104. * PIO transfers occasionally and thus map high pages temporarily. For
  105. * permanent PIO fall back, user is probably better off disabling highmem
  106. * I/O completely on that queue (see ide-dma for example)
  107. */
  108. #define __bio_kmap_atomic(bio, idx) \
  109. (kmap_atomic(bio_iovec_idx((bio), (idx))->bv_page) + \
  110. bio_iovec_idx((bio), (idx))->bv_offset)
  111. #define __bio_kunmap_atomic(addr) kunmap_atomic(addr)
  112. /*
  113. * merge helpers etc
  114. */
  115. #define __BVEC_END(bio) bio_iovec_idx((bio), (bio)->bi_vcnt - 1)
  116. #define __BVEC_START(bio) bio_iovec_idx((bio), (bio)->bi_iter.bi_idx)
  117. /* Default implementation of BIOVEC_PHYS_MERGEABLE */
  118. #define __BIOVEC_PHYS_MERGEABLE(vec1, vec2) \
  119. ((bvec_to_phys((vec1)) + (vec1)->bv_len) == bvec_to_phys((vec2)))
  120. /*
  121. * allow arch override, for eg virtualized architectures (put in asm/io.h)
  122. */
  123. #ifndef BIOVEC_PHYS_MERGEABLE
  124. #define BIOVEC_PHYS_MERGEABLE(vec1, vec2) \
  125. __BIOVEC_PHYS_MERGEABLE(vec1, vec2)
  126. #endif
  127. #define __BIO_SEG_BOUNDARY(addr1, addr2, mask) \
  128. (((addr1) | (mask)) == (((addr2) - 1) | (mask)))
  129. #define BIOVEC_SEG_BOUNDARY(q, b1, b2) \
  130. __BIO_SEG_BOUNDARY(bvec_to_phys((b1)), bvec_to_phys((b2)) + (b2)->bv_len, queue_segment_boundary((q)))
  131. #define BIO_SEG_BOUNDARY(q, b1, b2) \
  132. BIOVEC_SEG_BOUNDARY((q), __BVEC_END((b1)), __BVEC_START((b2)))
  133. #define bio_io_error(bio) bio_endio((bio), -EIO)
  134. /*
  135. * drivers should _never_ use the all version - the bio may have been split
  136. * before it got to the driver and the driver won't own all of it
  137. */
  138. #define bio_for_each_segment_all(bvl, bio, i) \
  139. for (i = 0; \
  140. bvl = bio_iovec_idx((bio), (i)), i < (bio)->bi_vcnt; \
  141. i++)
  142. static inline void bvec_iter_advance(struct bio_vec *bv, struct bvec_iter *iter,
  143. unsigned bytes)
  144. {
  145. WARN_ONCE(bytes > iter->bi_size,
  146. "Attempted to advance past end of bvec iter\n");
  147. while (bytes) {
  148. unsigned len = min(bytes, bvec_iter_len(bv, *iter));
  149. bytes -= len;
  150. iter->bi_size -= len;
  151. iter->bi_bvec_done += len;
  152. if (iter->bi_bvec_done == __bvec_iter_bvec(bv, *iter)->bv_len) {
  153. iter->bi_bvec_done = 0;
  154. iter->bi_idx++;
  155. }
  156. }
  157. }
  158. #define for_each_bvec(bvl, bio_vec, iter, start) \
  159. for ((iter) = start; \
  160. (bvl) = bvec_iter_bvec((bio_vec), (iter)), \
  161. (iter).bi_size; \
  162. bvec_iter_advance((bio_vec), &(iter), (bvl).bv_len))
  163. static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter,
  164. unsigned bytes)
  165. {
  166. iter->bi_sector += bytes >> 9;
  167. if (bio->bi_rw & BIO_NO_ADVANCE_ITER_MASK)
  168. iter->bi_size -= bytes;
  169. else
  170. bvec_iter_advance(bio->bi_io_vec, iter, bytes);
  171. }
  172. #define __bio_for_each_segment(bvl, bio, iter, start) \
  173. for (iter = (start); \
  174. (iter).bi_size && \
  175. ((bvl = bio_iter_iovec((bio), (iter))), 1); \
  176. bio_advance_iter((bio), &(iter), (bvl).bv_len))
  177. #define bio_for_each_segment(bvl, bio, iter) \
  178. __bio_for_each_segment(bvl, bio, iter, (bio)->bi_iter)
  179. #define bio_iter_last(bvec, iter) ((iter).bi_size == (bvec).bv_len)
  180. /*
  181. * get a reference to a bio, so it won't disappear. the intended use is
  182. * something like:
  183. *
  184. * bio_get(bio);
  185. * submit_bio(rw, bio);
  186. * if (bio->bi_flags ...)
  187. * do_something
  188. * bio_put(bio);
  189. *
  190. * without the bio_get(), it could potentially complete I/O before submit_bio
  191. * returns. and then bio would be freed memory when if (bio->bi_flags ...)
  192. * runs
  193. */
  194. #define bio_get(bio) atomic_inc(&(bio)->bi_cnt)
  195. #if defined(CONFIG_BLK_DEV_INTEGRITY)
  196. /*
  197. * bio integrity payload
  198. */
  199. struct bio_integrity_payload {
  200. struct bio *bip_bio; /* parent bio */
  201. struct bvec_iter bip_iter;
  202. /* kill - should just use bip_vec */
  203. void *bip_buf; /* generated integrity data */
  204. bio_end_io_t *bip_end_io; /* saved I/O completion fn */
  205. unsigned short bip_slab; /* slab the bip came from */
  206. unsigned short bip_vcnt; /* # of integrity bio_vecs */
  207. unsigned bip_owns_buf:1; /* should free bip_buf */
  208. struct work_struct bip_work; /* I/O completion */
  209. struct bio_vec *bip_vec;
  210. struct bio_vec bip_inline_vecs[0];/* embedded bvec array */
  211. };
  212. #endif /* CONFIG_BLK_DEV_INTEGRITY */
  213. /*
  214. * A bio_pair is used when we need to split a bio.
  215. * This can only happen for a bio that refers to just one
  216. * page of data, and in the unusual situation when the
  217. * page crosses a chunk/device boundary
  218. *
  219. * The address of the master bio is stored in bio1.bi_private
  220. * The address of the pool the pair was allocated from is stored
  221. * in bio2.bi_private
  222. */
  223. struct bio_pair {
  224. struct bio bio1, bio2;
  225. struct bio_vec bv1, bv2;
  226. #if defined(CONFIG_BLK_DEV_INTEGRITY)
  227. struct bio_integrity_payload bip1, bip2;
  228. struct bio_vec iv1, iv2;
  229. #endif
  230. atomic_t cnt;
  231. int error;
  232. };
  233. extern struct bio_pair *bio_split(struct bio *bi, int first_sectors);
  234. extern void bio_pair_release(struct bio_pair *dbio);
  235. extern void bio_trim(struct bio *bio, int offset, int size);
  236. extern struct bio_set *bioset_create(unsigned int, unsigned int);
  237. extern void bioset_free(struct bio_set *);
  238. extern mempool_t *biovec_create_pool(struct bio_set *bs, int pool_entries);
  239. extern struct bio *bio_alloc_bioset(gfp_t, int, struct bio_set *);
  240. extern void bio_put(struct bio *);
  241. extern void __bio_clone(struct bio *, struct bio *);
  242. extern struct bio *bio_clone_bioset(struct bio *, gfp_t, struct bio_set *bs);
  243. extern struct bio_set *fs_bio_set;
  244. static inline struct bio *bio_alloc(gfp_t gfp_mask, unsigned int nr_iovecs)
  245. {
  246. return bio_alloc_bioset(gfp_mask, nr_iovecs, fs_bio_set);
  247. }
  248. static inline struct bio *bio_clone(struct bio *bio, gfp_t gfp_mask)
  249. {
  250. return bio_clone_bioset(bio, gfp_mask, fs_bio_set);
  251. }
  252. static inline struct bio *bio_kmalloc(gfp_t gfp_mask, unsigned int nr_iovecs)
  253. {
  254. return bio_alloc_bioset(gfp_mask, nr_iovecs, NULL);
  255. }
  256. static inline struct bio *bio_clone_kmalloc(struct bio *bio, gfp_t gfp_mask)
  257. {
  258. return bio_clone_bioset(bio, gfp_mask, NULL);
  259. }
  260. extern void bio_endio(struct bio *, int);
  261. struct request_queue;
  262. extern int bio_phys_segments(struct request_queue *, struct bio *);
  263. extern int submit_bio_wait(int rw, struct bio *bio);
  264. extern void bio_advance(struct bio *, unsigned);
  265. extern void bio_init(struct bio *);
  266. extern void bio_reset(struct bio *);
  267. extern int bio_add_page(struct bio *, struct page *, unsigned int,unsigned int);
  268. extern int bio_add_pc_page(struct request_queue *, struct bio *, struct page *,
  269. unsigned int, unsigned int);
  270. extern int bio_get_nr_vecs(struct block_device *);
  271. extern sector_t bio_sector_offset(struct bio *, unsigned short, unsigned int);
  272. extern struct bio *bio_map_user(struct request_queue *, struct block_device *,
  273. unsigned long, unsigned int, int, gfp_t);
  274. struct sg_iovec;
  275. struct rq_map_data;
  276. extern struct bio *bio_map_user_iov(struct request_queue *,
  277. struct block_device *,
  278. struct sg_iovec *, int, int, gfp_t);
  279. extern void bio_unmap_user(struct bio *);
  280. extern struct bio *bio_map_kern(struct request_queue *, void *, unsigned int,
  281. gfp_t);
  282. extern struct bio *bio_copy_kern(struct request_queue *, void *, unsigned int,
  283. gfp_t, int);
  284. extern void bio_set_pages_dirty(struct bio *bio);
  285. extern void bio_check_pages_dirty(struct bio *bio);
  286. #ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
  287. # error "You should define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE for your platform"
  288. #endif
  289. #if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
  290. extern void bio_flush_dcache_pages(struct bio *bi);
  291. #else
  292. static inline void bio_flush_dcache_pages(struct bio *bi)
  293. {
  294. }
  295. #endif
  296. extern void bio_copy_data(struct bio *dst, struct bio *src);
  297. extern int bio_alloc_pages(struct bio *bio, gfp_t gfp);
  298. extern struct bio *bio_copy_user(struct request_queue *, struct rq_map_data *,
  299. unsigned long, unsigned int, int, gfp_t);
  300. extern struct bio *bio_copy_user_iov(struct request_queue *,
  301. struct rq_map_data *, struct sg_iovec *,
  302. int, int, gfp_t);
  303. extern int bio_uncopy_user(struct bio *);
  304. void zero_fill_bio(struct bio *bio);
  305. extern struct bio_vec *bvec_alloc(gfp_t, int, unsigned long *, mempool_t *);
  306. extern void bvec_free(mempool_t *, struct bio_vec *, unsigned int);
  307. extern unsigned int bvec_nr_vecs(unsigned short idx);
  308. #ifdef CONFIG_BLK_CGROUP
  309. int bio_associate_current(struct bio *bio);
  310. void bio_disassociate_task(struct bio *bio);
  311. #else /* CONFIG_BLK_CGROUP */
  312. static inline int bio_associate_current(struct bio *bio) { return -ENOENT; }
  313. static inline void bio_disassociate_task(struct bio *bio) { }
  314. #endif /* CONFIG_BLK_CGROUP */
  315. #ifdef CONFIG_HIGHMEM
  316. /*
  317. * remember never ever reenable interrupts between a bvec_kmap_irq and
  318. * bvec_kunmap_irq!
  319. */
  320. static inline char *bvec_kmap_irq(struct bio_vec *bvec, unsigned long *flags)
  321. {
  322. unsigned long addr;
  323. /*
  324. * might not be a highmem page, but the preempt/irq count
  325. * balancing is a lot nicer this way
  326. */
  327. local_irq_save(*flags);
  328. addr = (unsigned long) kmap_atomic(bvec->bv_page);
  329. BUG_ON(addr & ~PAGE_MASK);
  330. return (char *) addr + bvec->bv_offset;
  331. }
  332. static inline void bvec_kunmap_irq(char *buffer, unsigned long *flags)
  333. {
  334. unsigned long ptr = (unsigned long) buffer & PAGE_MASK;
  335. kunmap_atomic((void *) ptr);
  336. local_irq_restore(*flags);
  337. }
  338. #else
  339. static inline char *bvec_kmap_irq(struct bio_vec *bvec, unsigned long *flags)
  340. {
  341. return page_address(bvec->bv_page) + bvec->bv_offset;
  342. }
  343. static inline void bvec_kunmap_irq(char *buffer, unsigned long *flags)
  344. {
  345. *flags = 0;
  346. }
  347. #endif
  348. static inline char *__bio_kmap_irq(struct bio *bio, unsigned short idx,
  349. unsigned long *flags)
  350. {
  351. return bvec_kmap_irq(bio_iovec_idx(bio, idx), flags);
  352. }
  353. #define __bio_kunmap_irq(buf, flags) bvec_kunmap_irq(buf, flags)
  354. #define bio_kmap_irq(bio, flags) \
  355. __bio_kmap_irq((bio), (bio)->bi_iter.bi_idx, (flags))
  356. #define bio_kunmap_irq(buf,flags) __bio_kunmap_irq(buf, flags)
  357. /*
  358. * Check whether this bio carries any data or not. A NULL bio is allowed.
  359. */
  360. static inline bool bio_has_data(struct bio *bio)
  361. {
  362. if (bio && bio->bi_vcnt)
  363. return true;
  364. return false;
  365. }
  366. static inline bool bio_is_rw(struct bio *bio)
  367. {
  368. if (!bio_has_data(bio))
  369. return false;
  370. if (bio->bi_rw & REQ_WRITE_SAME)
  371. return false;
  372. return true;
  373. }
  374. static inline bool bio_mergeable(struct bio *bio)
  375. {
  376. if (bio->bi_rw & REQ_NOMERGE_FLAGS)
  377. return false;
  378. return true;
  379. }
  380. /*
  381. * BIO list management for use by remapping drivers (e.g. DM or MD) and loop.
  382. *
  383. * A bio_list anchors a singly-linked list of bios chained through the bi_next
  384. * member of the bio. The bio_list also caches the last list member to allow
  385. * fast access to the tail.
  386. */
  387. struct bio_list {
  388. struct bio *head;
  389. struct bio *tail;
  390. };
  391. static inline int bio_list_empty(const struct bio_list *bl)
  392. {
  393. return bl->head == NULL;
  394. }
  395. static inline void bio_list_init(struct bio_list *bl)
  396. {
  397. bl->head = bl->tail = NULL;
  398. }
  399. #define BIO_EMPTY_LIST { NULL, NULL }
  400. #define bio_list_for_each(bio, bl) \
  401. for (bio = (bl)->head; bio; bio = bio->bi_next)
  402. static inline unsigned bio_list_size(const struct bio_list *bl)
  403. {
  404. unsigned sz = 0;
  405. struct bio *bio;
  406. bio_list_for_each(bio, bl)
  407. sz++;
  408. return sz;
  409. }
  410. static inline void bio_list_add(struct bio_list *bl, struct bio *bio)
  411. {
  412. bio->bi_next = NULL;
  413. if (bl->tail)
  414. bl->tail->bi_next = bio;
  415. else
  416. bl->head = bio;
  417. bl->tail = bio;
  418. }
  419. static inline void bio_list_add_head(struct bio_list *bl, struct bio *bio)
  420. {
  421. bio->bi_next = bl->head;
  422. bl->head = bio;
  423. if (!bl->tail)
  424. bl->tail = bio;
  425. }
  426. static inline void bio_list_merge(struct bio_list *bl, struct bio_list *bl2)
  427. {
  428. if (!bl2->head)
  429. return;
  430. if (bl->tail)
  431. bl->tail->bi_next = bl2->head;
  432. else
  433. bl->head = bl2->head;
  434. bl->tail = bl2->tail;
  435. }
  436. static inline void bio_list_merge_head(struct bio_list *bl,
  437. struct bio_list *bl2)
  438. {
  439. if (!bl2->head)
  440. return;
  441. if (bl->head)
  442. bl2->tail->bi_next = bl->head;
  443. else
  444. bl->tail = bl2->tail;
  445. bl->head = bl2->head;
  446. }
  447. static inline struct bio *bio_list_peek(struct bio_list *bl)
  448. {
  449. return bl->head;
  450. }
  451. static inline struct bio *bio_list_pop(struct bio_list *bl)
  452. {
  453. struct bio *bio = bl->head;
  454. if (bio) {
  455. bl->head = bl->head->bi_next;
  456. if (!bl->head)
  457. bl->tail = NULL;
  458. bio->bi_next = NULL;
  459. }
  460. return bio;
  461. }
  462. static inline struct bio *bio_list_get(struct bio_list *bl)
  463. {
  464. struct bio *bio = bl->head;
  465. bl->head = bl->tail = NULL;
  466. return bio;
  467. }
  468. /*
  469. * bio_set is used to allow other portions of the IO system to
  470. * allocate their own private memory pools for bio and iovec structures.
  471. * These memory pools in turn all allocate from the bio_slab
  472. * and the bvec_slabs[].
  473. */
  474. #define BIO_POOL_SIZE 2
  475. #define BIOVEC_NR_POOLS 6
  476. #define BIOVEC_MAX_IDX (BIOVEC_NR_POOLS - 1)
  477. struct bio_set {
  478. struct kmem_cache *bio_slab;
  479. unsigned int front_pad;
  480. mempool_t *bio_pool;
  481. mempool_t *bvec_pool;
  482. #if defined(CONFIG_BLK_DEV_INTEGRITY)
  483. mempool_t *bio_integrity_pool;
  484. mempool_t *bvec_integrity_pool;
  485. #endif
  486. /*
  487. * Deadlock avoidance for stacking block drivers: see comments in
  488. * bio_alloc_bioset() for details
  489. */
  490. spinlock_t rescue_lock;
  491. struct bio_list rescue_list;
  492. struct work_struct rescue_work;
  493. struct workqueue_struct *rescue_workqueue;
  494. };
  495. struct biovec_slab {
  496. int nr_vecs;
  497. char *name;
  498. struct kmem_cache *slab;
  499. };
  500. /*
  501. * a small number of entries is fine, not going to be performance critical.
  502. * basically we just need to survive
  503. */
  504. #define BIO_SPLIT_ENTRIES 2
  505. #if defined(CONFIG_BLK_DEV_INTEGRITY)
  506. #define bip_vec_idx(bip, idx) (&(bip->bip_vec[(idx)]))
  507. #define bip_for_each_vec(bvl, bip, iter) \
  508. for_each_bvec(bvl, (bip)->bip_vec, iter, (bip)->bip_iter)
  509. #define bio_for_each_integrity_vec(_bvl, _bio, _iter) \
  510. for_each_bio(_bio) \
  511. bip_for_each_vec(_bvl, _bio->bi_integrity, _iter)
  512. #define bio_integrity(bio) (bio->bi_integrity != NULL)
  513. extern struct bio_integrity_payload *bio_integrity_alloc(struct bio *, gfp_t, unsigned int);
  514. extern void bio_integrity_free(struct bio *);
  515. extern int bio_integrity_add_page(struct bio *, struct page *, unsigned int, unsigned int);
  516. extern int bio_integrity_enabled(struct bio *bio);
  517. extern int bio_integrity_set_tag(struct bio *, void *, unsigned int);
  518. extern int bio_integrity_get_tag(struct bio *, void *, unsigned int);
  519. extern int bio_integrity_prep(struct bio *);
  520. extern void bio_integrity_endio(struct bio *, int);
  521. extern void bio_integrity_advance(struct bio *, unsigned int);
  522. extern void bio_integrity_trim(struct bio *, unsigned int, unsigned int);
  523. extern void bio_integrity_split(struct bio *, struct bio_pair *, int);
  524. extern int bio_integrity_clone(struct bio *, struct bio *, gfp_t);
  525. extern int bioset_integrity_create(struct bio_set *, int);
  526. extern void bioset_integrity_free(struct bio_set *);
  527. extern void bio_integrity_init(void);
  528. #else /* CONFIG_BLK_DEV_INTEGRITY */
  529. static inline int bio_integrity(struct bio *bio)
  530. {
  531. return 0;
  532. }
  533. static inline int bio_integrity_enabled(struct bio *bio)
  534. {
  535. return 0;
  536. }
  537. static inline int bioset_integrity_create(struct bio_set *bs, int pool_size)
  538. {
  539. return 0;
  540. }
  541. static inline void bioset_integrity_free (struct bio_set *bs)
  542. {
  543. return;
  544. }
  545. static inline int bio_integrity_prep(struct bio *bio)
  546. {
  547. return 0;
  548. }
  549. static inline void bio_integrity_free(struct bio *bio)
  550. {
  551. return;
  552. }
  553. static inline int bio_integrity_clone(struct bio *bio, struct bio *bio_src,
  554. gfp_t gfp_mask)
  555. {
  556. return 0;
  557. }
  558. static inline void bio_integrity_split(struct bio *bio, struct bio_pair *bp,
  559. int sectors)
  560. {
  561. return;
  562. }
  563. static inline void bio_integrity_advance(struct bio *bio,
  564. unsigned int bytes_done)
  565. {
  566. return;
  567. }
  568. static inline void bio_integrity_trim(struct bio *bio, unsigned int offset,
  569. unsigned int sectors)
  570. {
  571. return;
  572. }
  573. static inline void bio_integrity_init(void)
  574. {
  575. return;
  576. }
  577. #endif /* CONFIG_BLK_DEV_INTEGRITY */
  578. #endif /* CONFIG_BLOCK */
  579. #endif /* __LINUX_BIO_H */