Skip to content

Commit f037b5c

Browse files
johnpgarrymartinkpetersen
authored andcommitted
scsi: scsi_debug: Get command abort feature working again
The command abort feature allows us to test aborting a command which has timed-out. The idea is that for specific commands we just don't call scsi_done() and allow the request to timeout, which ensures SCSI EH kicks-in we try to abort the command. Since commit 4a0c6f4 ("scsi: scsi_debug: Add new defer type for mq_poll") this does not seem to work. The issue is that we clear the sd_dp->aborted flag in schedule_resp() before the completion callback has run. When the completion callback actually runs, it calls scsi_done() as normal as sd_dp->aborted unset. This is all very racy. Fix by not clearing sd_dp->aborted in schedule_resp(). Also move the call to blk_abort_request() from schedule_resp() to sdebug_q_cmd_complete(), which makes the code have a more logical sequence. I also note that this feature only works for commands which are classed as "SDEG_RES_IMMED_MASK", but only practically triggered with prior RW commands. So for my experiment I need to run fio to trigger the error on the "nth" command (see inject_on_this_cmd()), and then run something like sg_sync to queue a command to actually trigger the abort. Signed-off-by: John Garry <john.g.garry@oracle.com> Acked-by: Douglas Gilbert <dgilbert@interlog.com> Link: https://lore.kernel.org/r/20230313093114.1498305-11-john.g.garry@oracle.com Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 151f0ec commit f037b5c

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

drivers/scsi/scsi_debug.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4983,7 +4983,8 @@ static void sdebug_q_cmd_complete(struct sdebug_defer *sd_dp)
49834983
spin_unlock_irqrestore(&sqp->qc_lock, iflags);
49844984
if (unlikely(aborted)) {
49854985
if (sdebug_verbose)
4986-
pr_info("bypassing scsi_done() due to aborted cmd\n");
4986+
pr_info("bypassing scsi_done() due to aborted cmd, kicking-off EH\n");
4987+
blk_abort_request(scsi_cmd_to_rq(scp));
49874988
return;
49884989
}
49894990
scsi_done(scp); /* callback to mid level */
@@ -5712,8 +5713,13 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip,
57125713
sd_dp->issuing_cpu = raw_smp_processor_id();
57135714
} else { /* jdelay < 0, use work queue */
57145715
if (unlikely((sdebug_opts & SDEBUG_OPT_CMD_ABORT) &&
5715-
atomic_read(&sdeb_inject_pending)))
5716+
atomic_read(&sdeb_inject_pending))) {
57165717
sd_dp->aborted = true;
5718+
atomic_set(&sdeb_inject_pending, 0);
5719+
sdev_printk(KERN_INFO, sdp, "abort request tag=%#x\n",
5720+
blk_mq_unique_tag_to_tag(get_tag(cmnd)));
5721+
}
5722+
57175723
if (polled) {
57185724
sd_dp->cmpl_ts = ns_to_ktime(ns_from_boot);
57195725
spin_lock_irqsave(&sqp->qc_lock, iflags);
@@ -5738,13 +5744,6 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip,
57385744
}
57395745
if (sdebug_statistics)
57405746
sd_dp->issuing_cpu = raw_smp_processor_id();
5741-
if (unlikely(sd_dp->aborted)) {
5742-
sdev_printk(KERN_INFO, sdp, "abort request tag %d\n",
5743-
scsi_cmd_to_rq(cmnd)->tag);
5744-
blk_abort_request(scsi_cmd_to_rq(cmnd));
5745-
atomic_set(&sdeb_inject_pending, 0);
5746-
sd_dp->aborted = false;
5747-
}
57485747
}
57495748

57505749
return 0;

0 commit comments

Comments
 (0)