From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-f65.google.com ([209.85.166.65]:41369 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727510AbeLAEHY (ORCPT ); Fri, 30 Nov 2018 23:07:24 -0500 Received: by mail-io1-f65.google.com with SMTP id s22so5066958ioc.8 for ; Fri, 30 Nov 2018 08:57:28 -0800 (PST) From: Jens Axboe To: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-aio@kvack.org Cc: hch@lst.de, Jens Axboe Subject: [PATCH 24/27] block: implement bio helper to add iter kvec pages to bio Date: Fri, 30 Nov 2018 09:56:43 -0700 Message-Id: <20181130165646.27341-25-axboe@kernel.dk> In-Reply-To: <20181130165646.27341-1-axboe@kernel.dk> References: <20181130165646.27341-1-axboe@kernel.dk> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: For an ITER_KVEC, we can just iterate the iov and add the pages to the bio directly. Signed-off-by: Jens Axboe --- block/bio.c | 30 ++++++++++++++++++++++++++++++ include/linux/bio.h | 1 + 2 files changed, 31 insertions(+) diff --git a/block/bio.c b/block/bio.c index ab174bce5436..7e59ef547ed4 100644 --- a/block/bio.c +++ b/block/bio.c @@ -903,6 +903,36 @@ int bio_iov_iter_get_pages(struct bio *bio, struct iov_iter *iter) } EXPORT_SYMBOL_GPL(bio_iov_iter_get_pages); +/** + * bio_iov_kvec_add_pages - add pages from an ITER_KVEC to a bio + * @bio: bio to add pages to + * @iter: iov iterator describing the region to be added + * + * Iterate pages in the @iter and add them to the bio. We flag the + * @bio with BIO_HOLD_PAGES, telling IO completion not to free them. + */ +int bio_iov_kvec_add_pages(struct bio *bio, struct iov_iter *iter) +{ + unsigned short orig_vcnt = bio->bi_vcnt; + const struct kvec *kv; + + do { + struct page *page; + size_t size; + + kv = iter->kvec + iter->iov_offset; + page = virt_to_page(kv->iov_base); + size = bio_add_page(bio, page, kv->iov_len, + offset_in_page(kv->iov_base)); + if (size != kv->iov_len) + break; + iov_iter_advance(iter, size); + } while (iov_iter_count(iter) && !bio_full(bio)); + + bio_set_flag(bio, BIO_HOLD_PAGES); + return bio->bi_vcnt > orig_vcnt ? 0 : -EINVAL; +} + static void submit_bio_wait_endio(struct bio *bio) { complete(bio->bi_private); diff --git a/include/linux/bio.h b/include/linux/bio.h index 056fb627edb3..23ae8fb66b1e 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -434,6 +434,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); +int bio_iov_kvec_add_pages(struct bio *bio, struct iov_iter *iter); struct rq_map_data; extern struct bio *bio_map_user_iov(struct request_queue *, struct iov_iter *, gfp_t); -- 2.17.1