* [0/3] block cleanup patches @ 2008-08-28 6:05 FUJITA Tomonori 2008-08-28 6:05 ` [PATCH 1/3] bio: convert bio_copy_kern to use bio_copy_user FUJITA Tomonori 2008-08-28 7:34 ` [0/3] block cleanup patches Jens Axboe 0 siblings, 2 replies; 5+ messages in thread From: FUJITA Tomonori @ 2008-08-28 6:05 UTC (permalink / raw) To: jens.axboe; +Cc: linux-scsi, fujita.tomonori Here's some minor cleanup patches. This can be applied to the for-2.6.26 branch in the block tree including the sg conversion patchset. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] bio: convert bio_copy_kern to use bio_copy_user 2008-08-28 6:05 [0/3] block cleanup patches FUJITA Tomonori @ 2008-08-28 6:05 ` FUJITA Tomonori 2008-08-28 6:05 ` [PATCH 2/3] block: add blk_rq_aligned helper function FUJITA Tomonori 2008-08-28 7:34 ` [0/3] block cleanup patches Jens Axboe 1 sibling, 1 reply; 5+ messages in thread From: FUJITA Tomonori @ 2008-08-28 6:05 UTC (permalink / raw) To: jens.axboe; +Cc: linux-scsi, FUJITA Tomonori bio_copy_kern and bio_copy_user are very similar. This converts bio_copy_kern to use bio_copy_user. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Cc: Jens Axboe <jens.axboe@oracle.com> --- fs/bio.c | 54 ++++-------------------------------------------------- 1 files changed, 4 insertions(+), 50 deletions(-) diff --git a/fs/bio.c b/fs/bio.c index a2f0726..9d68ddb 100644 --- a/fs/bio.c +++ b/fs/bio.c @@ -995,48 +995,13 @@ static void bio_copy_kern_endio(struct bio *bio, int err) struct bio *bio_copy_kern(struct request_queue *q, void *data, unsigned int len, gfp_t gfp_mask, int reading) { - 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; struct bio *bio; struct bio_vec *bvec; - struct bio_map_data *bmd; - int i, ret; - struct sg_iovec iov; - - iov.iov_base = data; - iov.iov_len = len; - - bmd = bio_alloc_map_data(nr_pages, 1, gfp_mask); - if (!bmd) - return ERR_PTR(-ENOMEM); - - ret = -ENOMEM; - bio = bio_alloc(gfp_mask, nr_pages); - if (!bio) - goto out_bmd; - - while (len) { - struct page *page; - unsigned int bytes = PAGE_SIZE; - - if (bytes > len) - bytes = len; - - page = alloc_page(q->bounce_gfp | gfp_mask); - if (!page) { - ret = -ENOMEM; - goto cleanup; - } - - if (bio_add_pc_page(q, bio, page, bytes, 0) < bytes) { - ret = -EINVAL; - goto cleanup; - } + int i; - len -= bytes; - } + bio = bio_copy_user(q, NULL, (unsigned long)data, len, 1, gfp_mask); + if (IS_ERR(bio)) + return bio; if (!reading) { void *p = data; @@ -1049,20 +1014,9 @@ struct bio *bio_copy_kern(struct request_queue *q, void *data, unsigned int len, } } - bio->bi_private = bmd; bio->bi_end_io = bio_copy_kern_endio; - bio_set_map_data(bmd, bio, &iov, 1, 1); return bio; -cleanup: - bio_for_each_segment(bvec, bio, i) - __free_page(bvec->bv_page); - - bio_put(bio); -out_bmd: - bio_free_map_data(bmd); - - return ERR_PTR(ret); } /* -- 1.5.5.GIT ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] block: add blk_rq_aligned helper function 2008-08-28 6:05 ` [PATCH 1/3] bio: convert bio_copy_kern to use bio_copy_user FUJITA Tomonori @ 2008-08-28 6:05 ` FUJITA Tomonori 2008-08-28 6:05 ` [PATCH 3/3] sg: use " FUJITA Tomonori 0 siblings, 1 reply; 5+ messages in thread From: FUJITA Tomonori @ 2008-08-28 6:05 UTC (permalink / raw) To: jens.axboe; +Cc: linux-scsi, FUJITA Tomonori This adds blk_rq_aligned helper function to see if alignment and padding requirement is satisfied for DMA transfer. This also converts blk_rq_map_kern and __blk_rq_map_user to use the helper function. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Cc: Jens Axboe <jens.axboe@oracle.com> --- block/blk-map.c | 12 ++---------- include/linux/blkdev.h | 7 +++++++ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/block/blk-map.c b/block/blk-map.c index dad6a29..572140c 100644 --- a/block/blk-map.c +++ b/block/blk-map.c @@ -45,7 +45,6 @@ static int __blk_rq_map_user(struct request_queue *q, struct request *rq, unsigned int len, gfp_t gfp_mask) { unsigned long uaddr; - unsigned int alignment; struct bio *bio, *orig_bio; int reading, ret; @@ -56,8 +55,7 @@ static int __blk_rq_map_user(struct request_queue *q, struct request *rq, * direct dma. else, set up kernel bounce buffers */ uaddr = (unsigned long) ubuf; - alignment = queue_dma_alignment(q) | q->dma_pad_mask; - if (!(uaddr & alignment) && !(len & alignment) && !map_data) + if (blk_rq_aligned(q, ubuf, len) && !map_data) bio = bio_map_user(q, NULL, uaddr, len, reading, gfp_mask); else bio = bio_copy_user(q, map_data, uaddr, len, reading, gfp_mask); @@ -274,8 +272,6 @@ 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) { - unsigned long kaddr; - unsigned int alignment; int reading = rq_data_dir(rq) == READ; int do_copy = 0; struct bio *bio; @@ -285,11 +281,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf, if (!len || !kbuf) return -EINVAL; - kaddr = (unsigned long)kbuf; - alignment = queue_dma_alignment(q) | q->dma_pad_mask; - do_copy = ((kaddr & alignment) || (len & alignment) || - object_is_on_stack(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); else diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index d2faa72..4cd8caa 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -901,6 +901,13 @@ static inline int queue_dma_alignment(struct request_queue *q) return q ? q->dma_alignment : 511; } +static inline int blk_rq_aligned(struct request_queue *q, void *addr, + unsigned int len) +{ + unsigned int alignment = queue_dma_alignment(q) | q->dma_pad_mask; + return !((unsigned long)addr & alignment) && !(len & alignment); +} + /* assumes size > 256 */ static inline unsigned int blksize_bits(unsigned int size) { -- 1.5.5.GIT ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] sg: use blk_rq_aligned helper function 2008-08-28 6:05 ` [PATCH 2/3] block: add blk_rq_aligned helper function FUJITA Tomonori @ 2008-08-28 6:05 ` FUJITA Tomonori 0 siblings, 0 replies; 5+ messages in thread From: FUJITA Tomonori @ 2008-08-28 6:05 UTC (permalink / raw) To: jens.axboe; +Cc: linux-scsi, FUJITA Tomonori, Douglas Gilbert Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Cc: Douglas Gilbert <dougg@torque.net> Cc: Jens Axboe <jens.axboe@oracle.com> --- drivers/scsi/sg.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 56a5d96..61262bd 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -1656,11 +1656,9 @@ static int sg_start_req(Sg_request *srp, unsigned char *cmd) sg_io_hdr_t *hp = &srp->header; int dxfer_len = (int) hp->dxfer_len; int dxfer_dir = hp->dxfer_direction; - unsigned long uaddr = (unsigned long)hp->dxferp; Sg_scatter_hold *req_schp = &srp->data; Sg_scatter_hold *rsv_schp = &sfp->reserve; struct request_queue *q = sfp->parentdp->device->request_queue; - unsigned long alignment = queue_dma_alignment(q) | q->dma_pad_mask; struct rq_map_data map_data; SCSI_LOG_TIMEOUT(4, printk("sg_start_req: dxfer_len=%d\n", dxfer_len)); @@ -1676,7 +1674,7 @@ static int sg_start_req(Sg_request *srp, unsigned char *cmd) if (sg_allow_dio && (hp->flags & SG_FLAG_DIRECT_IO) && (dxfer_dir != SG_DXFER_UNKNOWN) && (0 == hp->iovec_count) && (!sfp->parentdp->device->host->unchecked_isa_dma) && - !(uaddr & alignment) && !(dxfer_len & alignment)) + blk_rq_aligned(q, hp->dxferp, dxfer_len)) return sg_build_direct(srp, sfp, dxfer_len); #endif if ((!sg_res_in_use(sfp)) && (dxfer_len <= rsv_schp->bufflen)) -- 1.5.5.GIT ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [0/3] block cleanup patches 2008-08-28 6:05 [0/3] block cleanup patches FUJITA Tomonori 2008-08-28 6:05 ` [PATCH 1/3] bio: convert bio_copy_kern to use bio_copy_user FUJITA Tomonori @ 2008-08-28 7:34 ` Jens Axboe 1 sibling, 0 replies; 5+ messages in thread From: Jens Axboe @ 2008-08-28 7:34 UTC (permalink / raw) To: FUJITA Tomonori; +Cc: linux-scsi On Thu, Aug 28 2008, FUJITA Tomonori wrote: > Here's some minor cleanup patches. This can be applied to the > for-2.6.26 branch in the block tree including the sg conversion > patchset. Very nice, thanks! Applied to for-2.6.28. -- Jens Axboe ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-08-28 7:54 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-08-28 6:05 [0/3] block cleanup patches FUJITA Tomonori 2008-08-28 6:05 ` [PATCH 1/3] bio: convert bio_copy_kern to use bio_copy_user FUJITA Tomonori 2008-08-28 6:05 ` [PATCH 2/3] block: add blk_rq_aligned helper function FUJITA Tomonori 2008-08-28 6:05 ` [PATCH 3/3] sg: use " FUJITA Tomonori 2008-08-28 7:34 ` [0/3] block cleanup patches Jens Axboe
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.