From patchwork Wed Nov 9 15:59:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 17318 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp101105wru; Tue, 8 Nov 2022 18:46:58 -0800 (PST) X-Google-Smtp-Source: AMsMyM5Zkas9HzGhqa+Au7jWgRfj0jxmtGCzTmceUb3I4buQkVPlIbF2/22huCNHCY+IVY4FCbKn X-Received: by 2002:a17:906:c151:b0:78d:cdbc:9fb7 with SMTP id dp17-20020a170906c15100b0078dcdbc9fb7mr53906322ejc.688.1667962018189; Tue, 08 Nov 2022 18:46:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667962018; cv=none; d=google.com; s=arc-20160816; b=rRnt5U9UCBVJ7F5Su41M9BOQlaSJhc4NaOxIS1ksP1spI6LWdu1YoML8RDqDIUocQr 3WawapwQKSW+CeUbCd15ju3nh0NsM2rYV4SD8XPAqSFD+KyPMx/pWVWZjr/jtIe51a4S XnmBJxHAibwHehz65F/QPFi/KHCsGJvnAPxjzLVhqbs+QEnD5TySRvEhl1kdT8V3IQe0 /LA2a2t9LfK/X7px6VOCN6DqH/8irg6LGczflOn02OgMY3Y8jcAFCNQtLzJCWBikMNGL lcF1+8Q/6osp+chY/DxkT8CUen9NjuYSgp6Td70dlQAxO71I+z2pKrskmXmnRC29vI0c tt3A== 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=51h05/9V4i48gZFkQoXTg8jfJAti0Qi8lv3tWJh+odo=; b=bROCCjZXXllfbHvoevNMPSweKndOHMCmZpfn+sIto6KEfKtxOpunc/EmFn9qkY+9dk 55RjR+XpBatXwyESF0VED7z6PMFlf7W5/thVnX6lGFpx9MEOpnAP5ysL4EfgFziT7Mo1 Y/LylX7DCv/TwXwTuV4RceKr1+KVUwPXkvCiIguvaK/c9AcyojD2PpvusYapfiKBw0De Pi2KJSafkr6fUloh21bRs9McshENCeOssYqmCFa2SjBYp/v3xho7FS/lm+SDMJboWVdA O6wO1xTC+uWe3xH0f9i5jMm0XcIrwBoDd2qE0mKKAc905XllscAcNcqFM5lHzvBKU/D9 V3tw== 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 x23-20020aa7d6d7000000b004594b742e0asi12720859edr.323.2022.11.08.18.46.32; Tue, 08 Nov 2022 18:46:58 -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 S230017AbiKICn5 (ORCPT + 99 others); Tue, 8 Nov 2022 21:43:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229735AbiKICnv (ORCPT ); Tue, 8 Nov 2022 21:43:51 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8810FD15; Tue, 8 Nov 2022 18:43:49 -0800 (PST) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N6Tmq19Y9zRp7Q; Wed, 9 Nov 2022 10:43:39 +0800 (CST) Received: from dggpemm500017.china.huawei.com (7.185.36.178) by dggpemm500021.china.huawei.com (7.185.36.109) 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 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 1/5] scsi:scsi_debug: Add sysfs interface to manager single devices' error inject Date: Wed, 9 Nov 2022 10:59:46 -0500 Message-ID: <20221109155950.3536976-2-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?1748984940840162356?= X-GMAIL-MSGID: =?utf-8?q?1748984940840162356?= Add interface "/sys/block/sdX/device/error_inject/error" which is readable and writable. Write this file to add new error injection, read it to get the error injection info which has been added. You can add error inject to specific scsi device's specific scsi command. And you can inject different error for one scsi command. When multiple error injects are added to one scsi command, the one with smaller error code would take effect. The format is line-by-line integer separated by spaces. The first two integer has a fixed meaning which are "error code" and "error count". Each error code is an unsigned integer which is 1 bytes length. It stands for which type of error to inject. Now I defined 3 error types: - 0: timeout specific SCSI command - 1: make queuecommand return specific value - 2: set scsi_cmd's status or sense data to specific value Error cnt stands for how many times this inject rules would take effect. a positive value means this rule would always take effect; a negative value means this rule would take effect for the absolute value of this error count; 0 means this rule would not take effect Timeout specific SCSI command format +--------+------+-------------------------------------------------------+ | Column | Type | Description | +--------+------+-------------------------------------------------------+ | 1 | s32 | Error type, fixed to 0x0 | +--------+------+-------------------------------------------------------+ | 2 | s32 | Error Count | | | | 0: this rule would not take effect | | | | positive: this rule would always take effect | | | | negative: take effect for the absolute of this value | +--------+------+-------------------------------------------------------+ | 3 | u8 | SCSI command this rule is for, 0xff for all command | +--------+------+-------------------------------------------------------+ the following command make sdb's inquiry timeout for 10 time: echo "0 -10 0x12" > /sys/block/sdb/device/error_inject/error the following command make sdb's inquiry timeout forever: echo "0 1 0x12" > /sys/block/sdb/device/error_inject/error Make queuecommand return specific value +--------+------+-------------------------------------------------------+ | Column | Type | Description | +--------+------+-------------------------------------------------------+ | 1 | s32 | Error type, fixed to 0x1 | +--------+------+-------------------------------------------------------+ | 2 | s32 | Error Count | | | | 0: this rule would not take effect | | | | positive: this rule would always take effect | | | | negative: take effect for the absolute of this value | +--------+------+-------------------------------------------------------+ | 3 | u8 | SCSI command this rule is for, 0xff for all command | +--------+------+-------------------------------------------------------+ | 4 | s32 | The return value of queuecommand we desired | +--------+------+-------------------------------------------------------+ for example the following command make sdb's inquiry command return 0x1055(SCSI_MLQUEUE_HOST_BUSY) forever: echo "1 1 0x12 0x1055" >/sys/block/sdb/device/error_inject/error Set scsi_cmd's status and sense data to specific value +--------+------+-------------------------------------------------------+ | Column | Type | Description | +--------+------+-------------------------------------------------------+ | 1 | s32 | Error type, fixed to 0x2 | +--------+------+-------------------------------------------------------+ | 2 | s32 | Error Count | | | | 0: this rule would not take effect | | | | positive: this rule would always take effect | | | | negative: take effect for the absolute of this value | +--------+------+-------------------------------------------------------+ | 3 | u8 | SCSI command this rule is for, 0xff for all command | +--------+------+-------------------------------------------------------+ | 4 | u8 | Host byte in scsi_cmd's status | +--------+------+-------------------------------------------------------+ | 5 | u8 | Driver byte in scsi_cmd's status | +--------+------+-------------------------------------------------------+ | 6 | u8 | Status byte in scsi_cmd's status | +--------+------+-------------------------------------------------------+ | 7 | u8 | Sense Key of scsi_cmnd | +--------+------+-------------------------------------------------------+ | 8 | u8 | ASC of scsi_cmnd | +--------+------+-------------------------------------------------------+ | 9 | u8 | ASQ of scsi_cmnd | +--------+------+-------------------------------------------------------+ for example the following means make sdb's read command return with media error UNC: error=/sys/block/sdb/device/error_inject/error echo "2 -10 0x88 0 0 0x2 0x3 0x11 0x0" >$error Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_debug.c | 161 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 697fc57bc711..0cdc9599b628 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -280,6 +280,41 @@ struct sdeb_zone_state { /* ZBC: per zone state */ sector_t z_wp; }; +enum sdebug_err_type { + ERR_TMOUT_CMD = 0, /* make specific scsi command timeout */ + ERR_FAIL_QUEUE_CMD = 1, /* make specific scsi command's */ + /* queuecmd return failed */ + ERR_FAIL_CMD = 2, /* make specific scsi command's */ + /* queuecmd return succeed but */ + /* with errors set in scsi_cmnd */ +}; + +struct sdebug_err_inject { + int type; + struct list_head list; + int cnt; + unsigned char cmd; + + union { + /* + * For ERR_FAIL_QUEUE_CMD + */ + int queuecmd_ret; + + /* + * For ERR_FAIL_CMD + */ + struct { + unsigned char host_byte; + unsigned char driver_byte; + unsigned char status_byte; + unsigned char sense_key; + unsigned char asc; + unsigned char asq; + }; + }; +}; + struct sdebug_dev_info { struct list_head dev_list; unsigned int channel; @@ -306,6 +341,8 @@ struct sdebug_dev_info { unsigned int max_open; ktime_t create_ts; /* time since bootup that this device was created */ struct sdeb_zone_state *zstate; + + struct list_head inject_err_list; }; struct sdebug_host_info { @@ -5150,6 +5187,7 @@ static struct sdebug_dev_info *sdebug_device_create( devip->sdbg_host = sdbg_host; devip->create_ts = ktime_get_boottime(); atomic_set(&devip->stopped, (sdeb_tur_ms_to_ready > 0 ? 2 : 0)); + INIT_LIST_HEAD(&devip->inject_err_list); list_add_tail(&devip->dev_list, &sdbg_host->dev_info_list); } return devip; @@ -7597,6 +7635,128 @@ static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num) return num_entries; } +static void sdebug_err_add(struct device *dev, struct sdebug_err_inject *new) +{ + 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; + + list_for_each_entry_safe(err, tmp, &devip->inject_err_list, list) { + if (err->type == new->type && err->cmd == new->cmd) { + sdev_printk(KERN_INFO, sdev, "Substituted %d 0x%x\n", + err->type, err->cmd); + list_del(&err->list); + kfree(err); + } + } + + list_add_tail(&new->list, &devip->inject_err_list); +} + +static ssize_t error_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + int tmp, ret = 0; + struct scsi_device *sdev = to_scsi_device(dev); + struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdev->hostdata; + struct sdebug_err_inject *err; + + tmp = sysfs_emit_at(buf, ret, "Type\tCount\tCommand\n"); + ret += tmp; + + list_for_each_entry(err, &devip->inject_err_list, list) { + switch (err->type) { + case ERR_TMOUT_CMD: + tmp = sysfs_emit_at(buf, ret, "%d\t%d\t0x%x\n", + err->type, err->cnt, err->cmd); + ret += tmp; + break; + + case ERR_FAIL_QUEUE_CMD: + tmp = sysfs_emit_at(buf, ret, "%d\t%d\t0x%x\t0x%x\n", + err->type, err->cnt, err->cmd, err->queuecmd_ret); + ret += tmp; + break; + + case ERR_FAIL_CMD: + tmp = sysfs_emit_at(buf, ret, + "%d\t%d\t0x%x\t0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n", + err->type, err->cnt, err->cmd, + err->host_byte, err->driver_byte, + err->status_byte, err->sense_key, + err->asc, err->asq); + ret += tmp; + break; + } + } + + return ret; +} +static ssize_t error_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned int inject_type; + struct sdebug_err_inject *inject; + + if (sscanf(buf, "%d", &inject_type) != 1) + return -EINVAL; + + inject = kzalloc(sizeof(struct sdebug_err_inject), GFP_KERNEL); + if (!inject) + return -ENOMEM; + + switch (inject_type) { + case ERR_TMOUT_CMD: + if (sscanf(buf, "%d %d %hhx", &inject->type, &inject->cnt, + &inject->cmd) != 3) + goto out_error; + break; + + case ERR_FAIL_QUEUE_CMD: + if (sscanf(buf, "%d %d %hhx %x", &inject->type, &inject->cnt, + &inject->cmd, &inject->queuecmd_ret) != 4) + goto out_error; + break; + + case ERR_FAIL_CMD: + if (sscanf(buf, "%d %d %hhx %hhx %hhx %hhx %hhx %hhx %hhx", + &inject->type, &inject->cnt, &inject->cmd, + &inject->host_byte, &inject->driver_byte, + &inject->status_byte, &inject->sense_key, + &inject->asc, &inject->asq) != 9) + goto out_error; + break; + + default: + goto out_error; + break; + } + + sdebug_err_add(dev, inject); + + return count; + +out_error: + kfree(inject); + return -EINVAL; +} +static DEVICE_ATTR_RW(error); + +static struct attribute *sdebug_sdev_attrs[] = { + &dev_attr_error.attr, + NULL +}; + +static const struct attribute_group sdebug_sdev_attr_group = { + .name = "error_inject", + .attrs = sdebug_sdev_attrs, +}; + +const struct attribute_group *sdebug_sdev_groups[] = { + &sdebug_sdev_attr_group, + NULL +}; + static int scsi_debug_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scp) { @@ -7776,6 +7936,7 @@ static struct scsi_host_template sdebug_driver_template = { .ioctl = scsi_debug_ioctl, .queuecommand = scsi_debug_queuecommand, .change_queue_depth = sdebug_change_qdepth, + .sdev_groups = sdebug_sdev_groups, .map_queues = sdebug_map_queues, .mq_poll = sdebug_blk_mq_poll, .eh_abort_handler = scsi_debug_abort, 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; From patchwork Wed Nov 9 15:59:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 17316 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp100790wru; Tue, 8 Nov 2022 18:45:55 -0800 (PST) X-Google-Smtp-Source: AMsMyM7svI3QfhlzKT8bLfbZi9KLo/f0jOZaSKZnip17sQH4FBth+/Ullb9aFfol2cG6bJV/qF3x X-Received: by 2002:a17:907:c1e:b0:7ae:31a0:571e with SMTP id ga30-20020a1709070c1e00b007ae31a0571emr23411025ejc.690.1667961955480; Tue, 08 Nov 2022 18:45:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667961955; cv=none; d=google.com; s=arc-20160816; b=flq+tevXAH76l0ep+APMkMj02HG/LO4ONAifx1tpv5j4bF8XovTqr2sDjCr0ZbvG7R hutKiRrSnL7nFK2l7L8X+jtPhnDhoHuuObNXMdG9odi1YnMvqMbi++O36bZKRKUmTCZT 2827gZz6V+kl0sG3V7lxPA2KHp+jMlE6q1ccUCMR+39PHuaUXb7kzHMfheeGUlDsah5x uUPBddOc+oWAyO+4xDq95lNXubxz4eaH6sx1I48QZ1eU6QhaCUkDN42UVyVRwKl6Ee0G mDHmgYO8Yjo3RCqjeGafjao9zP5Ew1Re6FbZIZZr3A8DdiMjX8tuk/RIMZ3bvceyFq+r 5+nA== 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=G+6girYijK3ZCCdFrWXl3TOagbXCrBtr4zvlIQpLxww=; b=O8V8JJ5p945/yydNMzPbfc+4iDk4MAg5je3s1aOrIFNZ0Jv/AfUT0h/yJsWTCVvz4P mlvhjpJBXKD4Z2Kuj56l2G7AlJ/cEGSM1TzD1FEQggJ70ksN8HYPiWr24v14lwgrQlD+ 0hjNz0INVax+W3VLOP5DHHV9X7PMWE36cGs4OX8J9EQdPafYqRGwK7FkjxL1Vc5amK+r Xoot88OMeOjVUkuDVktskTCtwhut1onHd7K13VILMm2VNCM1ACzgswIJtNDrmtAiopaR /G0w2yvgH7Lk+Sa+DqzRX/6BvHMhR6NTyYV6UxaJ3mbrzOym0BdQ1xjAsDAS1QE1bxBD OyHw== 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 a2-20020a50ff02000000b004593895fb89si12391045edu.390.2022.11.08.18.45.31; Tue, 08 Nov 2022 18:45:55 -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 S230035AbiKICoI (ORCPT + 99 others); Tue, 8 Nov 2022 21:44:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229926AbiKICnw (ORCPT ); Tue, 8 Nov 2022 21:43:52 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA09510063; Tue, 8 Nov 2022 18:43:50 -0800 (PST) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4N6TjW6sjZzHqVp; Wed, 9 Nov 2022 10:40:47 +0800 (CST) Received: from dggpemm500017.china.huawei.com (7.185.36.178) by dggpemm500022.china.huawei.com (7.185.36.162) 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:48 +0800 From: Wenchao Hao To: "James E . J . Bottomley" , "Martin K . Petersen" , Doug Gilbert CC: , , Wenchao Hao Subject: [RFC PATCH 3/5] scsi:scsi_debug: make command timeout if timeout error is injected Date: Wed, 9 Nov 2022 10:59:48 -0500 Message-ID: <20221109155950.3536976-4-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?1748984875271213325?= X-GMAIL-MSGID: =?utf-8?q?1748984875271213325?= If a timeout error is injected for specific scsi command, just return 0 in queuecommand to make it timeout. For example, the following command would inject timeout error for inquiry(0x12) command for 10 times: echo "0 -10 0x12" >/sys/block/sdb/device/error_inject/error Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_debug.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 06e3150812fa..761e1e3bcb9a 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -7784,6 +7784,30 @@ const struct attribute_group *sdebug_sdev_groups[] = { NULL }; +static int sdebug_timeout_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; + + list_for_each_entry(err, &devip->inject_err_list, list) { + if (err->type == ERR_TMOUT_CMD && + (err->cmd == cmd[0] || err->cmd == 0xff)) { + ret = !!err->cnt; + if (err->cnt < 0) + err->cnt++; + return ret; + } + } + + return 0; +} + static int scsi_debug_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scp) { @@ -7842,6 +7866,12 @@ static int scsi_debug_queuecommand(struct Scsi_Host *shost, if (NULL == devip) goto err_out; } + + if (sdebug_timeout_cmd(scp)) { + scmd_printk(KERN_INFO, scp, "timeout command 0x%x\n", opcode); + return 0; + } + if (unlikely(inject_now && !atomic_read(&sdeb_inject_pending))) atomic_set(&sdeb_inject_pending, 1); From patchwork Wed Nov 9 15:59:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 17315 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp100721wru; Tue, 8 Nov 2022 18:45:37 -0800 (PST) X-Google-Smtp-Source: AMsMyM75GZCZRySxnLtCEREEENvkra3FTVk+Q4e77mTPCOahCJ+YCUWDoUxMsSULIo1Ira4IHF82 X-Received: by 2002:a17:906:d142:b0:7ad:eb7f:bc9a with SMTP id br2-20020a170906d14200b007adeb7fbc9amr40654349ejb.337.1667961937591; Tue, 08 Nov 2022 18:45:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667961937; cv=none; d=google.com; s=arc-20160816; b=BG7gSraZVjsQCKG9jT1ONWwd71vP75sX3sIlsHMDkR0qyaiWJji/sbHOtEVCV7zear JUw6et445Q+SWdYKmj0dz+w3V+9BsFi6nIKrKxhk2dD4VA3sTQeXBcuR4udIkiKNwTe6 nR97V58jQdmIKBvVXMwPFDpIKPKWe9Ly5UTg927XMezpTvD769/cTvfpa75hZr44eGay vNvR3UxBiKqQJinlvWDgu6L1F74/3G/AmSqpMVs3UAhM+q6az8cmyJWCaZ7Jh3TY/7OD AlFzDzeyRmW2hLG8i9WqQX+w9JBV4TGmmzF9gpgUSF7yKJyg8vDEA+vnkaOKqhNyTRSF iRTw== 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=NWHBcXX8ztmFz6JSUdW4Q+r3ZnU+G+MNylLr1fMeRtU=; b=npRTqniL4M/OIQxL1CDKXIaOe+nuCXouPfvJIFhK/R/tkUjfGnxOeIplFuGWok7BFS piDWrs4h5gh0CziQCaLbUxbkAbfIEG3/JbQ9z8RgBryaBIS+gnvgYgc4irtuZxckqYpi N2W9EnlCv9msRe/ZoEKsjlkvpl8cwkGsCQk3R6fZ0GHfyfXqSC2RR0c0pvqZrU5/44B7 jXGGfXBnor+pij2RVcEbpeaisUvYMshT08jqJFEP8ZUGn2F8JLYm/xgP6GWC4nQrbl/a MqOvdSNqAwG67rRiB6j2gUOQjbpDN+GSXOoI2ABduVLnBMbtHmUp5ZhoNsewb+uJ+DPY ybOg== 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 ga38-20020a1709070c2600b0078cc4a8a956si15459283ejc.881.2022.11.08.18.45.13; Tue, 08 Nov 2022 18:45:37 -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 S230007AbiKICoE (ORCPT + 99 others); Tue, 8 Nov 2022 21:44:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229924AbiKICnw (ORCPT ); Tue, 8 Nov 2022 21:43:52 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC670FD14; Tue, 8 Nov 2022 18:43:50 -0800 (PST) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4N6Tmn2ypkz15MTp; Wed, 9 Nov 2022 10:43:37 +0800 (CST) Received: from dggpemm500017.china.huawei.com (7.185.36.178) by dggpemm500023.china.huawei.com (7.185.36.83) 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:49 +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:48 +0800 From: Wenchao Hao To: "James E . J . Bottomley" , "Martin K . Petersen" , Doug Gilbert CC: , , Wenchao Hao Subject: [RFC PATCH 4/5] scsi:scsi_debug: Return failed value for specific command's queuecommand Date: Wed, 9 Nov 2022 10:59:49 -0500 Message-ID: <20221109155950.3536976-5-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?1748984856643770743?= X-GMAIL-MSGID: =?utf-8?q?1748984856643770743?= If a fail queuecommand error is injected for specific scsi command, just return the failed value rejected in queuecommand. We can make any scsi command's queuecommand return the value we desired, for example make it return SCSI_MLQUEUE_HOST_BUSY. For example the following command would make all inquiry(0x12) command's queuecommand return 0x1055: echo "1 1 0x12 0x1055" >/sys/block/sdb/device/error_inject/error Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_debug.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 761e1e3bcb9a..217a9e892391 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -7808,6 +7808,30 @@ 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; + + list_for_each_entry(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++; + return ret; + } + } + + return 0; +} + static int scsi_debug_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scp) { @@ -7827,6 +7851,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) { @@ -7872,6 +7897,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); From patchwork Wed Nov 9 15:59:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenchao Hao X-Patchwork-Id: 17317 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp100817wru; Tue, 8 Nov 2022 18:46:03 -0800 (PST) X-Google-Smtp-Source: AMsMyM4kKOFxHJ1ocf0HiwKgyLxtSnxFWDysVY35EjJP2r9SpTUoVZrOcbtC1C+p48fkR+pMcwac X-Received: by 2002:a17:907:320b:b0:780:280:7b72 with SMTP id xg11-20020a170907320b00b0078002807b72mr57690753ejb.146.1667961963175; Tue, 08 Nov 2022 18:46:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667961963; cv=none; d=google.com; s=arc-20160816; b=IWmlBiSFswP3uNLaGbj3l2MzDeDgR8dxHUV1Zob1KnADXyCBQ/98j+pvFd4XAjJ89B VXlXS46MdTE1czy+evcUu6xF9PGkddWOpqUATF7kZtMzB2+/nYKrNmeszGQBizw08d3A rK2BYZG5AAm464S+GT0rxLIzjS+l+tvoKbRN4gW5wWL3CiPzZR9GdegvGD8AWoU1rLIy ECUR37MQer+oyoirruTg8dfa6BW2tzNE4myWiGlZD+BbQUdPgfPoqb+mXDbkff9kt+H1 Hx094SJOXiI8fcIagIuDWukGD/tkBHtcKPQ2j7Wh4EooAM1AaGYqM9izACpffzquXvZY KZdQ== 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=Ou0KYs/Nn55Lz1448WqOauMmkvkhnvdv09cVAf56VAk=; b=rsoOFc07o8DDWpTMla8gu0ZheMe1y7faSDQvQaoAD1Q4G0HHcmJR9OYJeSb/Q3wKyY fjVhM539orFG4Yxyg9hGfv9GX+5UtNdUY7wvw0Hnk82pFtcr0jXmfBXAu0LT//G8yMqe w0vmbaWbXBKJsL46UkjNI6o+t4nF8R7gdtAeXTUXC/lLdbOT9igUTGhY/R76hy+nmb8+ E2YjuRZg0M/LmKfCZCkT+oh5B/4MYxW1+c715gYVM6bUAFJ0QRMGrcn2NLAgklQsYOVx 9iMugHnLGH7jVLZ1nkAIDGIWaSUBGNxrzuuKQjtF3+jQxezarFNUoIHI5eBUaaZeY/AA B0RA== 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 sa7-20020a1709076d0700b0078dec48d442si14674006ejc.680.2022.11.08.18.45.36; Tue, 08 Nov 2022 18:46:03 -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 S230047AbiKICoL (ORCPT + 99 others); Tue, 8 Nov 2022 21:44:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229951AbiKICnw (ORCPT ); Tue, 8 Nov 2022 21:43:52 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D53210064; Tue, 8 Nov 2022 18:43:51 -0800 (PST) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4N6Tms09BtzRp7Z; Wed, 9 Nov 2022 10:43:41 +0800 (CST) Received: from dggpemm500017.china.huawei.com (7.185.36.178) by dggpemm500024.china.huawei.com (7.185.36.203) 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:49 +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:49 +0800 From: Wenchao Hao To: "James E . J . Bottomley" , "Martin K . Petersen" , Doug Gilbert CC: , , Wenchao Hao Subject: [RFC PATCH 5/5] scsi:scsi_debug: fail specific scsi command with result and sense data Date: Wed, 9 Nov 2022 10:59:50 -0500 Message-ID: <20221109155950.3536976-6-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?1748984883368193095?= X-GMAIL-MSGID: =?utf-8?q?1748984883368193095?= If a fail commnd error is injected for specific scsi command, set the scsi command's status and sense data, then finish this scsi command. For example, the following command would make read(0x88) command finished with UNC for 8 times: error=/sys/block/sdb/device/error_inject/error echo "2 -8 0x88 0 0 0x2 0x3 0x11 0x0" >$error Signed-off-by: Wenchao Hao --- drivers/scsi/scsi_debug.c | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 217a9e892391..06fe2914117f 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -7832,6 +7832,41 @@ static int sdebug_fail_queue_cmd(struct scsi_cmnd *cmnd) return 0; } +static int sdebug_fail_cmd(struct scsi_cmnd *cmnd, int *retval, + struct sdebug_err_inject *info) +{ + 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; + int result; + + if (devip == NULL) + return 0; + + list_for_each_entry(err, &devip->inject_err_list, list) { + if (err->type == ERR_FAIL_CMD && + (err->cmd == cmd[0] || err->cmd == 0xff)) { + if (!err->cnt) + return 0; + ret = !!err->cnt; + goto out_handle; + } + } + return 0; + +out_handle: + if (err->cnt < 0) + err->cnt++; + mk_sense_buffer(cmnd, err->sense_key, err->asc, err->asq); + result = err->status_byte | err->host_byte << 16 | err->driver_byte << 24; + *info = *err; + *retval = schedule_resp(cmnd, devip, result, NULL, 0, 0); + + return ret; +} + static int scsi_debug_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scp) { @@ -7852,6 +7887,7 @@ static int scsi_debug_queuecommand(struct Scsi_Host *shost, bool has_wlun_rl; bool inject_now; int ret = 0; + struct sdebug_err_inject err; scsi_set_resid(scp, 0); if (sdebug_statistics) { @@ -7904,6 +7940,16 @@ static int scsi_debug_queuecommand(struct Scsi_Host *shost, return ret; } + if (sdebug_fail_cmd(scp, &ret, &err)) { + scmd_printk(KERN_INFO, scp, + "fail command 0x%x with hostbyte=0x%x, " + "driverbyte=0x%x, statusbyte=0x%x, " + "sense_key=0x%x, asc=0x%x, asq=0x%x\n", + opcode, err.host_byte, err.driver_byte, + err.status_byte, err.sense_key, err.asc, err.asq); + return ret; + } + if (unlikely(inject_now && !atomic_read(&sdeb_inject_pending))) atomic_set(&sdeb_inject_pending, 1);