Commit 7a85f8896f4b4a4a0249563b92af9e3161a6b467
Committed by
Jens Axboe
1 parent
89b6e74378
Exists in
master
and in
7 other branches
block: restore the meaning of rq->data_len to the true data length
The meaning of rq->data_len was changed to the length of an allocated buffer from the true data length. It breaks SG_IO friends and bsg. This patch restores the meaning of rq->data_len to the true data length and adds rq->extra_len to store an extended length (due to drain buffer and padding). This patch also removes the code to update bio in blk_rq_map_user introduced by the commit 40b01b9bbdf51ae543a04744283bf2d56c4a6afa. The commit adjusts bio according to memory alignment (queue_dma_alignment). However, memory alignment is NOT padding alignment. This adjustment also breaks SG_IO friends and bsg. Padding alignment needs to be fixed in a proper way (by a separate patch). Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Signed-off-by: Jens Axboe <axboe@carl.home.kernel.dk>
Showing 7 changed files with 13 additions and 18 deletions Side-by-side Diff
block/blk-core.c
... | ... | @@ -127,7 +127,6 @@ |
127 | 127 | rq->nr_hw_segments = 0; |
128 | 128 | rq->ioprio = 0; |
129 | 129 | rq->special = NULL; |
130 | - rq->raw_data_len = 0; | |
131 | 130 | rq->buffer = NULL; |
132 | 131 | rq->tag = -1; |
133 | 132 | rq->errors = 0; |
... | ... | @@ -135,6 +134,7 @@ |
135 | 134 | rq->cmd_len = 0; |
136 | 135 | memset(rq->cmd, 0, sizeof(rq->cmd)); |
137 | 136 | rq->data_len = 0; |
137 | + rq->extra_len = 0; | |
138 | 138 | rq->sense_len = 0; |
139 | 139 | rq->data = NULL; |
140 | 140 | rq->sense = NULL; |
... | ... | @@ -2018,7 +2018,6 @@ |
2018 | 2018 | rq->hard_cur_sectors = rq->current_nr_sectors; |
2019 | 2019 | rq->hard_nr_sectors = rq->nr_sectors = bio_sectors(bio); |
2020 | 2020 | rq->buffer = bio_data(bio); |
2021 | - rq->raw_data_len = bio->bi_size; | |
2022 | 2021 | rq->data_len = bio->bi_size; |
2023 | 2022 | |
2024 | 2023 | rq->bio = rq->biotail = bio; |
block/blk-map.c
... | ... | @@ -19,7 +19,6 @@ |
19 | 19 | rq->biotail->bi_next = bio; |
20 | 20 | rq->biotail = bio; |
21 | 21 | |
22 | - rq->raw_data_len += bio->bi_size; | |
23 | 22 | rq->data_len += bio->bi_size; |
24 | 23 | } |
25 | 24 | return 0; |
26 | 25 | |
... | ... | @@ -151,11 +150,8 @@ |
151 | 150 | */ |
152 | 151 | if (len & queue_dma_alignment(q)) { |
153 | 152 | unsigned int pad_len = (queue_dma_alignment(q) & ~len) + 1; |
154 | - struct bio *bio = rq->biotail; | |
155 | 153 | |
156 | - bio->bi_io_vec[bio->bi_vcnt - 1].bv_len += pad_len; | |
157 | - bio->bi_size += pad_len; | |
158 | - rq->data_len += pad_len; | |
154 | + rq->extra_len += pad_len; | |
159 | 155 | } |
160 | 156 | |
161 | 157 | rq->buffer = rq->data = NULL; |
block/blk-merge.c
block/bsg.c
... | ... | @@ -437,14 +437,14 @@ |
437 | 437 | } |
438 | 438 | |
439 | 439 | if (rq->next_rq) { |
440 | - hdr->dout_resid = rq->raw_data_len; | |
441 | - hdr->din_resid = rq->next_rq->raw_data_len; | |
440 | + hdr->dout_resid = rq->data_len; | |
441 | + hdr->din_resid = rq->next_rq->data_len; | |
442 | 442 | blk_rq_unmap_user(bidi_bio); |
443 | 443 | blk_put_request(rq->next_rq); |
444 | 444 | } else if (rq_data_dir(rq) == READ) |
445 | - hdr->din_resid = rq->raw_data_len; | |
445 | + hdr->din_resid = rq->data_len; | |
446 | 446 | else |
447 | - hdr->dout_resid = rq->raw_data_len; | |
447 | + hdr->dout_resid = rq->data_len; | |
448 | 448 | |
449 | 449 | /* |
450 | 450 | * If the request generated a negative error number, return it |
block/scsi_ioctl.c
... | ... | @@ -266,7 +266,7 @@ |
266 | 266 | hdr->info = 0; |
267 | 267 | if (hdr->masked_status || hdr->host_status || hdr->driver_status) |
268 | 268 | hdr->info |= SG_INFO_CHECK; |
269 | - hdr->resid = rq->raw_data_len; | |
269 | + hdr->resid = rq->data_len; | |
270 | 270 | hdr->sb_len_wr = 0; |
271 | 271 | |
272 | 272 | if (rq->sense_len && hdr->sbp) { |
273 | 273 | |
... | ... | @@ -528,8 +528,8 @@ |
528 | 528 | rq = blk_get_request(q, WRITE, __GFP_WAIT); |
529 | 529 | rq->cmd_type = REQ_TYPE_BLOCK_PC; |
530 | 530 | rq->data = NULL; |
531 | - rq->raw_data_len = 0; | |
532 | 531 | rq->data_len = 0; |
532 | + rq->extra_len = 0; | |
533 | 533 | rq->timeout = BLK_DEFAULT_SG_TIMEOUT; |
534 | 534 | memset(rq->cmd, 0, sizeof(rq->cmd)); |
535 | 535 | rq->cmd[0] = cmd; |
drivers/ata/libata-scsi.c
... | ... | @@ -2538,7 +2538,7 @@ |
2538 | 2538 | } |
2539 | 2539 | |
2540 | 2540 | qc->tf.command = ATA_CMD_PACKET; |
2541 | - qc->nbytes = scsi_bufflen(scmd); | |
2541 | + qc->nbytes = scsi_bufflen(scmd) + scmd->request->extra_len; | |
2542 | 2542 | |
2543 | 2543 | /* check whether ATAPI DMA is safe */ |
2544 | 2544 | if (!using_pio && ata_check_atapi_dma(qc)) |
... | ... | @@ -2549,7 +2549,7 @@ |
2549 | 2549 | * want to set it properly, and for DMA where it is |
2550 | 2550 | * effectively meaningless. |
2551 | 2551 | */ |
2552 | - nbytes = min(scmd->request->raw_data_len, (unsigned int)63 * 1024); | |
2552 | + nbytes = min(scmd->request->data_len, (unsigned int)63 * 1024); | |
2553 | 2553 | |
2554 | 2554 | /* Most ATAPI devices which honor transfer chunk size don't |
2555 | 2555 | * behave according to the spec when odd chunk size which |
... | ... | @@ -2875,7 +2875,7 @@ |
2875 | 2875 | * TODO: find out if we need to do more here to |
2876 | 2876 | * cover scatter/gather case. |
2877 | 2877 | */ |
2878 | - qc->nbytes = scsi_bufflen(scmd); | |
2878 | + qc->nbytes = scsi_bufflen(scmd) + scmd->request->extra_len; | |
2879 | 2879 | |
2880 | 2880 | /* request result TF and be quiet about device error */ |
2881 | 2881 | qc->flags |= ATA_QCFLAG_RESULT_TF | ATA_QCFLAG_QUIET; |
include/linux/blkdev.h
... | ... | @@ -216,8 +216,8 @@ |
216 | 216 | unsigned int cmd_len; |
217 | 217 | unsigned char cmd[BLK_MAX_CDB]; |
218 | 218 | |
219 | - unsigned int raw_data_len; | |
220 | 219 | unsigned int data_len; |
220 | + unsigned int extra_len; /* length of alignment and padding */ | |
221 | 221 | unsigned int sense_len; |
222 | 222 | void *data; |
223 | 223 | void *sense; |