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