From patchwork Mon Apr 27 11:31:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11511941 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 11A9E1392 for ; Mon, 27 Apr 2020 11:32:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EDE07206BF for ; Mon, 27 Apr 2020 11:32:18 +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="J0/Ayq4J" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727075AbgD0LcS (ORCPT ); Mon, 27 Apr 2020 07:32:18 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:54659 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727062AbgD0LcQ (ORCPT ); Mon, 27 Apr 2020 07:32:16 -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=1587987136; x=1619523136; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Y2y9JE2e+xhXqZBIOpMaxRGLIW82IAv0qwYVeR1gK3Q=; b=J0/Ayq4JGu/lc0+gt3w7LDrYAk0j+zM/M0BSWeaq85xrHFLFUkSqRiX3 2u8HIFR9YaUAqEvw2++J6VP8CPrnhPM/vCZDRPSl7hGv9x3IaOIwJyxhl IvdGIrv8+hJ4MkgjFytjAjjd9JymgpQ+PPLgoiekKtiAI/BJAUYh/BUqT 7USXMLl6dbA91Ppg+I04gfbF2tRHBecKyaG3AX7g0kv21joMDHWX5HNP9 8301aiVMqzTqkSlX+3wwZFqXqYIWou/BCEs06OWlqMh33bYo7Kn6ghzCi q6wCFEt0Md9edETOGYQ2BmI1WeDUdMpHxQXWk2T4y90gyVfXp6xXFK2DB w==; IronPort-SDR: 2TB4LewquZxMyoBtAF9Y+iB5V4sZWpfSDVTAY2LbJPA65pEOd58ZIDi2ul2ORQ1wmVuir+shzU NYbYWBS5sOrMWp5TwY1aoSL/vaHUlH39rSoYkZBPUX2/PBX8FVY5KxiifQDTt6ZTWA6KrHEgnr KyFV2MhUaG4hmFuNnk56NaCLOXkLW7MOfAAGROtRhy53pEK1qP10uvu3rBAcVO58T2GljDcvck DY/AjbncOjApwr6s5QEhoUhuWK8X0YtIZQm/tmvhH6PFj73ht+L1IGfWGT8m3jnTIkHwIZYET4 GHI= X-IronPort-AV: E=Sophos;i="5.73,323,1583164800"; d="scan'208";a="136552019" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 Apr 2020 19:32:16 +0800 IronPort-SDR: Rtsup6uA2WpuNojgGyod5w5naESK9sLZq8wg4FLAnsOu01/Nns1/zdJJsm+YOKzCABNIImg5qN b/EYq3hnH/9tBpp8JKD6ILNUoUaQzanlE= 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; 27 Apr 2020 04:22:57 -0700 IronPort-SDR: CKAwR6QaVrB1QDyA7yBgX6DGKWWaZlTYkj6ldt7Wv9kB0o1Joc+lAhIzWllcEFegxFgf4NCEa5 N6BysOaxD/SQ== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Apr 2020 04:32:14 -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" , Johannes Thumshirn , Christoph Hellwig , Bart Van Assche Subject: [PATCH v8 07/11] scsi: sd_zbc: factor out sanity checks for zoned commands Date: Mon, 27 Apr 2020 20:31:49 +0900 Message-Id: <20200427113153.31246-8-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200427113153.31246-1-johannes.thumshirn@wdc.com> References: <20200427113153.31246-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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 Reviewed-by: Hannes Reinecke --- 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);