Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1053rdg; Tue, 10 Oct 2023 02:22:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGnTFWCoYnao4cOuCk8NprLPzXuR5CpkiuMkSDfgiNyCW0F9XraXB3wQaTfUKvNWM9R/emY X-Received: by 2002:a17:902:e811:b0:1b8:8af0:416f with SMTP id u17-20020a170902e81100b001b88af0416fmr22930338plg.1.1696929721633; Tue, 10 Oct 2023 02:22:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696929721; cv=none; d=google.com; s=arc-20160816; b=vYEko2W5bXZyBWtmFbSQ92l7faRbwmgkXk/3IIMAM2kb5+U3X+6SKjhMsssEB8qST+ QZf7lbm+yGNgF2f1oOqTRgdDqQX4o8dKKAI0oj69L7a5E3guAJgbFzvRf0h7UhQFsA2g zsnS4IZKQKqy1wK9dpnpjoHxyw6As/GlH3e/l1GCFQ/ElfirhTRiifPSIZbTl78z9Ssj DxqEs7ac/KWD35/zQIlXrLZQk0hGXAiqPjUMPjwFb5EV9tY05QRrrKgWZXStJyP3DX8Y yga5/+pznbJSVCoCZnHXrhi+mJe0p1Yc4sjxVb2ILDfG7EqMJkRP8zf/MutLrO5j1DGI RvHg== 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.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id jx2-20020a170903138200b001b025aba9f2si10735602plb.22.2023.10.10.02.22.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 02:22:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 5A476813A5B9; Tue, 10 Oct 2023 02:22:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230310AbjJJJVu (ORCPT + 99 others); Tue, 10 Oct 2023 05:21:50 -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 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=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 10 Oct 2023 02:22:00 -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 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); -- 2.32.0