Skip to content

Commit 64104f7

Browse files
KAGA-KOKOmartinkpetersen
authored andcommitted
scsi: Call scsi_initialize_rq() for filesystem requests
If a pass-through request is submitted then blk_get_request() initializes that request by calling scsi_initialize_rq(). Also call this function for filesystem requests. Introduce CMD_INITIALIZED to keep track of whether or not a request has already been initialized. Signed-off-by: Bart Van Assche <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Brian King <[email protected]> Cc: Hannes Reinecke <[email protected]> Cc: Johannes Thumshirn <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 3515832 commit 64104f7

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

drivers/scsi/scsi_lib.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,11 @@ static bool scsi_end_request(struct request *req, blk_status_t error,
642642
if (blk_queue_add_random(q))
643643
add_disk_randomness(req->rq_disk);
644644

645+
if (!blk_rq_is_scsi(req)) {
646+
WARN_ON_ONCE(!(cmd->flags & SCMD_INITIALIZED));
647+
cmd->flags &= ~SCMD_INITIALIZED;
648+
}
649+
645650
if (req->mq_ctx) {
646651
/*
647652
* In the MQ case the command gets freed by __blk_mq_end_request,
@@ -1110,7 +1115,8 @@ EXPORT_SYMBOL(scsi_init_io);
11101115
* scsi_initialize_rq - initialize struct scsi_cmnd.req
11111116
* @rq: Request associated with the SCSI command to be initialized.
11121117
*
1113-
* Called from inside blk_get_request().
1118+
* Called from inside blk_get_request() for pass-through requests and from
1119+
* inside scsi_init_command() for filesystem requests.
11141120
*/
11151121
void scsi_initialize_rq(struct request *rq)
11161122
{
@@ -1154,7 +1160,13 @@ void scsi_init_command(struct scsi_device *dev, struct scsi_cmnd *cmd)
11541160
{
11551161
void *buf = cmd->sense_buffer;
11561162
void *prot = cmd->prot_sdb;
1157-
unsigned int unchecked_isa_dma = cmd->flags & SCMD_UNCHECKED_ISA_DMA;
1163+
struct request *rq = blk_mq_rq_from_pdu(cmd);
1164+
unsigned int flags = cmd->flags & SCMD_PRESERVED_FLAGS;
1165+
1166+
if (!blk_rq_is_scsi(rq) && !(flags & SCMD_INITIALIZED)) {
1167+
flags |= SCMD_INITIALIZED;
1168+
scsi_initialize_rq(rq);
1169+
}
11581170

11591171
/* zero out the cmd, except for the embedded scsi_request */
11601172
memset((char *)cmd + sizeof(cmd->req), 0,
@@ -1163,7 +1175,7 @@ void scsi_init_command(struct scsi_device *dev, struct scsi_cmnd *cmd)
11631175
cmd->device = dev;
11641176
cmd->sense_buffer = buf;
11651177
cmd->prot_sdb = prot;
1166-
cmd->flags = unchecked_isa_dma;
1178+
cmd->flags = flags;
11671179
INIT_DELAYED_WORK(&cmd->abort_work, scmd_eh_abort_handler);
11681180
cmd->jiffies_at_alloc = jiffies;
11691181

@@ -1350,6 +1362,8 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req)
13501362

13511363
ret = scsi_setup_cmnd(sdev, req);
13521364
out:
1365+
if (ret != BLKPREP_OK)
1366+
cmd->flags &= ~SCMD_INITIALIZED;
13531367
return scsi_prep_return(q, req, ret);
13541368
}
13551369

@@ -1869,6 +1883,7 @@ static int scsi_mq_prep_fn(struct request *req)
18691883
struct scsi_device *sdev = req->q->queuedata;
18701884
struct Scsi_Host *shost = sdev->host;
18711885
struct scatterlist *sg;
1886+
int ret;
18721887

18731888
scsi_init_command(sdev, cmd);
18741889

@@ -1902,7 +1917,10 @@ static int scsi_mq_prep_fn(struct request *req)
19021917

19031918
blk_mq_start_request(req);
19041919

1905-
return scsi_setup_cmnd(sdev, req);
1920+
ret = scsi_setup_cmnd(sdev, req);
1921+
if (ret != BLK_STS_OK)
1922+
cmd->flags &= ~SCMD_INITIALIZED;
1923+
return ret;
19061924
}
19071925

19081926
static void scsi_mq_done(struct scsi_cmnd *cmd)

include/scsi/scsi_cmnd.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ struct scsi_pointer {
5757
/* for scmd->flags */
5858
#define SCMD_TAGGED (1 << 0)
5959
#define SCMD_UNCHECKED_ISA_DMA (1 << 1)
60+
#define SCMD_INITIALIZED (1 << 3)
61+
/* flags preserved across unprep / reprep */
62+
#define SCMD_PRESERVED_FLAGS (SCMD_UNCHECKED_ISA_DMA | SCMD_INITIALIZED)
6063

6164
struct scsi_cmnd {
6265
struct scsi_request req;

0 commit comments

Comments
 (0)