From patchwork Fri Sep 22 09:29:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 143300 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5438458vqi; Fri, 22 Sep 2023 02:44:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEGsXSnxLBa/ZOGhAiCf8whj3s1xxDZAv2hpDxedPLX8iLWuXp+Skvioet22BNbUGkOJBhc X-Received: by 2002:a05:6358:700f:b0:143:995b:6c27 with SMTP id 15-20020a056358700f00b00143995b6c27mr557853rwo.0.1695375868378; Fri, 22 Sep 2023 02:44:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695375868; cv=none; d=google.com; s=arc-20160816; b=mpr+hP6vpyijm5ICY6TmApiCCL8wu9jHYIrwsaC1lGOhCF18uAiqQNTJ+kK8SOA8I6 9kpVcOW4h+56ImsOxFUpsApRUUs/D8HLzYvFnKG31Zzp0iVEr8gpUWsbTZZfXTDGjNNq wP24BFrFMbaHPemjX4iovrFmoGvgShfyAitGzBQVF5dkT8pDqMaSSyi2kYYpi4nRBr83 HT5P0PQJpVNMfE6tY34GCCjEhhY3OBcWBEssoLEwqKNw2qCbwp6/1FfNErOAjvEJLn2h Ujsk2OSDcg9N3beW6/YIR2FKPqoOGc9oZLDwf5fW7b0UJ8wrRMOoI/obbpOghYIQctoN mjdg== 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 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id q17-20020a637511000000b005779c97fae5si3420619pgc.480.2023.09.22.02.44.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 02:44:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id CB5A58392303; Fri, 22 Sep 2023 02:30:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233269AbjIVJaV (ORCPT + 30 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 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=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Fri, 22 Sep 2023 02:30:26 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777730446587080989 X-GMAIL-MSGID: 1777730446587080989 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);