Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4506184rwb; Tue, 8 Nov 2022 18:47:07 -0800 (PST) X-Google-Smtp-Source: AMsMyM5HDCcduAS15+BMbLFlMx4Ha9yyeVLs5/LaoIFho+8NAQ6drFM0zGyj6wY16PLqj/nbVPJp X-Received: by 2002:a17:907:a059:b0:78d:1a16:fc5c with SMTP id gz25-20020a170907a05900b0078d1a16fc5cmr55796289ejc.31.1667962027601; Tue, 08 Nov 2022 18:47:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667962027; cv=none; d=google.com; s=arc-20160816; b=mcmQuvEfe7SwclKKCy7qsTssHZ6GFy7O5nTRLrwgW6iFFLcxZ5xSeVfeabp1Gchtqh Wg1BDrW0WvcpMLWiE5B6DzBxulGJCpF08S50rrcpDmc0uzYBiSDUvYYzLGqpu05/QfTq aeqYZG71m2lGNvoG2dUXQqpYDGMV5adjx0+BVPDxjXaEoJVKiKtRxe65ty1sNPTdJSrS BMliw6L+U0+McTwt6S126Cic/6ETSHtegqjEvJs/hl3pd4tFf/Tq+jfO3Tgfw795vlw9 +9fYtnYIfS0dxZo6H+MEBxh1Q+2Gfyi7DfvorBH30+iqN38j5JiY9rBN5suaiGaT1V4x MExQ== 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 Return-Path: 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.46.45; Tue, 08 Nov 2022 18:47:07 -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 + 93 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 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 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 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); -- 2.35.3