From patchwork Tue Aug 15 12:23:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 135657 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:3f2:4152:657d with SMTP id x8csp411012vqo; Tue, 15 Aug 2023 06:03:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHGbfZj8dPNWA0E2HCtif3bPp/mDiN5flR6fhDL/JLE//ClSz3CGGfL/5NvkkaJsBNOaMjT X-Received: by 2002:a17:90b:93:b0:26b:24ed:e0d9 with SMTP id bb19-20020a17090b009300b0026b24ede0d9mr11095808pjb.33.1692104587684; Tue, 15 Aug 2023 06:03:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692104587; cv=none; d=google.com; s=arc-20160816; b=pWNCWJMyHBEcvHvB33Q08bgcMYF4WxDdsj63V1N49DBM4PH01B+/d0O5TkstQRUcQo mKUzWnM3WOjR5GyxuNyzqHsTyX68UZJf74CExL0yENzLRnqLIOotSlD8+1ADCiWRF9L1 bqAaoth56wKRrA1hXLGBWYBLz1Apt3SPgpG+94iifXjxSQlCz0hLt3S524L3YAbRoiLK A71cxqLc11LGsD2SL0U0d4wBh0GNg0PV4dMGRXI/NysSVR0vNs4/NpcFwj6MdCwxfmhF +S3lELdBPGqprvKCwHUbORsgaKSyk4yfoON0E79/V3hKrSF8Wq/DQbh8yzRfvSnnPXqw ev2Q== 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=ID5AlypyiOf5+ZIZy3/7ZS0wWwKDdT1ss9Q7FfCvT2U=; fh=Ph6VnkDLF8u6GTEMEY9pZiFl2+IRsXBGXVaH+P3ZcSI=; b=FUD4hQsbVdp/QGInFfsNWUTX86snaSC/ZGoBqENbw/Y8MeqyIw2HYrtOaH1OOG2jvy x1v0xHQg1SYJI87QUPxrR8HL3DTHr7Rdtq2OzMzYLdGCqFr+h34d11VRjr+N82aWtpQN IyepUNVAfAE+q0vC3ntLWlUlFfQGrjhxXLLdBswdHM11dvm50EIrNwvE2aqr3pAHvFmj dx8WbhrCqFZ0x/lHhsgBNosq66XiAjrWLFUfqYPzgsm355gKqQ7TAG8cATFMlc3t4nFL x4wOZ+hKeINtOK4O6gisrYj3lmM9fPrXbQKnMsIdoxcNPflKxMbyzxQMxXU3q+AkwfSF xd6w== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d12-20020a17090a2a4c00b00262ca5c4c12si9794646pjg.178.2023.08.15.06.02.12; Tue, 15 Aug 2023 06:03:07 -0700 (PDT) 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 S237116AbjHOMX6 (ORCPT + 99 others); Tue, 15 Aug 2023 08:23:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235500AbjHOMXT (ORCPT ); Tue, 15 Aug 2023 08:23:19 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB10BE6B; Tue, 15 Aug 2023 05:23:17 -0700 (PDT) Received: from kwepemm600012.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4RQ9PJ5VK5z1GDZs; Tue, 15 Aug 2023 20:21:56 +0800 (CST) Received: from build.huawei.com (10.175.101.6) by kwepemm600012.china.huawei.com (7.193.23.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Tue, 15 Aug 2023 20:23:15 +0800 From: Wenchao Hao To: "James E . J . Bottomley" , "Martin K . Petersen" , Douglas Gilbert , , CC: , Wenchao Hao Subject: [PATCH v4 7/9] scsi:scsi_debug: Add new error injection abort failed Date: Tue, 15 Aug 2023 20:23:14 +0800 Message-ID: <20230815122316.4129333-8-haowenchao2@huawei.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230815122316.4129333-1-haowenchao2@huawei.com> References: <20230815122316.4129333-1-haowenchao2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600012.china.huawei.com (7.193.23.74) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774300259786947375 X-GMAIL-MSGID: 1774300259786947375 Add error injection type 3 to make scsi_debug_abort() return FAILED. Fail abort command foramt: +--------+------+-------------------------------------------------------+ | Column | Type | Description | +--------+------+-------------------------------------------------------+ | 1 | u8 | Error type, fixed to 0x3 | +--------+------+-------------------------------------------------------+ | 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 | +--------+------+-------------------------------------------------------+ Examples: error=/sys/kernel/debug/scsi_debug/0:0:0:1/error echo "0 -10 0x12" > ${error} will make the device return FAILED when abort inquiry command 10 times. 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 94c43b800694..9e4ea3b38cd0 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -293,6 +293,8 @@ enum sdebug_err_type { ERR_FAIL_CMD = 2, /* make specific scsi command's */ /* queuecmd return succeed but */ /* with errors set in scsi_cmnd */ + ERR_ABORT_CMD_FAILED = 3, /* control return FAILED from */ + /* scsi_debug_abort() */ }; struct sdebug_err_inject { @@ -958,6 +960,7 @@ static int sdebug_error_show(struct seq_file *m, void *p) list_for_each_entry(err, &devip->inject_err_list, list) { switch (err->type) { case ERR_TMOUT_CMD: + case ERR_ABORT_CMD_FAILED: seq_printf(m, "%d\t%d\t0x%x\n", err->type, err->cnt, err->cmd); break; @@ -1018,6 +1021,7 @@ static ssize_t sdebug_error_write(struct file *file, const char __user *ubuf, switch (inject_type) { case ERR_TMOUT_CMD: + case ERR_ABORT_CMD_FAILED: if (sscanf(buf, "%d %d %hhx", &inject->type, &inject->cnt, &inject->cmd) != 3) goto out_error; @@ -5488,9 +5492,35 @@ static void stop_all_queued(void) mutex_unlock(&sdebug_host_list_mutex); } +static int sdebug_fail_abort(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_ABORT_CMD_FAILED && + (err->cmd == cmd[0] || err->cmd == 0xff)) { + ret = !!err->cnt; + if (err->cnt < 0) + err->cnt++; + return ret; + } + } + + return 0; +} + static int scsi_debug_abort(struct scsi_cmnd *SCpnt) { bool ok = scsi_debug_abort_cmnd(SCpnt); + u8 *cmd = SCpnt->cmnd; + u8 opcode = cmd[0]; ++num_aborts; @@ -5499,6 +5529,12 @@ static int scsi_debug_abort(struct scsi_cmnd *SCpnt) "%s: command%s found\n", __func__, ok ? "" : " not"); + if (sdebug_fail_abort(SCpnt)) { + scmd_printk(KERN_INFO, SCpnt, "fail abort command 0x%x\n", + opcode); + return FAILED; + } + return SUCCESS; }