linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: Fix partition support for host aware zoned block devices
@ 2020-02-19  4:26 Shin'ichiro Kawasaki
  2020-02-19  8:37 ` Damien Le Moal
  2020-02-19 16:28 ` Christoph Hellwig
  0 siblings, 2 replies; 4+ messages in thread
From: Shin'ichiro Kawasaki @ 2020-02-19  4:26 UTC (permalink / raw)
  To: linux-block, Jens Axboe; +Cc: Damien Le Moal, Shinichiro Kawasaki

Commit b72053072c0b ("block: allow partitions on host aware zone
devices") introduced the helper function disk_has_partitions() to check
if a given disk has valid partitions. However, since this function result
directly depends on the disk partition table length rather than the
actual existence of valid partitions in the table, it returns true even
after all partitions are removed from the disk. For host aware zoned
block devices, this results in zone management support to be kept
disabled even after removing all partitions.

Fix this by changing disk_has_partitions() to walk through the partition
table entries and return true if and only if a valid non-zero size
partition is found.

Fixes: b72053072c0b ("block: allow partitions on host aware zone devices")
Cc: stable@vger.kernel.org # 5.5
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
 block/genhd.c         | 36 ++++++++++++++++++++++++++++++++++++
 include/linux/genhd.h | 13 +------------
 2 files changed, 37 insertions(+), 12 deletions(-)

diff --git a/block/genhd.c b/block/genhd.c
index ff6268970ddc..ed8cdebc2cf0 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -301,6 +301,42 @@ struct hd_struct *disk_map_sector_rcu(struct gendisk *disk, sector_t sector)
 }
 EXPORT_SYMBOL_GPL(disk_map_sector_rcu);
 
+/**
+ * disk_has_partitions
+ * @disk: gendisk of interest
+ *
+ * Walk through the partition table and check if valid partition exists.
+ *
+ * CONTEXT:
+ * Don't care.
+ *
+ * RETURNS:
+ * True if the gendisk has at least one valid non-zero size partition.
+ * Otherwise false.
+ */
+bool disk_has_partitions(struct gendisk *disk)
+{
+	struct disk_part_tbl *ptbl;
+	int i;
+	bool ret = false;
+
+	rcu_read_lock();
+	ptbl = rcu_dereference(disk->part_tbl);
+
+	/* Iterate partitions skipping the holder device at index 0 */
+	for (i = 1; i < ptbl->len; i++) {
+		if (rcu_dereference(ptbl->part[i])) {
+			ret = true;
+			break;
+		}
+	}
+
+	rcu_read_unlock();
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(disk_has_partitions);
+
 /*
  * Can be deleted altogether. Later.
  *
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 6fbe58538ad6..f1b5c86b096a 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -245,18 +245,6 @@ 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);
@@ -298,6 +286,7 @@ extern void disk_part_iter_exit(struct disk_part_iter *piter);
 
 extern struct hd_struct *disk_map_sector_rcu(struct gendisk *disk,
 					     sector_t sector);
+extern bool disk_has_partitions(struct gendisk *disk);
 
 /*
  * Macros to operate on percpu disk statistics:
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] block: Fix partition support for host aware zoned block devices
  2020-02-19  4:26 [PATCH] block: Fix partition support for host aware zoned block devices Shin'ichiro Kawasaki
@ 2020-02-19  8:37 ` Damien Le Moal
  2020-02-19 16:28 ` Christoph Hellwig
  1 sibling, 0 replies; 4+ messages in thread
From: Damien Le Moal @ 2020-02-19  8:37 UTC (permalink / raw)
  To: Shinichiro Kawasaki, linux-block, Jens Axboe

On 2020/02/19 13:26, Shin'ichiro Kawasaki wrote:
> Commit b72053072c0b ("block: allow partitions on host aware zone
> devices") introduced the helper function disk_has_partitions() to check
> if a given disk has valid partitions. However, since this function result
> directly depends on the disk partition table length rather than the
> actual existence of valid partitions in the table, it returns true even
> after all partitions are removed from the disk. For host aware zoned
> block devices, this results in zone management support to be kept
> disabled even after removing all partitions.
> 
> Fix this by changing disk_has_partitions() to walk through the partition
> table entries and return true if and only if a valid non-zero size
> partition is found.
> 
> Fixes: b72053072c0b ("block: allow partitions on host aware zone devices")
> Cc: stable@vger.kernel.org # 5.5
> Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>

Looks good to me.

Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>


> ---
>  block/genhd.c         | 36 ++++++++++++++++++++++++++++++++++++
>  include/linux/genhd.h | 13 +------------
>  2 files changed, 37 insertions(+), 12 deletions(-)
> 
> diff --git a/block/genhd.c b/block/genhd.c
> index ff6268970ddc..ed8cdebc2cf0 100644
> --- a/block/genhd.c
> +++ b/block/genhd.c
> @@ -301,6 +301,42 @@ struct hd_struct *disk_map_sector_rcu(struct gendisk *disk, sector_t sector)
>  }
>  EXPORT_SYMBOL_GPL(disk_map_sector_rcu);
>  
> +/**
> + * disk_has_partitions
> + * @disk: gendisk of interest
> + *
> + * Walk through the partition table and check if valid partition exists.
> + *
> + * CONTEXT:
> + * Don't care.
> + *
> + * RETURNS:
> + * True if the gendisk has at least one valid non-zero size partition.
> + * Otherwise false.
> + */
> +bool disk_has_partitions(struct gendisk *disk)
> +{
> +	struct disk_part_tbl *ptbl;
> +	int i;
> +	bool ret = false;
> +
> +	rcu_read_lock();
> +	ptbl = rcu_dereference(disk->part_tbl);
> +
> +	/* Iterate partitions skipping the holder device at index 0 */
> +	for (i = 1; i < ptbl->len; i++) {
> +		if (rcu_dereference(ptbl->part[i])) {
> +			ret = true;
> +			break;
> +		}
> +	}
> +
> +	rcu_read_unlock();
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(disk_has_partitions);
> +
>  /*
>   * Can be deleted altogether. Later.
>   *
> diff --git a/include/linux/genhd.h b/include/linux/genhd.h
> index 6fbe58538ad6..f1b5c86b096a 100644
> --- a/include/linux/genhd.h
> +++ b/include/linux/genhd.h
> @@ -245,18 +245,6 @@ 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);
> @@ -298,6 +286,7 @@ extern void disk_part_iter_exit(struct disk_part_iter *piter);
>  
>  extern struct hd_struct *disk_map_sector_rcu(struct gendisk *disk,
>  					     sector_t sector);
> +extern bool disk_has_partitions(struct gendisk *disk);
>  
>  /*
>   * Macros to operate on percpu disk statistics:
> 


-- 
Damien Le Moal
Western Digital Research

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] block: Fix partition support for host aware zoned block devices
  2020-02-19  4:26 [PATCH] block: Fix partition support for host aware zoned block devices Shin'ichiro Kawasaki
  2020-02-19  8:37 ` Damien Le Moal
@ 2020-02-19 16:28 ` Christoph Hellwig
  2020-02-20  8:36   ` Shinichiro Kawasaki
  1 sibling, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2020-02-19 16:28 UTC (permalink / raw)
  To: Shin'ichiro Kawasaki; +Cc: linux-block, Jens Axboe, Damien Le Moal

On Wed, Feb 19, 2020 at 01:26:32PM +0900, Shin'ichiro Kawasaki wrote:
> +	/* Iterate partitions skipping the holder device at index 0 */

s/holder/whole/ ?

> +extern bool disk_has_partitions(struct gendisk *disk);

No need for externs on function prototypes in headers.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] block: Fix partition support for host aware zoned block devices
  2020-02-19 16:28 ` Christoph Hellwig
@ 2020-02-20  8:36   ` Shinichiro Kawasaki
  0 siblings, 0 replies; 4+ messages in thread
From: Shinichiro Kawasaki @ 2020-02-20  8:36 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-block, Jens Axboe, Damien Le Moal

On Feb 19, 2020 / 08:28, Christoph Hellwig wrote:
> On Wed, Feb 19, 2020 at 01:26:32PM +0900, Shin'ichiro Kawasaki wrote:
> > +	/* Iterate partitions skipping the holder device at index 0 */
> 
> s/holder/whole/ ?

Ok, 'whole device' sounds more natural.

> 
> > +extern bool disk_has_partitions(struct gendisk *disk);
> 
> No need for externs on function prototypes in headers.

Thanks. I found that coding-style.rst says "Do not use the extern keyword with
function prototypes".

Will reflect to the v2 patch.

--
Best Regards,
Shin'ichiro Kawasaki

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-02-20  8:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-19  4:26 [PATCH] block: Fix partition support for host aware zoned block devices Shin'ichiro Kawasaki
2020-02-19  8:37 ` Damien Le Moal
2020-02-19 16:28 ` Christoph Hellwig
2020-02-20  8:36   ` Shinichiro Kawasaki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).