Skip to content

Commit

Permalink
block: allow partitions on host aware zone devices
Browse files Browse the repository at this point in the history
Host-aware SMR drives can be used with the commands to explicitly manage
zone state, but they can also be used as normal disks.  In the former
case it makes perfect sense to allow partitions on them, in the latter
it does not, just like for host managed devices.  Add a check to
add_partition to allow partitions on host aware devices, but give
up any zone management capabilities in that case, which also catches
the previously missed case of adding a partition vs just scanning it.

Because sd can rescan the attribute at runtime it needs to check if
a disk has partitions, for which a new helper is added to genhd.h.

Fixes: 5eac3eb ("block: Remove partition support for zoned block devices")
Reported-by: Borislav Petkov <[email protected]>
Signed-off-by: Christoph Hellwig <[email protected]>
Tested-by: Damien Le Moal <[email protected]>
Reviewed-by: Damien Le Moal <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Christoph Hellwig authored and axboe committed Jan 26, 2020
1 parent ad6bf88 commit b720530
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
26 changes: 22 additions & 4 deletions block/partition-generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,24 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
const char *dname;
int err;

/*
* Partitions are not supported on zoned block devices that are used as
* such.
*/
switch (disk->queue->limits.zoned) {
case BLK_ZONED_HM:
pr_warn("%s: partitions not supported on host managed zoned block device\n",
disk->disk_name);
return ERR_PTR(-ENXIO);
case BLK_ZONED_HA:
pr_info("%s: disabling host aware zoned block device support due to partitions\n",
disk->disk_name);
disk->queue->limits.zoned = BLK_ZONED_NONE;
break;
case BLK_ZONED_NONE:
break;
}

err = disk_expand_part_tbl(disk, partno);
if (err)
return ERR_PTR(err);
Expand Down Expand Up @@ -501,7 +519,7 @@ static bool blk_add_partition(struct gendisk *disk, struct block_device *bdev,

part = add_partition(disk, p, from, size, state->parts[p].flags,
&state->parts[p].info);
if (IS_ERR(part)) {
if (IS_ERR(part) && PTR_ERR(part) != -ENXIO) {
printk(KERN_ERR " %s: p%d could not be added: %ld\n",
disk->disk_name, p, -PTR_ERR(part));
return true;
Expand Down Expand Up @@ -540,10 +558,10 @@ int blk_add_partitions(struct gendisk *disk, struct block_device *bdev)
}

/*
* Partitions are not supported on zoned block devices.
* Partitions are not supported on host managed zoned block devices.
*/
if (bdev_is_zoned(bdev)) {
pr_warn("%s: ignoring partition table on zoned block device\n",
if (disk->queue->limits.zoned == BLK_ZONED_HM) {
pr_warn("%s: ignoring partition table on host managed zoned block device\n",
disk->disk_name);
ret = 0;
goto out_free_state;
Expand Down
9 changes: 5 additions & 4 deletions drivers/scsi/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2956,15 +2956,16 @@ static void sd_read_block_characteristics(struct scsi_disk *sdkp)
q->limits.zoned = BLK_ZONED_HM;
} else {
sdkp->zoned = (buffer[8] >> 4) & 3;
if (sdkp->zoned == 1)
if (sdkp->zoned == 1 && !disk_has_partitions(sdkp->disk)) {
/* Host-aware */
q->limits.zoned = BLK_ZONED_HA;
else
} else {
/*
* Treat drive-managed devices as
* regular block devices.
* Treat drive-managed devices and host-aware devices
* with partitions as regular block devices.
*/
q->limits.zoned = BLK_ZONED_NONE;
}
}
if (blk_queue_is_zoned(q) && sdkp->first_scan)
sd_printk(KERN_NOTICE, sdkp, "Host-%s zoned block device\n",
Expand Down
12 changes: 12 additions & 0 deletions include/linux/genhd.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,18 @@ static inline bool disk_part_scan_enabled(struct gendisk *disk)
!(disk->flags & GENHD_FL_NO_PART_SCAN);
}

static inline bool disk_has_partitions(struct gendisk *disk)
{
bool ret = false;

rcu_read_lock();
if (rcu_dereference(disk->part_tbl)->len > 1)
ret = true;
rcu_read_unlock();

return ret;
}

static inline dev_t disk_devt(struct gendisk *disk)
{
return MKDEV(disk->major, disk->first_minor);
Expand Down

0 comments on commit b720530

Please sign in to comment.