From: Boaz Harrosh <bharrosh@panasas.com>
To: Tejun Heo <tj@kernel.org>
Cc: axboe@kernel.dk, linux-kernel@vger.kernel.org,
fujita.tomonori@lab.ntt.co.jp
Subject: Re: [PATCH 05/17] bio: cleanup rw usage
Date: Thu, 02 Apr 2009 11:36:53 +0300 [thread overview]
Message-ID: <49D47925.5050307@panasas.com> (raw)
In-Reply-To: <1238593472-30360-6-git-send-email-tj@kernel.org>
On 04/01/2009 04:44 PM, Tejun Heo wrote:
> Impact: cleanup
>
> bio confusingly uses @write_to_vm and @reading for data directions,
> both of which mean the opposite of the usual block/bio convention of
> using READ and WRITE w.r.t. IO devices. The only place where the
> inversion is necessary is when caling get_user_pages_fast() in
> bio_copy_user_iov() as the gup uses the VM convention of read/write
> w.r.t. VM.
>
> This patch converts all bio functions to use READ/WRITE rw parameter
> and let the one place where inversion is necessary to rw == READ.
>
Hi one more nit picking just if you are at it. If you want
I can do the work and send it to you so you can squash it into this patch.
See bellow
> Signed-off-by: Tejun Heo <tj@kernel.org>
> ---
> block/blk-map.c | 10 +++++-----
> fs/bio.c | 50 +++++++++++++++++++++++++-------------------------
> include/linux/bio.h | 18 +++++++++---------
> 3 files changed, 39 insertions(+), 39 deletions(-)
>
> diff --git a/block/blk-map.c b/block/blk-map.c
> index b0b65ef..29aa60d 100644
> --- a/block/blk-map.c
> +++ b/block/blk-map.c
> @@ -68,15 +68,15 @@ int blk_rq_map_user_iov(struct request_queue *q, struct request *rq,
> int iov_count, unsigned int len, gfp_t gfp_mask)
> {
> struct bio *bio = ERR_PTR(-EINVAL);
> - int read = rq_data_dir(rq) == READ;
> + int rw = rq_data_dir(rq);
>
> if (!iov || iov_count <= 0)
> return -EINVAL;
>
> if (!map_data)
> - bio = bio_map_user_iov(q, NULL, iov, iov_count, read, gfp_mask);
> + bio = bio_map_user_iov(q, NULL, iov, iov_count, rw, gfp_mask);
> if (bio == ERR_PTR(-EINVAL))
> - bio = bio_copy_user_iov(q, map_data, iov, iov_count, read,
> + bio = bio_copy_user_iov(q, map_data, iov, iov_count, rw,
> gfp_mask);
> if (IS_ERR(bio))
> return PTR_ERR(bio);
> @@ -177,7 +177,7 @@ EXPORT_SYMBOL(blk_rq_unmap_user);
> int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
> unsigned int len, gfp_t gfp_mask)
> {
> - int reading = rq_data_dir(rq) == READ;
> + int rw = rq_data_dir(rq);
> int do_copy = 0;
> struct bio *bio;
>
> @@ -188,7 +188,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
>
> do_copy = !blk_rq_aligned(q, kbuf, len) || object_is_on_stack(kbuf);
> if (do_copy)
> - bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
> + bio = bio_copy_kern(q, kbuf, len, gfp_mask, rw);
> else
> bio = bio_map_kern(q, kbuf, len, gfp_mask);
>
> diff --git a/fs/bio.c b/fs/bio.c
> index 80f61ed..70e5153 100644
> --- a/fs/bio.c
> +++ b/fs/bio.c
> @@ -780,7 +780,7 @@ int bio_uncopy_user(struct bio *bio)
> * @map_data: pointer to the rq_map_data holding pages (if necessary)
> * @iov: the iovec.
> * @iov_count: number of elements in the iovec
> - * @write_to_vm: bool indicating writing to pages or not
> + * @rw: READ or WRITE
> * @gfp_mask: memory allocation flags
> *
> * Prepares and returns a bio for indirect user io, bouncing data
> @@ -789,8 +789,8 @@ int bio_uncopy_user(struct bio *bio)
> */
> struct bio *bio_copy_user_iov(struct request_queue *q,
> struct rq_map_data *map_data,
> - struct sg_iovec *iov, int iov_count,
> - int write_to_vm, gfp_t gfp_mask)
> + struct sg_iovec *iov, int iov_count, int rw,
> + gfp_t gfp_mask)
> {
> struct bio_map_data *bmd;
> struct bio_vec *bvec;
> @@ -823,7 +823,8 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
> if (!bio)
> goto out_bmd;
>
> - bio->bi_rw |= (!write_to_vm << BIO_RW);
> + if (rw == WRITE)
> + bio->bi_rw |= 1 << BIO_RW;
can we pleas have an inline that does that? Like bio_set_dir()?
and change all users. You will be surprised how many there are.
It gives me an hart attack every time I have to write yet another
one.
>
> ret = 0;
>
> @@ -872,7 +873,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
> */
> if (unlikely(map_data && map_data->null_mapped))
> bio->bi_flags |= (1 << BIO_NULL_MAPPED);
> - else if (!write_to_vm) {
> + else if (rw == WRITE) {
> ret = __bio_copy_iov(bio, bio->bi_io_vec, iov, iov_count, 0, 0);
> if (ret)
> goto cleanup;
> @@ -897,7 +898,7 @@ out_bmd:
> * @map_data: pointer to the rq_map_data holding pages (if necessary)
> * @uaddr: start of user address
> * @len: length in bytes
> - * @write_to_vm: bool indicating writing to pages or not
> + * @rw: READ or WRITE
> * @gfp_mask: memory allocation flags
> *
> * Prepares and returns a bio for indirect user io, bouncing data
> @@ -905,21 +906,21 @@ out_bmd:
> * call bio_uncopy_user() on io completion.
> */
> struct bio *bio_copy_user(struct request_queue *q, struct rq_map_data *map_data,
> - unsigned long uaddr, unsigned int len,
> - int write_to_vm, gfp_t gfp_mask)
> + unsigned long uaddr, unsigned int len, int rw,
> + gfp_t gfp_mask)
> {
> struct sg_iovec iov;
>
> iov.iov_base = (void __user *)uaddr;
> iov.iov_len = len;
>
> - return bio_copy_user_iov(q, map_data, &iov, 1, write_to_vm, gfp_mask);
> + return bio_copy_user_iov(q, map_data, &iov, 1, rw, gfp_mask);
> }
>
> static struct bio *__bio_map_user_iov(struct request_queue *q,
> struct block_device *bdev,
> struct sg_iovec *iov, int iov_count,
> - int write_to_vm, gfp_t gfp_mask)
> + int rw, gfp_t gfp_mask)
> {
> int i, j;
> size_t tot_len = 0;
> @@ -967,8 +968,8 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
> const int local_nr_pages = end - start;
> const int page_limit = cur_page + local_nr_pages;
>
> - ret = get_user_pages_fast(uaddr, local_nr_pages,
> - write_to_vm, &pages[cur_page]);
> + ret = get_user_pages_fast(uaddr, local_nr_pages, rw == READ,
> + &pages[cur_page]);
> if (ret < local_nr_pages) {
> ret = -EFAULT;
> goto out_unmap;
> @@ -1008,7 +1009,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
> /*
> * set data direction, and check if mapped pages need bouncing
> */
> - if (!write_to_vm)
> + if (rw == WRITE)
> bio->bi_rw |= (1 << BIO_RW);
Here
>
> bio->bi_bdev = bdev;
> @@ -1033,14 +1034,14 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
> * @bdev: destination block device
> * @uaddr: start of user address
> * @len: length in bytes
> - * @write_to_vm: bool indicating writing to pages or not
> + * @rw: READ or WRITE
> * @gfp_mask: memory allocation flags
> *
> * Map the user space address into a bio suitable for io to a block
> * device. Returns an error pointer in case of error.
> */
> struct bio *bio_map_user(struct request_queue *q, struct block_device *bdev,
> - unsigned long uaddr, unsigned int len, int write_to_vm,
> + unsigned long uaddr, unsigned int len, int rw,
> gfp_t gfp_mask)
> {
> struct sg_iovec iov;
> @@ -1048,7 +1049,7 @@ struct bio *bio_map_user(struct request_queue *q, struct block_device *bdev,
> iov.iov_base = (void __user *)uaddr;
> iov.iov_len = len;
>
> - return bio_map_user_iov(q, bdev, &iov, 1, write_to_vm, gfp_mask);
> + return bio_map_user_iov(q, bdev, &iov, 1, rw, gfp_mask);
> }
>
> /**
> @@ -1057,20 +1058,19 @@ struct bio *bio_map_user(struct request_queue *q, struct block_device *bdev,
> * @bdev: destination block device
> * @iov: the iovec.
> * @iov_count: number of elements in the iovec
> - * @write_to_vm: bool indicating writing to pages or not
> + * @rw: READ or WRITE
> * @gfp_mask: memory allocation flags
> *
> * Map the user space address into a bio suitable for io to a block
> * device. Returns an error pointer in case of error.
> */
> struct bio *bio_map_user_iov(struct request_queue *q, struct block_device *bdev,
> - struct sg_iovec *iov, int iov_count,
> - int write_to_vm, gfp_t gfp_mask)
> + struct sg_iovec *iov, int iov_count, int rw,
> + gfp_t gfp_mask)
> {
> struct bio *bio;
>
> - bio = __bio_map_user_iov(q, bdev, iov, iov_count, write_to_vm,
> - gfp_mask);
> + bio = __bio_map_user_iov(q, bdev, iov, iov_count, rw, gfp_mask);
> if (IS_ERR(bio))
> return bio;
>
> @@ -1219,23 +1219,23 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
> * @data: pointer to buffer to copy
> * @len: length in bytes
> * @gfp_mask: allocation flags for bio and page allocation
> - * @reading: data direction is READ
> + * @rw: READ or WRITE
> *
> * copy the kernel address into a bio suitable for io to a block
> * device. Returns an error pointer in case of error.
> */
> struct bio *bio_copy_kern(struct request_queue *q, void *data, unsigned int len,
> - gfp_t gfp_mask, int reading)
> + gfp_t gfp_mask, int rw)
> {
> struct bio *bio;
> struct bio_vec *bvec;
> int i;
>
> - bio = bio_copy_user(q, NULL, (unsigned long)data, len, 1, gfp_mask);
> + bio = bio_copy_user(q, NULL, (unsigned long)data, len, READ, gfp_mask);
> if (IS_ERR(bio))
> return bio;
>
> - if (!reading) {
> + if (rw == WRITE) {
> void *p = data;
>
> bio_for_each_segment(bvec, bio, i) {
> diff --git a/include/linux/bio.h b/include/linux/bio.h
> index 4bf7442..45f56d2 100644
> --- a/include/linux/bio.h
> +++ b/include/linux/bio.h
> @@ -387,24 +387,24 @@ int bio_get_nr_vecs(struct block_device *bdev);
> sector_t bio_sector_offset(struct bio *bio, unsigned short index,
> unsigned int offset);
> struct bio *bio_map_user(struct request_queue *q, struct block_device *bdev,
> - unsigned long uaddr, unsigned int len,
> - int write_to_vm, gfp_t gfp_mask);
> + unsigned long uaddr, unsigned int len, int rw,
> + gfp_t gfp_mask);
> struct bio *bio_map_user_iov(struct request_queue *q, struct block_device *bdev,
> - struct sg_iovec *iov, int iov_count,
> - int write_to_vm, gfp_t gfp_mask);
> + struct sg_iovec *iov, int iov_count, int rw,
> + gfp_t gfp_mask);
> void bio_unmap_user(struct bio *bio);
> struct bio *bio_copy_user(struct request_queue *q, struct rq_map_data *map_data,
> - unsigned long uaddr, unsigned int len,
> - int write_to_vm, gfp_t gfp_mask);
> + unsigned long uaddr, unsigned int len, int rw,
> + gfp_t gfp_mask);
> struct bio *bio_copy_user_iov(struct request_queue *q,
> struct rq_map_data *map_data,
> - struct sg_iovec *iov, int iov_count,
> - int write_to_vm, gfp_t gfp_mask);
> + struct sg_iovec *iov, int iov_count, int rw,
> + gfp_t gfp_mask);
> int bio_uncopy_user(struct bio *bio);
> struct bio *bio_map_kern(struct request_queue *q, void *data, unsigned int len,
> gfp_t gfp_mask);
> struct bio *bio_copy_kern(struct request_queue *q, void *data, unsigned int len,
> - gfp_t gfp_mask, int reading);
> + gfp_t gfp_mask, int rw);
> void bio_set_pages_dirty(struct bio *bio);
> void bio_check_pages_dirty(struct bio *bio);
> void zero_fill_bio(struct bio *bio);
Boaz
next prev parent reply other threads:[~2009-04-02 8:39 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-01 13:44 [RFC PATCHSET block] block: blk-map updates and API cleanup Tejun Heo
2009-04-01 13:44 ` [PATCH 01/17] blk-map: move blk_rq_map_user() below blk_rq_map_user_iov() Tejun Heo
2009-04-01 13:44 ` [PATCH 02/17] scatterlist: improve atomic mapping handling in mapping iterator Tejun Heo
2009-04-01 13:44 ` [PATCH 03/17] blk-map: improve alignment checking for blk_rq_map_user_iov() Tejun Heo
2009-04-01 13:44 ` [PATCH 04/17] bio: bio.h cleanup Tejun Heo
2009-04-01 13:44 ` [PATCH 05/17] bio: cleanup rw usage Tejun Heo
2009-04-02 8:36 ` Boaz Harrosh [this message]
2009-04-02 9:02 ` Tejun Heo
2009-04-02 9:07 ` Boaz Harrosh
2009-04-02 9:13 ` Tejun Heo
2009-04-01 13:44 ` [PATCH 06/17] blk-map/bio: use struct iovec instead of sg_iovec Tejun Heo
2009-04-01 14:50 ` Boaz Harrosh
2009-04-01 15:32 ` Tejun Heo
2009-04-01 13:44 ` [PATCH 07/17] blk-map/bio: rename stuff Tejun Heo
2009-04-01 13:44 ` [PATCH 08/17] bio: reimplement bio_copy_user_iov() Tejun Heo
2009-04-01 15:50 ` Boaz Harrosh
2009-04-01 23:57 ` Tejun Heo
2009-04-02 8:24 ` Boaz Harrosh
2009-04-02 8:59 ` Tejun Heo
2009-04-02 9:54 ` Boaz Harrosh
2009-04-02 1:38 ` Tejun Heo
2009-04-02 7:34 ` Boaz Harrosh
2009-04-02 7:51 ` Tejun Heo
2009-04-01 13:44 ` [PATCH 09/17] bio: collapse __bio_map_user_iov(), __bio_unmap_user() and __bio_map_kern() Tejun Heo
2009-04-01 13:44 ` [PATCH 10/17] bio: use bio_create_from_sgl() in bio_map_user_iov() Tejun Heo
2009-04-01 16:33 ` Boaz Harrosh
2009-04-01 22:20 ` Tejun Heo
2009-04-01 13:44 ` [PATCH 11/17] bio: add sgl source support to bci and implement bio_memcpy_sgl_sgl() Tejun Heo
2009-04-01 13:44 ` [PATCH 12/17] bio: implement bio_{map|copy}_kern_sgl() Tejun Heo
2009-04-01 13:44 ` [PATCH 13/17] blk-map: implement blk_rq_map_kern_sgl() Tejun Heo
2009-04-01 16:50 ` Boaz Harrosh
2009-04-01 22:25 ` Tejun Heo
2009-04-01 13:44 ` [PATCH 14/17] scsi: replace custom rq mapping with blk_rq_map_kern_sgl() Tejun Heo
2009-04-01 17:00 ` Boaz Harrosh
2009-04-01 17:05 ` James Bottomley
2009-04-01 17:17 ` Boaz Harrosh
2009-04-13 7:42 ` FUJITA Tomonori
2009-04-13 9:38 ` Tejun Heo
2009-04-13 10:07 ` FUJITA Tomonori
2009-04-13 12:59 ` Borislav Petkov
2009-04-14 0:44 ` FUJITA Tomonori
2009-04-14 10:01 ` Borislav Petkov
2009-04-14 23:44 ` FUJITA Tomonori
2009-04-15 4:25 ` Tejun Heo
2009-04-15 7:26 ` Borislav Petkov
2009-04-15 7:48 ` FUJITA Tomonori
2009-04-15 8:13 ` Borislav Petkov
2009-04-16 3:06 ` Tejun Heo
2009-04-16 3:06 ` Tejun Heo
2009-04-16 5:44 ` Borislav Petkov
2009-04-16 6:07 ` Tejun Heo
2009-04-16 6:07 ` Tejun Heo
2009-04-16 6:29 ` Borislav Petkov
2009-04-16 6:30 ` Tejun Heo
2009-04-16 6:30 ` Tejun Heo
2009-04-16 5:53 ` [PATCH 1/3] ide: add helpers for preparing sense requests Borislav Petkov
2009-04-16 5:53 ` [PATCH 2/3] ide-cd: convert to using generic sense request Borislav Petkov
2009-04-16 5:54 ` [PATCH 3/3] ide-atapi: convert ide-{floppy,tape} to using preallocated sense buffer Borislav Petkov
2009-04-01 13:44 ` [PATCH 15/17] bio/blk-map: kill unused stuff and un-export internal functions Tejun Heo
2009-04-01 13:54 ` Boaz Harrosh
2009-04-01 14:06 ` Tejun Heo
2009-04-01 13:44 ` [PATCH 16/17] blk-map/bio: remove superflous @len parameter from blk_rq_map_user_iov() Tejun Heo
2009-04-01 17:12 ` Boaz Harrosh
2009-04-01 22:17 ` Tejun Heo
2009-04-01 13:44 ` [PATCH 17/17] blk-map/bio: remove superflous @q from blk_rq_map_{user|kern}*() Tejun Heo
2009-04-01 17:05 ` Boaz Harrosh
2009-04-01 14:08 ` [RFC PATCHSET block] block: blk-map updates and API cleanup 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=49D47925.5050307@panasas.com \
--to=bharrosh@panasas.com \
--cc=axboe@kernel.dk \
--cc=fujita.tomonori@lab.ntt.co.jp \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@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.