From patchwork Wed Nov 9 15:59:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 17316 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp100790wru; Tue, 8 Nov 2022 18:45:55 -0800 (PST) X-Google-Smtp-Source: AMsMyM7svI3QfhlzKT8bLfbZi9KLo/f0jOZaSKZnip17sQH4FBth+/Ullb9aFfol2cG6bJV/qF3x X-Received: by 2002:a17:907:c1e:b0:7ae:31a0:571e with SMTP id ga30-20020a1709070c1e00b007ae31a0571emr23411025ejc.690.1667961955480; Tue, 08 Nov 2022 18:45:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667961955; cv=none; d=google.com; s=arc-20160816; b=flq+tevXAH76l0ep+APMkMj02HG/LO4ONAifx1tpv5j4bF8XovTqr2sDjCr0ZbvG7R hutKiRrSnL7nFK2l7L8X+jtPhnDhoHuuObNXMdG9odi1YnMvqMbi++O36bZKRKUmTCZT 2827gZz6V+kl0sG3V7lxPA2KHp+jMlE6q1ccUCMR+39PHuaUXb7kzHMfheeGUlDsah5x uUPBddOc+oWAyO+4xDq95lNXubxz4eaH6sx1I48QZ1eU6QhaCUkDN42UVyVRwKl6Ee0G mDHmgYO8Yjo3RCqjeGafjao9zP5Ew1Re6FbZIZZr3A8DdiMjX8tuk/RIMZ3bvceyFq+r 5+nA== 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=G+6girYijK3ZCCdFrWXl3TOagbXCrBtr4zvlIQpLxww=; b=O8V8JJ5p945/yydNMzPbfc+4iDk4MAg5je3s1aOrIFNZ0Jv/AfUT0h/yJsWTCVvz4P mlvhjpJBXKD4Z2Kuj56l2G7AlJ/cEGSM1TzD1FEQggJ70ksN8HYPiWr24v14lwgrQlD+ 0hjNz0INVax+W3VLOP5DHHV9X7PMWE36cGs4OX8J9EQdPafYqRGwK7FkjxL1Vc5amK+r Xoot88OMeOjVUkuDVktskTCtwhut1onHd7K13VILMm2VNCM1ACzgswIJtNDrmtAiopaR /G0w2yvgH7Lk+Sa+DqzRX/6BvHMhR6NTyYV6UxaJ3mbrzOym0BdQ1xjAsDAS1QE1bxBD OyHw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a2-20020a50ff02000000b004593895fb89si12391045edu.390.2022.11.08.18.45.31; Tue, 08 Nov 2022 18:45:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230035AbiKICoI (ORCPT + 99 others); Tue, 8 Nov 2022 21:44:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229926AbiKICnw (ORCPT ); Tue, 8 Nov 2022 21:43:52 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA09510063; Tue, 8 Nov 2022 18:43:50 -0800 (PST) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4N6TjW6sjZzHqVp; Wed, 9 Nov 2022 10:40:47 +0800 (CST) Received: from dggpemm500017.china.huawei.com (7.185.36.178) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 9 Nov 2022 10:43:48 +0800 Received: from build.huawei.com (10.175.101.6) by dggpemm500017.china.huawei.com (7.185.36.178) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 9 Nov 2022 10:43:48 +0800 From: Wenchao Hao To: "James E . J . Bottomley" , "Martin K . Petersen" , Doug Gilbert CC: , , Wenchao Hao Subject: [RFC PATCH 3/5] scsi:scsi_debug: make command timeout if timeout error is injected Date: Wed, 9 Nov 2022 10:59:48 -0500 Message-ID: <20221109155950.3536976-4-haowenchao@huawei.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20221109155950.3536976-1-haowenchao@huawei.com> References: <20221109155950.3536976-1-haowenchao@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 dggpemm500017.china.huawei.com (7.185.36.178) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_12_24, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=no 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748984875271213325?= X-GMAIL-MSGID: =?utf-8?q?1748984875271213325?= If a timeout error is injected for specific scsi command, just return 0 in queuecommand to make it timeout. For example, the following command would inject timeout error for inquiry(0x12) command for 10 times: echo "0 -10 0x12" >/sys/block/sdb/device/error_inject/error Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_debug.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 06e3150812fa..761e1e3bcb9a 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -7784,6 +7784,30 @@ const struct attribute_group *sdebug_sdev_groups[] = { NULL }; +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; + + list_for_each_entry(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++; + return ret; + } + } + + return 0; +} + static int scsi_debug_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scp) { @@ -7842,6 +7866,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);