From patchwork Tue Sep 11 00:22:33 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 1434541 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by patchwork2.kernel.org (Postfix) with ESMTP id 425CCDF28C for ; Tue, 11 Sep 2012 00:34:59 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q8B0WPcE017860; Mon, 10 Sep 2012 20:32:25 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q8B0NE6K009852 for ; Mon, 10 Sep 2012 20:23:14 -0400 Received: from mx1.redhat.com (ext-mx14.extmail.prod.ext.phx2.redhat.com [10.5.110.19]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q8B0N9d1008992 for ; Mon, 10 Sep 2012 20:23:09 -0400 Received: from mail-pb0-f46.google.com (mail-pb0-f46.google.com [209.85.160.46]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q8B0MiTB003121 for ; Mon, 10 Sep 2012 20:23:08 -0400 Received: by mail-pb0-f46.google.com with SMTP id rr13so20439pbb.33 for ; Mon, 10 Sep 2012 17:23:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=rTj8QK4TsxeoQVXiSIlQtkQltRf75SljgwlA04Q79r0=; b=e47TS9P68179CDijlBzoNl48B9eeLmR0m13/jWrduBttOVZt40JTNyOw757oe+Ts1/ NGWN+kajyJ7fEh6zkhC01nhL8gqJOHAzxWWkKOB/aCzUk9JO7psZUoOw9I7GIjEj0DIB 38J668QlhToTo2CxsxxLrrVYQChk3a37sDi/tVF6eEVUKtt4AppVQXJVW2zbtKH9TApB QPg1lujzczA5hYS/Hp6bE6RtoMmTmwBrPrzikqAfZRy00hs0Fayw2ruFFYWsdfBYBkWs HjiFtsi48wMBEN5AtgYmw9YI/jqZ+hW+V5n3wZGmsyLNwKdMYK1qPDff86Fi39kLZoZw LQpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=rTj8QK4TsxeoQVXiSIlQtkQltRf75SljgwlA04Q79r0=; b=OflQnVHbzPQI8pSCrDCcMjR3ywtw1wxMA0p42Tb32nxGs94Pqmb6d6QbwBBD+fi2Eo +xDeLB9ya1ArLGoXz7jkvCWZiSV/h+hWYSelPOpYYQlyLVgd6N/n0CCUNATxR2t6Yq2P oqubPXNvb2lDIRUq2+Xxm2Mcvt15L/1p3yn2uXxOQtLMbeA0R4c+G5OPZzSQZPqHJCMq g91EZoOj1sfGX5R2ViNdH+08LH+A7ZR2xHphstTZvOnBzWY4Xr4dAr1JX4uGMKy/jBNN 7lc+zpN/etFS2r78PkPWTUFCE/VVxgBU/CJDL17+DAmDupjHT0Lb2mYRntpORmkK9Pr3 NWxA== Received: by 10.68.189.70 with SMTP id gg6mr8529591pbc.125.1347322988565; Mon, 10 Sep 2012 17:23:08 -0700 (PDT) Received: by 10.68.189.70 with SMTP id gg6mr8529565pbc.125.1347322988408; Mon, 10 Sep 2012 17:23:08 -0700 (PDT) Received: from formenos.mtv.corp.google.com (formenos.mtv.corp.google.com [172.18.110.66]) by mx.google.com with ESMTPS id pj8sm8883986pbb.60.2012.09.10.17.23.07 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 10 Sep 2012 17:23:07 -0700 (PDT) From: Kent Overstreet To: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, dm-devel@redhat.com Date: Mon, 10 Sep 2012 17:22:33 -0700 Message-Id: <1347322957-25260-23-git-send-email-koverstreet@google.com> In-Reply-To: <1347322957-25260-1-git-send-email-koverstreet@google.com> References: <1347322957-25260-1-git-send-email-koverstreet@google.com> X-Gm-Message-State: ALoCoQnfzrclfjfzGa3bhjcIdDDI9kOe97TJD1croVivAWwKek7dsvYfY2wbb1dJKSyVQEUVolA10Th4+1EfL8pv9lPRPcIycDQe3gcQ9xSU8yXxtr21xKyrJ7KAKgrudUb2tmbK41E0FroGzHr9nreDF6E1FEqy7d7gfbrj3fILSEbf26YwWOpcz3Njpy+Q36Q11KRm42EU X-RedHat-Spam-Score: -3.075 (BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.19 X-loop: dm-devel@redhat.com Cc: axboe@kernel.dk, tj@kernel.org, Kent Overstreet Subject: [dm-devel] [PATCH v2 22/26] block: Add bio_alloc_pages() X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com More utility code to replace stuff that's getting open coded. Signed-off-by: Kent Overstreet CC: Jens Axboe --- fs/bio.c | 28 ++++++++++++++++++++++++++++ include/linux/bio.h | 1 + 2 files changed, 29 insertions(+) diff --git a/fs/bio.c b/fs/bio.c index d88ad77..65e6eac 100644 --- a/fs/bio.c +++ b/fs/bio.c @@ -828,6 +828,34 @@ 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/include/linux/bio.h b/include/linux/bio.h index b433ff8..bd45154 100644 --- a/include/linux/bio.h +++ b/include/linux/bio.h @@ -289,6 +289,7 @@ 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 struct bio *bio_copy_user(struct request_queue *, struct rq_map_data *, unsigned long, unsigned int, int, gfp_t);