From patchwork Fri Sep 22 09:29:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 143307 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5442011vqi; Fri, 22 Sep 2023 02:53:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF8r3xpEhfyO+6zLvwq3SWOJ1Db7zoT4L2BiDBDM9+ffmpib7r7c6fuGMLRovrigKdijQwk X-Received: by 2002:a05:6a00:14c2:b0:690:3793:17e5 with SMTP id w2-20020a056a0014c200b00690379317e5mr8600634pfu.4.1695376400332; Fri, 22 Sep 2023 02:53:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695376400; cv=none; d=google.com; s=arc-20160816; b=P+CxreKVZe4yp0YWMKI5NyPPOj5flY3i0lr55MOAlG6+OGRtk96xyji+Uy4ZyMeC2b d/Ey0h8LKkXlQFWVb35nTAADqRp6HeI3lStGPTBKevqqNoT+3aJiGLh8aPISdNirhrhB WE03i5N4nd2TIRgF5Q/Fg6Z6J88sq5aNVeMUfjS6jeTNA41rhOY4oUxeI1hteYTLbsqX beWfF7bALq/bGTYXmjapqtRGL4bFGjh9Trgr3czex8LCTGVFGYRCDwb5OXi0z8LR7fwQ K2mYPg/PlfmbC8iqU2dwQsWHChy77IqKVG5UoP+d1U7d7UnQUYDdrG57aiytorl7w+qW f4yA== 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.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 r20-20020a6560d4000000b00565eee2d0fesi3095115pgv.324.2023.09.22.02.53.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 02:53:20 -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 DAD5D807C5E0; Fri, 22 Sep 2023 02:30:30 -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 S233265AbjIVJaQ (ORCPT + 30 others); Fri, 22 Sep 2023 05:30:16 -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 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 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]); Fri, 22 Sep 2023 02:30:30 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777731003987879777 X-GMAIL-MSGID: 1777731003987879777 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);