aboutsummaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
authorJens Axboe <axboe@fb.com>2014-06-06 09:57:37 -0400
committerJens Axboe <axboe@fb.com>2014-06-06 09:57:37 -0400
commitf27b087b81b70513b8c61ec20596c868f7b93474 (patch)
tree5dbdf3552f2289c28e65b0fee4490803bff87d42 /block
parent762380ad9322951cea4ce9d24864265f9c66a916 (diff)
block: add blk_rq_set_block_pc()
With the optimizations around not clearing the full request at alloc time, we are leaving some of the needed init for REQ_TYPE_BLOCK_PC up to the user allocating the request. Add a blk_rq_set_block_pc() that sets the command type to REQ_TYPE_BLOCK_PC, and properly initializes the members associated with this type of request. Update callers to use this function instead of manipulating rq->cmd_type directly. Includes fixes from Christoph Hellwig <hch@lst.de> for my half-assed attempt. Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'block')
-rw-r--r--block/blk-core.c18
-rw-r--r--block/bsg.c3
-rw-r--r--block/scsi_ioctl.c6
3 files changed, 23 insertions, 4 deletions
diff --git a/block/blk-core.c b/block/blk-core.c
index 40d654861c33..9aca8c71e70b 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1218,6 +1218,8 @@ struct request *blk_make_request(struct request_queue *q, struct bio *bio,
1218 if (unlikely(!rq)) 1218 if (unlikely(!rq))
1219 return ERR_PTR(-ENOMEM); 1219 return ERR_PTR(-ENOMEM);
1220 1220
1221 blk_rq_set_block_pc(rq);
1222
1221 for_each_bio(bio) { 1223 for_each_bio(bio) {
1222 struct bio *bounce_bio = bio; 1224 struct bio *bounce_bio = bio;
1223 int ret; 1225 int ret;
@@ -1235,6 +1237,22 @@ struct request *blk_make_request(struct request_queue *q, struct bio *bio,
1235EXPORT_SYMBOL(blk_make_request); 1237EXPORT_SYMBOL(blk_make_request);
1236 1238
1237/** 1239/**
1240 * blk_rq_set_block_pc - initialize a requeest to type BLOCK_PC
1241 * @rq: request to be initialized
1242 *
1243 */
1244void blk_rq_set_block_pc(struct request *rq)
1245{
1246 rq->cmd_type = REQ_TYPE_BLOCK_PC;
1247 rq->__data_len = 0;
1248 rq->__sector = (sector_t) -1;
1249 rq->bio = rq->biotail = NULL;
1250 memset(rq->__cmd, 0, sizeof(rq->__cmd));
1251 rq->cmd = rq->__cmd;
1252}
1253EXPORT_SYMBOL(blk_rq_set_block_pc);
1254
1255/**
1238 * blk_requeue_request - put a request back on queue 1256 * blk_requeue_request - put a request back on queue
1239 * @q: request queue where request should be inserted 1257 * @q: request queue where request should be inserted
1240 * @rq: request to be inserted 1258 * @rq: request to be inserted
diff --git a/block/bsg.c b/block/bsg.c
index e5214c148096..ff46addde5d8 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -196,7 +196,6 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
196 * fill in request structure 196 * fill in request structure
197 */ 197 */
198 rq->cmd_len = hdr->request_len; 198 rq->cmd_len = hdr->request_len;
199 rq->cmd_type = REQ_TYPE_BLOCK_PC;
200 199
201 rq->timeout = msecs_to_jiffies(hdr->timeout); 200 rq->timeout = msecs_to_jiffies(hdr->timeout);
202 if (!rq->timeout) 201 if (!rq->timeout)
@@ -273,6 +272,8 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm,
273 rq = blk_get_request(q, rw, GFP_KERNEL); 272 rq = blk_get_request(q, rw, GFP_KERNEL);
274 if (!rq) 273 if (!rq)
275 return ERR_PTR(-ENOMEM); 274 return ERR_PTR(-ENOMEM);
275 blk_rq_set_block_pc(rq);
276
276 ret = blk_fill_sgv4_hdr_rq(q, rq, hdr, bd, has_write_perm); 277 ret = blk_fill_sgv4_hdr_rq(q, rq, hdr, bd, has_write_perm);
277 if (ret) 278 if (ret)
278 goto out; 279 goto out;
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index 9c28a5b38042..14695c6221c8 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -229,7 +229,6 @@ static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
229 * fill in request structure 229 * fill in request structure
230 */ 230 */
231 rq->cmd_len = hdr->cmd_len; 231 rq->cmd_len = hdr->cmd_len;
232 rq->cmd_type = REQ_TYPE_BLOCK_PC;
233 232
234 rq->timeout = msecs_to_jiffies(hdr->timeout); 233 rq->timeout = msecs_to_jiffies(hdr->timeout);
235 if (!rq->timeout) 234 if (!rq->timeout)
@@ -311,6 +310,7 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk,
311 rq = blk_get_request(q, writing ? WRITE : READ, GFP_KERNEL); 310 rq = blk_get_request(q, writing ? WRITE : READ, GFP_KERNEL);
312 if (!rq) 311 if (!rq)
313 return -ENOMEM; 312 return -ENOMEM;
313 blk_rq_set_block_pc(rq);
314 314
315 if (blk_fill_sghdr_rq(q, rq, hdr, mode)) { 315 if (blk_fill_sghdr_rq(q, rq, hdr, mode)) {
316 blk_put_request(rq); 316 blk_put_request(rq);
@@ -491,7 +491,7 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
491 memset(sense, 0, sizeof(sense)); 491 memset(sense, 0, sizeof(sense));
492 rq->sense = sense; 492 rq->sense = sense;
493 rq->sense_len = 0; 493 rq->sense_len = 0;
494 rq->cmd_type = REQ_TYPE_BLOCK_PC; 494 blk_rq_set_block_pc(rq);
495 495
496 blk_execute_rq(q, disk, rq, 0); 496 blk_execute_rq(q, disk, rq, 0);
497 497
@@ -524,7 +524,7 @@ static int __blk_send_generic(struct request_queue *q, struct gendisk *bd_disk,
524 int err; 524 int err;
525 525
526 rq = blk_get_request(q, WRITE, __GFP_WAIT); 526 rq = blk_get_request(q, WRITE, __GFP_WAIT);
527 rq->cmd_type = REQ_TYPE_BLOCK_PC; 527 blk_rq_set_block_pc(rq);
528 rq->timeout = BLK_DEFAULT_SG_TIMEOUT; 528 rq->timeout = BLK_DEFAULT_SG_TIMEOUT;
529 rq->cmd[0] = cmd; 529 rq->cmd[0] = cmd;
530 rq->cmd[4] = data; 530 rq->cmd[4] = data;