History

block: change how we get page references in bio_iov_iter_get_pages

Instead of needing a special macro to iterate over all pages in a bvec just do a second passs over the whole bio. This also matches what we do on the release side. The release side helper is moved up to where we need the get helper to clearly express the symmetry.

Christoph Hellwig committed 7 years ago

Commit 7321ecb1 parent 14eacf12 files · +25 −31Browse files

Unified · Split

2 files
  1. block/bio.c +25 −26
  2. include/linux/bvec.h +0 −5
block/bio.c+25−26
@@ -861,6 +861,26 @@ int bio_add_page(struct bio *bio, struct page *page, · 860 unmodified lines
861861 }
862862 EXPORT_SYMBOL(bio_add_page);
863863
864+static void bio_get_pages(struct bio *bio)
865+{
866+ struct bvec_iter_all iter_all;
867+ struct bio_vec *bvec;
868+ int i;
869+
870+ bio_for_each_segment_all(bvec, bio, i, iter_all)
871+ get_page(bvec->bv_page);
872+}
873+
874+static void bio_release_pages(struct bio *bio)
875+{
876+ struct bvec_iter_all iter_all;
877+ struct bio_vec *bvec;
878+ int i;
879+
880+ bio_for_each_segment_all(bvec, bio, i, iter_all)
881+ put_page(bvec->bv_page);
882+}
883+
864884 static int __bio_iov_bvec_add_pages(struct bio *bio, struct iov_iter *iter)
865885 {
866886 const struct bio_vec *bv = iter->bvec;
@@ -875,15 +895,6 @@ static int __bio_iov_bvec_add_pages(struct bio *bio, struct iov_iter *iter) · 8 unmodified lines
875895 bv->bv_offset + iter->iov_offset);
876896 if (unlikely(size != len))
877897 return -EINVAL;
878−
879− if (!bio_flagged(bio, BIO_NO_PAGE_REF)) {
880− struct page *page;
881− int i;
882−
883− mp_bvec_for_each_page(page, bv, i)
884− get_page(page);
885− }
886−
887898 iov_iter_advance(iter, size);
888899 return 0;
889900 }
@@ -963,13 +974,6 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) · 73 unmodified lines
963974 if (WARN_ON_ONCE(bio->bi_vcnt))
964975 return -EINVAL;
965976
966− /*
967− * If this is a BVEC iter, then the pages are kernel pages. Don't
968− * release them on IO completion, if the caller asked us to.
969− */
970− if (is_bvec && iov_iter_bvec_no_ref(iter))
971− bio_set_flag(bio, BIO_NO_PAGE_REF);
972−
973977 do {
974978 if (is_bvec)
975979 ret = __bio_iov_bvec_add_pages(bio, iter);
@@ -977,6 +981,11 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) · 1 unmodified line
977981 ret = __bio_iov_iter_get_pages(bio, iter);
978982 } while (!ret && iov_iter_count(iter) && !bio_full(bio));
979983
984+ if (iov_iter_bvec_no_ref(iter))
985+ bio_set_flag(bio, BIO_NO_PAGE_REF);
986+ else
987+ bio_get_pages(bio);
988+
980989 return bio->bi_vcnt ? 0 : ret;
981990 }
982991
@@ -1670,16 +1679,6 @@ void bio_set_pages_dirty(struct bio *bio) · 687 unmodified lines
16701679 }
16711680 }
16721681
1673−static void bio_release_pages(struct bio *bio)
1674−{
1675− struct bio_vec *bvec;
1676− int i;
1677− struct bvec_iter_all iter_all;
1678−
1679− bio_for_each_segment_all(bvec, bio, i, iter_all)
1680− put_page(bvec->bv_page);
1681−}
1682−
16831682 /*
16841683 * bio_check_pages_dirty() will check that all the BIO's pages are still dirty.
16851684 * If they are, then fine. If, however, some pages are clean then they must
include/linux/bvec.h+0−5
@@ -189,9 +189,4 @@ static inline void mp_bvec_last_segment(const struct bio_vec *bvec, · 188 unmodified lines
189189 }
190190 }
191191
192−#define mp_bvec_for_each_page(pg, bv, i) \
193− for (i = (bv)->bv_offset / PAGE_SIZE; \
194− (i <= (((bv)->bv_offset + (bv)->bv_len - 1) / PAGE_SIZE)) && \
195− (pg = bvec_nth_page((bv)->bv_page, i)); i += 1)
196−
197192 #endif /* __LINUX_BVEC_ITER_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t