From patchwork Thu Aug 9 19:41:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10561853 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9A0F790E3 for ; Thu, 9 Aug 2018 19:42:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A7302B979 for ; Thu, 9 Aug 2018 19:42:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E63D2B97F; Thu, 9 Aug 2018 19:42:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3A762B97D for ; Thu, 9 Aug 2018 19:42:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726961AbeHIWI1 (ORCPT ); Thu, 9 Aug 2018 18:08:27 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:1352 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726744AbeHIWI0 (ORCPT ); Thu, 9 Aug 2018 18:08:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1533843728; x=1565379728; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=la2tM5lVPV68V9GjAgWjh6p3WO/+Dy/yPPWGR7FUCxs=; b=Nx7ST7dwn2eJw5by449nuGnMG1mDSig/bG9OcFbqjk/MGF89wakSeXAb 1zKzudymZkhpyR7cKKfXIOV7jpwFJmD/oEbWF0EIcDe/f9251G2R+lSnl 1xzhJTxtdSctB9ksYJSJG60iJUP06ExC9KcTiU+Rq96ujt9fwQC8WO3vt TCU6HYmv8/cnKr/4G7nkVMCzrlBrdbfSoYUMNbu5jMu2qNTeySTBQBC/7 G3PG2YrO+5mGn7worLfJkHpgBlJg0ZgrX5wbbtTqqkfRhPhcfSXpuJSI8 SaIUTJuj5DAGuWNZWh2xMV48WXEbf+Z66/TS2Tyu8svSjq4nr1DemexN6 Q==; X-IronPort-AV: E=Sophos;i="5.53,215,1531756800"; d="scan'208";a="191119588" Received: from mail-sn1nam01lp0119.outbound.protection.outlook.com (HELO NAM01-SN1-obe.outbound.protection.outlook.com) ([207.46.163.119]) by ob1.hgst.iphmx.com with ESMTP; 10 Aug 2018 03:42:07 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=J668CqFV+Zum0lM2ipoVnOBDKILXv4aMiiHTopuGCdg=; b=Zzv2x7ta+l8V/Ddksr2KeoCnP1B9hT/+X0dHEqfDaccSMn9QqijlLWfX0ps1PgTtBaJJwQLazrmmDk4hhDJr598he1PCHDJbQ4U57BtgeuU/SqtOW7o2zz18m4jw1OeciINSqV5joHIrmHwLdPRJS7GG67DrYnGrKOWniyuEj/A= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Bart.VanAssche@wdc.com; Received: from asus.hsd1.ca.comcast.net (174.62.111.89) by MWHPR04MB1198.namprd04.prod.outlook.com (2603:10b6:300:71::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1038.23; Thu, 9 Aug 2018 19:42:05 +0000 From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , "Martin K . Petersen" , Ming Lei , Jianchao Wang , Hannes Reinecke , Johannes Thumshirn , Alan Stern Subject: [PATCH v6 02/12] scsi: Alter handling of RQF_DV requests Date: Thu, 9 Aug 2018 12:41:39 -0700 Message-Id: <20180809194149.15285-3-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180809194149.15285-1-bart.vanassche@wdc.com> References: <20180809194149.15285-1-bart.vanassche@wdc.com> MIME-Version: 1.0 X-Originating-IP: [174.62.111.89] X-ClientProxiedBy: MWHPR2201CA0066.namprd22.prod.outlook.com (2603:10b6:301:5e::19) To MWHPR04MB1198.namprd04.prod.outlook.com (2603:10b6:300:71::23) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c6b3af67-83c5-4887-5b0f-08d5fe302fe9 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020);SRVR:MWHPR04MB1198; X-Microsoft-Exchange-Diagnostics: 1;MWHPR04MB1198;3:nWet6JcqX1MQ5ApFO8qe8/8x8j3F98ezPsTXThgeqTlKKDI+OyhW00F6VbzD1AMXUELGzMoAeNYdqkGZXZkFswGfHkiAzV1APW9xbqpH41B9YPNBKL0C8ETBN5DHqolFnPxF6EH8SK2WOUMnl/uur67vCptXCRJuXaNlsoepBZLkK96M1clbabT782QOjj5HkQ0zvF4yutQDJrG7bF7nH3LXOgWTupNqfp7JLuUPTSxe6jOyhrALjcRbTjSd4rhE;25:T3pYzalT4Ycroe6ke00ZYenBxJpyyvyRh2KASTuVZsJvJEUq6q/jq05KvhiVFP/7IwMEPLlA2xniSeT7b6l2m3BASFbmKakpzMFc+NNxSrfDCVxMwcdPD+Nx0a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Os4B9Y3QPGGy3kjmzBOzDws6mydVBnhwBRIMIxGj03XK/1lYSk6x2t8QwwdGSpStKGyYu9ZiCYIR8bPtBpwf0aLqAYKpF0fMhEwlCRk+FdN0/e6Ts1QoBsFzaCccvjdYq/YvHbHXv7GT3WsTfbbmarF99VI1Elq6wGvHvh4a1wk2c1hHkLLue3q+R2URpkMyb67DB8mV09UWDc/mBH+JRtTbit0CJjuKsnvesqFDu0qSscsRqTpFgt1/JjYv4YX/erQlwGzl0zjTkuC4f2tVcUl2BfIEkCGz6mwVS2ck8L2Y57qU/fzdCOBqoMPRw0nXSc6ah+bX5LTL2lVkCe/fMWQKkqV00kXbTtXDlzyiE3CjETE X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(209352067349851)(35762410373642)(146099531331640); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231311)(944501410)(52105095)(3002001)(10201501046)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(6072148)(201708071742011)(7699016);SRVR:MWHPR04MB1198;BCL:0;PCL:0;RULEID:;SRVR:MWHPR04MB1198; X-Forefront-PRVS: 0759F7A50A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(396003)(39860400002)(136003)(366004)(346002)(376002)(199004)(189003)(76176011)(50466002)(476003)(51416003)(4326008)(478600001)(52116002)(6486002)(105586002)(72206003)(48376002)(5660300001)(47776003)(305945005)(2616005)(956004)(7736002)(6916009)(6666003)(486006)(8936002)(2906002)(68736007)(36756003)(66066001)(186003)(446003)(81166006)(50226002)(8676002)(81156014)(316002)(6506007)(386003)(106356001)(97736004)(25786009)(11346002)(16586007)(54906003)(14444005)(6116002)(1076002)(3846002)(86362001)(26005)(16526019)(53936002)(6512007);DIR:OUT;SFP:1102;SCL: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qu1SBOfC5b0CZvXmLf/fZ0QjcIJ5+uJMvxOUjyfTfUNw1JevfdnzB6k0KM2P+UTUkNdq3nBlT3YsYqkIosEJdtIbxPpPOZ7T9mJBvPigvCSQ==;5:msYEQbgmqxtHPDUcaK8fOHS7F7CHKUsa+nfM0g4y4nBwy8ATfczcNuUuWnVC2FNpzVGnXzQEAUVG1qXZYTSGHFBxqM+4hCOFbPtOt5xzDTZjURWoVIwXL8ivl7Y0HOGf9cLH52FrCLCimCGkPQsB7aE8EvBiAhmUibDgfrALzjM=;7:vLM7uVi88mcy0lBwR/3TsnJd1FPA984phzLHndplx9LouW+vXNBzjOqhtWmjEvzMFkmKYzMvIIzQhuFUFuF6yWjrqRQOCwlK7U8pjSpilgSnlVPvjnFp6E9b1h6E0O6dEMFylBTqZ/bSbL/Hmhv7uCjIATxq/C/EIz3HLUswg0LMUsCGp5OhAP+Uz2D4wYFJ7iX7D6jY+jAqawctfxKvvBunSrtqX6BtILfqZudEvzbtX7b2MMgduTc1MtJ2Q1Y3 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;MWHPR04MB1198;20:dUVr88rBhfzlKR375o9yZQNnmpGa6Zh03HD5rNdBhWin8ejwFaiVyHgCjqlaRZ87DWOogNlW4OEyU9ft9ZZ0I+Zm1c9C1PkcM4FlxreZOQh1oupTbzl1xIY9deOxNCErrRh7uCuMPbyzrmOnSKy2zg4FFOzOAOFTEvpvre4MC60= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Aug 2018 19:42:05.4457 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c6b3af67-83c5-4887-5b0f-08d5fe302fe9 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR04MB1198 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Process all requests in state SDEV_CREATED instead of only RQF_DV requests. This does not change the behavior of the SCSI core because the SCSI device state is modified into another state before SCSI devices become visible in sysfs and before any device nodes are created in /dev. Do not process RQF_DV requests in state SDEV_CANCEL because only power management requests should be processed in this state. Handle all SCSI device states explicitly in scsi_prep_state_check() instead of using a default case in the switch/case statement in scsi_prep_state_check(). This allows the compiler to verify whether all states have been handled. Signed-off-by: Bart Van Assche Cc: Martin K. Petersen Cc: Christoph Hellwig Cc: Ming Lei Cc: Jianchao Wang Cc: Hannes Reinecke Cc: Johannes Thumshirn Cc: Alan Stern --- drivers/scsi/scsi_lib.c | 78 +++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 42 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index a65a03e2bcc4..8685704f6c8b 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1331,49 +1331,43 @@ scsi_prep_state_check(struct scsi_device *sdev, struct request *req) * If the device is not in running state we will reject some * or all commands. */ - if (unlikely(sdev->sdev_state != SDEV_RUNNING)) { - switch (sdev->sdev_state) { - case SDEV_OFFLINE: - case SDEV_TRANSPORT_OFFLINE: - /* - * If the device is offline we refuse to process any - * commands. The device must be brought online - * before trying any recovery commands. - */ - sdev_printk(KERN_ERR, sdev, - "rejecting I/O to offline device\n"); - ret = BLKPREP_KILL; - break; - case SDEV_DEL: - /* - * If the device is fully deleted, we refuse to - * process any commands as well. - */ - sdev_printk(KERN_ERR, sdev, - "rejecting I/O to dead device\n"); - ret = BLKPREP_KILL; - break; - case SDEV_BLOCK: - case SDEV_CREATED_BLOCK: + switch (sdev->sdev_state) { + case SDEV_RUNNING: + case SDEV_CREATED: + break; + case SDEV_OFFLINE: + case SDEV_TRANSPORT_OFFLINE: + /* + * If the device is offline we refuse to process any commands. + * The device must be brought online before trying any + * recovery commands. + */ + sdev_printk(KERN_ERR, sdev, + "rejecting I/O to offline device\n"); + ret = BLKPREP_KILL; + break; + case SDEV_DEL: + /* + * If the device is fully deleted, we refuse to process any + * commands as well. + */ + sdev_printk(KERN_ERR, sdev, "rejecting I/O to dead device\n"); + ret = BLKPREP_KILL; + break; + case SDEV_BLOCK: + case SDEV_CREATED_BLOCK: + ret = BLKPREP_DEFER; + break; + case SDEV_QUIESCE: + /* Only allow RQF_PM and RQF_DV requests. */ + if (!(req->rq_flags & (RQF_PM | RQF_DV))) ret = BLKPREP_DEFER; - break; - case SDEV_QUIESCE: - /* - * If the devices is blocked we defer normal commands. - */ - if (req && !(req->rq_flags & (RQF_PM | RQF_DV))) - ret = BLKPREP_DEFER; - break; - default: - /* - * For any other not fully online state we only allow - * special commands. In particular any user initiated - * command is not allowed. - */ - if (req && !(req->rq_flags & (RQF_PM | RQF_DV))) - ret = BLKPREP_KILL; - break; - } + break; + case SDEV_CANCEL: + /* Only allow RQF_PM requests. */ + if (!(req->rq_flags & RQF_PM)) + ret = BLKPREP_KILL; + break; } return ret; }