Skip to contentSkip to conversation

Profile mask and calculation cleanups

PATCH In review David Sterba 4 participants 6 messages Jun 23, 2022 – Jun 24, 2022 Btrfs file system

lore
Share & tools
lore

David Sterba

author maintainer
#0 lore raw

cover Profile mask and calculation cleanups

There are still some instances of hardcoded values repeating what we have in the raid attr table or using a similar expresion to calculate things that can be simplified.

David Sterba (2):
btrfs: use mask for all RAID1* profiles in btrfs_calc_avail_data_space
btrfs: merge calculations for simple striped profiles in
btrfs_rmap_block

 fs/btrfs/block-group.c | 5 ++---
 fs/btrfs/super.c       | 8 ++------
 2 files changed, 4 insertions(+), 9 deletions(-)
Signature · 1 line
2.36.1
author maintainer
#1 lore raw

PATCH 1/2 btrfs: use mask for all RAID1* profiles in btrfs_calc_avail_data_space

There's a sequence of hard coded values for RAID1 profiles that are already stored in the raid_attr table that should be used instead.

---
 fs/btrfs/super.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
fs/btrfs/super.c +2 -6
index 41652dcd16f4..4c7089b1681b 100644
@@ -2243,12 +2243,8 @@ static inline int btrfs_calc_avail_data_space(struct btrfs_fs_info *fs_info,
 
 	if (type & BTRFS_BLOCK_GROUP_RAID0)
 		num_stripes = nr_devices;
-	else if (type & BTRFS_BLOCK_GROUP_RAID1)
-		num_stripes = 2;
-	else if (type & BTRFS_BLOCK_GROUP_RAID1C3)
-		num_stripes = 3;
-	else if (type & BTRFS_BLOCK_GROUP_RAID1C4)
-		num_stripes = 4;
+	else if (type & BTRFS_BLOCK_GROUP_RAID1_MASK)
+		num_stripes = rattr->ncopies;
 	else if (type & BTRFS_BLOCK_GROUP_RAID10)
 		num_stripes = 4;
 
Signature · 1 line
2.36.1
author maintainer
#2 lore raw

PATCH 2/2 btrfs: merge calculations for simple striped profiles in btrfs_rmap_block

In reply to David Sterba

Use the same expression for stripe_nr for RAID0 (map->sub_stripes is 1) and RAID10 (map->sub_stripes is 2), with equivalent results.

---
 fs/btrfs/block-group.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/btrfs/block-group.c +2 -3
index 13358fbc1629..e930749770ac 100644
@@ -1816,11 +1816,10 @@ int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start,
 		stripe_nr = physical - map->stripes[i].physical;
 		stripe_nr = div64_u64_rem(stripe_nr, map->stripe_len, &offset);
 
-		if (map->type & BTRFS_BLOCK_GROUP_RAID10) {
+		if (map->type & (BTRFS_BLOCK_GROUP_RAID0 |
+				 BTRFS_BLOCK_GROUP_RAID10)) {
 			stripe_nr = stripe_nr * map->num_stripes + i;
 			stripe_nr = div_u64(stripe_nr, map->sub_stripes);
-		} else if (map->type & BTRFS_BLOCK_GROUP_RAID0) {
-			stripe_nr = stripe_nr * map->num_stripes + i;
 		}
 		/*
 		 * The remaining case would be for RAID56, multiply by
Signature · 1 line
2.36.1
Reviewed-by on the v1 series
#3 lore raw
In reply to David Sterba
Quoted 4 lines · David Sterba

There are still some instances of hardcoded values repeating what we have in the raid attr table or using a similar expresion to calculate things that can be simplified.

Quoted 9 lines

David Sterba (2):
btrfs: use mask for all RAID1* profiles in btrfs_calc_avail_data_space
btrfs: merge calculations for simple striped profiles in
btrfs_rmap_block

  fs/btrfs/block-group.c | 5 ++---
  fs/btrfs/super.c       | 8 ++------
  2 files changed, 4 insertions(+), 9 deletions(-)
Reviewed-by on the v1 series
#4 lore raw
In reply to David Sterba
Quoted 4 lines · David Sterba

There are still some instances of hardcoded values repeating what we have in the raid attr table or using a similar expresion to calculate things that can be simplified.

Quoted 9 lines

David Sterba (2):
btrfs: use mask for all RAID1* profiles in btrfs_calc_avail_data_space
btrfs: merge calculations for simple striped profiles in
btrfs_rmap_block

 fs/btrfs/block-group.c | 5 ++---
 fs/btrfs/super.c       | 8 ++------
 2 files changed, 4 insertions(+), 9 deletions(-)

Looks good,

#5 lore raw
In reply to David Sterba
Quoted 8 lines · David Sterba

There are still some instances of hardcoded values repeating what we have in the raid attr table or using a similar expresion to calculate things that can be simplified.

David Sterba (2):
btrfs: use mask for all RAID1* profiles in btrfs_calc_avail_data_space
btrfs: merge calculations for simple striped profiles in
btrfs_rmap_block

Added to misc-next.