block: move the BIO_NO_PAGE_REF check into bio_release_pages
authorChristoph Hellwig <hch@lst.de>
Wed, 26 Jun 2019 13:49:20 +0000 (15:49 +0200)
committerJens Axboe <axboe@kernel.dk>
Sat, 29 Jun 2019 15:47:31 +0000 (09:47 -0600)
Move the BIO_NO_PAGE_REF check into bio_release_pages instead of
duplicating it in both callers.

Also make the function available outside of bio.c so that we can
reuse it in other direct I/O implementations.

Reviewed-by: Minwoo Im <minwoo.im.dev@gmail.com>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/bio.c
include/linux/bio.h

index bb55b94bb36129fa5b81d36505aa945ca9f25de6..b35356c6093b06a031465e88aa03293b55411223 100644 (file)
@@ -845,11 +845,14 @@ static void bio_get_pages(struct bio *bio)
                get_page(bvec->bv_page);
 }
 
-static void bio_release_pages(struct bio *bio)
+void bio_release_pages(struct bio *bio)
 {
        struct bvec_iter_all iter_all;
        struct bio_vec *bvec;
 
+       if (bio_flagged(bio, BIO_NO_PAGE_REF))
+               return;
+
        bio_for_each_segment_all(bvec, bio, iter_all)
                put_page(bvec->bv_page);
 }
@@ -1681,8 +1684,7 @@ static void bio_dirty_fn(struct work_struct *work)
                next = bio->bi_private;
 
                bio_set_pages_dirty(bio);
-               if (!bio_flagged(bio, BIO_NO_PAGE_REF))
-                       bio_release_pages(bio);
+               bio_release_pages(bio);
                bio_put(bio);
        }
 }
@@ -1698,8 +1700,7 @@ void bio_check_pages_dirty(struct bio *bio)
                        goto defer;
        }
 
-       if (!bio_flagged(bio, BIO_NO_PAGE_REF))
-               bio_release_pages(bio);
+       bio_release_pages(bio);
        bio_put(bio);
        return;
 defer:
index 5a8ae56e09ff8a3ad0813a197936f54754bd772c..6d82b4856282ef911377e67797796ccd833b07ca 100644 (file)
@@ -426,6 +426,7 @@ bool __bio_try_merge_page(struct bio *bio, struct page *page,
 void __bio_add_page(struct bio *bio, struct page *page,
                unsigned int len, unsigned int off);
 int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter);
+void bio_release_pages(struct bio *bio);
 struct rq_map_data;
 extern struct bio *bio_map_user_iov(struct request_queue *,
                                    struct iov_iter *, gfp_t);