bio.c 32 KB

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