On Sat, Oct 16, 2021 at 06:34:50AM +0200, Christoph Hellwig wrote: > On Fri, Oct 15, 2021 at 11:07:40AM +0900, Shin'ichiro Kawasaki wrote: > > To fix the issues, call the helper function disk_has_partitions() in > > place of disk->part_tbl empty check. Since the function was removed with > > the commit a33df75c6328, reimplement it to walk through entries in the > > xarray disk->part_tbl. > > Looks good, > > Reviewed-by: Christoph Hellwig <hch@xxxxxx> > > Matthew, > > we talked about possiblig adding a xa_nr_entries helper a while ago. > This would be a good place for it, as we could just check > xa_nr_entries() > 1 for example. Do I understand the problem correctly, that you don't actually want to know whether there's more than one entry in the array, but rather that there's an entry at an index other than 0? If so, that's an easy question to answer, we just don't have a helper for it yet. Something like this should do: static inline bool xa_is_trivial(const struct xarray *xa) { void *entry = READ_ONCE(xa->xa_head); return entry || !xa_is_node(entry); } Probably needs a better name than that. > > > > Fixes: a33df75c6328 ("block: use an xarray for disk->part_tbl") > > Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@xxxxxxx> > > Cc: stable@xxxxxxxxxxxxxxx # v5.14+ > > --- > > block/blk-settings.c | 20 +++++++++++++++++++- > > 1 file changed, 19 insertions(+), 1 deletion(-) > > > > diff --git a/block/blk-settings.c b/block/blk-settings.c > > index a7c857ad7d10..b880c70e22e4 100644 > > --- a/block/blk-settings.c > > +++ b/block/blk-settings.c > > @@ -842,6 +842,24 @@ bool blk_queue_can_use_dma_map_merging(struct request_queue *q, > > } > > EXPORT_SYMBOL_GPL(blk_queue_can_use_dma_map_merging); > > > > +static bool disk_has_partitions(struct gendisk *disk) > > +{ > > + unsigned long idx; > > + struct block_device *part; > > + bool ret = false; > > + > > + rcu_read_lock(); > > + xa_for_each(&disk->part_tbl, idx, part) { > > + if (bdev_is_partition(part)) { > > + ret = true; > > + break; > > + } > > + } > > + rcu_read_unlock(); > > + > > + return ret; > > +} > > + > > /** > > * blk_queue_set_zoned - configure a disk queue zoned model. > > * @disk: the gendisk of the queue to configure > > @@ -876,7 +894,7 @@ void blk_queue_set_zoned(struct gendisk *disk, enum blk_zoned_model model) > > * we do nothing special as far as the block layer is concerned. > > */ > > if (!IS_ENABLED(CONFIG_BLK_DEV_ZONED) || > > - !xa_empty(&disk->part_tbl)) > > + disk_has_partitions(disk)) > > model = BLK_ZONED_NONE; > > break; > > case BLK_ZONED_NONE: > > -- > > 2.31.1 > ---end quoted text---