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 03/14] block: implement blk_rq_map_kern_prealloc()
Date: Wed, 25 Mar 2009 01:06:05 +0900 [thread overview]
Message-ID: <1237910776-10983-4-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1237910776-10983-1-git-send-email-tj@kernel.org>
Impact: implement new API
There still are a few places where request is allocated statically and
manually initialized. Till now, those sites used their own custom
mechanisms to pass data buffer through request queue. This patch
implements blk_rq_map_kern_prealloc() which initializes rq with
pre-allocated bio and bvec so that those code paths can be converted
to bio.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>
---
block/blk-map.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
fs/bio.c | 23 ++++++++++++++++++++++
include/linux/bio.h | 3 ++
include/linux/blkdev.h | 4 +++
4 files changed, 80 insertions(+), 0 deletions(-)
diff --git a/block/blk-map.c b/block/blk-map.c
index f103729..c50aac2 100644
--- a/block/blk-map.c
+++ b/block/blk-map.c
@@ -317,3 +317,53 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
return 0;
}
EXPORT_SYMBOL(blk_rq_map_kern);
+
+/**
+ * blk_rq_map_kern_prealloc - map kernel data using preallocated structures
+ * @q: request queue where request should be inserted
+ * @rq: request to fill
+ * @bio: bio to use
+ * @bvec: bio_vec array to use
+ * @bvec_len: the number of available bvecs in @bvec
+ * @kbuf: the kernel buffer to map
+ * @len: length of @kbuf
+ * @force: bypass @kbuf alignment and on stack check
+ *
+ * Description:
+ * @len bytes at @kbuf will be mapped into @rq using @bio and
+ * @bvec. The buffer must be suitable for direct mapping and
+ * should not require more than @bvec_len elements to map. This
+ * function doesn't do any allocation and can be called from atomic
+ * context. 0 is returned on success, -errno on failure. Note
+ * that this function does not handle bouncing.
+ *
+ * WARNING: Using this function is strongly discouraged. Use
+ * blk_rq_map_kern() if at all possible.
+ */
+int blk_rq_map_kern_prealloc(struct request_queue *q,
+ struct request *rq, struct bio *bio,
+ struct bio_vec *bvec, unsigned short bvec_len,
+ void *kbuf, unsigned int len, bool force)
+{
+ int error;
+
+ if (len > (q->max_hw_sectors << 9))
+ return -EINVAL;
+ if (!len || !kbuf)
+ return -EINVAL;
+ if (!force &&
+ (!blk_rq_aligned(q, kbuf, len) || object_is_on_stack(kbuf)))
+ return -EINVAL;
+
+ error = bio_map_kern_prealloc(q, bio, bvec, bvec_len, kbuf, len);
+ if (error)
+ return error;
+
+ if (rq_data_dir(rq) == WRITE)
+ bio->bi_rw |= (1 << BIO_RW);
+
+ blk_rq_bio_prep(q, rq, bio);
+ rq->buffer = rq->data = NULL;
+ return 0;
+}
+EXPORT_SYMBOL(blk_rq_map_kern_prealloc);
diff --git a/fs/bio.c b/fs/bio.c
index 746b566..ab3c9c9 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -1165,6 +1165,29 @@ struct bio *bio_map_kern(struct request_queue *q, void *data, unsigned int len,
return bio;
}
+/**
+ * bio_map_kern_prealloc - map kernel address into preallocated bio/bvec
+ * @q: the struct request_queue for the bio
+ * @bio: bio to initialize
+ * @bvec: bio_vec array to initialize
+ * @bvec_len: how many elements are available in @bvec
+ * @data: pointer to buffer to map
+ * @len: length in bytes
+ *
+ * Map @data into @bvec and initialize @bio with it. If there
+ * aren't enough @bvec entries, -EINVAL is returned.
+ */
+int bio_map_kern_prealloc(struct request_queue *q, struct bio *bio,
+ struct bio_vec *bvec, unsigned short bvec_len,
+ void *data, unsigned int len)
+{
+ bio_init(bio);
+ bio->bi_io_vec = bvec;
+ bio->bi_max_vecs = bvec_len;
+
+ return __bio_map_kern(q, bio, data, len);
+}
+
static void bio_copy_kern_endio(struct bio *bio, int err)
{
struct bio_vec *bvec;
diff --git a/include/linux/bio.h b/include/linux/bio.h
index d8bd43b..39619eb 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -388,6 +388,9 @@ extern struct bio *bio_map_user_iov(struct request_queue *,
extern void bio_unmap_user(struct bio *);
extern struct bio *bio_map_kern(struct request_queue *, void *, unsigned int,
gfp_t);
+extern int bio_map_kern_prealloc(struct request_queue *q, struct bio *bio,
+ struct bio_vec *bvec, unsigned short bvec_len,
+ void *data, unsigned int len);
extern struct bio *bio_copy_kern(struct request_queue *, void *, unsigned int,
gfp_t, int);
extern void bio_set_pages_dirty(struct bio *bio);
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 465d6ba..e322e94 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -781,6 +781,10 @@ extern int blk_rq_map_user(struct request_queue *, struct request *,
gfp_t);
extern int blk_rq_unmap_user(struct bio *);
extern int blk_rq_map_kern(struct request_queue *, struct request *, void *, unsigned int, gfp_t);
+extern int blk_rq_map_kern_prealloc(struct request_queue *q,
+ struct request *rq, struct bio *bio,
+ struct bio_vec *bvec, unsigned short bvec_len,
+ void *kbuf, unsigned int len, bool force);
extern int blk_rq_map_user_iov(struct request_queue *, struct request *,
struct rq_map_data *, struct sg_iovec *, int,
unsigned int, gfp_t);
--
1.6.0.2
next prev parent reply other threads:[~2009-03-24 16:06 UTC|newest]
Thread overview: 50+ 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 ` [PATCH 02/14] block: reorganize [__]bio_map_kern() Tejun Heo
2009-03-24 16:06 ` Tejun Heo [this message]
2009-03-25 15:18 ` [PATCH 03/14] block: implement blk_rq_map_kern_prealloc() 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 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-4-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 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).