From patchwork Wed Nov 9 15:59:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 17319 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp101121wru; Tue, 8 Nov 2022 18:47:00 -0800 (PST) X-Google-Smtp-Source: AMsMyM5EHzyy4G7cQ9EDR5RKmbilq6hR+WVVrS7Fg0rkeS+IaTezRM7fxSapk1BIIxEgjoMGaRQr X-Received: by 2002:a05:6402:718:b0:463:275:4753 with SMTP id w24-20020a056402071800b0046302754753mr55070627edx.160.1667962020508; Tue, 08 Nov 2022 18:47:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667962020; cv=none; d=google.com; s=arc-20160816; b=ro3H0imRO4AwMg1hMlP3RO/hb7j76wGP+YBY2KJ76jUf3W2LmSUXFuJ0DwXp75nm/4 fTe/msRDwVpuKIYhI4JI7BK7CIDshd5XzHzwzUp5qcH91wuMW/jmCRT55/b3sT5J8brv 0riMnfiF4zHJEtUw9OprNp7laVd27QJwMv/dfJ+pzfwH5vFHUTxKCYMMRKrniKdFblZn J7WiqlQXmCC5FcCoaMQp8WLH6faOFkPpr0U1vAOYXO4zZhy/X7QrShKa/DF7lTj959hy ttyB0425HA94vYy37YWQxv5FDuR7g/WynjeXz+bHkQ6zt+t5JRWdJQg6o3SrX32xJPJL lTzA== 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=GGASoIHQZD7JgYEzLTYYtjiECg9ul1T8sz6/vjLNXnk=; b=OxXutU3eLAOc5ZPvANNZpLP5/NeyXhc2fGjThbKg6ig4T5oy42UpHMHLn/Tw0FXfvr 72C8uX9KXSSHXVdp85Ix0V7CTy7KqmX0Z8pKSJA5T46F3T7ezchm9PJGoi9DcWClg4kA sYsyCi98sZ546gXhz65D9kd1EEUfL98ZPn+3ZimwkxS2cMSxvZ03H1aSNkMBz52WeY5d 8bK/PplooqmDgreTNG1Js+pxMHXb+cXlitf11po0vpioPu00EHSYt2sYuewmxLqCp1v9 ZLEbptO5DpEQMqfvF9CtwZjPKjwmkv15FBN4CD8J5eNAhDh5KYuJtLocJ+5ogr3oWqOv /hqQ== 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 sb3-20020a1709076d8300b0077945c44b7fsi15945328ejc.856.2022.11.08.18.46.36; Tue, 08 Nov 2022 18:47:00 -0800 (PST) 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 S230029AbiKICoA (ORCPT + 99 others); Tue, 8 Nov 2022 21:44:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229602AbiKICnv (ORCPT ); Tue, 8 Nov 2022 21:43:51 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E1F81005F; Tue, 8 Nov 2022 18:43:50 -0800 (PST) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4N6Tmm3MyBz15MTw; Wed, 9 Nov 2022 10:43:36 +0800 (CST) Received: from dggpemm500017.china.huawei.com (7.185.36.178) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 9 Nov 2022 10:43:48 +0800 Received: from build.huawei.com (10.175.101.6) by dggpemm500017.china.huawei.com (7.185.36.178) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 9 Nov 2022 10:43:47 +0800 From: Wenchao Hao To: "James E . J . Bottomley" , "Martin K . Petersen" , Doug Gilbert CC: , , Wenchao Hao Subject: [RFC PATCH 2/5] scsi:scsi_debug: Add interface to remove injection which has been added Date: Wed, 9 Nov 2022 10:59:47 -0500 Message-ID: <20221109155950.3536976-3-haowenchao@huawei.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20221109155950.3536976-1-haowenchao@huawei.com> References: <20221109155950.3536976-1-haowenchao@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 dggpemm500017.china.huawei.com (7.185.36.178) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_12_24, RCVD_IN_DNSWL_MED,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748984943595325082?= X-GMAIL-MSGID: =?utf-8?q?1748984943595325082?= The removal interface is still "/sys/block/sdX/device/error_inect/error". The format is still line-by-line integer separated by spaces with fixed 3 column. first column is "-", which tells this is a removal operation; second column is error code; third column is the scsi command. For example the following command would remove timeout injection of inquiry command. echo "- 0 0x12" > /sys/block/sdb/device/error_inect/error Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_debug.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 0cdc9599b628..06e3150812fa 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -7653,6 +7653,30 @@ static void sdebug_err_add(struct device *dev, struct sdebug_err_inject *new) list_add_tail(&new->list, &devip->inject_err_list); } +static int sdebug_err_remove(struct device *dev, const char *buf, size_t count) +{ + struct scsi_device *sdev = to_scsi_device(dev); + struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdev->hostdata; + struct sdebug_err_inject *tmp, *err; + int type; + unsigned char cmd; + + if (sscanf(buf, "- %d %hhx", &type, &cmd) != 2) + return -EINVAL; + + list_for_each_entry_safe(err, tmp, &devip->inject_err_list, list) { + if (err->type == type && err->cmd == cmd) { + sdev_printk(KERN_INFO, sdev, "Remove %d 0x%x\n", + err->type, err->cmd); + list_del(&err->list); + kfree(err); + return count; + } + } + + return -EINVAL; +} + static ssize_t error_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -7698,6 +7722,9 @@ static ssize_t error_store(struct device *dev, struct device_attribute *attr, unsigned int inject_type; struct sdebug_err_inject *inject; + if (buf[0] == '-') + return sdebug_err_remove(dev, buf, count); + if (sscanf(buf, "%d", &inject_type) != 1) return -EINVAL;