From patchwork Tue Oct 10 09:20:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 150606 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp63724vqb; Tue, 10 Oct 2023 02:22:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEEtbMePxv/j6MVjeqQcHd9Tlu0IUuV96MdPVoozF4JpoKu53xizKTWKb0tu7Iefdg6EPIw X-Received: by 2002:a05:6a20:938b:b0:15a:2c0b:6c73 with SMTP id x11-20020a056a20938b00b0015a2c0b6c73mr22142834pzh.12.1696929724114; Tue, 10 Oct 2023 02:22:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696929724; cv=none; d=google.com; s=arc-20160816; b=kTMlCZdd5Ha5IiEV3/94XMoHpFuedxt5gV6zL5kiDZ0ut9BhU1XCP5vueA36o863Be 1PJFLO8+2dGCBdnbz2zRL94xL2Y5DGBDR1/sjxQ61PRyAtb0P16I2Khyh/ktZqQQVccx SPcxQziWHmOB4V53W+4MW7CCXMesA/uL+dnzaX6d3vuKCyP+bhXezhJfIyDG5EEJHU7I WbntdovCUOAmRCyOkX3TlQB9NHWjpO6EXexFq/+uYtUFQha6Lxof4xTz9Xvwte9HZ0zv 2u7TWgjCnXvEBDtdUIHcRqIvQ5i4QXCMGsqjAMwB2LeGwJpEm20WY+DT5T5Lq8xI86/d XtjQ== 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=758jz2xflU6VO4PAOY+K8i5j/U21VY0J+x7zoUMpxKc=; fh=Bw74vauKC02eaEbQr8FoniTYtc//6dp3BvPBLCS/H3M=; b=yMtqKSIivW6LZZrMtBKZMXa+lZ4YoN21XFApNlOkQMwKZSJJycK4wSIisVuTks8YjD 9kFedx0GSkX/BKJbjghPe19jbJlD5tH1Gy89G7DnuPrrz+R1yXtKv5GCEe/PJtKPQYpz EmOEVwKf/c73Z6Hf5Tu5++ljD6zeRjJVBGXWO1lG6AKtGU95cI9xQ+ni2jyJQnSsZIWh z5+okaEO9rsgDgeBI2C1PLheWD5JJMaz8j7kdGxwBHRBKaVp7tzv9B2ALdl6VmX9pM9l 1Oj6/uhUehaD68ekx+/ek2vd4ExnAL25uvv+5G1gTsP+KAhmj+l7sOQMfFvPSD1p4L7T 1P4w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id e13-20020a056a001a8d00b006934a431c55si9240721pfv.163.2023.10.10.02.22.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 02:22:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 87F48814596C; Tue, 10 Oct 2023 02:22:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230085AbjJJJVv (ORCPT + 20 others); Tue, 10 Oct 2023 05:21:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230075AbjJJJV0 (ORCPT ); Tue, 10 Oct 2023 05:21:26 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A50DA7; Tue, 10 Oct 2023 02:21:23 -0700 (PDT) Received: from kwepemm000012.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4S4VfY434qzNp5d; Tue, 10 Oct 2023 17:17:25 +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; Tue, 10 Oct 2023 17:21:20 +0800 From: Wenchao Hao To: "Martin K . Petersen" , Douglas Gilbert CC: "James E . J . Bottomley" , , , , Wenchao Hao Subject: [PATCH v6 05/10] scsi: scsi_debug: Return failed value if the error is injected Date: Tue, 10 Oct 2023 17:20:46 +0800 Message-ID: <20231010092051.608007-6-haowenchao2@huawei.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20231010092051.608007-1-haowenchao2@huawei.com> References: <20231010092051.608007-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=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 10 Oct 2023 02:22:01 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779359782240322768 X-GMAIL-MSGID: 1779359782240322768 If a fail queuecommand error is injected, return the failed value defined in the rule from queuecommand. Make queuecommand return format: +--------+------+-------------------------------------------------------+ | Column | Type | Description | +--------+------+-------------------------------------------------------+ | 1 | u8 | Error type, fixed to 0x1 | +--------+------+-------------------------------------------------------+ | 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 | +--------+------+-------------------------------------------------------+ | 4 | x32 | The queuecommand() return value we want | +--------+------+-------------------------------------------------------+ Examples: error=/sys/kernel/debug/scsi_debug/0:0:0:1/error echo "1 1 0x12 0x1055" > ${error} will make each INQUIRY command sent to that device return 0x1055 (SCSI_MLQUEUE_HOST_BUSY). Acked-by: Douglas Gilbert Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_debug.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 9081c9d22882..efdd63dd6d25 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -7769,6 +7769,34 @@ static int sdebug_timeout_cmd(struct scsi_cmnd *cmnd) return 0; } +static int sdebug_fail_queue_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_FAIL_QUEUE_CMD && + (err->cmd == cmd[0] || err->cmd == 0xff)) { + ret = err->cnt ? err->queuecmd_ret : 0; + 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) { @@ -7788,6 +7816,7 @@ static int scsi_debug_queuecommand(struct Scsi_Host *shost, u8 opcode = cmd[0]; bool has_wlun_rl; bool inject_now; + int ret = 0; scsi_set_resid(scp, 0); if (sdebug_statistics) { @@ -7833,6 +7862,13 @@ static int scsi_debug_queuecommand(struct Scsi_Host *shost, return 0; } + ret = sdebug_fail_queue_cmd(scp); + if (ret) { + scmd_printk(KERN_INFO, scp, "fail queue command 0x%x with 0x%x\n", + opcode, ret); + return ret; + } + if (unlikely(inject_now && !atomic_read(&sdeb_inject_pending))) atomic_set(&sdeb_inject_pending, 1);