Skip to content

Commit 6b00769

Browse files
htejunJens Axboe
authored andcommitted
block: add request->raw_data_len
With padding and draining moved into it, block layer now may extend requests as directed by queue parameters, so now a request has two sizes - the original request size and the extended size which matches the size of area pointed to by bios and later by sgs. The latter size is what lower layers are primarily interested in when allocating, filling up DMA tables and setting up the controller. Both padding and draining extend the data area to accomodate controller characteristics. As any controller which speaks SCSI can handle underflows, feeding larger data area is safe. So, this patch makes the primary data length field, request->data_len, indicate the size of full data area and add a separate length field, request->raw_data_len, for the unmodified request size. The latter is used to report to higher layer (userland) and where the original request size should be fed to the controller or device. Signed-off-by: Tejun Heo <htejun@gmail.com> Cc: James Bottomley <James.Bottomley@HansenPartnership.com> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
1 parent 40b01b9 commit 6b00769

7 files changed

Lines changed: 16 additions & 9 deletions

File tree

‎block/blk-core.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ void rq_init(struct request_queue *q, struct request *rq)
127127
rq->nr_hw_segments = 0;
128128
rq->ioprio = 0;
129129
rq->special = NULL;
130+
rq->raw_data_len = 0;
130131
rq->buffer = NULL;
131132
rq->tag = -1;
132133
rq->errors = 0;
@@ -2015,6 +2016,7 @@ void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
20152016
rq->hard_cur_sectors = rq->current_nr_sectors;
20162017
rq->hard_nr_sectors = rq->nr_sectors = bio_sectors(bio);
20172018
rq->buffer = bio_data(bio);
2019+
rq->raw_data_len = bio->bi_size;
20182020
rq->data_len = bio->bi_size;
20192021

20202022
rq->bio = rq->biotail = bio;

‎block/blk-map.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ int blk_rq_append_bio(struct request_queue *q, struct request *rq,
1919
rq->biotail->bi_next = bio;
2020
rq->biotail = bio;
2121

22+
rq->raw_data_len += bio->bi_size;
2223
rq->data_len += bio->bi_size;
2324
}
2425
return 0;
@@ -154,6 +155,7 @@ int blk_rq_map_user(struct request_queue *q, struct request *rq,
154155

155156
bio->bi_io_vec[bio->bi_vcnt - 1].bv_len += pad_len;
156157
bio->bi_size += pad_len;
158+
rq->data_len += pad_len;
157159
}
158160

159161
rq->buffer = rq->data = NULL;

‎block/blk-merge.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ int blk_rq_map_sg(struct request_queue *q, struct request *rq,
228228
((unsigned long)q->dma_drain_buffer) &
229229
(PAGE_SIZE - 1));
230230
nsegs++;
231+
rq->data_len += q->dma_drain_size;
231232
}
232233

233234
if (sg)

‎block/bsg.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,14 +437,14 @@ static int blk_complete_sgv4_hdr_rq(struct request *rq, struct sg_io_v4 *hdr,
437437
}
438438

439439
if (rq->next_rq) {
440-
hdr->dout_resid = rq->data_len;
441-
hdr->din_resid = rq->next_rq->data_len;
440+
hdr->dout_resid = rq->raw_data_len;
441+
hdr->din_resid = rq->next_rq->raw_data_len;
442442
blk_rq_unmap_user(bidi_bio);
443443
blk_put_request(rq->next_rq);
444444
} else if (rq_data_dir(rq) == READ)
445-
hdr->din_resid = rq->data_len;
445+
hdr->din_resid = rq->raw_data_len;
446446
else
447-
hdr->dout_resid = rq->data_len;
447+
hdr->dout_resid = rq->raw_data_len;
448448

449449
/*
450450
* If the request generated a negative error number, return it

‎block/scsi_ioctl.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static int blk_complete_sghdr_rq(struct request *rq, struct sg_io_hdr *hdr,
266266
hdr->info = 0;
267267
if (hdr->masked_status || hdr->host_status || hdr->driver_status)
268268
hdr->info |= SG_INFO_CHECK;
269-
hdr->resid = rq->data_len;
269+
hdr->resid = rq->raw_data_len;
270270
hdr->sb_len_wr = 0;
271271

272272
if (rq->sense_len && hdr->sbp) {
@@ -528,6 +528,7 @@ static int __blk_send_generic(struct request_queue *q, struct gendisk *bd_disk,
528528
rq = blk_get_request(q, WRITE, __GFP_WAIT);
529529
rq->cmd_type = REQ_TYPE_BLOCK_PC;
530530
rq->data = NULL;
531+
rq->raw_data_len = 0;
531532
rq->data_len = 0;
532533
rq->timeout = BLK_DEFAULT_SG_TIMEOUT;
533534
memset(rq->cmd, 0, sizeof(rq->cmd));

‎drivers/scsi/scsi_lib.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,10 +1014,6 @@ static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb,
10141014
}
10151015

10161016
req->buffer = NULL;
1017-
if (blk_pc_request(req))
1018-
sdb->length = req->data_len;
1019-
else
1020-
sdb->length = req->nr_sectors << 9;
10211017

10221018
/*
10231019
* Next, walk the list, and fill in the addresses and sizes of
@@ -1026,6 +1022,10 @@ static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb,
10261022
count = blk_rq_map_sg(req->q, req, sdb->table.sgl);
10271023
BUG_ON(count > sdb->table.nents);
10281024
sdb->table.nents = count;
1025+
if (blk_pc_request(req))
1026+
sdb->length = req->data_len;
1027+
else
1028+
sdb->length = req->nr_sectors << 9;
10291029
return BLKPREP_OK;
10301030
}
10311031

‎include/linux/blkdev.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ struct request {
216216
unsigned int cmd_len;
217217
unsigned char cmd[BLK_MAX_CDB];
218218

219+
unsigned int raw_data_len;
219220
unsigned int data_len;
220221
unsigned int sense_len;
221222
void *data;

0 commit comments

Comments
 (0)