Skip to content

Commit aebf526

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: fold cmd_type into the REQ_OP_ space
Instead of keeping two levels of indirection for requests types, fold it all into the operations. The little caveat here is that previously cmd_type only applied to struct request, while the request and bio op fields were set to plain REQ_OP_READ/WRITE even for passthrough operations. Instead this patch adds new REQ_OP_* for SCSI passthrough and driver private requests, althought it has to add two for each so that we can communicate the data in/out nature of the request. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 2f5a8e8 commit aebf526

53 files changed

Lines changed: 338 additions & 326 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎block/bio.c‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,9 +1227,6 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
12271227
if (!bio)
12281228
goto out_bmd;
12291229

1230-
if (iter->type & WRITE)
1231-
bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
1232-
12331230
ret = 0;
12341231

12351232
if (map_data) {
@@ -1394,12 +1391,6 @@ struct bio *bio_map_user_iov(struct request_queue *q,
13941391

13951392
kfree(pages);
13961393

1397-
/*
1398-
* set data direction, and check if mapped pages need bouncing
1399-
*/
1400-
if (iter->type & WRITE)
1401-
bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
1402-
14031394
bio_set_flag(bio, BIO_USER_MAPPED);
14041395

14051396
/*
@@ -1590,7 +1581,6 @@ struct bio *bio_copy_kern(struct request_queue *q, void *data, unsigned int len,
15901581
bio->bi_private = data;
15911582
} else {
15921583
bio->bi_end_io = bio_copy_kern_endio;
1593-
bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
15941584
}
15951585

15961586
return bio;

‎block/blk-core.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ static void req_bio_endio(struct request *rq, struct bio *bio,
158158

159159
void blk_dump_rq_flags(struct request *rq, char *msg)
160160
{
161-
printk(KERN_INFO "%s: dev %s: type=%x, flags=%llx\n", msg,
162-
rq->rq_disk ? rq->rq_disk->disk_name : "?", rq->cmd_type,
161+
printk(KERN_INFO "%s: dev %s: flags=%llx\n", msg,
162+
rq->rq_disk ? rq->rq_disk->disk_name : "?",
163163
(unsigned long long) rq->cmd_flags);
164164

165165
printk(KERN_INFO " sector %llu, nr/cnr %u/%u\n",
@@ -1593,7 +1593,6 @@ unsigned int blk_plug_queued_count(struct request_queue *q)
15931593

15941594
void init_request_from_bio(struct request *req, struct bio *bio)
15951595
{
1596-
req->cmd_type = REQ_TYPE_FS;
15971596
if (bio->bi_opf & REQ_RAHEAD)
15981597
req->cmd_flags |= REQ_FAILFAST_MASK;
15991598

@@ -2983,7 +2982,6 @@ EXPORT_SYMBOL_GPL(blk_rq_unprep_clone);
29832982
static void __blk_rq_prep_clone(struct request *dst, struct request *src)
29842983
{
29852984
dst->cpu = src->cpu;
2986-
dst->cmd_type = src->cmd_type;
29872985
dst->__sector = blk_rq_pos(src);
29882986
dst->__data_len = blk_rq_bytes(src);
29892987
dst->nr_phys_segments = src->nr_phys_segments;

‎block/blk-flush.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ static bool blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq)
327327
blk_mq_tag_set_rq(hctx, first_rq->tag, flush_rq);
328328
}
329329

330-
flush_rq->cmd_type = REQ_TYPE_FS;
331330
flush_rq->cmd_flags = REQ_OP_FLUSH | REQ_PREFLUSH;
332331
flush_rq->rq_flags |= RQF_FLUSH_SEQ;
333332
flush_rq->rq_disk = first_rq->rq_disk;

‎block/blk-map.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
int blk_rq_append_bio(struct request *rq, struct bio *bio)
1717
{
1818
if (!rq->bio) {
19-
rq->cmd_flags &= REQ_OP_MASK;
20-
rq->cmd_flags |= (bio->bi_opf & REQ_OP_MASK);
2119
blk_rq_bio_prep(rq->q, rq, bio);
2220
} else {
2321
if (!ll_back_merge_fn(rq->q, rq, bio))
@@ -62,6 +60,9 @@ static int __blk_rq_map_user_iov(struct request *rq,
6260
if (IS_ERR(bio))
6361
return PTR_ERR(bio);
6462

63+
bio->bi_opf &= ~REQ_OP_MASK;
64+
bio->bi_opf |= req_op(rq);
65+
6566
if (map_data && map_data->null_mapped)
6667
bio_set_flag(bio, BIO_NULL_MAPPED);
6768

@@ -90,7 +91,7 @@ static int __blk_rq_map_user_iov(struct request *rq,
9091
}
9192

9293
/**
93-
* blk_rq_map_user_iov - map user data to a request, for REQ_TYPE_BLOCK_PC usage
94+
* blk_rq_map_user_iov - map user data to a request, for passthrough requests
9495
* @q: request queue where request should be inserted
9596
* @rq: request to map data to
9697
* @map_data: pointer to the rq_map_data holding pages (if necessary)
@@ -199,7 +200,7 @@ int blk_rq_unmap_user(struct bio *bio)
199200
EXPORT_SYMBOL(blk_rq_unmap_user);
200201

201202
/**
202-
* blk_rq_map_kern - map kernel data to a request, for REQ_TYPE_BLOCK_PC usage
203+
* blk_rq_map_kern - map kernel data to a request, for passthrough requests
203204
* @q: request queue where request should be inserted
204205
* @rq: request to fill
205206
* @kbuf: the kernel buffer
@@ -234,8 +235,8 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
234235
if (IS_ERR(bio))
235236
return PTR_ERR(bio);
236237

237-
if (!reading)
238-
bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
238+
bio->bi_opf &= ~REQ_OP_MASK;
239+
bio->bi_opf |= req_op(rq);
239240

240241
if (do_copy)
241242
rq->rq_flags |= RQF_COPY_USER;

‎block/blk-mq-debugfs.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ static int blk_mq_debugfs_rq_show(struct seq_file *m, void *v)
8888
{
8989
struct request *rq = list_entry_rq(v);
9090

91-
seq_printf(m, "%p {.cmd_type=%u, .cmd_flags=0x%x, .rq_flags=0x%x, .tag=%d, .internal_tag=%d}\n",
92-
rq, rq->cmd_type, rq->cmd_flags, (unsigned int)rq->rq_flags,
91+
seq_printf(m, "%p {.cmd_flags=0x%x, .rq_flags=0x%x, .tag=%d, .internal_tag=%d}\n",
92+
rq, rq->cmd_flags, (unsigned int)rq->rq_flags,
9393
rq->tag, rq->internal_tag);
9494
return 0;
9595
}

‎block/bsg.c‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
177177
* Check if sg_io_v4 from user is allowed and valid
178178
*/
179179
static int
180-
bsg_validate_sgv4_hdr(struct sg_io_v4 *hdr, int *rw)
180+
bsg_validate_sgv4_hdr(struct sg_io_v4 *hdr, int *op)
181181
{
182182
int ret = 0;
183183

@@ -198,7 +198,7 @@ bsg_validate_sgv4_hdr(struct sg_io_v4 *hdr, int *rw)
198198
ret = -EINVAL;
199199
}
200200

201-
*rw = hdr->dout_xfer_len ? WRITE : READ;
201+
*op = hdr->dout_xfer_len ? REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN;
202202
return ret;
203203
}
204204

@@ -210,8 +210,8 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm)
210210
{
211211
struct request_queue *q = bd->queue;
212212
struct request *rq, *next_rq = NULL;
213-
int ret, rw;
214-
unsigned int dxfer_len;
213+
int ret;
214+
unsigned int op, dxfer_len;
215215
void __user *dxferp = NULL;
216216
struct bsg_class_device *bcd = &q->bsg_dev;
217217

@@ -226,14 +226,14 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm)
226226
hdr->dout_xfer_len, (unsigned long long) hdr->din_xferp,
227227
hdr->din_xfer_len);
228228

229-
ret = bsg_validate_sgv4_hdr(hdr, &rw);
229+
ret = bsg_validate_sgv4_hdr(hdr, &op);
230230
if (ret)
231231
return ERR_PTR(ret);
232232

233233
/*
234234
* map scatter-gather elements separately and string them to request
235235
*/
236-
rq = blk_get_request(q, rw, GFP_KERNEL);
236+
rq = blk_get_request(q, op, GFP_KERNEL);
237237
if (IS_ERR(rq))
238238
return rq;
239239
scsi_req_init(rq);
@@ -242,20 +242,19 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm)
242242
if (ret)
243243
goto out;
244244

245-
if (rw == WRITE && hdr->din_xfer_len) {
245+
if (op == REQ_OP_SCSI_OUT && hdr->din_xfer_len) {
246246
if (!test_bit(QUEUE_FLAG_BIDI, &q->queue_flags)) {
247247
ret = -EOPNOTSUPP;
248248
goto out;
249249
}
250250

251-
next_rq = blk_get_request(q, READ, GFP_KERNEL);
251+
next_rq = blk_get_request(q, REQ_OP_SCSI_IN, GFP_KERNEL);
252252
if (IS_ERR(next_rq)) {
253253
ret = PTR_ERR(next_rq);
254254
next_rq = NULL;
255255
goto out;
256256
}
257257
rq->next_rq = next_rq;
258-
next_rq->cmd_type = rq->cmd_type;
259258

260259
dxferp = (void __user *)(unsigned long)hdr->din_xferp;
261260
ret = blk_rq_map_user(q, next_rq, NULL, dxferp,

‎block/scsi_ioctl.c‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk,
321321
at_head = 1;
322322

323323
ret = -ENOMEM;
324-
rq = blk_get_request(q, writing ? WRITE : READ, GFP_KERNEL);
324+
rq = blk_get_request(q, writing ? REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN,
325+
GFP_KERNEL);
325326
if (IS_ERR(rq))
326327
return PTR_ERR(rq);
327328
req = scsi_req(rq);
@@ -448,7 +449,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
448449

449450
}
450451

451-
rq = blk_get_request(q, in_len ? WRITE : READ, __GFP_RECLAIM);
452+
rq = blk_get_request(q, in_len ? REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN,
453+
__GFP_RECLAIM);
452454
if (IS_ERR(rq)) {
453455
err = PTR_ERR(rq);
454456
goto error_free_buffer;
@@ -537,7 +539,7 @@ static int __blk_send_generic(struct request_queue *q, struct gendisk *bd_disk,
537539
struct request *rq;
538540
int err;
539541

540-
rq = blk_get_request(q, WRITE, __GFP_RECLAIM);
542+
rq = blk_get_request(q, REQ_OP_SCSI_OUT, __GFP_RECLAIM);
541543
if (IS_ERR(rq))
542544
return PTR_ERR(rq);
543545
scsi_req_init(rq);
@@ -745,7 +747,6 @@ void scsi_req_init(struct request *rq)
745747
{
746748
struct scsi_request *req = scsi_req(rq);
747749

748-
rq->cmd_type = REQ_TYPE_BLOCK_PC;
749750
memset(req->__cmd, 0, sizeof(req->__cmd));
750751
req->cmd = req->__cmd;
751752
req->cmd_len = BLK_MAX_CDB;

‎drivers/block/cciss.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3394,7 +3394,9 @@ static void do_cciss_request(struct request_queue *q)
33943394
c->Header.SGList = h->max_cmd_sgentries;
33953395
set_performant_mode(h, c);
33963396

3397-
if (likely(creq->cmd_type == REQ_TYPE_FS)) {
3397+
switch (req_op(creq)) {
3398+
case REQ_OP_READ:
3399+
case REQ_OP_WRITE:
33983400
if(h->cciss_read == CCISS_READ_10) {
33993401
c->Request.CDB[1] = 0;
34003402
c->Request.CDB[2] = (start_blk >> 24) & 0xff; /* MSB */
@@ -3424,13 +3426,16 @@ static void do_cciss_request(struct request_queue *q)
34243426
c->Request.CDB[13]= blk_rq_sectors(creq) & 0xff;
34253427
c->Request.CDB[14] = c->Request.CDB[15] = 0;
34263428
}
3427-
} else if (creq->cmd_type == REQ_TYPE_BLOCK_PC) {
3429+
break;
3430+
case REQ_OP_SCSI_IN:
3431+
case REQ_OP_SCSI_OUT:
34283432
c->Request.CDBLen = scsi_req(creq)->cmd_len;
34293433
memcpy(c->Request.CDB, scsi_req(creq)->cmd, BLK_MAX_CDB);
34303434
scsi_req(creq)->sense = c->err_info->SenseInfo;
3431-
} else {
3435+
break;
3436+
default:
34323437
dev_warn(&h->pdev->dev, "bad request type %d\n",
3433-
creq->cmd_type);
3438+
creq->cmd_flags);
34343439
BUG();
34353440
}
34363441

‎drivers/block/floppy.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2900,8 +2900,8 @@ static void do_fd_request(struct request_queue *q)
29002900
return;
29012901

29022902
if (WARN(atomic_read(&usage_count) == 0,
2903-
"warning: usage count=0, current_req=%p sect=%ld type=%x flags=%llx\n",
2904-
current_req, (long)blk_rq_pos(current_req), current_req->cmd_type,
2903+
"warning: usage count=0, current_req=%p sect=%ld flags=%llx\n",
2904+
current_req, (long)blk_rq_pos(current_req),
29052905
(unsigned long long) current_req->cmd_flags))
29062906
return;
29072907

‎drivers/block/hd.c‎

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -626,30 +626,29 @@ static void hd_request(void)
626626
req_data_dir(req) == READ ? "read" : "writ",
627627
cyl, head, sec, nsect, bio_data(req->bio));
628628
#endif
629-
if (req->cmd_type == REQ_TYPE_FS) {
630-
switch (rq_data_dir(req)) {
631-
case READ:
632-
hd_out(disk, nsect, sec, head, cyl, ATA_CMD_PIO_READ,
633-
&read_intr);
634-
if (reset)
635-
goto repeat;
636-
break;
637-
case WRITE:
638-
hd_out(disk, nsect, sec, head, cyl, ATA_CMD_PIO_WRITE,
639-
&write_intr);
640-
if (reset)
641-
goto repeat;
642-
if (wait_DRQ()) {
643-
bad_rw_intr();
644-
goto repeat;
645-
}
646-
outsw(HD_DATA, bio_data(req->bio), 256);
647-
break;
648-
default:
649-
printk("unknown hd-command\n");
650-
hd_end_request_cur(-EIO);
651-
break;
629+
630+
switch (req_op(req)) {
631+
case REQ_OP_READ:
632+
hd_out(disk, nsect, sec, head, cyl, ATA_CMD_PIO_READ,
633+
&read_intr);
634+
if (reset)
635+
goto repeat;
636+
break;
637+
case REQ_OP_WRITE:
638+
hd_out(disk, nsect, sec, head, cyl, ATA_CMD_PIO_WRITE,
639+
&write_intr);
640+
if (reset)
641+
goto repeat;
642+
if (wait_DRQ()) {
643+
bad_rw_intr();
644+
goto repeat;
652645
}
646+
outsw(HD_DATA, bio_data(req->bio), 256);
647+
break;
648+
default:
649+
printk("unknown hd-command\n");
650+
hd_end_request_cur(-EIO);
651+
break;
653652
}
654653
}
655654

0 commit comments

Comments
 (0)