Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2576598rdb; Fri, 22 Sep 2023 02:46:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXDq8dDdy0y3V0mb2EdS2gGWFccK3N8V0CuSMiuP75Tznbd/Fg5fMQG6LYqox8+Py4k4do X-Received: by 2002:a17:903:11c7:b0:1c5:eebb:5071 with SMTP id q7-20020a17090311c700b001c5eebb5071mr491337plh.27.1695375982529; Fri, 22 Sep 2023 02:46:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695375982; cv=none; d=google.com; s=arc-20160816; b=zrDrIEXhxBcOgGkIZWx5vWSyLxC5/vH+MKYtyLQaSZgyfrRn5sRX/D5nBzlOVymZxl FHl5R/FiaJRZ7shAbhM2rrNTr9JWd2y21ZZFwRWSkv/Pf8R8OnVZITyBtJRvr/Y0y5Mt esrAvxd0kTonZ/LfFjdmSZYKGq1+HuP0/TU6ByQ3J6TQx6/TFycKMJ+m66XUAzSITDbm 0TumJ0QUHKxNcCqbLn9XiG7QiQBvpCL8QPDZcV+QyB8zO3Xe0PlApSocejLVXHaFAEwN U7TC33fUP7q+32oFFxkaJZ2cONzLehPPGbk69zpgohLJEv6wIoMBLsKHntpVVxWP5KqC utLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=tnp7C2Py8vCPoe4eoheh5UWAyaPwzxtuqHIYfIZl5QQ=; fh=efbNbptNhbD3foczTZf5UTdQGTI/0Ud9virqYphOI9o=; b=TEXHn0YvlOceSb/HH5qpbvjF8hzAddSON+HJktGb2moUR4C/p+cvxTVapuItKQP1hH pSG/oTe012txTJ4GnGzCPHiaCrGt1wjkQ2YvLeTZ+eJVU6IUKdeABCPU/89PumUGHR0A BZPkSvTkvQ3ao0xHSJjxW+ty72jGIu3B0DCffXzlA5KdtpXGz9jNQJHrfTOPsVBV4Qnr Nmb0LnMfSx+2VyNuueuxq+q1B5S87HIevc6phCN5KQZsQtjzSRA/FE4UhMm0qHdN49Bs AWCVAgnNiqZ8rs/o/Sp+FbKrxtoDYuZ82mxqxwr5GoSZCD4CKB3RkQlXAxHU6cA/+KWh 5CRA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id u6-20020a170902714600b001c3a6902ff1si3224323plm.288.2023.09.22.02.46.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 02:46:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 4F7DC8582064; Fri, 22 Sep 2023 02:30:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233167AbjIVJaV (ORCPT + 99 others); Fri, 22 Sep 2023 05:30:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232965AbjIVJ3v (ORCPT ); Fri, 22 Sep 2023 05:29:51 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7656BCE0; Fri, 22 Sep 2023 02:29:37 -0700 (PDT) Received: from kwepemm000012.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4RsRkQ40kfz15NRJ; Fri, 22 Sep 2023 17:27:26 +0800 (CST) Received: from build.huawei.com (10.175.101.6) by kwepemm000012.china.huawei.com (7.193.23.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 22 Sep 2023 17:29:34 +0800 From: Wenchao Hao To: "James E . J . Bottomley" , "Martin K . Petersen" , Douglas Gilbert , , CC: , , Wenchao Hao Subject: [PATCH v5 04/10] scsi: scsi_debug: timeout command if the error is injected Date: Fri, 22 Sep 2023 17:29:00 +0800 Message-ID: <20230922092906.2645265-5-haowenchao2@huawei.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230922092906.2645265-1-haowenchao2@huawei.com> References: <20230922092906.2645265-1-haowenchao2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm000012.china.huawei.com (7.193.23.142) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Fri, 22 Sep 2023 02:30:26 -0700 (PDT) If a timeout error is injected, return 0 from scsi_debug_queuecommand to make the command timeout. Timeout SCSI command format: +--------+------+-------------------------------------------------------+ | Column | Type | Description | +--------+------+-------------------------------------------------------+ | 1 | u8 | Error type, fixed to 0x0 | +--------+------+-------------------------------------------------------+ | 2 | s32 | Error count | | | | 0: this rule will be ignored | | | | positive: the rule will always take effect | | | | negative: the rule takes effect n times where -n is | | | | the value given. Ignored after n times | +--------+------+-------------------------------------------------------+ | 3 | x8 | SCSI command opcode, 0xff for all commands | +--------+------+-------------------------------------------------------+ Examples: error=/sys/kernel/debug/scsi_debug/0:0:0:1/error echo "0 -10 0x12" > ${error} will make the device's inquiry command timeout 10 times. echo "0 1 0x12" > ${error} will make the device's inquiry timeout each time it is invoked on this device. Acked-by: Douglas Gilbert Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_debug.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 6235e828c430..785ad5e5b4a4 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -7731,6 +7731,34 @@ static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num) return num_entries; } +static int sdebug_timeout_cmd(struct scsi_cmnd *cmnd) +{ + struct scsi_device *sdp = cmnd->device; + struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata; + struct sdebug_err_inject *err; + unsigned char *cmd = cmnd->cmnd; + int ret = 0; + + if (devip == NULL) + return 0; + + rcu_read_lock(); + list_for_each_entry_rcu(err, &devip->inject_err_list, list) { + if (err->type == ERR_TMOUT_CMD && + (err->cmd == cmd[0] || err->cmd == 0xff)) { + ret = !!err->cnt; + if (err->cnt < 0) + err->cnt++; + + rcu_read_unlock(); + return ret; + } + } + rcu_read_unlock(); + + return 0; +} + static int scsi_debug_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scp) { @@ -7789,6 +7817,12 @@ static int scsi_debug_queuecommand(struct Scsi_Host *shost, if (NULL == devip) goto err_out; } + + if (sdebug_timeout_cmd(scp)) { + scmd_printk(KERN_INFO, scp, "timeout command 0x%x\n", opcode); + return 0; + } + if (unlikely(inject_now && !atomic_read(&sdeb_inject_pending))) atomic_set(&sdeb_inject_pending, 1); -- 2.32.0