Issuing read commands to offline zones of a ZBC disk will result in failures. So do not issue such command and fail them early in sd_setup_read_write_cmnd(). This change also checks write commands, which is fine but should actually never happen as the block layer zone write plugging code already fails write BIOs to offline zones early in the submission path. As the code comment explains, since disk_zone_is_offline() uses the block layer cached zone condition, this is inherently racy with zone revalidation updating the zone condition. However, this will never prevent valid read operations as the only case where we could proceed is if the read is received after a restoration of the disk storage element completes but before the zones are revalidated. And in that case, all zones are empty and thus have no data to read. Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig Reviewed-by: Martin K. Petersen Reviewed-by: Hannes Reinecke --- drivers/scsi/sd.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 34b44d72b2b7..8b1c05de541d 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -1424,7 +1424,8 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *cmd) { struct request *rq = scsi_cmd_to_rq(cmd); struct scsi_device *sdp = cmd->device; - struct scsi_disk *sdkp = scsi_disk(rq->q->disk); + struct gendisk *disk = rq->q->disk; + struct scsi_disk *sdkp = scsi_disk(disk); sector_t lba = sectors_to_logical(sdp, blk_rq_pos(rq)); sector_t threshold; unsigned int nr_blocks = sectors_to_logical(sdp, blk_rq_sectors(rq)); @@ -1456,6 +1457,23 @@ static blk_status_t sd_setup_read_write_cmnd(struct scsi_cmnd *cmd) goto fail; } + /* + * The block layer already prevents writes to offline zones of zoned + * block devices. But there are no checks for reads, so check this here. + * Since disk_zone_is_offline() uses the block layer cached zone + * condition, this is inherently racy with zone revalidation updating + * the zone condition. However, this will never prevent valid read + * operations as the only case where we could proceed is if the read is + * received after a restoration of the disk storage element completes + * but before the zones are revalidated. And in that case, all zones are + * empty and thus have no data to read. + * Note that we are quiet about the error (no message) to avoid flooding + * the kernel log. + */ + if (sdkp->device->type == TYPE_ZBC && + disk_zone_is_offline(disk, blk_rq_pos(rq))) + goto fail; + /* * Some SD card readers can't handle accesses which touch the * last one or two logical blocks. Split accesses as needed. -- 2.56.0