From patchwork Fri Apr 17 12:15:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11495017 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F409214B4 for ; Fri, 17 Apr 2020 12:16:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D88CD22202 for ; Fri, 17 Apr 2020 12:16:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="k1rJxI3X" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728549AbgDQMQE (ORCPT ); Fri, 17 Apr 2020 08:16:04 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:50643 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728307AbgDQMP7 (ORCPT ); Fri, 17 Apr 2020 08:15:59 -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=1587125761; x=1618661761; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=af+TpmrNaP6opwMEPh6jKrw6Bxfh1IsevFX/PW8xfPo=; b=k1rJxI3XnEdr/6iX0iiw7HW1lT1xop1JToB4jfJPrZKsZL6084iOGPQp bX6UlUu5mlCTrcptejcVkdonNd1PM/IjFB2S6NLH7NNaDG3sN9Zf9FsI0 4cTvdS8X+9tWv4++3xSAucxQgszpQfraJJGdCWhc2aPOOSlpQwz3lN/HS T1ygK3jOEhD2hlhrgkO86ataVT7Z67aKRxQMbGsTIj9C7/YA/QuETLiTs Bj6RZSDh8wjNguBeRYiZmdRO2j7pNXsko32MIrcPk4xZF4EFu3HZj5zpL wJdJjdN+Qu/+IprIBqdquBI21CHmof7DH6fixITRVzTVTBWziUdpHp9OK w==; IronPort-SDR: 2NxYaZNOOMxf+C1aWYvlE7cMmPwDxW9D91TsOYnQ3lbppxnxbZCTn3aeHrd9z9vQYZ9zZpRWLB kUhx2P++lEzk7YDCLLSHyfB9IdCHDfHDnjgHCxDVLf65IfbceDUDbTFYDvupvr68Zpa9Lg93fx 2R/M6MBSpgLIxhjMz+X2Jv7/591Hwy/1LFHzvOwj4wX5TuLQPuxeUNNhB+h/ggmQY8zhdCW8LK EFo5DIRd84EIMrKTWYszUVGQb/T15BMJkpGFu98BjHaSOC6auZt7J9rxT2SLkQeon2ZRJQdgkT fJ0= X-IronPort-AV: E=Sophos;i="5.72,394,1580745600"; d="scan'208";a="237989218" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 17 Apr 2020 20:16:01 +0800 IronPort-SDR: KsXl1vBG+6ZBip9e3uAPneaPVddJ0Jx1jxSmQ5t4ouCv/lZuyW8ZcOdjPjyBTkiUZ96WhoYSLw VK8s7nfBLv90FX8wW7uwu+ON8L8lAoEwQ= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Apr 2020 05:06:57 -0700 IronPort-SDR: tSViJ805KU4pd2c4z3dOxyqqjih10k5hKp/Krbbs/A3O3yBitmqV/5GkKBdY3iQkcRuGGUBnRK ifgealMRFGCw== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 17 Apr 2020 05:15:57 -0700 From: Johannes Thumshirn To: Jens Axboe Cc: Christoph Hellwig , linux-block , Damien Le Moal , Keith Busch , "linux-scsi @ vger . kernel . org" , "Martin K . Petersen" , "linux-fsdevel @ vger . kernel . org" , Daniel Wagner , Johannes Thumshirn , Christoph Hellwig Subject: [PATCH v7 07/11] scsi: sd_zbc: factor out sanity checks for zoned commands Date: Fri, 17 Apr 2020 21:15:32 +0900 Message-Id: <20200417121536.5393-8-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200417121536.5393-1-johannes.thumshirn@wdc.com> References: <20200417121536.5393-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Factor sanity checks for zoned commands from sd_zbc_setup_zone_mgmt_cmnd(). This will help with the introduction of an emulated ZONE_APPEND command. Signed-off-by: Johannes Thumshirn Reviewed-by: Christoph Hellwig Reviewed-by: Bart Van Assche --- drivers/scsi/sd_zbc.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c index f45c22b09726..ee156fbf3780 100644 --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -209,6 +209,26 @@ int sd_zbc_report_zones(struct gendisk *disk, sector_t sector, return ret; } +static blk_status_t sd_zbc_cmnd_checks(struct scsi_cmnd *cmd) +{ + struct request *rq = cmd->request; + struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); + sector_t sector = blk_rq_pos(rq); + + if (!sd_is_zoned(sdkp)) + /* Not a zoned device */ + return BLK_STS_IOERR; + + if (sdkp->device->changed) + return BLK_STS_IOERR; + + if (sector & (sd_zbc_zone_sectors(sdkp) - 1)) + /* Unaligned request */ + return BLK_STS_IOERR; + + return BLK_STS_OK; +} + /** * sd_zbc_setup_zone_mgmt_cmnd - Prepare a zone ZBC_OUT command. The operations * can be RESET WRITE POINTER, OPEN, CLOSE or FINISH. @@ -223,20 +243,14 @@ blk_status_t sd_zbc_setup_zone_mgmt_cmnd(struct scsi_cmnd *cmd, unsigned char op, bool all) { struct request *rq = cmd->request; - struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); sector_t sector = blk_rq_pos(rq); + struct scsi_disk *sdkp = scsi_disk(rq->rq_disk); sector_t block = sectors_to_logical(sdkp->device, sector); + blk_status_t ret; - if (!sd_is_zoned(sdkp)) - /* Not a zoned device */ - return BLK_STS_IOERR; - - if (sdkp->device->changed) - return BLK_STS_IOERR; - - if (sector & (sd_zbc_zone_sectors(sdkp) - 1)) - /* Unaligned request */ - return BLK_STS_IOERR; + ret = sd_zbc_cmnd_checks(cmd); + if (ret != BLK_STS_OK) + return ret; cmd->cmd_len = 16; memset(cmd->cmnd, 0, cmd->cmd_len);