Skip to content

Commit c2df40d

Browse files
Mike Christieaxboe
authored andcommitted
drivers: use req op accessor
The req operation REQ_OP is separated from the rq_flag_bits definition. This converts the block layer drivers to use req_op to get the op from the request struct. Signed-off-by: Mike Christie <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent d9d8c5c commit c2df40d

File tree

14 files changed

+43
-34
lines changed

14 files changed

+43
-34
lines changed

drivers/block/loop.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq)
544544
if (op_is_write(req_op(rq))) {
545545
if (rq->cmd_flags & REQ_FLUSH)
546546
ret = lo_req_flush(lo, rq);
547-
else if (rq->cmd_flags & REQ_DISCARD)
547+
else if (req_op(rq) == REQ_OP_DISCARD)
548548
ret = lo_discard(lo, rq, pos);
549549
else if (lo->transfer)
550550
ret = lo_write_transfer(lo, rq, pos);
@@ -1659,8 +1659,8 @@ static int loop_queue_rq(struct blk_mq_hw_ctx *hctx,
16591659
if (lo->lo_state != Lo_bound)
16601660
return -EIO;
16611661

1662-
if (lo->use_dio && !(cmd->rq->cmd_flags & (REQ_FLUSH |
1663-
REQ_DISCARD)))
1662+
if (lo->use_dio && (!(cmd->rq->cmd_flags & REQ_FLUSH) ||
1663+
req_op(cmd->rq) == REQ_OP_DISCARD))
16641664
cmd->use_aio = true;
16651665
else
16661666
cmd->use_aio = false;

drivers/block/mtip32xx/mtip32xx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3765,7 +3765,7 @@ static int mtip_submit_request(struct blk_mq_hw_ctx *hctx, struct request *rq)
37653765
return -ENODATA;
37663766
}
37673767

3768-
if (rq->cmd_flags & REQ_DISCARD) {
3768+
if (req_op(rq) == REQ_OP_DISCARD) {
37693769
int err;
37703770

37713771
err = mtip_send_trim(dd, blk_rq_pos(rq), blk_rq_sectors(rq));

drivers/block/nbd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static int nbd_send_req(struct nbd_device *nbd, struct request *req)
282282

283283
if (req->cmd_type == REQ_TYPE_DRV_PRIV)
284284
type = NBD_CMD_DISC;
285-
else if (req->cmd_flags & REQ_DISCARD)
285+
else if (req_op(req) == REQ_OP_DISCARD)
286286
type = NBD_CMD_TRIM;
287287
else if (req->cmd_flags & REQ_FLUSH)
288288
type = NBD_CMD_FLUSH;

drivers/block/rbd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3286,9 +3286,9 @@ static void rbd_queue_workfn(struct work_struct *work)
32863286
goto err;
32873287
}
32883288

3289-
if (rq->cmd_flags & REQ_DISCARD)
3289+
if (req_op(rq) == REQ_OP_DISCARD)
32903290
op_type = OBJ_OP_DISCARD;
3291-
else if (rq->cmd_flags & REQ_WRITE)
3291+
else if (req_op(rq) == REQ_OP_WRITE)
32923292
op_type = OBJ_OP_WRITE;
32933293
else
32943294
op_type = OBJ_OP_READ;

drivers/block/xen-blkfront.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,8 @@ static int blkif_queue_request(struct request *req, struct blkfront_ring_info *r
844844
if (unlikely(rinfo->dev_info->connected != BLKIF_STATE_CONNECTED))
845845
return 1;
846846

847-
if (unlikely(req->cmd_flags & (REQ_DISCARD | REQ_SECURE)))
847+
if (unlikely(req_op(req) == REQ_OP_DISCARD ||
848+
req->cmd_flags & REQ_SECURE))
848849
return blkif_queue_discard_req(req, rinfo);
849850
else
850851
return blkif_queue_rw_req(req, rinfo);
@@ -2054,8 +2055,9 @@ static int blkif_recover(struct blkfront_info *info)
20542055
/*
20552056
* Get the bios in the request so we can re-queue them.
20562057
*/
2057-
if (copy[i].request->cmd_flags &
2058-
(REQ_FLUSH | REQ_FUA | REQ_DISCARD | REQ_SECURE)) {
2058+
if (copy[i].request->cmd_flags & REQ_FLUSH ||
2059+
req_op(copy[i].request) == REQ_OP_DISCARD ||
2060+
copy[i].request->cmd_flags & (REQ_FUA | REQ_SECURE)) {
20592061
/*
20602062
* Flush operations don't contain bios, so
20612063
* we need to requeue the whole request

drivers/ide/ide-floppy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ static void idefloppy_create_rw_cmd(ide_drive_t *drive,
206206
memcpy(rq->cmd, pc->c, 12);
207207

208208
pc->rq = rq;
209-
if (rq->cmd_flags & REQ_WRITE)
209+
if (cmd == WRITE)
210210
pc->flags |= PC_FLAG_WRITING;
211211

212212
pc->flags |= PC_FLAG_DMA_OK;

drivers/md/dm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ static void dm_done(struct request *clone, int error, bool mapped)
13221322
r = rq_end_io(tio->ti, clone, error, &tio->info);
13231323
}
13241324

1325-
if (unlikely(r == -EREMOTEIO && (clone->cmd_flags & REQ_WRITE_SAME) &&
1325+
if (unlikely(r == -EREMOTEIO && (req_op(clone) == REQ_OP_WRITE_SAME) &&
13261326
!clone->q->limits.max_write_same_sectors))
13271327
disable_write_same(tio->md);
13281328

drivers/mmc/card/block.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,8 +1722,7 @@ static u8 mmc_blk_prep_packed_list(struct mmc_queue *mq, struct request *req)
17221722
!IS_ALIGNED(blk_rq_sectors(next), 8))
17231723
break;
17241724

1725-
if (next->cmd_flags & REQ_DISCARD ||
1726-
next->cmd_flags & REQ_FLUSH)
1725+
if (req_op(next) == REQ_OP_DISCARD || next->cmd_flags & REQ_FLUSH)
17271726
break;
17281727

17291728
if (rq_data_dir(cur) != rq_data_dir(next))
@@ -2164,7 +2163,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
21642163
}
21652164

21662165
mq->flags &= ~MMC_QUEUE_NEW_REQUEST;
2167-
if (cmd_flags & REQ_DISCARD) {
2166+
if (req && req_op(req) == REQ_OP_DISCARD) {
21682167
/* complete ongoing async transfer before issuing discard */
21692168
if (card->host->areq)
21702169
mmc_blk_issue_rw_rq(mq, NULL);
@@ -2188,7 +2187,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
21882187

21892188
out:
21902189
if ((!req && !(mq->flags & MMC_QUEUE_NEW_REQUEST)) ||
2191-
(cmd_flags & MMC_REQ_SPECIAL_MASK))
2190+
mmc_req_is_special(req))
21922191
/*
21932192
* Release host when there are no more requests
21942193
* and after special request(discard, flush) is done.

drivers/mmc/card/queue.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static int mmc_prep_request(struct request_queue *q, struct request *req)
3333
/*
3434
* We only like normal block requests and discards.
3535
*/
36-
if (req->cmd_type != REQ_TYPE_FS && !(req->cmd_flags & REQ_DISCARD)) {
36+
if (req->cmd_type != REQ_TYPE_FS && req_op(req) != REQ_OP_DISCARD) {
3737
blk_dump_rq_flags(req, "MMC bad request");
3838
return BLKPREP_KILL;
3939
}
@@ -56,7 +56,6 @@ static int mmc_queue_thread(void *d)
5656
down(&mq->thread_sem);
5757
do {
5858
struct request *req = NULL;
59-
unsigned int cmd_flags = 0;
6059

6160
spin_lock_irq(q->queue_lock);
6261
set_current_state(TASK_INTERRUPTIBLE);
@@ -66,7 +65,6 @@ static int mmc_queue_thread(void *d)
6665

6766
if (req || mq->mqrq_prev->req) {
6867
set_current_state(TASK_RUNNING);
69-
cmd_flags = req ? req->cmd_flags : 0;
7068
mq->issue_fn(mq, req);
7169
cond_resched();
7270
if (mq->flags & MMC_QUEUE_NEW_REQUEST) {
@@ -81,7 +79,7 @@ static int mmc_queue_thread(void *d)
8179
* has been finished. Do not assign it to previous
8280
* request.
8381
*/
84-
if (cmd_flags & MMC_REQ_SPECIAL_MASK)
82+
if (mmc_req_is_special(req))
8583
mq->mqrq_cur->req = NULL;
8684

8785
mq->mqrq_prev->brq.mrq.data = NULL;

drivers/mmc/card/queue.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#ifndef MMC_QUEUE_H
22
#define MMC_QUEUE_H
33

4-
#define MMC_REQ_SPECIAL_MASK (REQ_DISCARD | REQ_FLUSH)
4+
static inline bool mmc_req_is_special(struct request *req)
5+
{
6+
return req && (req->cmd_flags & REQ_FLUSH || req_op(req) == REQ_OP_DISCARD);
7+
}
58

69
struct request;
710
struct task_struct;

drivers/mtd/mtd_blkdevs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
9494
get_capacity(req->rq_disk))
9595
return -EIO;
9696

97-
if (req->cmd_flags & REQ_DISCARD)
97+
if (req_op(req) == REQ_OP_DISCARD)
9898
return tr->discard(dev, block, nsect);
9999

100100
if (rq_data_dir(req) == READ) {

drivers/nvme/host/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ int nvme_setup_cmd(struct nvme_ns *ns, struct request *req,
292292
memcpy(cmd, req->cmd, sizeof(*cmd));
293293
else if (req->cmd_flags & REQ_FLUSH)
294294
nvme_setup_flush(ns, cmd);
295-
else if (req->cmd_flags & REQ_DISCARD)
295+
else if (req_op(req) == REQ_OP_DISCARD)
296296
ret = nvme_setup_discard(ns, req, cmd);
297297
else
298298
nvme_setup_rw(ns, req, cmd);

drivers/nvme/host/nvme.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,15 @@ static inline u64 nvme_block_nr(struct nvme_ns *ns, sector_t sector)
177177

178178
static inline unsigned nvme_map_len(struct request *rq)
179179
{
180-
if (rq->cmd_flags & REQ_DISCARD)
180+
if (req_op(rq) == REQ_OP_DISCARD)
181181
return sizeof(struct nvme_dsm_range);
182182
else
183183
return blk_rq_bytes(rq);
184184
}
185185

186186
static inline void nvme_cleanup_cmd(struct request *req)
187187
{
188-
if (req->cmd_flags & REQ_DISCARD)
188+
if (req_op(req) == REQ_OP_DISCARD)
189189
kfree(req->completion_data);
190190
}
191191

drivers/scsi/sd.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,8 @@ static int sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt)
10121012
} else if (rq_data_dir(rq) == READ) {
10131013
SCpnt->cmnd[0] = READ_6;
10141014
} else {
1015-
scmd_printk(KERN_ERR, SCpnt, "Unknown command %llx\n", (unsigned long long) rq->cmd_flags);
1015+
scmd_printk(KERN_ERR, SCpnt, "Unknown command %d,%llx\n",
1016+
req_op(rq), (unsigned long long) rq->cmd_flags);
10161017
goto out;
10171018
}
10181019

@@ -1137,21 +1138,27 @@ static int sd_init_command(struct scsi_cmnd *cmd)
11371138
{
11381139
struct request *rq = cmd->request;
11391140

1140-
if (rq->cmd_flags & REQ_DISCARD)
1141+
switch (req_op(rq)) {
1142+
case REQ_OP_DISCARD:
11411143
return sd_setup_discard_cmnd(cmd);
1142-
else if (rq->cmd_flags & REQ_WRITE_SAME)
1144+
case REQ_OP_WRITE_SAME:
11431145
return sd_setup_write_same_cmnd(cmd);
1144-
else if (rq->cmd_flags & REQ_FLUSH)
1145-
return sd_setup_flush_cmnd(cmd);
1146-
else
1147-
return sd_setup_read_write_cmnd(cmd);
1146+
case REQ_OP_READ:
1147+
case REQ_OP_WRITE:
1148+
if (rq->cmd_flags & REQ_FLUSH)
1149+
return sd_setup_flush_cmnd(cmd);
1150+
else
1151+
return sd_setup_read_write_cmnd(cmd);
1152+
default:
1153+
BUG();
1154+
}
11481155
}
11491156

11501157
static void sd_uninit_command(struct scsi_cmnd *SCpnt)
11511158
{
11521159
struct request *rq = SCpnt->request;
11531160

1154-
if (rq->cmd_flags & REQ_DISCARD)
1161+
if (req_op(rq) == REQ_OP_DISCARD)
11551162
__free_page(rq->completion_data);
11561163

11571164
if (SCpnt->cmnd != rq->cmd) {
@@ -1774,7 +1781,7 @@ static int sd_done(struct scsi_cmnd *SCpnt)
17741781
unsigned char op = SCpnt->cmnd[0];
17751782
unsigned char unmap = SCpnt->cmnd[1] & 8;
17761783

1777-
if (req->cmd_flags & REQ_DISCARD || req->cmd_flags & REQ_WRITE_SAME) {
1784+
if (req_op(req) == REQ_OP_DISCARD || req_op(req) == REQ_OP_WRITE_SAME) {
17781785
if (!result) {
17791786
good_bytes = blk_rq_bytes(req);
17801787
scsi_set_resid(SCpnt, 0);

0 commit comments

Comments
 (0)