Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2575854rdb; Fri, 22 Sep 2023 02:44:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG+68XK3a/VZrAGf2ZemzF8iqLnhpuLO4lS1rFalOgjCrNvc9tTpWLCREsggBRmPUVYNXHE X-Received: by 2002:a05:6a21:498a:b0:15d:5f9a:3921 with SMTP id ax10-20020a056a21498a00b0015d5f9a3921mr3830356pzc.27.1695375864476; Fri, 22 Sep 2023 02:44:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695375864; cv=none; d=google.com; s=arc-20160816; b=OxXYmLGP90x6Q/tHKHSwCb04NVQFVHHX6ByCj6BIfZQ9DCmatUz1n6u4urI8F41IpD P8YTWQzMLDfz7V2xl08R0Wfi5LzDNLAU5b3RW3k5ui55duaKJQkNMS+2PknAJf8Gf9K5 qKejDdx2jCOW73bYUOoy9q9JBry6r8JAxMj7NK0na/x8TIItEP3wpiZlJC3bS1LNa/PQ gNKHjbrQ0o2uI+kaBmMXgrGKpLhIvk25U1X1EqsLsBJR5mwlcTlQ67h9jeORwpo+CzDB sfzDU8+NlA6iwXLT+bSIyllzo58RY2rxVjbpycNBLBWVAemA/mvmbhXIhbBNN8npEzM6 ap/w== 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=qWv5LonYmPiD7WUth0ZsecslzGM0F1X9yLhVUO+Zb3Q=; fh=efbNbptNhbD3foczTZf5UTdQGTI/0Ud9virqYphOI9o=; b=hCiE36ADNiRgpmWQSNQMSb8LwJNqnRgmdIez28dT3SV2Bs7USX8wGW4lMqEp1nWNE6 uCPXc6YyB/Y/I6uYnEsQbl8AoCezjSfMtT6HTf0QgHBsbFH52JW/DFRfehLQHckYkKkn wWaMkQq8c5UPBQlTBlH+tvyNK4QhXEePimgwKgAqhN9u4d5jKgg69o1hoRzbrBdRQINj CZ5Aba7egtIA6KBL3e7Jx5J4nIPoRq/4pqaqIw9i8kpXPggzNmv/wF5s+ZtTV6HR9oyQ KHn7gkGLCSIgVFSN/EytSjwY+6SaCI7acaNMnUg9fq6KL9v7RgeQUfs3WZEN10nvsgUR rkUQ== 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 Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id q27-20020a63751b000000b0057458518e20si3478435pgc.164.2023.09.22.02.44.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 02:44:24 -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 B506C81E5CDB; Fri, 22 Sep 2023 02:30:18 -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 S233263AbjIVJaP (ORCPT + 99 others); Fri, 22 Sep 2023 05:30:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232946AbjIVJ3u (ORCPT ); Fri, 22 Sep 2023 05:29:50 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0FB4CE8; Fri, 22 Sep 2023 02:29:37 -0700 (PDT) Received: from kwepemm000012.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RsRgz1mgCztSCF; Fri, 22 Sep 2023 17:25:19 +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 05/10] scsi: scsi_debug: Return failed value if the error is injected Date: Fri, 22 Sep 2023 17:29:01 +0800 Message-ID: <20230922092906.2645265-6-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=-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:18 -0700 (PDT) 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 785ad5e5b4a4..dea40d983155 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -7759,6 +7759,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) { @@ -7778,6 +7806,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) { @@ -7823,6 +7852,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); -- 2.32.0