From: Tejun Heo <tj@kernel.org>
To: bzolnier@gmail.com, linux-kernel@vger.kernel.org,
axboe@kernel.dk, linux-ide@vger.kernel.org
Cc: Tejun Heo <tj@kernel.org>
Subject: [PATCH 02/14] block: reorganize [__]bio_map_kern()
Date: Wed, 25 Mar 2009 01:06:04 +0900 [thread overview]
Message-ID: <1237910776-10983-3-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1237910776-10983-1-git-send-email-tj@kernel.org>
Impact: code reorganization, cleanup
Reorganize [__]bio_map_kern() such that __bio_map_kern() only maps the
pages while bio_map_kern() handles allocation. Also, if not all pages
can be mapped, __bio_map_kern() fails directly instead of doing
partial mapping and letting bio_map_kern() detect it and fail.
While at it, convert to PFN_*() macros for page number calculations.
The reorganized __bio_map_kern() will be used in the next patch for
bio_map_kern_prealloc().
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>
---
fs/bio.c | 56 +++++++++++++++++++++++---------------------------------
1 files changed, 23 insertions(+), 33 deletions(-)
diff --git a/fs/bio.c b/fs/bio.c
index d4f0632..746b566 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -26,6 +26,7 @@
#include <linux/mempool.h>
#include <linux/workqueue.h>
#include <linux/blktrace_api.h>
+#include <linux/pfn.h>
#include <trace/block.h>
#include <scsi/sg.h> /* for struct sg_iovec */
@@ -1109,41 +1110,27 @@ static void bio_map_kern_endio(struct bio *bio, int err)
}
-static struct bio *__bio_map_kern(struct request_queue *q, void *data,
- unsigned int len, gfp_t gfp_mask)
+static int __bio_map_kern(struct request_queue *q, struct bio *bio,
+ void *data, unsigned int len)
{
- unsigned long kaddr = (unsigned long)data;
- unsigned long end = (kaddr + len + PAGE_SIZE - 1) >> PAGE_SHIFT;
- unsigned long start = kaddr >> PAGE_SHIFT;
- const int nr_pages = end - start;
int offset, i;
- struct bio *bio;
-
- bio = bio_alloc(gfp_mask, nr_pages);
- if (!bio)
- return ERR_PTR(-ENOMEM);
-
- offset = offset_in_page(kaddr);
- for (i = 0; i < nr_pages; i++) {
- unsigned int bytes = PAGE_SIZE - offset;
- if (len <= 0)
- break;
-
- if (bytes > len)
- bytes = len;
+ offset = offset_in_page(data);
+ for (i = 0; len; i++) {
+ unsigned int bytes = min_t(unsigned int,
+ len, PAGE_SIZE - offset);
+ /* don't support partial mapping */
if (bio_add_pc_page(q, bio, virt_to_page(data), bytes,
offset) < bytes)
- break;
+ return -EINVAL;
data += bytes;
len -= bytes;
offset = 0;
}
- bio->bi_end_io = bio_map_kern_endio;
- return bio;
+ return 0;
}
/**
@@ -1159,20 +1146,23 @@ static struct bio *__bio_map_kern(struct request_queue *q, void *data,
struct bio *bio_map_kern(struct request_queue *q, void *data, unsigned int len,
gfp_t gfp_mask)
{
+ const unsigned long kaddr = (unsigned long)data;
+ const int nr_pages = PFN_UP(kaddr + len) - PFN_DOWN(kaddr);
struct bio *bio;
+ int error;
- bio = __bio_map_kern(q, data, len, gfp_mask);
- if (IS_ERR(bio))
- return bio;
+ bio = bio_alloc(gfp_mask, nr_pages);
+ if (unlikely(!bio))
+ return ERR_PTR(-ENOMEM);
+ bio->bi_end_io = bio_map_kern_endio;
- if (bio->bi_size == len)
- return bio;
+ error = __bio_map_kern(q, bio, data, len);
+ if (unlikely(error)) {
+ bio_put(bio);
+ return ERR_PTR(error);
+ }
- /*
- * Don't support partial mappings.
- */
- bio_put(bio);
- return ERR_PTR(-EINVAL);
+ return bio;
}
static void bio_copy_kern_endio(struct bio *bio, int err)
--
1.6.0.2
next prev parent reply other threads:[~2009-03-24 16:06 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-24 16:06 [PATCHSET pata-2.6] ide: rq->buffer, data, special and misc cleanups Tejun Heo
2009-03-24 16:06 ` [PATCH 01/14] block: clear req->errors on bio completion only for fs requests Tejun Heo
2009-03-24 16:06 ` Tejun Heo [this message]
2009-03-24 16:06 ` [PATCH 03/14] block: implement blk_rq_map_kern_prealloc() Tejun Heo
2009-03-25 15:18 ` Boaz Harrosh
2009-03-26 2:10 ` Tejun Heo
2009-03-26 7:42 ` Tejun Heo
2009-03-26 8:05 ` Boaz Harrosh
2009-03-26 8:10 ` Boaz Harrosh
2009-03-26 10:19 ` Tejun Heo
2009-03-26 11:23 ` Boaz Harrosh
2009-03-26 12:07 ` Tejun Heo
2009-03-26 14:44 ` Boaz Harrosh
2009-03-27 2:26 ` Tejun Heo
2009-04-13 10:07 ` FUJITA Tomonori
2009-03-24 16:06 ` [PATCH 04/14] ide: use blk_run_queue() instead of blk_start_queueing() Tejun Heo
2009-03-24 16:06 ` [PATCH 05/14] ide: don't set REQ_SOFTBARRIER Tejun Heo
2009-03-24 16:06 ` [PATCH 06/14] ide kill unused ide_cmd->special Tejun Heo
2009-03-24 16:06 ` [PATCH 07/14] ide-cd: clear sense buffer before issuing request sense Tejun Heo
2009-03-26 7:20 ` Borislav Petkov
2009-03-26 7:26 ` Tejun Heo
2009-03-24 16:06 ` [PATCH 08/14] ide-floppy: block pc always uses bio Tejun Heo
2009-03-24 16:06 ` [PATCH 09/14] ide-taskfile: don't abuse rq->buffer Tejun Heo
2009-03-24 16:06 ` [PATCH 10/14] ide-atapi: " Tejun Heo
2009-03-24 16:06 ` [PATCH 11/14] ide-cd: " Tejun Heo
2009-03-26 8:34 ` Borislav Petkov
2009-03-24 16:06 ` [PATCH 12/14] ide-pm: don't abuse rq->data Tejun Heo
2009-03-24 16:06 ` [PATCH 13/14] ide-atapi: use bio for request sense Tejun Heo
2009-03-28 8:43 ` Borislav Petkov
2009-03-24 16:06 ` [PATCH 14/14] ide-cd: " Tejun Heo
2009-04-13 8:52 ` Borislav Petkov
2009-03-28 13:51 ` [PATCHSET pata-2.6] ide: rq->buffer, data, special and misc cleanups Bartlomiej Zolnierkiewicz
2009-03-28 14:04 ` Borislav Petkov
2009-03-30 9:12 ` Tejun Heo
2009-03-30 11:14 ` Boaz Harrosh
2009-03-30 17:20 ` Tejun Heo
2009-03-31 8:43 ` Boaz Harrosh
2009-03-31 9:05 ` Tejun Heo
2009-03-31 9:10 ` Tejun Heo
2009-03-31 13:04 ` Boaz Harrosh
2009-03-31 13:43 ` Tejun Heo
2009-04-01 11:50 ` Boaz Harrosh
2009-04-13 7:41 ` FUJITA Tomonori
2009-04-13 7:54 ` Jeff Garzik
2009-04-13 8:22 ` FUJITA Tomonori
2009-04-13 8:31 ` Jeff Garzik
2009-04-13 10:07 ` FUJITA Tomonori
2009-04-13 14:16 ` James Bottomley
2009-03-30 14:50 ` Bartlomiej Zolnierkiewicz
2009-03-30 14:50 ` Bartlomiej Zolnierkiewicz
2009-03-30 17:21 ` Tejun Heo
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=1237910776-10983-3-git-send-email-tj@kernel.org \
--to=tj@kernel.org \
--cc=axboe@kernel.dk \
--cc=bzolnier@gmail.com \
--cc=linux-ide@vger.kernel.org \
--cc=linux-kernel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.