From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@fb.com>, linux-block@vger.kernel.org
Cc: Christoph Hellwig <hch@infradead.org>, Ming Lei <ming.lei@redhat.com>
Subject: [PATCH 08/10] block: move bio_alloc_pages() to bcache
Date: Fri, 8 Dec 2017 21:14:07 +0800 [thread overview]
Message-ID: <20171208131409.11889-9-ming.lei@redhat.com> (raw)
In-Reply-To: <20171208131409.11889-1-ming.lei@redhat.com>
bcache is the only user of bio_alloc_pages(), and all users should use
bio_add_page() instead, so move this function into bcache, and avoid
it misused in future.
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
block/bio.c | 28 ----------------------------
drivers/md/bcache/util.c | 27 +++++++++++++++++++++++++++
drivers/md/bcache/util.h | 1 +
include/linux/bio.h | 1 -
4 files changed, 28 insertions(+), 29 deletions(-)
diff --git a/block/bio.c b/block/bio.c
index 228229f3bb76..76bb3dafffea 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -969,34 +969,6 @@ void bio_advance(struct bio *bio, unsigned bytes)
EXPORT_SYMBOL(bio_advance);
/**
- * bio_alloc_pages - allocates a single page for each bvec in a bio
- * @bio: bio to allocate pages for
- * @gfp_mask: flags for allocation
- *
- * Allocates pages up to @bio->bi_vcnt.
- *
- * Returns 0 on success, -ENOMEM on failure. On failure, any allocated pages are
- * freed.
- */
-int bio_alloc_pages(struct bio *bio, gfp_t gfp_mask)
-{
- int i;
- struct bio_vec *bv;
-
- bio_for_each_segment_all(bv, bio, i) {
- bv->bv_page = alloc_page(gfp_mask);
- if (!bv->bv_page) {
- while (--bv >= bio->bi_io_vec)
- __free_page(bv->bv_page);
- return -ENOMEM;
- }
- }
-
- return 0;
-}
-EXPORT_SYMBOL(bio_alloc_pages);
-
-/**
* bio_copy_data - copy contents of data buffers from one chain of bios to
* another
* @src: source bio list
diff --git a/drivers/md/bcache/util.c b/drivers/md/bcache/util.c
index 61813d230015..ac557e8c7ef5 100644
--- a/drivers/md/bcache/util.c
+++ b/drivers/md/bcache/util.c
@@ -283,6 +283,33 @@ start: bv->bv_len = min_t(size_t, PAGE_SIZE - bv->bv_offset,
}
}
+/**
+ * bio_alloc_pages - allocates a single page for each bvec in a bio
+ * @bio: bio to allocate pages for
+ * @gfp_mask: flags for allocation
+ *
+ * Allocates pages up to @bio->bi_vcnt.
+ *
+ * Returns 0 on success, -ENOMEM on failure. On failure, any allocated pages are
+ * freed.
+ */
+int bio_alloc_pages(struct bio *bio, gfp_t gfp_mask)
+{
+ int i;
+ struct bio_vec *bv;
+
+ bio_for_each_segment_all(bv, bio, i) {
+ bv->bv_page = alloc_page(gfp_mask);
+ if (!bv->bv_page) {
+ while (--bv >= bio->bi_io_vec)
+ __free_page(bv->bv_page);
+ return -ENOMEM;
+ }
+ }
+
+ return 0;
+}
+
/*
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group (Any
* use permitted, subject to terms of PostgreSQL license; see.)
diff --git a/drivers/md/bcache/util.h b/drivers/md/bcache/util.h
index ed5e8a412eb8..c92de937bcab 100644
--- a/drivers/md/bcache/util.h
+++ b/drivers/md/bcache/util.h
@@ -558,6 +558,7 @@ static inline unsigned fract_exp_two(unsigned x, unsigned fract_bits)
}
void bch_bio_map(struct bio *bio, void *base);
+int bio_alloc_pages(struct bio *bio, gfp_t gfp_mask);
static inline sector_t bdev_sectors(struct block_device *bdev)
{
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 3f314e17364a..46cdbe0335a5 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -501,7 +501,6 @@ static inline void bio_flush_dcache_pages(struct bio *bi)
#endif
extern void bio_copy_data(struct bio *dst, struct bio *src);
-extern int bio_alloc_pages(struct bio *bio, gfp_t gfp);
extern void bio_free_pages(struct bio *bio);
extern struct bio *bio_copy_user_iov(struct request_queue *,
--
2.9.5
next prev parent reply other threads:[~2017-12-08 13:15 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-08 13:13 [PATCH 00/10] block: cleanup on direct access to bvec table(prepare for multipage bvec) Ming Lei
2017-12-08 13:14 ` [PATCH 01/10] block: introduce bio helpers for converting to multipage bvec Ming Lei
2017-12-08 13:14 ` [PATCH 02/10] block: conver to bio_first_bvec() & bio_first_page() Ming Lei
2017-12-08 13:14 ` [PATCH 03/10] fs: convert to bio_last_bvec() Ming Lei
2017-12-08 13:14 ` [PATCH 04/10] block: bounce: avoid direct access to bvec table Ming Lei
2017-12-08 13:14 ` [PATCH 05/10] block: bounce: don't access bio->bi_io_vec in copy_to_high_bio_irq Ming Lei
2017-12-08 13:14 ` [PATCH 06/10] dm: limit the max bio size as BIO_MAX_PAGES * PAGE_SIZE Ming Lei
2017-12-08 13:14 ` [PATCH 07/10] bcache: comment on direct access to bvec table Ming Lei
2017-12-08 13:14 ` Ming Lei [this message]
2018-01-08 18:05 ` [PATCH 08/10] block: move bio_alloc_pages() to bcache Michael Lyle
2018-01-09 1:21 ` Ming Lei
2017-12-08 13:14 ` [PATCH 09/10] btrfs: avoid access to .bi_vcnt directly Ming Lei
2017-12-08 13:14 ` [PATCH 10/10] btrfs: avoid to access bvec table directly for a cloned bio Ming Lei
2017-12-12 7:57 ` [PATCH 00/10] block: cleanup on direct access to bvec table(prepare for multipage bvec) Christoph Hellwig
2017-12-12 9:18 ` Ming Lei
2017-12-13 17:55 ` Ming Lei
2018-01-05 19:02 ` Jens Axboe
2018-01-06 9:18 ` Ming Lei
2018-01-06 16:21 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171208131409.11889-9-ming.lei@redhat.com \
--to=ming.lei@redhat.com \
--cc=axboe@fb.com \
--cc=hch@infradead.org \
--cc=linux-block@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).