bio.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374
  1. /*
  2. * Copyright (C) 2001 Jens Axboe <axboe@kernel.dk>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public Licens
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-
  16. *
  17. */
  18. #include <linux/mm.h>
  19. #include <linux/swap.h>
  20. #include <linux/bio.h>
  21. #include <linux/blkdev.h>
  22. #include <linux/slab.h>
  23. #include <linux/init.h>
  24. #include <linux/kernel.h>
  25. #include <linux/module.h>
  26. #include <linux/mempool.h>
  27. #include <linux/workqueue.h>
  28. #include <linux/blktrace_api.h>
  29. #include <scsi/sg.h> /* for struct sg_iovec */
  30. #define BIO_POOL_SIZE 2
  31. static struct kmem_cache *bio_slab __read_mostly;
  32. #define BIOVEC_NR_POOLS 6
  33. /*
  34. * a small number of entries is fine, not going to be performance critical.
  35. * basically we just need to survive
  36. */
  37. #define BIO_SPLIT_ENTRIES 2
  38. mempool_t *bio_split_pool __read_mostly;
  39. struct biovec_slab {
  40. int nr_vecs;
  41. char *name;
  42. struct kmem_cache *slab;
  43. };
  44. /*
  45. * if you change this list, also change bvec_alloc or things will
  46. * break badly! cannot be bigger than what you can fit into an
  47. * unsigned short
  48. */
  49. #define BV(x) { .nr_vecs = x, .name = "biovec-"__stringify(x) }
  50. static struct biovec_slab bvec_slabs[BIOVEC_NR_POOLS] __read_mostly = {
  51. BV(1), BV(4), BV(16), BV(64), BV(128), BV(BIO_MAX_PAGES),
  52. };
  53. #undef BV
  54. /*
  55. * bio_set is used to allow other portions of the IO system to
  56. * allocate their own private memory pools for bio and iovec structures.
  57. * These memory pools in turn all allocate from the bio_slab
  58. * and the bvec_slabs[].
  59. */
  60. struct bio_set {
  61. mempool_t *bio_pool;
  62. mempool_t *bvec_pools[BIOVEC_NR_POOLS];
  63. };
  64. /*
  65. * fs_bio_set is the bio_set containing bio and iovec memory pools used by
  66. * IO code that does not need private memory pools.
  67. */
  68. static struct bio_set *fs_bio_set;
  69. static inline struct bio_vec *bvec_alloc_bs(gfp_t gfp_mask, int nr, unsigned long *idx, struct bio_set *bs)
  70. {
  71. struct bio_vec *bvl;
  72. /*
  73. * see comment near bvec_array define!
  74. */
  75. switch (nr) {
  76. case 1 : *idx = 0; break;
  77. case 2 ... 4: *idx = 1; break;
  78. case 5 ... 16: *idx = 2; break;
  79. case 17 ... 64: *idx = 3; break;
  80. case 65 ... 128: *idx = 4; break;
  81. case 129 ... BIO_MAX_PAGES: *idx = 5; break;
  82. default:
  83. return NULL;
  84. }
  85. /*
  86. * idx now points to the pool we want to allocate from
  87. */
  88. bvl = mempool_alloc(bs->bvec_pools[*idx], gfp_mask);
  89. if (bvl) {
  90. struct biovec_slab *bp = bvec_slabs + *idx;
  91. memset(bvl, 0, bp->nr_vecs * sizeof(struct bio_vec));
  92. }
  93. return bvl;
  94. }
  95. void bio_free(struct bio *bio, struct bio_set *bio_set)
  96. {
  97. if (bio->bi_io_vec) {
  98. const int pool_idx = BIO_POOL_IDX(bio);
  99. BIO_BUG_ON(pool_idx >= BIOVEC_NR_POOLS);
  100. mempool_free(bio->bi_io_vec, bio_set->bvec_pools[pool_idx]);
  101. }
  102. mempool_free(bio, bio_set->bio_pool);
  103. }
  104. /*
  105. * default destructor for a bio allocated with bio_alloc_bioset()
  106. */
  107. static void bio_fs_destructor(struct bio *bio)
  108. {
  109. bio_free(bio, fs_bio_set);
  110. }
  111. void bio_init(struct bio *bio)
  112. {
  113. memset(bio, 0, sizeof(*bio));
  114. bio->bi_flags = 1 << BIO_UPTODATE;
  115. atomic_set(&bio->bi_cnt, 1);
  116. }
  117. /**
  118. * bio_alloc_bioset - allocate a bio for I/O
  119. * @gfp_mask: the GFP_ mask given to the slab allocator
  120. * @nr_iovecs: number of iovecs to pre-allocate
  121. * @bs: the bio_set to allocate from
  122. *
  123. * Description:
  124. * bio_alloc_bioset will first try it's on mempool to satisfy the allocation.
  125. * If %__GFP_WAIT is set then we will block on the internal pool waiting
  126. * for a &struct bio to become free.
  127. *
  128. * allocate bio and iovecs from the memory pools specified by the
  129. * bio_set structure.
  130. **/
  131. struct bio *bio_alloc_bioset(gfp_t gfp_mask, int nr_iovecs, struct bio_set *bs)
  132. {
  133. struct bio *bio = mempool_alloc(bs->bio_pool, gfp_mask);
  134. if (likely(bio)) {
  135. struct bio_vec *bvl = NULL;
  136. bio_init(bio);
  137. if (likely(nr_iovecs)) {
  138. unsigned long uninitialized_var(idx);
  139. bvl = bvec_alloc_bs(gfp_mask, nr_iovecs, &idx, bs);
  140. if (unlikely(!bvl)) {
  141. mempool_free(bio, bs->bio_pool);
  142. bio = NULL;
  143. goto out;
  144. }
  145. bio->bi_flags |= idx << BIO_POOL_OFFSET;
  146. bio->bi_max_vecs = bvec_slabs[idx].nr_vecs;
  147. }
  148. bio->bi_io_vec = bvl;
  149. }
  150. out:
  151. return bio;
  152. }
  153. struct bio *bio_alloc(gfp_t gfp_mask, int nr_iovecs)
  154. {
  155. struct bio *bio = bio_alloc_bioset(gfp_mask, nr_iovecs, fs_bio_set);
  156. if (bio)
  157. bio->bi_destructor = bio_fs_destructor;
  158. return bio;
  159. }
  160. void zero_fill_bio(struct bio *bio)
  161. {
  162. unsigned long flags;
  163. struct bio_vec *bv;
  164. int i;
  165. bio_for_each_segment(bv, bio, i) {
  166. char *data = bvec_kmap_irq(bv, &flags);
  167. memset(data, 0, bv->bv_len);
  168. flush_dcache_page(bv->bv_page);
  169. bvec_kunmap_irq(data, &flags);
  170. }
  171. }
  172. EXPORT_SYMBOL(zero_fill_bio);
  173. /**
  174. * bio_put - release a reference to a bio
  175. * @bio: bio to release reference to
  176. *
  177. * Description:
  178. * Put a reference to a &struct bio, either one you have gotten with
  179. * bio_alloc or bio_get. The last put of a bio will free it.
  180. **/
  181. void bio_put(struct bio *bio)
  182. {
  183. BIO_BUG_ON(!atomic_read(&bio->bi_cnt));
  184. /*
  185. * last put frees it
  186. */
  187. if (atomic_dec_and_test(&bio->bi_cnt)) {
  188. bio->bi_next = NULL;
  189. bio->bi_destructor(bio);
  190. }
  191. }
  192. inline int bio_phys_segments(struct request_queue *q, struct bio *bio)
  193. {
  194. if (unlikely(!bio_flagged(bio, BIO_SEG_VALID)))
  195. blk_recount_segments(q, bio);
  196. return bio->bi_phys_segments;
  197. }
  198. inline int bio_hw_segments(struct request_queue *q, struct bio *bio)
  199. {
  200. if (unlikely(!bio_flagged(bio, BIO_SEG_VALID)))
  201. blk_recount_segments(q, bio);
  202. return bio->bi_hw_segments;
  203. }
  204. /**
  205. * __bio_clone - clone a bio
  206. * @bio: destination bio
  207. * @bio_src: bio to clone
  208. *
  209. * Clone a &bio. Caller will own the returned bio, but not
  210. * the actual data it points to. Reference count of returned
  211. * bio will be one.
  212. */
  213. void __bio_clone(struct bio *bio, struct bio *bio_src)
  214. {
  215. memcpy(bio->bi_io_vec, bio_src->bi_io_vec,
  216. bio_src->bi_max_vecs * sizeof(struct bio_vec));
  217. /*
  218. * most users will be overriding ->bi_bdev with a new target,
  219. * so we don't set nor calculate new physical/hw segment counts here
  220. */
  221. bio->bi_sector = bio_src->bi_sector;
  222. bio->bi_bdev = bio_src->bi_bdev;
  223. bio->bi_flags |= 1 << BIO_CLONED;
  224. bio->bi_rw = bio_src->bi_rw;
  225. bio->bi_vcnt = bio_src->bi_vcnt;
  226. bio->bi_size = bio_src->bi_size;
  227. bio->bi_idx = bio_src->bi_idx;
  228. }
  229. /**
  230. * bio_clone - clone a bio
  231. * @bio: bio to clone
  232. * @gfp_mask: allocation priority
  233. *
  234. * Like __bio_clone, only also allocates the returned bio
  235. */
  236. struct bio *bio_clone(struct bio *bio, gfp_t gfp_mask)
  237. {
  238. struct bio *b = bio_alloc_bioset(gfp_mask, bio->bi_max_vecs, fs_bio_set);
  239. if (b) {
  240. b->bi_destructor = bio_fs_destructor;
  241. __bio_clone(b, bio);
  242. }
  243. return b;
  244. }
  245. /**
  246. * bio_get_nr_vecs - return approx number of vecs
  247. * @bdev: I/O target
  248. *
  249. * Return the approximate number of pages we can send to this target.
  250. * There's no guarantee that you will be able to fit this number of pages
  251. * into a bio, it does not account for dynamic restrictions that vary
  252. * on offset.
  253. */
  254. int bio_get_nr_vecs(struct block_device *bdev)
  255. {
  256. struct request_queue *q = bdev_get_queue(bdev);
  257. int nr_pages;
  258. nr_pages = ((q->max_sectors << 9) + PAGE_SIZE - 1) >> PAGE_SHIFT;
  259. if (nr_pages > q->max_phys_segments)
  260. nr_pages = q->max_phys_segments;
  261. if (nr_pages > q->max_hw_segments)
  262. nr_pages = q->max_hw_segments;
  263. return nr_pages;
  264. }
  265. static int __bio_add_page(struct request_queue *q, struct bio *bio, struct page
  266. *page, unsigned int len, unsigned int offset,
  267. unsigned short max_sectors)
  268. {
  269. int retried_segments = 0;
  270. struct bio_vec *bvec;
  271. /*
  272. * cloned bio must not modify vec list
  273. */
  274. if (unlikely(bio_flagged(bio, BIO_CLONED)))
  275. return 0;
  276. if (((bio->bi_size + len) >> 9) > max_sectors)
  277. return 0;
  278. /*
  279. * For filesystems with a blocksize smaller than the pagesize
  280. * we will often be called with the same page as last time and
  281. * a consecutive offset. Optimize this special case.
  282. */
  283. if (bio->bi_vcnt > 0) {
  284. struct bio_vec *prev = &bio->bi_io_vec[bio->bi_vcnt - 1];
  285. if (page == prev->bv_page &&
  286. offset == prev->bv_offset + prev->bv_len) {
  287. prev->bv_len += len;
  288. if (q->merge_bvec_fn &&
  289. q->merge_bvec_fn(q, bio, prev) < len) {
  290. prev->bv_len -= len;
  291. return 0;
  292. }
  293. goto done;
  294. }
  295. }
  296. if (bio->bi_vcnt >= bio->bi_max_vecs)
  297. return 0;
  298. /*
  299. * we might lose a segment or two here, but rather that than
  300. * make this too complex.
  301. */
  302. while (bio->bi_phys_segments >= q->max_phys_segments
  303. || bio->bi_hw_segments >= q->max_hw_segments
  304. || BIOVEC_VIRT_OVERSIZE(bio->bi_size)) {
  305. if (retried_segments)
  306. return 0;
  307. retried_segments = 1;
  308. blk_recount_segments(q, bio);
  309. }
  310. /*
  311. * setup the new entry, we might clear it again later if we
  312. * cannot add the page
  313. */
  314. bvec = &bio->bi_io_vec[bio->bi_vcnt];
  315. bvec->bv_page = page;
  316. bvec->bv_len = len;
  317. bvec->bv_offset = offset;
  318. /*
  319. * if queue has other restrictions (eg varying max sector size
  320. * depending on offset), it can specify a merge_bvec_fn in the
  321. * queue to get further control
  322. */
  323. if (q->merge_bvec_fn) {
  324. /*
  325. * merge_bvec_fn() returns number of bytes it can accept
  326. * at this offset
  327. */
  328. if (q->merge_bvec_fn(q, bio, bvec) < len) {
  329. bvec->bv_page = NULL;
  330. bvec->bv_len = 0;
  331. bvec->bv_offset = 0;
  332. return 0;
  333. }
  334. }
  335. /* If we may be able to merge these biovecs, force a recount */
  336. if (bio->bi_vcnt && (BIOVEC_PHYS_MERGEABLE(bvec-1, bvec) ||
  337. BIOVEC_VIRT_MERGEABLE(bvec-1, bvec)))
  338. bio->bi_flags &= ~(1 << BIO_SEG_VALID);
  339. bio->bi_vcnt++;
  340. bio->bi_phys_segments++;
  341. bio->bi_hw_segments++;
  342. done:
  343. bio->bi_size += len;
  344. return len;
  345. }
  346. /**
  347. * bio_add_pc_page - attempt to add page to bio
  348. * @q: the target queue
  349. * @bio: destination bio
  350. * @page: page to add
  351. * @len: vec entry length
  352. * @offset: vec entry offset
  353. *
  354. * Attempt to add a page to the bio_vec maplist. This can fail for a
  355. * number of reasons, such as the bio being full or target block
  356. * device limitations. The target block device must allow bio's
  357. * smaller than PAGE_SIZE, so it is always possible to add a single
  358. * page to an empty bio. This should only be used by REQ_PC bios.
  359. */
  360. int bio_add_pc_page(struct request_queue *q, struct bio *bio, struct page *page,
  361. unsigned int len, unsigned int offset)
  362. {
  363. return __bio_add_page(q, bio, page, len, offset, q->max_hw_sectors);
  364. }
  365. /**
  366. * bio_add_page - attempt to add page to bio
  367. * @bio: destination bio
  368. * @page: page to add
  369. * @len: vec entry length
  370. * @offset: vec entry offset
  371. *
  372. * Attempt to add a page to the bio_vec maplist. This can fail for a
  373. * number of reasons, such as the bio being full or target block
  374. * device limitations. The target block device must allow bio's
  375. * smaller than PAGE_SIZE, so it is always possible to add a single
  376. * page to an empty bio.
  377. */
  378. int bio_add_page(struct bio *bio, struct page *page, unsigned int len,
  379. unsigned int offset)
  380. {
  381. struct request_queue *q = bdev_get_queue(bio->bi_bdev);
  382. return __bio_add_page(q, bio, page, len, offset, q->max_sectors);
  383. }
  384. struct bio_map_data {
  385. struct bio_vec *iovecs;
  386. int nr_sgvecs;
  387. struct sg_iovec *sgvecs;
  388. };
  389. static void bio_set_map_data(struct bio_map_data *bmd, struct bio *bio,
  390. struct sg_iovec *iov, int iov_count)
  391. {
  392. memcpy(bmd->iovecs, bio->bi_io_vec, sizeof(struct bio_vec) * bio->bi_vcnt);
  393. memcpy(bmd->sgvecs, iov, sizeof(struct sg_iovec) * iov_count);
  394. bmd->nr_sgvecs = iov_count;
  395. bio->bi_private = bmd;
  396. }
  397. static void bio_free_map_data(struct bio_map_data *bmd)
  398. {
  399. kfree(bmd->iovecs);
  400. kfree(bmd->sgvecs);
  401. kfree(bmd);
  402. }
  403. static struct bio_map_data *bio_alloc_map_data(int nr_segs, int iov_count)
  404. {
  405. struct bio_map_data *bmd = kmalloc(sizeof(*bmd), GFP_KERNEL);
  406. if (!bmd)
  407. return NULL;
  408. bmd->iovecs = kmalloc(sizeof(struct bio_vec) * nr_segs, GFP_KERNEL);
  409. if (!bmd->iovecs) {
  410. kfree(bmd);
  411. return NULL;
  412. }
  413. bmd->sgvecs = kmalloc(sizeof(struct sg_iovec) * iov_count, GFP_KERNEL);
  414. if (bmd->sgvecs)
  415. return bmd;
  416. kfree(bmd->iovecs);
  417. kfree(bmd);
  418. return NULL;
  419. }
  420. static int __bio_copy_iov(struct bio *bio, struct sg_iovec *iov, int iov_count,
  421. int uncopy)
  422. {
  423. int ret = 0, i;
  424. struct bio_vec *bvec;
  425. int iov_idx = 0;
  426. unsigned int iov_off = 0;
  427. int read = bio_data_dir(bio) == READ;
  428. __bio_for_each_segment(bvec, bio, i, 0) {
  429. char *bv_addr = page_address(bvec->bv_page);
  430. unsigned int bv_len = bvec->bv_len;
  431. while (bv_len && iov_idx < iov_count) {
  432. unsigned int bytes;
  433. char *iov_addr;
  434. bytes = min_t(unsigned int,
  435. iov[iov_idx].iov_len - iov_off, bv_len);
  436. iov_addr = iov[iov_idx].iov_base + iov_off;
  437. if (!ret) {
  438. if (!read && !uncopy)
  439. ret = copy_from_user(bv_addr, iov_addr,
  440. bytes);
  441. if (read && uncopy)
  442. ret = copy_to_user(iov_addr, bv_addr,
  443. bytes);
  444. if (ret)
  445. ret = -EFAULT;
  446. }
  447. bv_len -= bytes;
  448. bv_addr += bytes;
  449. iov_addr += bytes;
  450. iov_off += bytes;
  451. if (iov[iov_idx].iov_len == iov_off) {
  452. iov_idx++;
  453. iov_off = 0;
  454. }
  455. }
  456. if (uncopy)
  457. __free_page(bvec->bv_page);
  458. }
  459. return ret;
  460. }
  461. /**
  462. * bio_uncopy_user - finish previously mapped bio
  463. * @bio: bio being terminated
  464. *
  465. * Free pages allocated from bio_copy_user() and write back data
  466. * to user space in case of a read.
  467. */
  468. int bio_uncopy_user(struct bio *bio)
  469. {
  470. struct bio_map_data *bmd = bio->bi_private;
  471. int ret;
  472. ret = __bio_copy_iov(bio, bmd->sgvecs, bmd->nr_sgvecs, 1);
  473. bio_free_map_data(bmd);
  474. bio_put(bio);
  475. return ret;
  476. }
  477. /**
  478. * bio_copy_user_iov - copy user data to bio
  479. * @q: destination block queue
  480. * @iov: the iovec.
  481. * @iov_count: number of elements in the iovec
  482. * @write_to_vm: bool indicating writing to pages or not
  483. *
  484. * Prepares and returns a bio for indirect user io, bouncing data
  485. * to/from kernel pages as necessary. Must be paired with
  486. * call bio_uncopy_user() on io completion.
  487. */
  488. struct bio *bio_copy_user_iov(struct request_queue *q, struct sg_iovec *iov,
  489. int iov_count, int write_to_vm)
  490. {
  491. struct bio_map_data *bmd;
  492. struct bio_vec *bvec;
  493. struct page *page;
  494. struct bio *bio;
  495. int i, ret;
  496. int nr_pages = 0;
  497. unsigned int len = 0;
  498. for (i = 0; i < iov_count; i++) {
  499. unsigned long uaddr;
  500. unsigned long end;
  501. unsigned long start;
  502. uaddr = (unsigned long)iov[i].iov_base;
  503. end = (uaddr + iov[i].iov_len + PAGE_SIZE - 1) >> PAGE_SHIFT;
  504. start = uaddr >> PAGE_SHIFT;
  505. nr_pages += end - start;
  506. len += iov[i].iov_len;
  507. }
  508. bmd = bio_alloc_map_data(nr_pages, iov_count);
  509. if (!bmd)
  510. return ERR_PTR(-ENOMEM);
  511. ret = -ENOMEM;
  512. bio = bio_alloc(GFP_KERNEL, nr_pages);
  513. if (!bio)
  514. goto out_bmd;
  515. bio->bi_rw |= (!write_to_vm << BIO_RW);
  516. ret = 0;
  517. while (len) {
  518. unsigned int bytes = PAGE_SIZE;
  519. if (bytes > len)
  520. bytes = len;
  521. page = alloc_page(q->bounce_gfp | GFP_KERNEL);
  522. if (!page) {
  523. ret = -ENOMEM;
  524. break;
  525. }
  526. if (bio_add_pc_page(q, bio, page, bytes, 0) < bytes)
  527. break;
  528. len -= bytes;
  529. }
  530. if (ret)
  531. goto cleanup;
  532. /*
  533. * success
  534. */
  535. if (!write_to_vm) {
  536. ret = __bio_copy_iov(bio, iov, iov_count, 0);
  537. if (ret)
  538. goto cleanup;
  539. }
  540. bio_set_map_data(bmd, bio, iov, iov_count);
  541. return bio;
  542. cleanup:
  543. bio_for_each_segment(bvec, bio, i)
  544. __free_page(bvec->bv_page);
  545. bio_put(bio);
  546. out_bmd:
  547. bio_free_map_data(bmd);
  548. return ERR_PTR(ret);
  549. }
  550. /**
  551. * bio_copy_user - copy user data to bio
  552. * @q: destination block queue
  553. * @uaddr: start of user address
  554. * @len: length in bytes
  555. * @write_to_vm: bool indicating writing to pages or not
  556. *
  557. * Prepares and returns a bio for indirect user io, bouncing data
  558. * to/from kernel pages as necessary. Must be paired with
  559. * call bio_uncopy_user() on io completion.
  560. */
  561. struct bio *bio_copy_user(struct request_queue *q, unsigned long uaddr,
  562. unsigned int len, int write_to_vm)
  563. {
  564. struct sg_iovec iov;
  565. iov.iov_base = (void __user *)uaddr;
  566. iov.iov_len = len;
  567. return bio_copy_user_iov(q, &iov, 1, write_to_vm);
  568. }
  569. static struct bio *__bio_map_user_iov(struct request_queue *q,
  570. struct block_device *bdev,
  571. struct sg_iovec *iov, int iov_count,
  572. int write_to_vm)
  573. {
  574. int i, j;
  575. int nr_pages = 0;
  576. struct page **pages;
  577. struct bio *bio;
  578. int cur_page = 0;
  579. int ret, offset;
  580. for (i = 0; i < iov_count; i++) {
  581. unsigned long uaddr = (unsigned long)iov[i].iov_base;
  582. unsigned long len = iov[i].iov_len;
  583. unsigned long end = (uaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
  584. unsigned long start = uaddr >> PAGE_SHIFT;
  585. nr_pages += end - start;
  586. /*
  587. * buffer must be aligned to at least hardsector size for now
  588. */
  589. if (uaddr & queue_dma_alignment(q))
  590. return ERR_PTR(-EINVAL);
  591. }
  592. if (!nr_pages)
  593. return ERR_PTR(-EINVAL);
  594. bio = bio_alloc(GFP_KERNEL, nr_pages);
  595. if (!bio)
  596. return ERR_PTR(-ENOMEM);
  597. ret = -ENOMEM;
  598. pages = kcalloc(nr_pages, sizeof(struct page *), GFP_KERNEL);
  599. if (!pages)
  600. goto out;
  601. for (i = 0; i < iov_count; i++) {
  602. unsigned long uaddr = (unsigned long)iov[i].iov_base;
  603. unsigned long len = iov[i].iov_len;
  604. unsigned long end = (uaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
  605. unsigned long start = uaddr >> PAGE_SHIFT;
  606. const int local_nr_pages = end - start;
  607. const int page_limit = cur_page + local_nr_pages;
  608. down_read(&current->mm->mmap_sem);
  609. ret = get_user_pages(current, current->mm, uaddr,
  610. local_nr_pages,
  611. write_to_vm, 0, &pages[cur_page], NULL);
  612. up_read(&current->mm->mmap_sem);
  613. if (ret < local_nr_pages) {
  614. ret = -EFAULT;
  615. goto out_unmap;
  616. }
  617. offset = uaddr & ~PAGE_MASK;
  618. for (j = cur_page; j < page_limit; j++) {
  619. unsigned int bytes = PAGE_SIZE - offset;
  620. if (len <= 0)
  621. break;
  622. if (bytes > len)
  623. bytes = len;
  624. /*
  625. * sorry...
  626. */
  627. if (bio_add_pc_page(q, bio, pages[j], bytes, offset) <
  628. bytes)
  629. break;
  630. len -= bytes;
  631. offset = 0;
  632. }
  633. cur_page = j;
  634. /*
  635. * release the pages we didn't map into the bio, if any
  636. */
  637. while (j < page_limit)
  638. page_cache_release(pages[j++]);
  639. }
  640. kfree(pages);
  641. /*
  642. * set data direction, and check if mapped pages need bouncing
  643. */
  644. if (!write_to_vm)
  645. bio->bi_rw |= (1 << BIO_RW);
  646. bio->bi_bdev = bdev;
  647. bio->bi_flags |= (1 << BIO_USER_MAPPED);
  648. return bio;
  649. out_unmap:
  650. for (i = 0; i < nr_pages; i++) {
  651. if(!pages[i])
  652. break;
  653. page_cache_release(pages[i]);
  654. }
  655. out:
  656. kfree(pages);
  657. bio_put(bio);
  658. return ERR_PTR(ret);
  659. }
  660. /**
  661. * bio_map_user - map user address into bio
  662. * @q: the struct request_queue for the bio
  663. * @bdev: destination block device
  664. * @uaddr: start of user address
  665. * @len: length in bytes
  666. * @write_to_vm: bool indicating writing to pages or not
  667. *
  668. * Map the user space address into a bio suitable for io to a block
  669. * device. Returns an error pointer in case of error.
  670. */
  671. struct bio *bio_map_user(struct request_queue *q, struct block_device *bdev,
  672. unsigned long uaddr, unsigned int len, int write_to_vm)
  673. {
  674. struct sg_iovec iov;
  675. iov.iov_base = (void __user *)uaddr;
  676. iov.iov_len = len;
  677. return bio_map_user_iov(q, bdev, &iov, 1, write_to_vm);
  678. }
  679. /**
  680. * bio_map_user_iov - map user sg_iovec table into bio
  681. * @q: the struct request_queue for the bio
  682. * @bdev: destination block device
  683. * @iov: the iovec.
  684. * @iov_count: number of elements in the iovec
  685. * @write_to_vm: bool indicating writing to pages or not
  686. *
  687. * Map the user space address into a bio suitable for io to a block
  688. * device. Returns an error pointer in case of error.
  689. */
  690. struct bio *bio_map_user_iov(struct request_queue *q, struct block_device *bdev,
  691. struct sg_iovec *iov, int iov_count,
  692. int write_to_vm)
  693. {
  694. struct bio *bio;
  695. bio = __bio_map_user_iov(q, bdev, iov, iov_count, write_to_vm);
  696. if (IS_ERR(bio))
  697. return bio;
  698. /*
  699. * subtle -- if __bio_map_user() ended up bouncing a bio,
  700. * it would normally disappear when its bi_end_io is run.
  701. * however, we need it for the unmap, so grab an extra
  702. * reference to it
  703. */
  704. bio_get(bio);
  705. return bio;
  706. }
  707. static void __bio_unmap_user(struct bio *bio)
  708. {
  709. struct bio_vec *bvec;
  710. int i;
  711. /*
  712. * make sure we dirty pages we wrote to
  713. */
  714. __bio_for_each_segment(bvec, bio, i, 0) {
  715. if (bio_data_dir(bio) == READ)
  716. set_page_dirty_lock(bvec->bv_page);
  717. page_cache_release(bvec->bv_page);
  718. }
  719. bio_put(bio);
  720. }
  721. /**
  722. * bio_unmap_user - unmap a bio
  723. * @bio: the bio being unmapped
  724. *
  725. * Unmap a bio previously mapped by bio_map_user(). Must be called with
  726. * a process context.
  727. *
  728. * bio_unmap_user() may sleep.
  729. */
  730. void bio_unmap_user(struct bio *bio)
  731. {
  732. __bio_unmap_user(bio);
  733. bio_put(bio);
  734. }
  735. static void bio_map_kern_endio(struct bio *bio, int err)
  736. {
  737. bio_put(bio);
  738. }
  739. static struct bio *__bio_map_kern(struct request_queue *q, void *data,
  740. unsigned int len, gfp_t gfp_mask)
  741. {
  742. unsigned long kaddr = (unsigned long)data;
  743. unsigned long end = (kaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
  744. unsigned long start = kaddr >> PAGE_SHIFT;
  745. const int nr_pages = end - start;
  746. int offset, i;
  747. struct bio *bio;
  748. bio = bio_alloc(gfp_mask, nr_pages);
  749. if (!bio)
  750. return ERR_PTR(-ENOMEM);
  751. offset = offset_in_page(kaddr);
  752. for (i = 0; i < nr_pages; i++) {
  753. unsigned int bytes = PAGE_SIZE - offset;
  754. if (len <= 0)
  755. break;
  756. if (bytes > len)
  757. bytes = len;
  758. if (bio_add_pc_page(q, bio, virt_to_page(data), bytes,
  759. offset) < bytes)
  760. break;
  761. data += bytes;
  762. len -= bytes;
  763. offset = 0;
  764. }
  765. bio->bi_end_io = bio_map_kern_endio;
  766. return bio;
  767. }
  768. /**
  769. * bio_map_kern - map kernel address into bio
  770. * @q: the struct request_queue for the bio
  771. * @data: pointer to buffer to map
  772. * @len: length in bytes
  773. * @gfp_mask: allocation flags for bio allocation
  774. *
  775. * Map the kernel address into a bio suitable for io to a block
  776. * device. Returns an error pointer in case of error.
  777. */
  778. struct bio *bio_map_kern(struct request_queue *q, void *data, unsigned int len,
  779. gfp_t gfp_mask)
  780. {
  781. struct bio *bio;
  782. bio = __bio_map_kern(q, data, len, gfp_mask);
  783. if (IS_ERR(bio))
  784. return bio;
  785. if (bio->bi_size == len)
  786. return bio;
  787. /*
  788. * Don't support partial mappings.
  789. */
  790. bio_put(bio);
  791. return ERR_PTR(-EINVAL);
  792. }
  793. static void bio_copy_kern_endio(struct bio *bio, int err)
  794. {
  795. struct bio_vec *bvec;
  796. const int read = bio_data_dir(bio) == READ;
  797. char *p = bio->bi_private;
  798. int i;
  799. __bio_for_each_segment(bvec, bio, i, 0) {
  800. char *addr = page_address(bvec->bv_page);
  801. if (read && !err)
  802. memcpy(p, addr, bvec->bv_len);
  803. __free_page(bvec->bv_page);
  804. p += bvec->bv_len;
  805. }
  806. bio_put(bio);
  807. }
  808. /**
  809. * bio_copy_kern - copy kernel address into bio
  810. * @q: the struct request_queue for the bio
  811. * @data: pointer to buffer to copy
  812. * @len: length in bytes
  813. * @gfp_mask: allocation flags for bio and page allocation
  814. * @reading: data direction is READ
  815. *
  816. * copy the kernel address into a bio suitable for io to a block
  817. * device. Returns an error pointer in case of error.
  818. */
  819. struct bio *bio_copy_kern(struct request_queue *q, void *data, unsigned int len,
  820. gfp_t gfp_mask, int reading)
  821. {
  822. unsigned long kaddr = (unsigned long)data;
  823. unsigned long end = (kaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
  824. unsigned long start = kaddr >> PAGE_SHIFT;
  825. const int nr_pages = end - start;
  826. struct bio *bio;
  827. struct bio_vec *bvec;
  828. int i, ret;
  829. bio = bio_alloc(gfp_mask, nr_pages);
  830. if (!bio)
  831. return ERR_PTR(-ENOMEM);
  832. while (len) {
  833. struct page *page;
  834. unsigned int bytes = PAGE_SIZE;
  835. if (bytes > len)
  836. bytes = len;
  837. page = alloc_page(q->bounce_gfp | gfp_mask);
  838. if (!page) {
  839. ret = -ENOMEM;
  840. goto cleanup;
  841. }
  842. if (bio_add_pc_page(q, bio, page, bytes, 0) < bytes) {
  843. ret = -EINVAL;
  844. goto cleanup;
  845. }
  846. len -= bytes;
  847. }
  848. if (!reading) {
  849. void *p = data;
  850. bio_for_each_segment(bvec, bio, i) {
  851. char *addr = page_address(bvec->bv_page);
  852. memcpy(addr, p, bvec->bv_len);
  853. p += bvec->bv_len;
  854. }
  855. }
  856. bio->bi_private = data;
  857. bio->bi_end_io = bio_copy_kern_endio;
  858. return bio;
  859. cleanup:
  860. bio_for_each_segment(bvec, bio, i)
  861. __free_page(bvec->bv_page);
  862. bio_put(bio);
  863. return ERR_PTR(ret);
  864. }
  865. /*
  866. * bio_set_pages_dirty() and bio_check_pages_dirty() are support functions
  867. * for performing direct-IO in BIOs.
  868. *
  869. * The problem is that we cannot run set_page_dirty() from interrupt context
  870. * because the required locks are not interrupt-safe. So what we can do is to
  871. * mark the pages dirty _before_ performing IO. And in interrupt context,
  872. * check that the pages are still dirty. If so, fine. If not, redirty them
  873. * in process context.
  874. *
  875. * We special-case compound pages here: normally this means reads into hugetlb
  876. * pages. The logic in here doesn't really work right for compound pages
  877. * because the VM does not uniformly chase down the head page in all cases.
  878. * But dirtiness of compound pages is pretty meaningless anyway: the VM doesn't
  879. * handle them at all. So we skip compound pages here at an early stage.
  880. *
  881. * Note that this code is very hard to test under normal circumstances because
  882. * direct-io pins the pages with get_user_pages(). This makes
  883. * is_page_cache_freeable return false, and the VM will not clean the pages.
  884. * But other code (eg, pdflush) could clean the pages if they are mapped
  885. * pagecache.
  886. *
  887. * Simply disabling the call to bio_set_pages_dirty() is a good way to test the
  888. * deferred bio dirtying paths.
  889. */
  890. /*
  891. * bio_set_pages_dirty() will mark all the bio's pages as dirty.
  892. */
  893. void bio_set_pages_dirty(struct bio *bio)
  894. {
  895. struct bio_vec *bvec = bio->bi_io_vec;
  896. int i;
  897. for (i = 0; i < bio->bi_vcnt; i++) {
  898. struct page *page = bvec[i].bv_page;
  899. if (page && !PageCompound(page))
  900. set_page_dirty_lock(page);
  901. }
  902. }
  903. static void bio_release_pages(struct bio *bio)
  904. {
  905. struct bio_vec *bvec = bio->bi_io_vec;
  906. int i;
  907. for (i = 0; i < bio->bi_vcnt; i++) {
  908. struct page *page = bvec[i].bv_page;
  909. if (page)
  910. put_page(page);
  911. }
  912. }
  913. /*
  914. * bio_check_pages_dirty() will check that all the BIO's pages are still dirty.
  915. * If they are, then fine. If, however, some pages are clean then they must
  916. * have been written out during the direct-IO read. So we take another ref on
  917. * the BIO and the offending pages and re-dirty the pages in process context.
  918. *
  919. * It is expected that bio_check_pages_dirty() will wholly own the BIO from
  920. * here on. It will run one page_cache_release() against each page and will
  921. * run one bio_put() against the BIO.
  922. */
  923. static void bio_dirty_fn(struct work_struct *work);
  924. static DECLARE_WORK(bio_dirty_work, bio_dirty_fn);
  925. static DEFINE_SPINLOCK(bio_dirty_lock);
  926. static struct bio *bio_dirty_list;
  927. /*
  928. * This runs in process context
  929. */
  930. static void bio_dirty_fn(struct work_struct *work)
  931. {
  932. unsigned long flags;
  933. struct bio *bio;
  934. spin_lock_irqsave(&bio_dirty_lock, flags);
  935. bio = bio_dirty_list;
  936. bio_dirty_list = NULL;
  937. spin_unlock_irqrestore(&bio_dirty_lock, flags);
  938. while (bio) {
  939. struct bio *next = bio->bi_private;
  940. bio_set_pages_dirty(bio);
  941. bio_release_pages(bio);
  942. bio_put(bio);
  943. bio = next;
  944. }
  945. }
  946. void bio_check_pages_dirty(struct bio *bio)
  947. {
  948. struct bio_vec *bvec = bio->bi_io_vec;
  949. int nr_clean_pages = 0;
  950. int i;
  951. for (i = 0; i < bio->bi_vcnt; i++) {
  952. struct page *page = bvec[i].bv_page;
  953. if (PageDirty(page) || PageCompound(page)) {
  954. page_cache_release(page);
  955. bvec[i].bv_page = NULL;
  956. } else {
  957. nr_clean_pages++;
  958. }
  959. }
  960. if (nr_clean_pages) {
  961. unsigned long flags;
  962. spin_lock_irqsave(&bio_dirty_lock, flags);
  963. bio->bi_private = bio_dirty_list;
  964. bio_dirty_list = bio;
  965. spin_unlock_irqrestore(&bio_dirty_lock, flags);
  966. schedule_work(&bio_dirty_work);
  967. } else {
  968. bio_put(bio);
  969. }
  970. }
  971. /**
  972. * bio_endio - end I/O on a bio
  973. * @bio: bio
  974. * @error: error, if any
  975. *
  976. * Description:
  977. * bio_endio() will end I/O on the whole bio. bio_endio() is the
  978. * preferred way to end I/O on a bio, it takes care of clearing
  979. * BIO_UPTODATE on error. @error is 0 on success, and and one of the
  980. * established -Exxxx (-EIO, for instance) error values in case
  981. * something went wrong. Noone should call bi_end_io() directly on a
  982. * bio unless they own it and thus know that it has an end_io
  983. * function.
  984. **/
  985. void bio_endio(struct bio *bio, int error)
  986. {
  987. if (error)
  988. clear_bit(BIO_UPTODATE, &bio->bi_flags);
  989. else if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
  990. error = -EIO;
  991. if (bio->bi_end_io)
  992. bio->bi_end_io(bio, error);
  993. }
  994. void bio_pair_release(struct bio_pair *bp)
  995. {
  996. if (atomic_dec_and_test(&bp->cnt)) {
  997. struct bio *master = bp->bio1.bi_private;
  998. bio_endio(master, bp->error);
  999. mempool_free(bp, bp->bio2.bi_private);
  1000. }
  1001. }
  1002. static void bio_pair_end_1(struct bio *bi, int err)
  1003. {
  1004. struct bio_pair *bp = container_of(bi, struct bio_pair, bio1);
  1005. if (err)
  1006. bp->error = err;
  1007. bio_pair_release(bp);
  1008. }
  1009. static void bio_pair_end_2(struct bio *bi, int err)
  1010. {
  1011. struct bio_pair *bp = container_of(bi, struct bio_pair, bio2);
  1012. if (err)
  1013. bp->error = err;
  1014. bio_pair_release(bp);
  1015. }
  1016. /*
  1017. * split a bio - only worry about a bio with a single page
  1018. * in it's iovec
  1019. */
  1020. struct bio_pair *bio_split(struct bio *bi, mempool_t *pool, int first_sectors)
  1021. {
  1022. struct bio_pair *bp = mempool_alloc(pool, GFP_NOIO);
  1023. if (!bp)
  1024. return bp;
  1025. blk_add_trace_pdu_int(bdev_get_queue(bi->bi_bdev), BLK_TA_SPLIT, bi,
  1026. bi->bi_sector + first_sectors);
  1027. BUG_ON(bi->bi_vcnt != 1);
  1028. BUG_ON(bi->bi_idx != 0);
  1029. atomic_set(&bp->cnt, 3);
  1030. bp->error = 0;
  1031. bp->bio1 = *bi;
  1032. bp->bio2 = *bi;
  1033. bp->bio2.bi_sector += first_sectors;
  1034. bp->bio2.bi_size -= first_sectors << 9;
  1035. bp->bio1.bi_size = first_sectors << 9;
  1036. bp->bv1 = bi->bi_io_vec[0];
  1037. bp->bv2 = bi->bi_io_vec[0];
  1038. bp->bv2.bv_offset += first_sectors << 9;
  1039. bp->bv2.bv_len -= first_sectors << 9;
  1040. bp->bv1.bv_len = first_sectors << 9;
  1041. bp->bio1.bi_io_vec = &bp->bv1;
  1042. bp->bio2.bi_io_vec = &bp->bv2;
  1043. bp->bio1.bi_max_vecs = 1;
  1044. bp->bio2.bi_max_vecs = 1;
  1045. bp->bio1.bi_end_io = bio_pair_end_1;
  1046. bp->bio2.bi_end_io = bio_pair_end_2;
  1047. bp->bio1.bi_private = bi;
  1048. bp->bio2.bi_private = pool;
  1049. return bp;
  1050. }
  1051. /*
  1052. * create memory pools for biovec's in a bio_set.
  1053. * use the global biovec slabs created for general use.
  1054. */
  1055. static int biovec_create_pools(struct bio_set *bs, int pool_entries)
  1056. {
  1057. int i;
  1058. for (i = 0; i < BIOVEC_NR_POOLS; i++) {
  1059. struct biovec_slab *bp = bvec_slabs + i;
  1060. mempool_t **bvp = bs->bvec_pools + i;
  1061. *bvp = mempool_create_slab_pool(pool_entries, bp->slab);
  1062. if (!*bvp)
  1063. return -ENOMEM;
  1064. }
  1065. return 0;
  1066. }
  1067. static void biovec_free_pools(struct bio_set *bs)
  1068. {
  1069. int i;
  1070. for (i = 0; i < BIOVEC_NR_POOLS; i++) {
  1071. mempool_t *bvp = bs->bvec_pools[i];
  1072. if (bvp)
  1073. mempool_destroy(bvp);
  1074. }
  1075. }
  1076. void bioset_free(struct bio_set *bs)
  1077. {
  1078. if (bs->bio_pool)
  1079. mempool_destroy(bs->bio_pool);
  1080. biovec_free_pools(bs);
  1081. kfree(bs);
  1082. }
  1083. struct bio_set *bioset_create(int bio_pool_size, int bvec_pool_size)
  1084. {
  1085. struct bio_set *bs = kzalloc(sizeof(*bs), GFP_KERNEL);
  1086. if (!bs)
  1087. return NULL;
  1088. bs->bio_pool = mempool_create_slab_pool(bio_pool_size, bio_slab);
  1089. if (!bs->bio_pool)
  1090. goto bad;
  1091. if (!biovec_create_pools(bs, bvec_pool_size))
  1092. return bs;
  1093. bad:
  1094. bioset_free(bs);
  1095. return NULL;
  1096. }
  1097. static void __init biovec_init_slabs(void)
  1098. {
  1099. int i;
  1100. for (i = 0; i < BIOVEC_NR_POOLS; i++) {
  1101. int size;
  1102. struct biovec_slab *bvs = bvec_slabs + i;
  1103. size = bvs->nr_vecs * sizeof(struct bio_vec);
  1104. bvs->slab = kmem_cache_create(bvs->name, size, 0,
  1105. SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
  1106. }
  1107. }
  1108. static int __init init_bio(void)
  1109. {
  1110. bio_slab = KMEM_CACHE(bio, SLAB_HWCACHE_ALIGN|SLAB_PANIC);
  1111. biovec_init_slabs();
  1112. fs_bio_set = bioset_create(BIO_POOL_SIZE, 2);
  1113. if (!fs_bio_set)
  1114. panic("bio: can't allocate bios\n");
  1115. bio_split_pool = mempool_create_kmalloc_pool(BIO_SPLIT_ENTRIES,
  1116. sizeof(struct bio_pair));
  1117. if (!bio_split_pool)
  1118. panic("bio: can't create split pool\n");
  1119. return 0;
  1120. }
  1121. subsys_initcall(init_bio);
  1122. EXPORT_SYMBOL(bio_alloc);
  1123. EXPORT_SYMBOL(bio_put);
  1124. EXPORT_SYMBOL(bio_free);
  1125. EXPORT_SYMBOL(bio_endio);
  1126. EXPORT_SYMBOL(bio_init);
  1127. EXPORT_SYMBOL(__bio_clone);
  1128. EXPORT_SYMBOL(bio_clone);
  1129. EXPORT_SYMBOL(bio_phys_segments);
  1130. EXPORT_SYMBOL(bio_hw_segments);
  1131. EXPORT_SYMBOL(bio_add_page);
  1132. EXPORT_SYMBOL(bio_add_pc_page);
  1133. EXPORT_SYMBOL(bio_get_nr_vecs);
  1134. EXPORT_SYMBOL(bio_map_user);
  1135. EXPORT_SYMBOL(bio_unmap_user);
  1136. EXPORT_SYMBOL(bio_map_kern);
  1137. EXPORT_SYMBOL(bio_copy_kern);
  1138. EXPORT_SYMBOL(bio_pair_release);
  1139. EXPORT_SYMBOL(bio_split);
  1140. EXPORT_SYMBOL(bio_split_pool);
  1141. EXPORT_SYMBOL(bio_copy_user);
  1142. EXPORT_SYMBOL(bio_uncopy_user);
  1143. EXPORT_SYMBOL(bioset_create);
  1144. EXPORT_SYMBOL(bioset_free);
  1145. EXPORT_SYMBOL(bio_alloc_bioset);