]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
block: move the padding adjustment to blk_rq_map_sg
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Fri, 11 Apr 2008 10:56:52 +0000 (12:56 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Mon, 21 Apr 2008 07:50:08 +0000 (09:50 +0200)
blk_rq_map_user adjusts bi_size of the last bio. It breaks the rule
that req->data_len (the true data length) is equal to sum(bio). It
broke the scsi command completion code.

commit e97a294ef6938512b655b1abf17656cf2b26f709 was introduced to fix
the above issue. However, the partial completion code doesn't work
with it. The commit is also a layer violation (scsi mid-layer should
not know about the block layer's padding).

This patch moves the padding adjustment to blk_rq_map_sg (suggested by
James). The padding works like the drain buffer. This patch breaks the
rule that req->data_len is equal to sum(sg), however, the drain buffer
already broke it. So this patch just restores the rule that
req->data_len is equal to sub(bio) without breaking anything new.

Now when a low level driver needs padding, blk_rq_map_user and
blk_rq_map_user_iov guarantee there's enough room for padding.
blk_rq_map_sg can safely extend the last entry of a scatter list.

blk_rq_map_sg must extend the last entry of a scatter list only for a
request that got through bio_copy_user_iov. This patches introduces
new REQ_COPY_USER flag.

Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: Tejun Heo <htejun@gmail.com>
Cc: Mike Christie <michaelc@cs.wisc.edu>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
block/blk-map.c
block/blk-merge.c
drivers/scsi/scsi.c
include/linux/blkdev.h

index ab43533ba641be51a8ed02129054d4d8530d684f..3c942bd6422a2ba639597ace2ad9f3768ccf1456 100644 (file)
@@ -141,25 +141,8 @@ int blk_rq_map_user(struct request_queue *q, struct request *rq,
                ubuf += ret;
        }
 
-       /*
-        * __blk_rq_map_user() copies the buffers if starting address
-        * or length isn't aligned to dma_pad_mask.  As the copied
-        * buffer is always page aligned, we know that there's enough
-        * room for padding.  Extend the last bio and update
-        * rq->data_len accordingly.
-        *
-        * On unmap, bio_uncopy_user() will use unmodified
-        * bio_map_data pointed to by bio->bi_private.
-        */
-       if (len & q->dma_pad_mask) {
-               unsigned int pad_len = (q->dma_pad_mask & ~len) + 1;
-               struct bio *tail = rq->biotail;
-
-               tail->bi_io_vec[tail->bi_vcnt - 1].bv_len += pad_len;
-               tail->bi_size += pad_len;
-
-               rq->extra_len += pad_len;
-       }
+       if (!bio_flagged(bio, BIO_USER_MAPPED))
+               rq->cmd_flags |= REQ_COPY_USER;
 
        rq->buffer = rq->data = NULL;
        return 0;
@@ -224,6 +207,9 @@ int blk_rq_map_user_iov(struct request_queue *q, struct request *rq,
                return -EINVAL;
        }
 
+       if (!bio_flagged(bio, BIO_USER_MAPPED))
+               rq->cmd_flags |= REQ_COPY_USER;
+
        bio_get(bio);
        blk_rq_bio_prep(q, rq, bio);
        rq->buffer = rq->data = NULL;
index 0f58616bcd7f183514c43eb913f0e0c23c855215..b5c5c4a9e3f08d051a25d44e92689580d19cbce5 100644 (file)
@@ -220,6 +220,15 @@ new_segment:
                bvprv = bvec;
        } /* segments in rq */
 
+
+       if (unlikely(rq->cmd_flags & REQ_COPY_USER) &&
+           (rq->data_len & q->dma_pad_mask)) {
+               unsigned int pad_len = (q->dma_pad_mask & ~rq->data_len) + 1;
+
+               sg->length += pad_len;
+               rq->extra_len += pad_len;
+       }
+
        if (q->dma_drain_size && q->dma_drain_needed(rq)) {
                if (rq->cmd_flags & REQ_RW)
                        memset(q->dma_drain_buffer, 0, q->dma_drain_size);
index f6980bd9d8f9a9a8b75a57de89cd9c8e26cc214c..12d69d7c85775475ce89de8fc6a6381ba4453809 100644 (file)
@@ -852,7 +852,7 @@ void scsi_finish_command(struct scsi_cmnd *cmd)
                                "Notifying upper driver of completion "
                                "(result %x)\n", cmd->result));
 
-       good_bytes = scsi_bufflen(cmd) + cmd->request->extra_len;
+       good_bytes = scsi_bufflen(cmd);
         if (cmd->request->cmd_type != REQ_TYPE_BLOCK_PC) {
                drv = scsi_cmd_to_driver(cmd);
                if (drv->done)
index 6f79d40dd3c01f25c105b9bdae4f5e70a7c88e1e..b3a58adc435282ed0a3ad55f0cb2cf96ade5428d 100644 (file)
@@ -112,6 +112,7 @@ enum rq_flag_bits {
        __REQ_RW_SYNC,          /* request is sync (O_DIRECT) */
        __REQ_ALLOCED,          /* request came from our alloc pool */
        __REQ_RW_META,          /* metadata io request */
+       __REQ_COPY_USER,        /* contains copies of user pages */
        __REQ_NR_BITS,          /* stops here */
 };
 
@@ -133,6 +134,7 @@ enum rq_flag_bits {
 #define REQ_RW_SYNC    (1 << __REQ_RW_SYNC)
 #define REQ_ALLOCED    (1 << __REQ_ALLOCED)
 #define REQ_RW_META    (1 << __REQ_RW_META)
+#define REQ_COPY_USER  (1 << __REQ_COPY_USER)
 
 #define BLK_MAX_CDB    16