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