2019-06-01 16:08:25 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2016-10-18 14:40:34 +08:00
|
|
|
/*
|
|
|
|
* SCSI Zoned Block commands
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014-2015 SUSE Linux GmbH
|
|
|
|
* Written by: Hannes Reinecke <hare@suse.de>
|
|
|
|
* Modified by: Damien Le Moal <damien.lemoal@hgst.com>
|
|
|
|
* Modified by: Shaun Tancheff <shaun.tancheff@seagate.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/blkdev.h>
|
2019-07-01 13:09:17 +08:00
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
#include <linux/sched/mm.h>
|
2016-10-18 14:40:34 +08:00
|
|
|
|
|
|
|
#include <asm/unaligned.h>
|
|
|
|
|
|
|
|
#include <scsi/scsi.h>
|
|
|
|
#include <scsi/scsi_cmnd.h>
|
|
|
|
|
|
|
|
#include "sd.h"
|
|
|
|
|
2019-11-11 10:39:30 +08:00
|
|
|
static int sd_zbc_parse_report(struct scsi_disk *sdkp, u8 *buf,
|
|
|
|
unsigned int idx, report_zones_cb cb, void *data)
|
2016-10-18 14:40:34 +08:00
|
|
|
{
|
|
|
|
struct scsi_device *sdp = sdkp->device;
|
2019-11-11 10:39:30 +08:00
|
|
|
struct blk_zone zone = { 0 };
|
2016-10-18 14:40:34 +08:00
|
|
|
|
2019-11-11 10:39:30 +08:00
|
|
|
zone.type = buf[0] & 0x0f;
|
|
|
|
zone.cond = (buf[1] >> 4) & 0xf;
|
2016-10-18 14:40:34 +08:00
|
|
|
if (buf[1] & 0x01)
|
2019-11-11 10:39:30 +08:00
|
|
|
zone.reset = 1;
|
2016-10-18 14:40:34 +08:00
|
|
|
if (buf[1] & 0x02)
|
2019-11-11 10:39:30 +08:00
|
|
|
zone.non_seq = 1;
|
|
|
|
|
|
|
|
zone.len = logical_to_sectors(sdp, get_unaligned_be64(&buf[8]));
|
|
|
|
zone.start = logical_to_sectors(sdp, get_unaligned_be64(&buf[16]));
|
|
|
|
zone.wp = logical_to_sectors(sdp, get_unaligned_be64(&buf[24]));
|
|
|
|
if (zone.type != ZBC_ZONE_TYPE_CONV &&
|
|
|
|
zone.cond == ZBC_ZONE_COND_FULL)
|
|
|
|
zone.wp = zone.start + zone.len;
|
|
|
|
|
|
|
|
return cb(&zone, idx, data);
|
2016-10-18 14:40:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-12 18:08:49 +08:00
|
|
|
* sd_zbc_do_report_zones - Issue a REPORT ZONES scsi command.
|
2017-10-11 04:54:22 +08:00
|
|
|
* @sdkp: The target disk
|
2019-07-01 13:09:17 +08:00
|
|
|
* @buf: vmalloc-ed buffer to use for the reply
|
2017-10-11 04:54:22 +08:00
|
|
|
* @buflen: the buffer size
|
|
|
|
* @lba: Start LBA of the report
|
2018-10-12 18:08:41 +08:00
|
|
|
* @partial: Do partial report
|
2017-10-11 04:54:22 +08:00
|
|
|
*
|
|
|
|
* For internal use during device validation.
|
2018-10-12 18:08:41 +08:00
|
|
|
* Using partial=true can significantly speed up execution of a report zones
|
|
|
|
* command because the disk does not have to count all possible report matching
|
|
|
|
* zones and will only report the count of zones fitting in the command reply
|
|
|
|
* buffer.
|
2016-10-18 14:40:34 +08:00
|
|
|
*/
|
2018-10-12 18:08:49 +08:00
|
|
|
static int sd_zbc_do_report_zones(struct scsi_disk *sdkp, unsigned char *buf,
|
|
|
|
unsigned int buflen, sector_t lba,
|
|
|
|
bool partial)
|
2016-10-18 14:40:34 +08:00
|
|
|
{
|
|
|
|
struct scsi_device *sdp = sdkp->device;
|
|
|
|
const int timeout = sdp->request_queue->rq_timeout;
|
|
|
|
struct scsi_sense_hdr sshdr;
|
|
|
|
unsigned char cmd[16];
|
|
|
|
unsigned int rep_len;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
memset(cmd, 0, 16);
|
|
|
|
cmd[0] = ZBC_IN;
|
|
|
|
cmd[1] = ZI_REPORT_ZONES;
|
|
|
|
put_unaligned_be64(lba, &cmd[2]);
|
|
|
|
put_unaligned_be32(buflen, &cmd[10]);
|
2018-10-12 18:08:41 +08:00
|
|
|
if (partial)
|
|
|
|
cmd[14] = ZBC_REPORT_ZONE_PARTIAL;
|
2016-10-18 14:40:34 +08:00
|
|
|
|
|
|
|
result = scsi_execute_req(sdp, cmd, DMA_FROM_DEVICE,
|
|
|
|
buf, buflen, &sshdr,
|
|
|
|
timeout, SD_MAX_RETRIES, NULL);
|
|
|
|
if (result) {
|
|
|
|
sd_printk(KERN_ERR, sdkp,
|
2019-11-25 15:05:18 +08:00
|
|
|
"REPORT ZONES start lba %llu failed\n", lba);
|
|
|
|
sd_print_result(sdkp, "REPORT ZONES", result);
|
|
|
|
if (driver_byte(result) == DRIVER_SENSE &&
|
|
|
|
scsi_sense_valid(&sshdr))
|
|
|
|
sd_print_sense_hdr(sdkp, &sshdr);
|
2016-10-18 14:40:34 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
rep_len = get_unaligned_be32(&buf[0]);
|
|
|
|
if (rep_len < 64) {
|
|
|
|
sd_printk(KERN_ERR, sdkp,
|
|
|
|
"REPORT ZONES report invalid length %u\n",
|
|
|
|
rep_len);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-01 13:09:17 +08:00
|
|
|
/**
|
|
|
|
* Allocate a buffer for report zones reply.
|
|
|
|
* @sdkp: The target disk
|
|
|
|
* @nr_zones: Maximum number of zones to report
|
|
|
|
* @buflen: Size of the buffer allocated
|
|
|
|
*
|
|
|
|
* Try to allocate a reply buffer for the number of requested zones.
|
|
|
|
* The size of the buffer allocated may be smaller than requested to
|
|
|
|
* satify the device constraint (max_hw_sectors, max_segments, etc).
|
|
|
|
*
|
|
|
|
* Return the address of the allocated buffer and update @buflen with
|
|
|
|
* the size of the allocated buffer.
|
|
|
|
*/
|
|
|
|
static void *sd_zbc_alloc_report_buffer(struct scsi_disk *sdkp,
|
|
|
|
unsigned int nr_zones, size_t *buflen)
|
|
|
|
{
|
|
|
|
struct request_queue *q = sdkp->disk->queue;
|
|
|
|
size_t bufsize;
|
|
|
|
void *buf;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Report zone buffer size should be at most 64B times the number of
|
|
|
|
* zones requested plus the 64B reply header, but should be at least
|
|
|
|
* SECTOR_SIZE for ATA devices.
|
|
|
|
* Make sure that this size does not exceed the hardware capabilities.
|
|
|
|
* Furthermore, since the report zone command cannot be split, make
|
|
|
|
* sure that the allocated buffer can always be mapped by limiting the
|
|
|
|
* number of pages allocated to the HBA max segments limit.
|
|
|
|
*/
|
2019-11-11 10:39:29 +08:00
|
|
|
nr_zones = min(nr_zones, sdkp->nr_zones);
|
|
|
|
bufsize = roundup((nr_zones + 1) * 64, SECTOR_SIZE);
|
2019-07-01 13:09:17 +08:00
|
|
|
bufsize = min_t(size_t, bufsize,
|
|
|
|
queue_max_hw_sectors(q) << SECTOR_SHIFT);
|
|
|
|
bufsize = min_t(size_t, bufsize, queue_max_segments(q) << PAGE_SHIFT);
|
|
|
|
|
2019-11-11 10:39:29 +08:00
|
|
|
while (bufsize >= SECTOR_SIZE) {
|
|
|
|
buf = __vmalloc(bufsize,
|
|
|
|
GFP_KERNEL | __GFP_ZERO | __GFP_NORETRY,
|
|
|
|
PAGE_KERNEL);
|
|
|
|
if (buf) {
|
|
|
|
*buflen = bufsize;
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
bufsize >>= 1;
|
|
|
|
}
|
2019-07-01 13:09:17 +08:00
|
|
|
|
2019-11-11 10:39:29 +08:00
|
|
|
return NULL;
|
2019-07-01 13:09:17 +08:00
|
|
|
}
|
|
|
|
|
2017-10-11 04:54:22 +08:00
|
|
|
/**
|
2019-11-11 10:39:30 +08:00
|
|
|
* sd_zbc_zone_sectors - Get the device zone size in number of 512B sectors.
|
|
|
|
* @sdkp: The target disk
|
2017-10-11 04:54:22 +08:00
|
|
|
*/
|
2019-11-11 10:39:30 +08:00
|
|
|
static inline sector_t sd_zbc_zone_sectors(struct scsi_disk *sdkp)
|
|
|
|
{
|
|
|
|
return logical_to_sectors(sdkp->device, sdkp->zone_blocks);
|
|
|
|
}
|
|
|
|
|
2018-10-12 18:08:49 +08:00
|
|
|
int sd_zbc_report_zones(struct gendisk *disk, sector_t sector,
|
2019-11-11 10:39:30 +08:00
|
|
|
unsigned int nr_zones, report_zones_cb cb, void *data)
|
2016-10-18 14:40:34 +08:00
|
|
|
{
|
2018-10-12 18:08:49 +08:00
|
|
|
struct scsi_disk *sdkp = scsi_disk(disk);
|
2020-02-19 14:38:00 +08:00
|
|
|
sector_t capacity = logical_to_sectors(sdkp->device, sdkp->capacity);
|
2019-11-11 10:39:30 +08:00
|
|
|
unsigned int nr, i;
|
2018-10-12 18:08:49 +08:00
|
|
|
unsigned char *buf;
|
2019-11-11 10:39:30 +08:00
|
|
|
size_t offset, buflen = 0;
|
|
|
|
int zone_idx = 0;
|
|
|
|
int ret;
|
2016-10-18 14:40:34 +08:00
|
|
|
|
|
|
|
if (!sd_is_zoned(sdkp))
|
|
|
|
/* Not a zoned device */
|
2018-10-12 18:08:49 +08:00
|
|
|
return -EOPNOTSUPP;
|
2016-10-18 14:40:34 +08:00
|
|
|
|
2020-02-19 14:38:00 +08:00
|
|
|
if (!capacity)
|
|
|
|
/* Device gone or invalid */
|
|
|
|
return -ENODEV;
|
|
|
|
|
2019-11-11 10:39:30 +08:00
|
|
|
buf = sd_zbc_alloc_report_buffer(sdkp, nr_zones, &buflen);
|
2018-10-12 18:08:49 +08:00
|
|
|
if (!buf)
|
|
|
|
return -ENOMEM;
|
2016-10-18 14:40:34 +08:00
|
|
|
|
2020-02-19 14:38:00 +08:00
|
|
|
while (zone_idx < nr_zones && sector < capacity) {
|
2019-11-11 10:39:30 +08:00
|
|
|
ret = sd_zbc_do_report_zones(sdkp, buf, buflen,
|
|
|
|
sectors_to_logical(sdkp->device, sector), true);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
offset = 0;
|
|
|
|
nr = min(nr_zones, get_unaligned_be32(&buf[0]) / 64);
|
|
|
|
if (!nr)
|
|
|
|
break;
|
|
|
|
|
|
|
|
for (i = 0; i < nr && zone_idx < nr_zones; i++) {
|
|
|
|
offset += 64;
|
|
|
|
ret = sd_zbc_parse_report(sdkp, buf + offset, zone_idx,
|
|
|
|
cb, data);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
zone_idx++;
|
|
|
|
}
|
2016-10-18 14:40:34 +08:00
|
|
|
|
2019-11-11 10:39:30 +08:00
|
|
|
sector += sd_zbc_zone_sectors(sdkp) * i;
|
2018-10-12 18:08:49 +08:00
|
|
|
}
|
2016-10-18 14:40:34 +08:00
|
|
|
|
2019-11-11 10:39:30 +08:00
|
|
|
ret = zone_idx;
|
2019-07-01 13:09:17 +08:00
|
|
|
out:
|
|
|
|
kvfree(buf);
|
2018-10-12 18:08:49 +08:00
|
|
|
return ret;
|
2016-10-18 14:40:34 +08:00
|
|
|
}
|
|
|
|
|
2017-10-11 04:54:22 +08:00
|
|
|
/**
|
2019-10-27 22:05:47 +08:00
|
|
|
* sd_zbc_setup_zone_mgmt_cmnd - Prepare a zone ZBC_OUT command. The operations
|
|
|
|
* can be RESET WRITE POINTER, OPEN, CLOSE or FINISH.
|
2017-10-11 04:54:22 +08:00
|
|
|
* @cmd: the command to setup
|
2019-10-27 22:05:47 +08:00
|
|
|
* @op: Operation to be performed
|
|
|
|
* @all: All zones control
|
2017-10-11 04:54:22 +08:00
|
|
|
*
|
2019-10-27 22:05:47 +08:00
|
|
|
* Called from sd_init_command() for REQ_OP_ZONE_RESET, REQ_OP_ZONE_RESET_ALL,
|
|
|
|
* REQ_OP_ZONE_OPEN, REQ_OP_ZONE_CLOSE or REQ_OP_ZONE_FINISH requests.
|
2017-10-11 04:54:22 +08:00
|
|
|
*/
|
2019-10-27 22:05:47 +08:00
|
|
|
blk_status_t sd_zbc_setup_zone_mgmt_cmnd(struct scsi_cmnd *cmd,
|
|
|
|
unsigned char op, bool all)
|
2016-10-18 14:40:34 +08:00
|
|
|
{
|
|
|
|
struct request *rq = cmd->request;
|
|
|
|
struct scsi_disk *sdkp = scsi_disk(rq->rq_disk);
|
|
|
|
sector_t sector = blk_rq_pos(rq);
|
|
|
|
sector_t block = sectors_to_logical(sdkp->device, sector);
|
|
|
|
|
|
|
|
if (!sd_is_zoned(sdkp))
|
|
|
|
/* Not a zoned device */
|
2018-11-09 21:42:39 +08:00
|
|
|
return BLK_STS_IOERR;
|
2016-10-18 14:40:34 +08:00
|
|
|
|
|
|
|
if (sdkp->device->changed)
|
2018-11-09 21:42:39 +08:00
|
|
|
return BLK_STS_IOERR;
|
2016-10-18 14:40:34 +08:00
|
|
|
|
|
|
|
if (sector & (sd_zbc_zone_sectors(sdkp) - 1))
|
|
|
|
/* Unaligned request */
|
2018-11-09 21:42:39 +08:00
|
|
|
return BLK_STS_IOERR;
|
2016-10-18 14:40:34 +08:00
|
|
|
|
|
|
|
cmd->cmd_len = 16;
|
|
|
|
memset(cmd->cmnd, 0, cmd->cmd_len);
|
|
|
|
cmd->cmnd[0] = ZBC_OUT;
|
2019-10-27 22:05:47 +08:00
|
|
|
cmd->cmnd[1] = op;
|
2019-08-02 01:26:37 +08:00
|
|
|
if (all)
|
|
|
|
cmd->cmnd[14] = 0x1;
|
|
|
|
else
|
|
|
|
put_unaligned_be64(block, &cmd->cmnd[2]);
|
2016-10-18 14:40:34 +08:00
|
|
|
|
|
|
|
rq->timeout = SD_TIMEOUT;
|
|
|
|
cmd->sc_data_direction = DMA_NONE;
|
|
|
|
cmd->transfersize = 0;
|
|
|
|
cmd->allowed = 0;
|
|
|
|
|
2018-11-09 21:42:39 +08:00
|
|
|
return BLK_STS_OK;
|
2016-10-18 14:40:34 +08:00
|
|
|
}
|
|
|
|
|
2017-10-11 04:54:22 +08:00
|
|
|
/**
|
|
|
|
* sd_zbc_complete - ZBC command post processing.
|
|
|
|
* @cmd: Completed command
|
|
|
|
* @good_bytes: Command reply bytes
|
|
|
|
* @sshdr: command sense header
|
|
|
|
*
|
|
|
|
* Called from sd_done(). Process report zones reply and handle reset zone
|
|
|
|
* and write commands errors.
|
|
|
|
*/
|
|
|
|
void sd_zbc_complete(struct scsi_cmnd *cmd, unsigned int good_bytes,
|
2016-10-18 14:40:34 +08:00
|
|
|
struct scsi_sense_hdr *sshdr)
|
|
|
|
{
|
|
|
|
int result = cmd->result;
|
|
|
|
struct request *rq = cmd->request;
|
|
|
|
|
2019-10-27 22:05:47 +08:00
|
|
|
if (op_is_zone_mgmt(req_op(rq)) &&
|
2019-10-27 22:05:44 +08:00
|
|
|
result &&
|
|
|
|
sshdr->sense_key == ILLEGAL_REQUEST &&
|
|
|
|
sshdr->asc == 0x24) {
|
|
|
|
/*
|
2019-10-27 22:05:47 +08:00
|
|
|
* INVALID FIELD IN CDB error: a zone management command was
|
|
|
|
* attempted on a conventional zone. Nothing to worry about,
|
|
|
|
* so be quiet about the error.
|
2019-10-27 22:05:44 +08:00
|
|
|
*/
|
|
|
|
rq->rq_flags |= RQF_QUIET;
|
2016-10-18 14:40:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-12 18:08:40 +08:00
|
|
|
* sd_zbc_check_zoned_characteristics - Check zoned block device characteristics
|
2017-10-11 04:54:22 +08:00
|
|
|
* @sdkp: Target disk
|
|
|
|
* @buf: Buffer where to store the VPD page data
|
|
|
|
*
|
2018-10-12 18:08:40 +08:00
|
|
|
* Read VPD page B6, get information and check that reads are unconstrained.
|
2016-10-18 14:40:34 +08:00
|
|
|
*/
|
2018-10-12 18:08:40 +08:00
|
|
|
static int sd_zbc_check_zoned_characteristics(struct scsi_disk *sdkp,
|
|
|
|
unsigned char *buf)
|
2016-10-18 14:40:34 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
if (scsi_get_vpd_page(sdkp->device, 0xb6, buf, 64)) {
|
|
|
|
sd_printk(KERN_NOTICE, sdkp,
|
2018-10-12 18:08:40 +08:00
|
|
|
"Read zoned characteristics VPD page failed\n");
|
2016-10-18 14:40:34 +08:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sdkp->device->type != TYPE_ZBC) {
|
|
|
|
/* Host-aware */
|
|
|
|
sdkp->urswrz = 1;
|
2017-10-11 04:54:25 +08:00
|
|
|
sdkp->zones_optimal_open = get_unaligned_be32(&buf[8]);
|
|
|
|
sdkp->zones_optimal_nonseq = get_unaligned_be32(&buf[12]);
|
2016-10-18 14:40:34 +08:00
|
|
|
sdkp->zones_max_open = 0;
|
|
|
|
} else {
|
|
|
|
/* Host-managed */
|
|
|
|
sdkp->urswrz = buf[4] & 1;
|
|
|
|
sdkp->zones_optimal_open = 0;
|
|
|
|
sdkp->zones_optimal_nonseq = 0;
|
2017-10-11 04:54:25 +08:00
|
|
|
sdkp->zones_max_open = get_unaligned_be32(&buf[16]);
|
2016-10-18 14:40:34 +08:00
|
|
|
}
|
|
|
|
|
2018-10-12 18:08:40 +08:00
|
|
|
/*
|
|
|
|
* Check for unconstrained reads: host-managed devices with
|
|
|
|
* constrained reads (drives failing read after write pointer)
|
|
|
|
* are not supported.
|
|
|
|
*/
|
|
|
|
if (!sdkp->urswrz) {
|
|
|
|
if (sdkp->first_scan)
|
|
|
|
sd_printk(KERN_NOTICE, sdkp,
|
|
|
|
"constrained reads devices are not supported\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2016-10-18 14:40:34 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-11 04:54:22 +08:00
|
|
|
/**
|
2019-12-20 15:58:23 +08:00
|
|
|
* sd_zbc_check_capacity - Check the device capacity
|
2017-10-11 04:54:22 +08:00
|
|
|
* @sdkp: Target disk
|
2019-12-20 15:58:23 +08:00
|
|
|
* @buf: command buffer
|
|
|
|
* @zblock: zone size in number of blocks
|
2017-10-11 04:54:22 +08:00
|
|
|
*
|
2019-12-20 15:58:23 +08:00
|
|
|
* Get the device zone size and check that the device capacity as reported
|
|
|
|
* by READ CAPACITY matches the max_lba value (plus one) of the report zones
|
|
|
|
* command reply for devices with RC_BASIS == 0.
|
2018-04-17 09:04:41 +08:00
|
|
|
*
|
2019-12-20 15:58:23 +08:00
|
|
|
* Returns 0 upon success or an error code upon failure.
|
2017-10-11 04:54:22 +08:00
|
|
|
*/
|
2019-12-20 15:58:23 +08:00
|
|
|
static int sd_zbc_check_capacity(struct scsi_disk *sdkp, unsigned char *buf,
|
|
|
|
u32 *zblocks)
|
2016-10-18 14:40:34 +08:00
|
|
|
{
|
2019-12-20 15:58:23 +08:00
|
|
|
u64 zone_blocks;
|
block: Enhance blk_revalidate_disk_zones()
For ZBC and ZAC zoned devices, the scsi driver revalidation processing
implemented by sd_revalidate_disk() includes a call to
sd_zbc_read_zones() which executes a full disk zone report used to
check that all zones of the disk are the same size. This processing is
followed by a call to blk_revalidate_disk_zones(), used to initialize
the device request queue zone bitmaps (zone type and zone write lock
bitmaps). To do so, blk_revalidate_disk_zones() also executes a full
device zone report to obtain zone types. As a result, the entire
zoned block device revalidation process includes two full device zone
report.
By moving the zone size checks into blk_revalidate_disk_zones(), this
process can be optimized to a single full device zone report, leading to
shorter device scan and revalidation times. This patch implements this
optimization, reducing the original full device zone report implemented
in sd_zbc_check_zones() to a single, small, report zones command
execution to obtain the size of the first zone of the device. Checks
whether all zones of the device are the same size as the first zone
size are moved to the generic blk_check_zone() function called from
blk_revalidate_disk_zones().
This optimization also has the following benefits:
1) fewer memory allocations in the scsi layer during disk revalidation
as the potentailly large buffer for zone report execution is not
needed.
2) Implement zone checks in a generic manner, reducing the burden on
device driver which only need to obtain the zone size and check that
this size is a power of 2 number of LBAs. Any new type of zoned
block device will benefit from this.
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2019-11-11 10:39:22 +08:00
|
|
|
sector_t max_lba;
|
2016-10-18 14:40:34 +08:00
|
|
|
unsigned char *rec;
|
2018-10-12 18:08:42 +08:00
|
|
|
int ret;
|
2019-07-01 13:09:17 +08:00
|
|
|
|
block: Enhance blk_revalidate_disk_zones()
For ZBC and ZAC zoned devices, the scsi driver revalidation processing
implemented by sd_revalidate_disk() includes a call to
sd_zbc_read_zones() which executes a full disk zone report used to
check that all zones of the disk are the same size. This processing is
followed by a call to blk_revalidate_disk_zones(), used to initialize
the device request queue zone bitmaps (zone type and zone write lock
bitmaps). To do so, blk_revalidate_disk_zones() also executes a full
device zone report to obtain zone types. As a result, the entire
zoned block device revalidation process includes two full device zone
report.
By moving the zone size checks into blk_revalidate_disk_zones(), this
process can be optimized to a single full device zone report, leading to
shorter device scan and revalidation times. This patch implements this
optimization, reducing the original full device zone report implemented
in sd_zbc_check_zones() to a single, small, report zones command
execution to obtain the size of the first zone of the device. Checks
whether all zones of the device are the same size as the first zone
size are moved to the generic blk_check_zone() function called from
blk_revalidate_disk_zones().
This optimization also has the following benefits:
1) fewer memory allocations in the scsi layer during disk revalidation
as the potentailly large buffer for zone report execution is not
needed.
2) Implement zone checks in a generic manner, reducing the burden on
device driver which only need to obtain the zone size and check that
this size is a power of 2 number of LBAs. Any new type of zoned
block device will benefit from this.
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2019-11-11 10:39:22 +08:00
|
|
|
/* Do a report zone to get max_lba and the size of the first zone */
|
|
|
|
ret = sd_zbc_do_report_zones(sdkp, buf, SD_BUF_SIZE, 0, false);
|
2018-03-02 06:19:28 +08:00
|
|
|
if (ret)
|
block: Enhance blk_revalidate_disk_zones()
For ZBC and ZAC zoned devices, the scsi driver revalidation processing
implemented by sd_revalidate_disk() includes a call to
sd_zbc_read_zones() which executes a full disk zone report used to
check that all zones of the disk are the same size. This processing is
followed by a call to blk_revalidate_disk_zones(), used to initialize
the device request queue zone bitmaps (zone type and zone write lock
bitmaps). To do so, blk_revalidate_disk_zones() also executes a full
device zone report to obtain zone types. As a result, the entire
zoned block device revalidation process includes two full device zone
report.
By moving the zone size checks into blk_revalidate_disk_zones(), this
process can be optimized to a single full device zone report, leading to
shorter device scan and revalidation times. This patch implements this
optimization, reducing the original full device zone report implemented
in sd_zbc_check_zones() to a single, small, report zones command
execution to obtain the size of the first zone of the device. Checks
whether all zones of the device are the same size as the first zone
size are moved to the generic blk_check_zone() function called from
blk_revalidate_disk_zones().
This optimization also has the following benefits:
1) fewer memory allocations in the scsi layer during disk revalidation
as the potentailly large buffer for zone report execution is not
needed.
2) Implement zone checks in a generic manner, reducing the burden on
device driver which only need to obtain the zone size and check that
this size is a power of 2 number of LBAs. Any new type of zoned
block device will benefit from this.
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2019-11-11 10:39:22 +08:00
|
|
|
return ret;
|
2016-10-18 14:40:34 +08:00
|
|
|
|
2018-10-12 18:08:41 +08:00
|
|
|
if (sdkp->rc_basis == 0) {
|
|
|
|
/* The max_lba field is the capacity of this device */
|
|
|
|
max_lba = get_unaligned_be64(&buf[8]);
|
|
|
|
if (sdkp->capacity != max_lba + 1) {
|
|
|
|
if (sdkp->first_scan)
|
|
|
|
sd_printk(KERN_WARNING, sdkp,
|
|
|
|
"Changing capacity from %llu to max LBA+1 %llu\n",
|
|
|
|
(unsigned long long)sdkp->capacity,
|
|
|
|
(unsigned long long)max_lba + 1);
|
|
|
|
sdkp->capacity = max_lba + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-20 15:58:23 +08:00
|
|
|
/* Get the size of the first reported zone */
|
block: Enhance blk_revalidate_disk_zones()
For ZBC and ZAC zoned devices, the scsi driver revalidation processing
implemented by sd_revalidate_disk() includes a call to
sd_zbc_read_zones() which executes a full disk zone report used to
check that all zones of the disk are the same size. This processing is
followed by a call to blk_revalidate_disk_zones(), used to initialize
the device request queue zone bitmaps (zone type and zone write lock
bitmaps). To do so, blk_revalidate_disk_zones() also executes a full
device zone report to obtain zone types. As a result, the entire
zoned block device revalidation process includes two full device zone
report.
By moving the zone size checks into blk_revalidate_disk_zones(), this
process can be optimized to a single full device zone report, leading to
shorter device scan and revalidation times. This patch implements this
optimization, reducing the original full device zone report implemented
in sd_zbc_check_zones() to a single, small, report zones command
execution to obtain the size of the first zone of the device. Checks
whether all zones of the device are the same size as the first zone
size are moved to the generic blk_check_zone() function called from
blk_revalidate_disk_zones().
This optimization also has the following benefits:
1) fewer memory allocations in the scsi layer during disk revalidation
as the potentailly large buffer for zone report execution is not
needed.
2) Implement zone checks in a generic manner, reducing the burden on
device driver which only need to obtain the zone size and check that
this size is a power of 2 number of LBAs. Any new type of zoned
block device will benefit from this.
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2019-11-11 10:39:22 +08:00
|
|
|
rec = buf + 64;
|
|
|
|
zone_blocks = get_unaligned_be64(&rec[8]);
|
|
|
|
if (logical_to_sectors(sdkp->device, zone_blocks) > UINT_MAX) {
|
2016-10-18 14:40:34 +08:00
|
|
|
if (sdkp->first_scan)
|
|
|
|
sd_printk(KERN_NOTICE, sdkp,
|
|
|
|
"Zone size too large\n");
|
block: Enhance blk_revalidate_disk_zones()
For ZBC and ZAC zoned devices, the scsi driver revalidation processing
implemented by sd_revalidate_disk() includes a call to
sd_zbc_read_zones() which executes a full disk zone report used to
check that all zones of the disk are the same size. This processing is
followed by a call to blk_revalidate_disk_zones(), used to initialize
the device request queue zone bitmaps (zone type and zone write lock
bitmaps). To do so, blk_revalidate_disk_zones() also executes a full
device zone report to obtain zone types. As a result, the entire
zoned block device revalidation process includes two full device zone
report.
By moving the zone size checks into blk_revalidate_disk_zones(), this
process can be optimized to a single full device zone report, leading to
shorter device scan and revalidation times. This patch implements this
optimization, reducing the original full device zone report implemented
in sd_zbc_check_zones() to a single, small, report zones command
execution to obtain the size of the first zone of the device. Checks
whether all zones of the device are the same size as the first zone
size are moved to the generic blk_check_zone() function called from
blk_revalidate_disk_zones().
This optimization also has the following benefits:
1) fewer memory allocations in the scsi layer during disk revalidation
as the potentailly large buffer for zone report execution is not
needed.
2) Implement zone checks in a generic manner, reducing the burden on
device driver which only need to obtain the zone size and check that
this size is a power of 2 number of LBAs. Any new type of zoned
block device will benefit from this.
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2019-11-11 10:39:22 +08:00
|
|
|
return -EFBIG;
|
2016-10-18 14:40:34 +08:00
|
|
|
}
|
|
|
|
|
block: Enhance blk_revalidate_disk_zones()
For ZBC and ZAC zoned devices, the scsi driver revalidation processing
implemented by sd_revalidate_disk() includes a call to
sd_zbc_read_zones() which executes a full disk zone report used to
check that all zones of the disk are the same size. This processing is
followed by a call to blk_revalidate_disk_zones(), used to initialize
the device request queue zone bitmaps (zone type and zone write lock
bitmaps). To do so, blk_revalidate_disk_zones() also executes a full
device zone report to obtain zone types. As a result, the entire
zoned block device revalidation process includes two full device zone
report.
By moving the zone size checks into blk_revalidate_disk_zones(), this
process can be optimized to a single full device zone report, leading to
shorter device scan and revalidation times. This patch implements this
optimization, reducing the original full device zone report implemented
in sd_zbc_check_zones() to a single, small, report zones command
execution to obtain the size of the first zone of the device. Checks
whether all zones of the device are the same size as the first zone
size are moved to the generic blk_check_zone() function called from
blk_revalidate_disk_zones().
This optimization also has the following benefits:
1) fewer memory allocations in the scsi layer during disk revalidation
as the potentailly large buffer for zone report execution is not
needed.
2) Implement zone checks in a generic manner, reducing the burden on
device driver which only need to obtain the zone size and check that
this size is a power of 2 number of LBAs. Any new type of zoned
block device will benefit from this.
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2019-11-11 10:39:22 +08:00
|
|
|
*zblocks = zone_blocks;
|
2016-10-18 14:40:34 +08:00
|
|
|
|
block: Enhance blk_revalidate_disk_zones()
For ZBC and ZAC zoned devices, the scsi driver revalidation processing
implemented by sd_revalidate_disk() includes a call to
sd_zbc_read_zones() which executes a full disk zone report used to
check that all zones of the disk are the same size. This processing is
followed by a call to blk_revalidate_disk_zones(), used to initialize
the device request queue zone bitmaps (zone type and zone write lock
bitmaps). To do so, blk_revalidate_disk_zones() also executes a full
device zone report to obtain zone types. As a result, the entire
zoned block device revalidation process includes two full device zone
report.
By moving the zone size checks into blk_revalidate_disk_zones(), this
process can be optimized to a single full device zone report, leading to
shorter device scan and revalidation times. This patch implements this
optimization, reducing the original full device zone report implemented
in sd_zbc_check_zones() to a single, small, report zones command
execution to obtain the size of the first zone of the device. Checks
whether all zones of the device are the same size as the first zone
size are moved to the generic blk_check_zone() function called from
blk_revalidate_disk_zones().
This optimization also has the following benefits:
1) fewer memory allocations in the scsi layer during disk revalidation
as the potentailly large buffer for zone report execution is not
needed.
2) Implement zone checks in a generic manner, reducing the burden on
device driver which only need to obtain the zone size and check that
this size is a power of 2 number of LBAs. Any new type of zoned
block device will benefit from this.
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2019-11-11 10:39:22 +08:00
|
|
|
return 0;
|
2016-10-18 14:40:34 +08:00
|
|
|
}
|
|
|
|
|
2017-10-11 04:54:22 +08:00
|
|
|
int sd_zbc_read_zones(struct scsi_disk *sdkp, unsigned char *buf)
|
2016-10-18 14:40:34 +08:00
|
|
|
{
|
2018-10-12 18:08:50 +08:00
|
|
|
struct gendisk *disk = sdkp->disk;
|
|
|
|
unsigned int nr_zones;
|
2019-07-17 09:51:49 +08:00
|
|
|
u32 zone_blocks = 0;
|
2017-04-24 15:51:14 +08:00
|
|
|
int ret;
|
2016-10-18 14:40:34 +08:00
|
|
|
|
|
|
|
if (!sd_is_zoned(sdkp))
|
|
|
|
/*
|
|
|
|
* Device managed or normal SCSI disk,
|
|
|
|
* no special handling required
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
|
2018-10-12 18:08:40 +08:00
|
|
|
/* Check zoned block device characteristics (unconstrained reads) */
|
|
|
|
ret = sd_zbc_check_zoned_characteristics(sdkp, buf);
|
2016-10-18 14:40:34 +08:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
2019-12-20 15:58:23 +08:00
|
|
|
/* Check the device capacity reported by report zones */
|
|
|
|
ret = sd_zbc_check_capacity(sdkp, buf, &zone_blocks);
|
2018-10-12 18:08:42 +08:00
|
|
|
if (ret != 0)
|
2016-10-18 14:40:34 +08:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* The drive satisfies the kernel restrictions: set it up */
|
2019-08-02 01:26:37 +08:00
|
|
|
blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, sdkp->disk->queue);
|
2019-09-05 17:51:35 +08:00
|
|
|
blk_queue_required_elevator_features(sdkp->disk->queue,
|
|
|
|
ELEVATOR_F_ZBD_SEQ_WRITE);
|
2018-10-12 18:08:50 +08:00
|
|
|
nr_zones = round_up(sdkp->capacity, zone_blocks) >> ilog2(zone_blocks);
|
|
|
|
|
|
|
|
/* READ16/WRITE16 is mandatory for ZBC disks */
|
|
|
|
sdkp->device->use_16_for_rw = 1;
|
|
|
|
sdkp->device->use_10_for_rw = 0;
|
|
|
|
|
|
|
|
/*
|
2019-01-30 14:54:58 +08:00
|
|
|
* Revalidate the disk zone bitmaps once the block device capacity is
|
|
|
|
* set on the second revalidate execution during disk scan and if
|
|
|
|
* something changed when executing a normal revalidate.
|
2018-10-12 18:08:50 +08:00
|
|
|
*/
|
2019-01-30 14:54:58 +08:00
|
|
|
if (sdkp->first_scan) {
|
|
|
|
sdkp->zone_blocks = zone_blocks;
|
|
|
|
sdkp->nr_zones = nr_zones;
|
2018-10-12 18:08:50 +08:00
|
|
|
return 0;
|
2019-01-30 14:54:58 +08:00
|
|
|
}
|
|
|
|
|
2018-10-12 18:08:50 +08:00
|
|
|
if (sdkp->zone_blocks != zone_blocks ||
|
|
|
|
sdkp->nr_zones != nr_zones ||
|
|
|
|
disk->queue->nr_zones != nr_zones) {
|
|
|
|
ret = blk_revalidate_disk_zones(disk);
|
|
|
|
if (ret != 0)
|
|
|
|
goto err;
|
|
|
|
sdkp->zone_blocks = zone_blocks;
|
|
|
|
sdkp->nr_zones = nr_zones;
|
|
|
|
}
|
2016-10-18 14:40:34 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
sdkp->capacity = 0;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sd_zbc_print_zones(struct scsi_disk *sdkp)
|
|
|
|
{
|
|
|
|
if (!sd_is_zoned(sdkp) || !sdkp->capacity)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (sdkp->capacity & (sdkp->zone_blocks - 1))
|
|
|
|
sd_printk(KERN_NOTICE, sdkp,
|
|
|
|
"%u zones of %u logical blocks + 1 runt zone\n",
|
|
|
|
sdkp->nr_zones - 1,
|
|
|
|
sdkp->zone_blocks);
|
|
|
|
else
|
|
|
|
sd_printk(KERN_NOTICE, sdkp,
|
|
|
|
"%u zones of %u logical blocks\n",
|
|
|
|
sdkp->nr_zones,
|
|
|
|
sdkp->zone_blocks);
|
|
|
|
}
|