From patchwork Mon Oct 15 20:09:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 1595861 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by patchwork1.kernel.org (Postfix) with ESMTP id 309E13FD86 for ; Mon, 15 Oct 2012 20:14:30 +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 q9FKBVop010479; Mon, 15 Oct 2012 16:11:32 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q9FKB3Ql027352 for ; Mon, 15 Oct 2012 16:11:03 -0400 Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.21]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q9FKAwfm024071 for ; Mon, 15 Oct 2012 16:10:58 -0400 Received: from mail-pa0-f46.google.com (mail-pa0-f46.google.com [209.85.220.46]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9FK9gLJ018945 for ; Mon, 15 Oct 2012 16:10:57 -0400 Received: by mail-pa0-f46.google.com with SMTP id hz1so5214109pad.33 for ; Mon, 15 Oct 2012 13:10:57 -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=bqdoMGzRstAFJ+Au6P0WzQ0Ljx0aURa8GI0aTCM2InHAAQ/7KusOfmLWmwVFurJWDE 33Zm0qTBCJYhN0zsTrLmQgudOXfHpVW9pbD/PTrlqqjyS3iX/vMwEFyXZ4vEFNHYMQtw 5uASIjcva+qftYMa6SqZNcmpWAhsU3DeoH3aZcaCQbnQnw+JVAvkZMFBvzi4Jictbwjy WeLEd4KDKm2k+ua0Fa2vYnB1xMwsRQoRaguPZkwoDtNXNi7t8SNH89dkHPiWLDBAoYdN MpN8DGUmqjZlhakJ4enQBUg4prWDZDiahlG5FCIYVUjljXpX5hgZmGsjuDEzhVHVlKY+ tPYw== 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=Oxf74HC5P9R4mV71c3ggyat3jiAa47YqqD2K2pzwqTQ7AxwYHBksIkYbfGLCIFjOSK dEf66JkG12X9bAT0S+Sef0VB5W6wtgaQRoBjCwZPODwcV/7jjt32g+xu+z9JPCbXoMNS pqHBQtAVi+lZmRK3GJF4fg8wV8Z7GhtEvnYT/OdbdhTOjgxuKG1ZOsKQZl1xUfK6t0r0 XWw/vsxfX0z8mNK9uV1ZG2B8AeVl9X9OBx489mMCeZyLd1/+YfvOGboqHD9EeLNJqnPg SWqLaxQuVwWkCzK/rW+KqWNNex9p9/lovQMW7DjZi+zzQT5bPKvD/2AB014Ehg3gYpWk RBvA== Received: by 10.66.86.2 with SMTP id l2mr35862852paz.70.1350331857430; Mon, 15 Oct 2012 13:10:57 -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 k9sm3021703paz.22.2012.10.15.13.10.56 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 15 Oct 2012 13:10:56 -0700 (PDT) From: Kent Overstreet To: linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, dm-devel@redhat.com Date: Mon, 15 Oct 2012 13:09:25 -0700 Message-Id: <1350331769-14856-52-git-send-email-koverstreet@google.com> In-Reply-To: <1350331769-14856-1-git-send-email-koverstreet@google.com> References: <1350331769-14856-1-git-send-email-koverstreet@google.com> X-Gm-Message-State: ALoCoQnqU4EeKvfNhFN8EzJQdRd3/Xi4ekY+eAFSlLisqcC+0OkxrIfGENge+AxlMzHmLUC2fNkoEF5uM2gwQ+jHnhfzcY6ZgRuavik+loArHbTZeDqzlEt/ej/eVi5/OzcqhiDbteKQkZCx+vud4OrN5ZpN53hGYGBaLfG1AAKe82fReZpcBdaECs4+qCFkBkhYLVTGqH+o X-RedHat-Spam-Score: -3.072 (BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.21 X-loop: dm-devel@redhat.com Cc: tj@kernel.org, axboe@kernel.dk, 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);