bio.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  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. struct sg_iovec *sgvecs;
  380. int nr_sgvecs;
  381. int is_our_pages;
  382. };
  383. static void bio_set_map_data(struct bio_map_data *bmd, struct bio *bio,
  384. struct sg_iovec *iov, int iov_count,
  385. int is_our_pages)
  386. {
  387. memcpy(bmd->iovecs, bio->bi_io_vec, sizeof(struct bio_vec) * bio->bi_vcnt);
  388. memcpy(bmd->sgvecs, iov, sizeof(struct sg_iovec) * iov_count);
  389. bmd->nr_sgvecs = iov_count;
  390. bmd->is_our_pages = is_our_pages;
  391. bio->bi_private = bmd;
  392. }
  393. static void bio_free_map_data(struct bio_map_data *bmd)
  394. {
  395. kfree(bmd->iovecs);
  396. kfree(bmd->sgvecs);
  397. kfree(bmd);
  398. }
  399. static struct bio_map_data *bio_alloc_map_data(int nr_segs, int iov_count,
  400. gfp_t gfp_mask)
  401. {
  402. struct bio_map_data *bmd = kmalloc(sizeof(*bmd), gfp_mask);
  403. if (!bmd)
  404. return NULL;
  405. bmd->iovecs = kmalloc(sizeof(struct bio_vec) * nr_segs, gfp_mask);
  406. if (!bmd->iovecs) {
  407. kfree(bmd);
  408. return NULL;
  409. }
  410. bmd->sgvecs = kmalloc(sizeof(struct sg_iovec) * iov_count, gfp_mask);
  411. if (bmd->sgvecs)
  412. return bmd;
  413. kfree(bmd->iovecs);
  414. kfree(bmd);
  415. return NULL;
  416. }
  417. static int __bio_copy_iov(struct bio *bio, struct bio_vec *iovecs,
  418. struct sg_iovec *iov, int iov_count, int uncopy,
  419. int do_free_page)
  420. {
  421. int ret = 0, i;
  422. struct bio_vec *bvec;
  423. int iov_idx = 0;
  424. unsigned int iov_off = 0;
  425. int read = bio_data_dir(bio) == READ;
  426. __bio_for_each_segment(bvec, bio, i, 0) {
  427. char *bv_addr = page_address(bvec->bv_page);
  428. unsigned int bv_len = iovecs[i].bv_len;
  429. while (bv_len && iov_idx < iov_count) {
  430. unsigned int bytes;
  431. char *iov_addr;
  432. bytes = min_t(unsigned int,
  433. iov[iov_idx].iov_len - iov_off, bv_len);
  434. iov_addr = iov[iov_idx].iov_base + iov_off;
  435. if (!ret) {
  436. if (!read && !uncopy)
  437. ret = copy_from_user(bv_addr, iov_addr,
  438. bytes);
  439. if (read && uncopy)
  440. ret = copy_to_user(iov_addr, bv_addr,
  441. bytes);
  442. if (ret)
  443. ret = -EFAULT;
  444. }
  445. bv_len -= bytes;
  446. bv_addr += bytes;
  447. iov_addr += bytes;
  448. iov_off += bytes;
  449. if (iov[iov_idx].iov_len == iov_off) {
  450. iov_idx++;
  451. iov_off = 0;
  452. }
  453. }
  454. if (do_free_page)
  455. __free_page(bvec->bv_page);
  456. }
  457. return ret;
  458. }
  459. /**
  460. * bio_uncopy_user - finish previously mapped bio
  461. * @bio: bio being terminated
  462. *
  463. * Free pages allocated from bio_copy_user() and write back data
  464. * to user space in case of a read.
  465. */
  466. int bio_uncopy_user(struct bio *bio)
  467. {
  468. struct bio_map_data *bmd = bio->bi_private;
  469. int ret;
  470. ret = __bio_copy_iov(bio, bmd->iovecs, bmd->sgvecs, bmd->nr_sgvecs, 1,
  471. bmd->is_our_pages);
  472. bio_free_map_data(bmd);
  473. bio_put(bio);
  474. return ret;
  475. }
  476. /**
  477. * bio_copy_user_iov - copy user data to bio
  478. * @q: destination block queue
  479. * @map_data: pointer to the rq_map_data holding pages (if necessary)
  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. * @gfp_mask: memory allocation flags
  484. *
  485. * Prepares and returns a bio for indirect user io, bouncing data
  486. * to/from kernel pages as necessary. Must be paired with
  487. * call bio_uncopy_user() on io completion.
  488. */
  489. struct bio *bio_copy_user_iov(struct request_queue *q,
  490. struct rq_map_data *map_data,
  491. struct sg_iovec *iov, int iov_count,
  492. int write_to_vm, gfp_t gfp_mask)
  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, gfp_mask);
  512. if (!bmd)
  513. return ERR_PTR(-ENOMEM);
  514. ret = -ENOMEM;
  515. bio = bio_alloc(gfp_mask, nr_pages);
  516. if (!bio)
  517. goto out_bmd;
  518. bio->bi_rw |= (!write_to_vm << BIO_RW);
  519. ret = 0;
  520. i = 0;
  521. while (len) {
  522. unsigned int bytes;
  523. if (map_data)
  524. bytes = 1U << (PAGE_SHIFT + map_data->page_order);
  525. else
  526. bytes = PAGE_SIZE;
  527. if (bytes > len)
  528. bytes = len;
  529. if (map_data) {
  530. if (i == map_data->nr_entries) {
  531. ret = -ENOMEM;
  532. break;
  533. }
  534. page = map_data->pages[i++];
  535. } else
  536. page = alloc_page(q->bounce_gfp | gfp_mask);
  537. if (!page) {
  538. ret = -ENOMEM;
  539. break;
  540. }
  541. if (bio_add_pc_page(q, bio, page, bytes, 0) < bytes)
  542. break;
  543. len -= bytes;
  544. }
  545. if (ret)
  546. goto cleanup;
  547. /*
  548. * success
  549. */
  550. if (!write_to_vm) {
  551. ret = __bio_copy_iov(bio, bio->bi_io_vec, iov, iov_count, 0, 0);
  552. if (ret)
  553. goto cleanup;
  554. }
  555. bio_set_map_data(bmd, bio, iov, iov_count, map_data ? 0 : 1);
  556. return bio;
  557. cleanup:
  558. if (!map_data)
  559. bio_for_each_segment(bvec, bio, i)
  560. __free_page(bvec->bv_page);
  561. bio_put(bio);
  562. out_bmd:
  563. bio_free_map_data(bmd);
  564. return ERR_PTR(ret);
  565. }
  566. /**
  567. * bio_copy_user - copy user data to bio
  568. * @q: destination block queue
  569. * @map_data: pointer to the rq_map_data holding pages (if necessary)
  570. * @uaddr: start of user address
  571. * @len: length in bytes
  572. * @write_to_vm: bool indicating writing to pages or not
  573. * @gfp_mask: memory allocation flags
  574. *
  575. * Prepares and returns a bio for indirect user io, bouncing data
  576. * to/from kernel pages as necessary. Must be paired with
  577. * call bio_uncopy_user() on io completion.
  578. */
  579. struct bio *bio_copy_user(struct request_queue *q, struct rq_map_data *map_data,
  580. unsigned long uaddr, unsigned int len,
  581. int write_to_vm, gfp_t gfp_mask)
  582. {
  583. struct sg_iovec iov;
  584. iov.iov_base = (void __user *)uaddr;
  585. iov.iov_len = len;
  586. return bio_copy_user_iov(q, map_data, &iov, 1, write_to_vm, gfp_mask);
  587. }
  588. static struct bio *__bio_map_user_iov(struct request_queue *q,
  589. struct block_device *bdev,
  590. struct sg_iovec *iov, int iov_count,
  591. int write_to_vm, gfp_t gfp_mask)
  592. {
  593. int i, j;
  594. int nr_pages = 0;
  595. struct page **pages;
  596. struct bio *bio;
  597. int cur_page = 0;
  598. int ret, offset;
  599. for (i = 0; i < iov_count; i++) {
  600. unsigned long uaddr = (unsigned long)iov[i].iov_base;
  601. unsigned long len = iov[i].iov_len;
  602. unsigned long end = (uaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
  603. unsigned long start = uaddr >> PAGE_SHIFT;
  604. nr_pages += end - start;
  605. /*
  606. * buffer must be aligned to at least hardsector size for now
  607. */
  608. if (uaddr & queue_dma_alignment(q))
  609. return ERR_PTR(-EINVAL);
  610. }
  611. if (!nr_pages)
  612. return ERR_PTR(-EINVAL);
  613. bio = bio_alloc(gfp_mask, nr_pages);
  614. if (!bio)
  615. return ERR_PTR(-ENOMEM);
  616. ret = -ENOMEM;
  617. pages = kcalloc(nr_pages, sizeof(struct page *), gfp_mask);
  618. if (!pages)
  619. goto out;
  620. for (i = 0; i < iov_count; i++) {
  621. unsigned long uaddr = (unsigned long)iov[i].iov_base;
  622. unsigned long len = iov[i].iov_len;
  623. unsigned long end = (uaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
  624. unsigned long start = uaddr >> PAGE_SHIFT;
  625. const int local_nr_pages = end - start;
  626. const int page_limit = cur_page + local_nr_pages;
  627. ret = get_user_pages_fast(uaddr, local_nr_pages,
  628. write_to_vm, &pages[cur_page]);
  629. if (ret < local_nr_pages) {
  630. ret = -EFAULT;
  631. goto out_unmap;
  632. }
  633. offset = uaddr & ~PAGE_MASK;
  634. for (j = cur_page; j < page_limit; j++) {
  635. unsigned int bytes = PAGE_SIZE - offset;
  636. if (len <= 0)
  637. break;
  638. if (bytes > len)
  639. bytes = len;
  640. /*
  641. * sorry...
  642. */
  643. if (bio_add_pc_page(q, bio, pages[j], bytes, offset) <
  644. bytes)
  645. break;
  646. len -= bytes;
  647. offset = 0;
  648. }
  649. cur_page = j;
  650. /*
  651. * release the pages we didn't map into the bio, if any
  652. */
  653. while (j < page_limit)
  654. page_cache_release(pages[j++]);
  655. }
  656. kfree(pages);
  657. /*
  658. * set data direction, and check if mapped pages need bouncing
  659. */
  660. if (!write_to_vm)
  661. bio->bi_rw |= (1 << BIO_RW);
  662. bio->bi_bdev = bdev;
  663. bio->bi_flags |= (1 << BIO_USER_MAPPED);
  664. return bio;
  665. out_unmap:
  666. for (i = 0; i < nr_pages; i++) {
  667. if(!pages[i])
  668. break;
  669. page_cache_release(pages[i]);
  670. }
  671. out:
  672. kfree(pages);
  673. bio_put(bio);
  674. return ERR_PTR(ret);
  675. }
  676. /**
  677. * bio_map_user - map user address into bio
  678. * @q: the struct request_queue for the bio
  679. * @bdev: destination block device
  680. * @uaddr: start of user address
  681. * @len: length in bytes
  682. * @write_to_vm: bool indicating writing to pages or not
  683. * @gfp_mask: memory allocation flags
  684. *
  685. * Map the user space address into a bio suitable for io to a block
  686. * device. Returns an error pointer in case of error.
  687. */
  688. struct bio *bio_map_user(struct request_queue *q, struct block_device *bdev,
  689. unsigned long uaddr, unsigned int len, int write_to_vm,
  690. gfp_t gfp_mask)
  691. {
  692. struct sg_iovec iov;
  693. iov.iov_base = (void __user *)uaddr;
  694. iov.iov_len = len;
  695. return bio_map_user_iov(q, bdev, &iov, 1, write_to_vm, gfp_mask);
  696. }
  697. /**
  698. * bio_map_user_iov - map user sg_iovec table into bio
  699. * @q: the struct request_queue for the bio
  700. * @bdev: destination block device
  701. * @iov: the iovec.
  702. * @iov_count: number of elements in the iovec
  703. * @write_to_vm: bool indicating writing to pages or not
  704. * @gfp_mask: memory allocation flags
  705. *
  706. * Map the user space address into a bio suitable for io to a block
  707. * device. Returns an error pointer in case of error.
  708. */
  709. struct bio *bio_map_user_iov(struct request_queue *q, struct block_device *bdev,
  710. struct sg_iovec *iov, int iov_count,
  711. int write_to_vm, gfp_t gfp_mask)
  712. {
  713. struct bio *bio;
  714. bio = __bio_map_user_iov(q, bdev, iov, iov_count, write_to_vm,
  715. gfp_mask);
  716. if (IS_ERR(bio))
  717. return bio;
  718. /*
  719. * subtle -- if __bio_map_user() ended up bouncing a bio,
  720. * it would normally disappear when its bi_end_io is run.
  721. * however, we need it for the unmap, so grab an extra
  722. * reference to it
  723. */
  724. bio_get(bio);
  725. return bio;
  726. }
  727. static void __bio_unmap_user(struct bio *bio)
  728. {
  729. struct bio_vec *bvec;
  730. int i;
  731. /*
  732. * make sure we dirty pages we wrote to
  733. */
  734. __bio_for_each_segment(bvec, bio, i, 0) {
  735. if (bio_data_dir(bio) == READ)
  736. set_page_dirty_lock(bvec->bv_page);
  737. page_cache_release(bvec->bv_page);
  738. }
  739. bio_put(bio);
  740. }
  741. /**
  742. * bio_unmap_user - unmap a bio
  743. * @bio: the bio being unmapped
  744. *
  745. * Unmap a bio previously mapped by bio_map_user(). Must be called with
  746. * a process context.
  747. *
  748. * bio_unmap_user() may sleep.
  749. */
  750. void bio_unmap_user(struct bio *bio)
  751. {
  752. __bio_unmap_user(bio);
  753. bio_put(bio);
  754. }
  755. static void bio_map_kern_endio(struct bio *bio, int err)
  756. {
  757. bio_put(bio);
  758. }
  759. static struct bio *__bio_map_kern(struct request_queue *q, void *data,
  760. unsigned int len, gfp_t gfp_mask)
  761. {
  762. unsigned long kaddr = (unsigned long)data;
  763. unsigned long end = (kaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
  764. unsigned long start = kaddr >> PAGE_SHIFT;
  765. const int nr_pages = end - start;
  766. int offset, i;
  767. struct bio *bio;
  768. bio = bio_alloc(gfp_mask, nr_pages);
  769. if (!bio)
  770. return ERR_PTR(-ENOMEM);
  771. offset = offset_in_page(kaddr);
  772. for (i = 0; i < nr_pages; i++) {
  773. unsigned int bytes = PAGE_SIZE - offset;
  774. if (len <= 0)
  775. break;
  776. if (bytes > len)
  777. bytes = len;
  778. if (bio_add_pc_page(q, bio, virt_to_page(data), bytes,
  779. offset) < bytes)
  780. break;
  781. data += bytes;
  782. len -= bytes;
  783. offset = 0;
  784. }
  785. bio->bi_end_io = bio_map_kern_endio;
  786. return bio;
  787. }
  788. /**
  789. * bio_map_kern - map kernel address into bio
  790. * @q: the struct request_queue for the bio
  791. * @data: pointer to buffer to map
  792. * @len: length in bytes
  793. * @gfp_mask: allocation flags for bio allocation
  794. *
  795. * Map the kernel address into a bio suitable for io to a block
  796. * device. Returns an error pointer in case of error.
  797. */
  798. struct bio *bio_map_kern(struct request_queue *q, void *data, unsigned int len,
  799. gfp_t gfp_mask)
  800. {
  801. struct bio *bio;
  802. bio = __bio_map_kern(q, data, len, gfp_mask);
  803. if (IS_ERR(bio))
  804. return bio;
  805. if (bio->bi_size == len)
  806. return bio;
  807. /*
  808. * Don't support partial mappings.
  809. */
  810. bio_put(bio);
  811. return ERR_PTR(-EINVAL);
  812. }
  813. static void bio_copy_kern_endio(struct bio *bio, int err)
  814. {
  815. struct bio_vec *bvec;
  816. const int read = bio_data_dir(bio) == READ;
  817. struct bio_map_data *bmd = bio->bi_private;
  818. int i;
  819. char *p = bmd->sgvecs[0].iov_base;
  820. __bio_for_each_segment(bvec, bio, i, 0) {
  821. char *addr = page_address(bvec->bv_page);
  822. int len = bmd->iovecs[i].bv_len;
  823. if (read && !err)
  824. memcpy(p, addr, len);
  825. __free_page(bvec->bv_page);
  826. p += len;
  827. }
  828. bio_free_map_data(bmd);
  829. bio_put(bio);
  830. }
  831. /**
  832. * bio_copy_kern - copy kernel address into bio
  833. * @q: the struct request_queue for the bio
  834. * @data: pointer to buffer to copy
  835. * @len: length in bytes
  836. * @gfp_mask: allocation flags for bio and page allocation
  837. * @reading: data direction is READ
  838. *
  839. * copy the kernel address into a bio suitable for io to a block
  840. * device. Returns an error pointer in case of error.
  841. */
  842. struct bio *bio_copy_kern(struct request_queue *q, void *data, unsigned int len,
  843. gfp_t gfp_mask, int reading)
  844. {
  845. struct bio *bio;
  846. struct bio_vec *bvec;
  847. int i;
  848. bio = bio_copy_user(q, NULL, (unsigned long)data, len, 1, gfp_mask);
  849. if (IS_ERR(bio))
  850. return bio;
  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_end_io = bio_copy_kern_endio;
  860. return bio;
  861. }
  862. /*
  863. * bio_set_pages_dirty() and bio_check_pages_dirty() are support functions
  864. * for performing direct-IO in BIOs.
  865. *
  866. * The problem is that we cannot run set_page_dirty() from interrupt context
  867. * because the required locks are not interrupt-safe. So what we can do is to
  868. * mark the pages dirty _before_ performing IO. And in interrupt context,
  869. * check that the pages are still dirty. If so, fine. If not, redirty them
  870. * in process context.
  871. *
  872. * We special-case compound pages here: normally this means reads into hugetlb
  873. * pages. The logic in here doesn't really work right for compound pages
  874. * because the VM does not uniformly chase down the head page in all cases.
  875. * But dirtiness of compound pages is pretty meaningless anyway: the VM doesn't
  876. * handle them at all. So we skip compound pages here at an early stage.
  877. *
  878. * Note that this code is very hard to test under normal circumstances because
  879. * direct-io pins the pages with get_user_pages(). This makes
  880. * is_page_cache_freeable return false, and the VM will not clean the pages.
  881. * But other code (eg, pdflush) could clean the pages if they are mapped
  882. * pagecache.
  883. *
  884. * Simply disabling the call to bio_set_pages_dirty() is a good way to test the
  885. * deferred bio dirtying paths.
  886. */
  887. /*
  888. * bio_set_pages_dirty() will mark all the bio's pages as dirty.
  889. */
  890. void bio_set_pages_dirty(struct bio *bio)
  891. {
  892. struct bio_vec *bvec = bio->bi_io_vec;
  893. int i;
  894. for (i = 0; i < bio->bi_vcnt; i++) {
  895. struct page *page = bvec[i].bv_page;
  896. if (page && !PageCompound(page))
  897. set_page_dirty_lock(page);
  898. }
  899. }
  900. static void bio_release_pages(struct bio *bio)
  901. {
  902. struct bio_vec *bvec = bio->bi_io_vec;
  903. int i;
  904. for (i = 0; i < bio->bi_vcnt; i++) {
  905. struct page *page = bvec[i].bv_page;
  906. if (page)
  907. put_page(page);
  908. }
  909. }
  910. /*
  911. * bio_check_pages_dirty() will check that all the BIO's pages are still dirty.
  912. * If they are, then fine. If, however, some pages are clean then they must
  913. * have been written out during the direct-IO read. So we take another ref on
  914. * the BIO and the offending pages and re-dirty the pages in process context.
  915. *
  916. * It is expected that bio_check_pages_dirty() will wholly own the BIO from
  917. * here on. It will run one page_cache_release() against each page and will
  918. * run one bio_put() against the BIO.
  919. */
  920. static void bio_dirty_fn(struct work_struct *work);
  921. static DECLARE_WORK(bio_dirty_work, bio_dirty_fn);
  922. static DEFINE_SPINLOCK(bio_dirty_lock);
  923. static struct bio *bio_dirty_list;
  924. /*
  925. * This runs in process context
  926. */
  927. static void bio_dirty_fn(struct work_struct *work)
  928. {
  929. unsigned long flags;
  930. struct bio *bio;
  931. spin_lock_irqsave(&bio_dirty_lock, flags);
  932. bio = bio_dirty_list;
  933. bio_dirty_list = NULL;
  934. spin_unlock_irqrestore(&bio_dirty_lock, flags);
  935. while (bio) {
  936. struct bio *next = bio->bi_private;
  937. bio_set_pages_dirty(bio);
  938. bio_release_pages(bio);
  939. bio_put(bio);
  940. bio = next;
  941. }
  942. }
  943. void bio_check_pages_dirty(struct bio *bio)
  944. {
  945. struct bio_vec *bvec = bio->bi_io_vec;
  946. int nr_clean_pages = 0;
  947. int i;
  948. for (i = 0; i < bio->bi_vcnt; i++) {
  949. struct page *page = bvec[i].bv_page;
  950. if (PageDirty(page) || PageCompound(page)) {
  951. page_cache_release(page);
  952. bvec[i].bv_page = NULL;
  953. } else {
  954. nr_clean_pages++;
  955. }
  956. }
  957. if (nr_clean_pages) {
  958. unsigned long flags;
  959. spin_lock_irqsave(&bio_dirty_lock, flags);
  960. bio->bi_private = bio_dirty_list;
  961. bio_dirty_list = bio;
  962. spin_unlock_irqrestore(&bio_dirty_lock, flags);
  963. schedule_work(&bio_dirty_work);
  964. } else {
  965. bio_put(bio);
  966. }
  967. }
  968. /**
  969. * bio_endio - end I/O on a bio
  970. * @bio: bio
  971. * @error: error, if any
  972. *
  973. * Description:
  974. * bio_endio() will end I/O on the whole bio. bio_endio() is the
  975. * preferred way to end I/O on a bio, it takes care of clearing
  976. * BIO_UPTODATE on error. @error is 0 on success, and and one of the
  977. * established -Exxxx (-EIO, for instance) error values in case
  978. * something went wrong. Noone should call bi_end_io() directly on a
  979. * bio unless they own it and thus know that it has an end_io
  980. * function.
  981. **/
  982. void bio_endio(struct bio *bio, int error)
  983. {
  984. if (error)
  985. clear_bit(BIO_UPTODATE, &bio->bi_flags);
  986. else if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
  987. error = -EIO;
  988. if (bio->bi_end_io)
  989. bio->bi_end_io(bio, error);
  990. }
  991. void bio_pair_release(struct bio_pair *bp)
  992. {
  993. if (atomic_dec_and_test(&bp->cnt)) {
  994. struct bio *master = bp->bio1.bi_private;
  995. bio_endio(master, bp->error);
  996. mempool_free(bp, bp->bio2.bi_private);
  997. }
  998. }
  999. static void bio_pair_end_1(struct bio *bi, int err)
  1000. {
  1001. struct bio_pair *bp = container_of(bi, struct bio_pair, bio1);
  1002. if (err)
  1003. bp->error = err;
  1004. bio_pair_release(bp);
  1005. }
  1006. static void bio_pair_end_2(struct bio *bi, int err)
  1007. {
  1008. struct bio_pair *bp = container_of(bi, struct bio_pair, bio2);
  1009. if (err)
  1010. bp->error = err;
  1011. bio_pair_release(bp);
  1012. }
  1013. /*
  1014. * split a bio - only worry about a bio with a single page
  1015. * in it's iovec
  1016. */
  1017. struct bio_pair *bio_split(struct bio *bi, mempool_t *pool, int first_sectors)
  1018. {
  1019. struct bio_pair *bp = mempool_alloc(pool, GFP_NOIO);
  1020. if (!bp)
  1021. return bp;
  1022. blk_add_trace_pdu_int(bdev_get_queue(bi->bi_bdev), BLK_TA_SPLIT, bi,
  1023. bi->bi_sector + first_sectors);
  1024. BUG_ON(bi->bi_vcnt != 1);
  1025. BUG_ON(bi->bi_idx != 0);
  1026. atomic_set(&bp->cnt, 3);
  1027. bp->error = 0;
  1028. bp->bio1 = *bi;
  1029. bp->bio2 = *bi;
  1030. bp->bio2.bi_sector += first_sectors;
  1031. bp->bio2.bi_size -= first_sectors << 9;
  1032. bp->bio1.bi_size = first_sectors << 9;
  1033. bp->bv1 = bi->bi_io_vec[0];
  1034. bp->bv2 = bi->bi_io_vec[0];
  1035. bp->bv2.bv_offset += first_sectors << 9;
  1036. bp->bv2.bv_len -= first_sectors << 9;
  1037. bp->bv1.bv_len = first_sectors << 9;
  1038. bp->bio1.bi_io_vec = &bp->bv1;
  1039. bp->bio2.bi_io_vec = &bp->bv2;
  1040. bp->bio1.bi_max_vecs = 1;
  1041. bp->bio2.bi_max_vecs = 1;
  1042. bp->bio1.bi_end_io = bio_pair_end_1;
  1043. bp->bio2.bi_end_io = bio_pair_end_2;
  1044. bp->bio1.bi_private = bi;
  1045. bp->bio2.bi_private = pool;
  1046. if (bio_integrity(bi))
  1047. bio_integrity_split(bi, bp, first_sectors);
  1048. return bp;
  1049. }
  1050. /*
  1051. * create memory pools for biovec's in a bio_set.
  1052. * use the global biovec slabs created for general use.
  1053. */
  1054. static int biovec_create_pools(struct bio_set *bs, int pool_entries)
  1055. {
  1056. int i;
  1057. for (i = 0; i < BIOVEC_NR_POOLS; i++) {
  1058. struct biovec_slab *bp = bvec_slabs + i;
  1059. mempool_t **bvp = bs->bvec_pools + i;
  1060. *bvp = mempool_create_slab_pool(pool_entries, bp->slab);
  1061. if (!*bvp)
  1062. return -ENOMEM;
  1063. }
  1064. return 0;
  1065. }
  1066. static void biovec_free_pools(struct bio_set *bs)
  1067. {
  1068. int i;
  1069. for (i = 0; i < BIOVEC_NR_POOLS; i++) {
  1070. mempool_t *bvp = bs->bvec_pools[i];
  1071. if (bvp)
  1072. mempool_destroy(bvp);
  1073. }
  1074. }
  1075. void bioset_free(struct bio_set *bs)
  1076. {
  1077. if (bs->bio_pool)
  1078. mempool_destroy(bs->bio_pool);
  1079. bioset_integrity_free(bs);
  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 (bioset_integrity_create(bs, bio_pool_size))
  1092. goto bad;
  1093. if (!biovec_create_pools(bs, bvec_pool_size))
  1094. return bs;
  1095. bad:
  1096. bioset_free(bs);
  1097. return NULL;
  1098. }
  1099. static void __init biovec_init_slabs(void)
  1100. {
  1101. int i;
  1102. for (i = 0; i < BIOVEC_NR_POOLS; i++) {
  1103. int size;
  1104. struct biovec_slab *bvs = bvec_slabs + i;
  1105. size = bvs->nr_vecs * sizeof(struct bio_vec);
  1106. bvs->slab = kmem_cache_create(bvs->name, size, 0,
  1107. SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
  1108. }
  1109. }
  1110. static int __init init_bio(void)
  1111. {
  1112. bio_slab = KMEM_CACHE(bio, SLAB_HWCACHE_ALIGN|SLAB_PANIC);
  1113. bio_integrity_init_slab();
  1114. biovec_init_slabs();
  1115. fs_bio_set = bioset_create(BIO_POOL_SIZE, 2);
  1116. if (!fs_bio_set)
  1117. panic("bio: can't allocate bios\n");
  1118. bio_split_pool = mempool_create_kmalloc_pool(BIO_SPLIT_ENTRIES,
  1119. sizeof(struct bio_pair));
  1120. if (!bio_split_pool)
  1121. panic("bio: can't create split pool\n");
  1122. return 0;
  1123. }
  1124. subsys_initcall(init_bio);
  1125. EXPORT_SYMBOL(bio_alloc);
  1126. EXPORT_SYMBOL(bio_put);
  1127. EXPORT_SYMBOL(bio_free);
  1128. EXPORT_SYMBOL(bio_endio);
  1129. EXPORT_SYMBOL(bio_init);
  1130. EXPORT_SYMBOL(__bio_clone);
  1131. EXPORT_SYMBOL(bio_clone);
  1132. EXPORT_SYMBOL(bio_phys_segments);
  1133. EXPORT_SYMBOL(bio_add_page);
  1134. EXPORT_SYMBOL(bio_add_pc_page);
  1135. EXPORT_SYMBOL(bio_get_nr_vecs);
  1136. EXPORT_SYMBOL(bio_map_user);
  1137. EXPORT_SYMBOL(bio_unmap_user);
  1138. EXPORT_SYMBOL(bio_map_kern);
  1139. EXPORT_SYMBOL(bio_copy_kern);
  1140. EXPORT_SYMBOL(bio_pair_release);
  1141. EXPORT_SYMBOL(bio_split);
  1142. EXPORT_SYMBOL(bio_split_pool);
  1143. EXPORT_SYMBOL(bio_copy_user);
  1144. EXPORT_SYMBOL(bio_uncopy_user);
  1145. EXPORT_SYMBOL(bioset_create);
  1146. EXPORT_SYMBOL(bioset_free);
  1147. EXPORT_SYMBOL(bio_alloc_bioset);