All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Thumshirn <johannes.thumshirn@wdc.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: Christoph Hellwig <hch@infradead.org>,
	linux-block <linux-block@vger.kernel.org>,
	Damien Le Moal <Damien.LeMoal@wdc.com>,
	Keith Busch <kbusch@kernel.org>,
	"linux-scsi @ vger . kernel . org" <linux-scsi@vger.kernel.org>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	"linux-fsdevel @ vger . kernel . org"
	<linux-fsdevel@vger.kernel.org>,
	"Darrick J . Wong" <darrick.wong@oracle.com>,
	Johannes Thumshirn <johannes.thumshirn@wdc.com>
Subject: [PATCH v2 06/11] scsi: sd_zbc: factor out sanity checks for zoned commands
Date: Wed, 25 Mar 2020 00:24:49 +0900	[thread overview]
Message-ID: <20200324152454.4954-7-johannes.thumshirn@wdc.com> (raw)
In-Reply-To: <20200324152454.4954-1-johannes.thumshirn@wdc.com>

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 <johannes.thumshirn@wdc.com>
---
 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);
-- 
2.24.1


  parent reply	other threads:[~2020-03-24 15:25 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-24 15:24 [PATCH v2 00/11] Introduce Zone Append for writing to zoned block devices Johannes Thumshirn
2020-03-24 15:24 ` [PATCH v2 01/11] block: factor out requeue handling from dispatch code Johannes Thumshirn
2020-03-25  8:40   ` Christoph Hellwig
2020-03-25 15:40     ` Jens Axboe
2020-03-24 15:24 ` [PATCH v2 02/11] block: provide fallbacks for blk_queue_zone_is_seq and blk_queue_zone_no Johannes Thumshirn
2020-03-24 15:24 ` [PATCH v2 03/11] block: Introduce REQ_OP_ZONE_APPEND Johannes Thumshirn
2020-03-24 16:07   ` Johannes Thumshirn
2020-03-25 16:24   ` Johannes Thumshirn
2020-03-24 15:24 ` [PATCH v2 04/11] block: introduce blk_req_zone_write_trylock Johannes Thumshirn
2020-03-24 15:24 ` [PATCH v2 05/11] block: Introduce zone write pointer offset caching Johannes Thumshirn
2020-03-24 15:24 ` Johannes Thumshirn [this message]
2020-03-24 15:24 ` [PATCH v2 07/11] scsi: sd_zbc: emulate ZONE_APPEND commands Johannes Thumshirn
2020-03-24 15:24 ` [PATCH v2 08/11] null_blk: Cleanup zoned device initialization Johannes Thumshirn
2020-03-24 15:24 ` [PATCH v2 09/11] null_blk: Support REQ_OP_ZONE_APPEND Johannes Thumshirn
2020-03-24 15:24 ` [PATCH v2 10/11] iomap: Add support for zone append writes Johannes Thumshirn
2020-03-24 15:41   ` Christoph Hellwig
2020-03-25  5:27     ` Damien Le Moal
2020-03-25  6:25       ` hch
2020-03-25  9:45     ` Johannes Thumshirn
2020-03-25  9:48       ` hch
2020-03-25  9:54         ` Johannes Thumshirn
2020-03-25  9:59         ` Damien Le Moal
2020-03-25 10:01           ` hch
2020-03-25 10:15             ` Johannes Thumshirn
2020-03-24 22:45   ` Dave Chinner
2020-03-25  5:38     ` Damien Le Moal
2020-03-25  8:32     ` Johannes Thumshirn
2020-03-24 15:24 ` [PATCH v2 11/11] zonefs: use zone-append for sequential zones Johannes Thumshirn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200324152454.4954-7-johannes.thumshirn@wdc.com \
    --to=johannes.thumshirn@wdc.com \
    --cc=Damien.LeMoal@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=darrick.wong@oracle.com \
    --cc=hch@infradead.org \
    --cc=kbusch@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.