bio.c (712cba5d87a6c0e980ee5fad45734e189c4d7151) bio.c (3a83f4677539bce8eaa2bca9ee9c20e172d7ab04)
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,

--- 256 unchanged lines hidden (view full) ---

265
266 mempool_free(p, bs->bio_pool);
267 } else {
268 /* Bio was allocated by bio_kmalloc() */
269 kfree(bio);
270 }
271}
272
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,

--- 256 unchanged lines hidden (view full) ---

265
266 mempool_free(p, bs->bio_pool);
267 } else {
268 /* Bio was allocated by bio_kmalloc() */
269 kfree(bio);
270 }
271}
272
273void bio_init(struct bio *bio)
273void bio_init(struct bio *bio, struct bio_vec *table,
274 unsigned short max_vecs)
274{
275 memset(bio, 0, sizeof(*bio));
276 atomic_set(&bio->__bi_remaining, 1);
277 atomic_set(&bio->__bi_cnt, 1);
275{
276 memset(bio, 0, sizeof(*bio));
277 atomic_set(&bio->__bi_remaining, 1);
278 atomic_set(&bio->__bi_cnt, 1);
279
280 bio->bi_io_vec = table;
281 bio->bi_max_vecs = max_vecs;
278}
279EXPORT_SYMBOL(bio_init);
280
281/**
282 * bio_reset - reinitialize a bio
283 * @bio: bio to reset
284 *
285 * Description:

--- 189 unchanged lines hidden (view full) ---

475 front_pad = bs->front_pad;
476 inline_vecs = BIO_INLINE_VECS;
477 }
478
479 if (unlikely(!p))
480 return NULL;
481
482 bio = p + front_pad;
282}
283EXPORT_SYMBOL(bio_init);
284
285/**
286 * bio_reset - reinitialize a bio
287 * @bio: bio to reset
288 *
289 * Description:

--- 189 unchanged lines hidden (view full) ---

479 front_pad = bs->front_pad;
480 inline_vecs = BIO_INLINE_VECS;
481 }
482
483 if (unlikely(!p))
484 return NULL;
485
486 bio = p + front_pad;
483 bio_init(bio);
487 bio_init(bio, NULL, 0);
484
485 if (nr_iovecs > inline_vecs) {
486 unsigned long idx = 0;
487
488 bvl = bvec_alloc(gfp_mask, nr_iovecs, &idx, bs->bvec_pool);
489 if (!bvl && gfp_mask != saved_gfp) {
490 punt_bios_to_rescuer(bs);
491 gfp_mask = saved_gfp;

--- 350 unchanged lines hidden (view full) ---

842
843 bio->bi_vcnt++;
844done:
845 bio->bi_iter.bi_size += len;
846 return len;
847}
848EXPORT_SYMBOL(bio_add_page);
849
488
489 if (nr_iovecs > inline_vecs) {
490 unsigned long idx = 0;
491
492 bvl = bvec_alloc(gfp_mask, nr_iovecs, &idx, bs->bvec_pool);
493 if (!bvl && gfp_mask != saved_gfp) {
494 punt_bios_to_rescuer(bs);
495 gfp_mask = saved_gfp;

--- 350 unchanged lines hidden (view full) ---

846
847 bio->bi_vcnt++;
848done:
849 bio->bi_iter.bi_size += len;
850 return len;
851}
852EXPORT_SYMBOL(bio_add_page);
853
854/**
855 * bio_iov_iter_get_pages - pin user or kernel pages and add them to a bio
856 * @bio: bio to add pages to
857 * @iter: iov iterator describing the region to be mapped
858 *
859 * Pins as many pages from *iter and appends them to @bio's bvec array. The
860 * pages will have to be released using put_page() when done.
861 */
862int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter)
863{
864 unsigned short nr_pages = bio->bi_max_vecs - bio->bi_vcnt;
865 struct bio_vec *bv = bio->bi_io_vec + bio->bi_vcnt;
866 struct page **pages = (struct page **)bv;
867 size_t offset, diff;
868 ssize_t size;
869
870 size = iov_iter_get_pages(iter, pages, LONG_MAX, nr_pages, &offset);
871 if (unlikely(size <= 0))
872 return size ? size : -EFAULT;
873 nr_pages = (size + offset + PAGE_SIZE - 1) / PAGE_SIZE;
874
875 /*
876 * Deep magic below: We need to walk the pinned pages backwards
877 * because we are abusing the space allocated for the bio_vecs
878 * for the page array. Because the bio_vecs are larger than the
879 * page pointers by definition this will always work. But it also
880 * means we can't use bio_add_page, so any changes to it's semantics
881 * need to be reflected here as well.
882 */
883 bio->bi_iter.bi_size += size;
884 bio->bi_vcnt += nr_pages;
885
886 diff = (nr_pages * PAGE_SIZE - offset) - size;
887 while (nr_pages--) {
888 bv[nr_pages].bv_page = pages[nr_pages];
889 bv[nr_pages].bv_len = PAGE_SIZE;
890 bv[nr_pages].bv_offset = 0;
891 }
892
893 bv[0].bv_offset += offset;
894 bv[0].bv_len -= offset;
895 if (diff)
896 bv[bio->bi_vcnt - 1].bv_len -= diff;
897
898 iov_iter_advance(iter, size);
899 return 0;
900}
901EXPORT_SYMBOL_GPL(bio_iov_iter_get_pages);
902
850struct submit_bio_ret {
851 struct completion event;
852 int error;
853};
854
855static void submit_bio_wait_endio(struct bio *bio)
856{
857 struct submit_bio_ret *ret = bio->bi_private;

--- 1208 unchanged lines hidden ---
903struct submit_bio_ret {
904 struct completion event;
905 int error;
906};
907
908static void submit_bio_wait_endio(struct bio *bio)
909{
910 struct submit_bio_ret *ret = bio->bi_private;

--- 1208 unchanged lines hidden ---