btrfs: add mask for all RAID1 types
authorDavid Sterba <dsterba@suse.com>
Fri, 31 May 2019 13:39:31 +0000 (15:39 +0200)
committerDavid Sterba <dsterba@suse.com>
Tue, 2 Jul 2019 10:30:48 +0000 (12:30 +0200)
Preparatory patch for additional RAID1 profiles with more copies. The
mask will contain 3-copy and 4-copy, most of the checks for plain RAID1
work the same for the other profiles.

Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent-tree.c
fs/btrfs/scrub.c
fs/btrfs/volumes.c
include/uapi/linux/btrfs_tree.h

index f24ef902032308546b253f152b844344788e8f44..13c17f94f15db032bd00b3e1d2f168f5ccaa0d57 100644 (file)
@@ -7873,7 +7873,7 @@ search:
                 */
                if (!block_group_bits(block_group, flags)) {
                        u64 extra = BTRFS_BLOCK_GROUP_DUP |
-                               BTRFS_BLOCK_GROUP_RAID1 |
+                               BTRFS_BLOCK_GROUP_RAID1_MASK |
                                BTRFS_BLOCK_GROUP_RAID5 |
                                BTRFS_BLOCK_GROUP_RAID6 |
                                BTRFS_BLOCK_GROUP_RAID10;
@@ -9564,7 +9564,7 @@ static u64 update_block_group_flags(struct btrfs_fs_info *fs_info, u64 flags)
 
        stripped = BTRFS_BLOCK_GROUP_RAID0 |
                BTRFS_BLOCK_GROUP_RAID5 | BTRFS_BLOCK_GROUP_RAID6 |
-               BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID10;
+               BTRFS_BLOCK_GROUP_RAID1_MASK | BTRFS_BLOCK_GROUP_RAID10;
 
        if (num_devices == 1) {
                stripped |= BTRFS_BLOCK_GROUP_DUP;
@@ -9575,7 +9575,7 @@ static u64 update_block_group_flags(struct btrfs_fs_info *fs_info, u64 flags)
                        return stripped;
 
                /* turn mirroring into duplication */
-               if (flags & (BTRFS_BLOCK_GROUP_RAID1 |
+               if (flags & (BTRFS_BLOCK_GROUP_RAID1_MASK |
                             BTRFS_BLOCK_GROUP_RAID10))
                        return stripped | BTRFS_BLOCK_GROUP_DUP;
        } else {
@@ -10445,7 +10445,7 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
        list_for_each_entry_rcu(space_info, &info->space_info, list) {
                if (!(get_alloc_profile(info, space_info->flags) &
                      (BTRFS_BLOCK_GROUP_RAID10 |
-                      BTRFS_BLOCK_GROUP_RAID1 |
+                      BTRFS_BLOCK_GROUP_RAID1_MASK |
                       BTRFS_BLOCK_GROUP_RAID5 |
                       BTRFS_BLOCK_GROUP_RAID6 |
                       BTRFS_BLOCK_GROUP_DUP)))
index 9f0297d529d4835fb8c64d623ed45b6551ce1bf7..0c99cf9fb595c25e8954223ef27ccc2da33f3777 100644 (file)
@@ -3091,7 +3091,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
                offset = map->stripe_len * (num / map->sub_stripes);
                increment = map->stripe_len * factor;
                mirror_num = num % map->sub_stripes + 1;
-       } else if (map->type & BTRFS_BLOCK_GROUP_RAID1) {
+       } else if (map->type & BTRFS_BLOCK_GROUP_RAID1_MASK) {
                increment = map->stripe_len;
                mirror_num = num % map->num_stripes + 1;
        } else if (map->type & BTRFS_BLOCK_GROUP_DUP) {
index 776f5c7ca7c5a533dc1d8f046c667adb53b33c29..9e5167a0e406ae6ace556705420a481555b99911 100644 (file)
@@ -5400,7 +5400,7 @@ int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len)
                return 1;
 
        map = em->map_lookup;
-       if (map->type & (BTRFS_BLOCK_GROUP_DUP | BTRFS_BLOCK_GROUP_RAID1))
+       if (map->type & (BTRFS_BLOCK_GROUP_DUP | BTRFS_BLOCK_GROUP_RAID1_MASK))
                ret = map->num_stripes;
        else if (map->type & BTRFS_BLOCK_GROUP_RAID10)
                ret = map->sub_stripes;
@@ -5474,7 +5474,7 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
        struct btrfs_device *srcdev;
 
        ASSERT((map->type &
-                (BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID10)));
+                (BTRFS_BLOCK_GROUP_RAID1_MASK | BTRFS_BLOCK_GROUP_RAID10)));
 
        if (map->type & BTRFS_BLOCK_GROUP_RAID10)
                num_stripes = map->sub_stripes;
@@ -5663,7 +5663,7 @@ static int __btrfs_map_block_for_discard(struct btrfs_fs_info *fs_info,
                                              &remaining_stripes);
                div_u64_rem(stripe_nr_end - 1, factor, &last_stripe);
                last_stripe *= sub_stripes;
-       } else if (map->type & (BTRFS_BLOCK_GROUP_RAID1 |
+       } else if (map->type & (BTRFS_BLOCK_GROUP_RAID1_MASK |
                                BTRFS_BLOCK_GROUP_DUP)) {
                num_stripes = map->num_stripes;
        } else {
@@ -6035,7 +6035,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
                                &stripe_index);
                if (!need_full_stripe(op))
                        mirror_num = 1;
-       } else if (map->type & BTRFS_BLOCK_GROUP_RAID1) {
+       } else if (map->type & BTRFS_BLOCK_GROUP_RAID1_MASK) {
                if (need_full_stripe(op))
                        num_stripes = map->num_stripes;
                else if (mirror_num)
index 421239b98db2c79e9a9e3fe57c5013716af43603..34d5b34286facd92b92d896f4a87905d4f86b0ff 100644 (file)
@@ -866,6 +866,8 @@ enum btrfs_raid_types {
 #define BTRFS_BLOCK_GROUP_RAID56_MASK  (BTRFS_BLOCK_GROUP_RAID5 |   \
                                         BTRFS_BLOCK_GROUP_RAID6)
 
+#define BTRFS_BLOCK_GROUP_RAID1_MASK   (BTRFS_BLOCK_GROUP_RAID1)
+
 /*
  * We need a bit for restriper to be able to tell when chunks of type
  * SINGLE are available.  This "extended" profile format is used in