Skip to content

Commit

Permalink
scsi: sd: Add zoned capabilities device attribute
Browse files Browse the repository at this point in the history
Export through sysfs as a scsi_disk attribute the zoned capabilities of a
disk ("zoned_cap" attribute file). This new attribute indicates in human
readable form (i.e. a string) the zoned block capabilities implemented by
the disk as found in the ZONED field of the disk block device
characteristics VPD page. The possible values are:

 - "none": ZONED=00b (not reported), regular disk

 - "host-aware": ZONED=01b, host-aware ZBC disk

 - "drive-managed": ZONED=10b, drive-managed ZBC disk (regular disk
   interface)

For completeness, also add the following value which is detected using the
device type rather than the ZONED field:

 - "host-managed": device type = 0x14 (TYPE_ZBC), host-managed ZBC disk

This new sysfs attribute is purely informational and complementary to the
"zoned" device request queue sysfs attribute as it allows applications and
user daemons (e.g.  udev) to easily differentiate regular disks from
drive-managed SMR disks without the need for direct access tools such as
provided by sg3utils.

Link: https://lore.kernel.org/r/[email protected]
Reviewed-by: Johannes Thumshirn <[email protected]>
Signed-off-by: Damien Le Moal <[email protected]>
Signed-off-by: Martin K. Petersen <[email protected]>
  • Loading branch information
damien-lemoal authored and martinkpetersen committed May 20, 2020
1 parent 5cac109 commit c5f8852
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions drivers/scsi/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,21 @@ max_write_same_blocks_store(struct device *dev, struct device_attribute *attr,
}
static DEVICE_ATTR_RW(max_write_same_blocks);

static ssize_t
zoned_cap_show(struct device *dev, struct device_attribute *attr, char *buf)
{
struct scsi_disk *sdkp = to_scsi_disk(dev);

if (sdkp->device->type == TYPE_ZBC)
return sprintf(buf, "host-managed\n");
if (sdkp->zoned == 1)
return sprintf(buf, "host-aware\n");
if (sdkp->zoned == 2)
return sprintf(buf, "drive-managed\n");
return sprintf(buf, "none\n");
}
static DEVICE_ATTR_RO(zoned_cap);

static struct attribute *sd_disk_attrs[] = {
&dev_attr_cache_type.attr,
&dev_attr_FUA.attr,
Expand All @@ -541,6 +556,7 @@ static struct attribute *sd_disk_attrs[] = {
&dev_attr_zeroing_mode.attr,
&dev_attr_max_write_same_blocks.attr,
&dev_attr_max_medium_access_timeouts.attr,
&dev_attr_zoned_cap.attr,
NULL,
};
ATTRIBUTE_GROUPS(sd_disk);
Expand Down

0 comments on commit c5f8852

Please sign in to comment.