diff mbox series

btrfs: zoned: fix btrfs_can_activate_zone() to support DUP profile

Message ID b0e431dcee052cd66decba8a4484d28055d5d843.1678692557.git.naohiro.aota@wdc.com (mailing list archive)
State New, archived
Headers show
Series btrfs: zoned: fix btrfs_can_activate_zone() to support DUP profile | expand

Commit Message

Naohiro Aota March 13, 2023, 7:29 a.m. UTC
btrfs_can_activate_zone() returns true if at least one device has one zone
available for activation. This is OK for the single profile, but not OK for
DUP profile. We need two zones to create a DUP block group. Fix it buy
properly handle the case with the profile flags.

Fixes: 265f7237dd25 ("btrfs: zoned: allow DUP on meta-data block groups")
CC: stable@vger.kernel.org # 6.1+
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 fs/btrfs/zoned.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

Comments

Johannes Thumshirn March 13, 2023, 8:45 a.m. UTC | #1
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
David Sterba March 14, 2023, 5:49 p.m. UTC | #2
On Mon, Mar 13, 2023 at 04:29:49PM +0900, Naohiro Aota wrote:
> btrfs_can_activate_zone() returns true if at least one device has one zone
> available for activation. This is OK for the single profile, but not OK for
> DUP profile. We need two zones to create a DUP block group. Fix it buy
> properly handle the case with the profile flags.
> 
> Fixes: 265f7237dd25 ("btrfs: zoned: allow DUP on meta-data block groups")
> CC: stable@vger.kernel.org # 6.1+
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>

Added to misc-next, thanks.

> ---
>  fs/btrfs/zoned.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
> index f3fcc3e09550..f7397680cde9 100644
> --- a/fs/btrfs/zoned.c
> +++ b/fs/btrfs/zoned.c
> @@ -2099,11 +2099,21 @@ bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags)
>  		if (!device->bdev)
>  			continue;
>  
> -		if (!zinfo->max_active_zones ||
> -		    atomic_read(&zinfo->active_zones_left)) {
> +		if (!zinfo->max_active_zones) {
>  			ret = true;
>  			break;
>  		}
> +
> +		switch (flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) {
> +		case 0: /* single */
> +			ret = atomic_read(&zinfo->active_zones_left) >= 1;

With ( ) around the expression it's more obvious that it's not a simple
assignment:

			ret = (atomic_read(&zinfo->active_zones_left) >= 1);

Updated in the commit.
diff mbox series

Patch

diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index f3fcc3e09550..f7397680cde9 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -2099,11 +2099,21 @@  bool btrfs_can_activate_zone(struct btrfs_fs_devices *fs_devices, u64 flags)
 		if (!device->bdev)
 			continue;
 
-		if (!zinfo->max_active_zones ||
-		    atomic_read(&zinfo->active_zones_left)) {
+		if (!zinfo->max_active_zones) {
 			ret = true;
 			break;
 		}
+
+		switch (flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) {
+		case 0: /* single */
+			ret = atomic_read(&zinfo->active_zones_left) >= 1;
+			break;
+		case BTRFS_BLOCK_GROUP_DUP:
+			ret = atomic_read(&zinfo->active_zones_left) >= 2;
+			break;
+		}
+		if (ret)
+			break;
 	}
 	mutex_unlock(&fs_info->chunk_mutex);