bio.c 32 KB

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