btrfs: migrate the alloc_profile helpers
authorJosef Bacik <josef@toxicpanda.com>
Thu, 20 Jun 2019 19:38:05 +0000 (15:38 -0400)
committerDavid Sterba <dsterba@suse.com>
Mon, 9 Sep 2019 12:59:10 +0000 (14:59 +0200)
These feel more at home in block-group.c.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
[ refresh, adjust btrfs_get_alloc_profile exports ]
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/block-group.c
fs/btrfs/block-group.h
fs/btrfs/ctree.h
fs/btrfs/extent-tree.c

index 8f702cf4c0dbf475fa2838604beb9aab7dafe57c..2608f91a00ef46a72bad29ce3b0d08a8582db919 100644 (file)
 #include "delalloc-space.h"
 #include "math.h"
 
+/*
+ * Return target flags in extended format or 0 if restripe for this chunk_type
+ * is not in progress
+ *
+ * Should be called with balance_lock held
+ */
+u64 btrfs_get_restripe_target(struct btrfs_fs_info *fs_info, u64 flags)
+{
+       struct btrfs_balance_control *bctl = fs_info->balance_ctl;
+       u64 target = 0;
+
+       if (!bctl)
+               return 0;
+
+       if (flags & BTRFS_BLOCK_GROUP_DATA &&
+           bctl->data.flags & BTRFS_BALANCE_ARGS_CONVERT) {
+               target = BTRFS_BLOCK_GROUP_DATA | bctl->data.target;
+       } else if (flags & BTRFS_BLOCK_GROUP_SYSTEM &&
+                  bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT) {
+               target = BTRFS_BLOCK_GROUP_SYSTEM | bctl->sys.target;
+       } else if (flags & BTRFS_BLOCK_GROUP_METADATA &&
+                  bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT) {
+               target = BTRFS_BLOCK_GROUP_METADATA | bctl->meta.target;
+       }
+
+       return target;
+}
+
+/*
+ * @flags: available profiles in extended format (see ctree.h)
+ *
+ * Return reduced profile in chunk format.  If profile changing is in progress
+ * (either running or paused) picks the target profile (if it's already
+ * available), otherwise falls back to plain reducing.
+ */
+static u64 btrfs_reduce_alloc_profile(struct btrfs_fs_info *fs_info, u64 flags)
+{
+       u64 num_devices = fs_info->fs_devices->rw_devices;
+       u64 target;
+       u64 raid_type;
+       u64 allowed = 0;
+
+       /*
+        * See if restripe for this chunk_type is in progress, if so try to
+        * reduce to the target profile
+        */
+       spin_lock(&fs_info->balance_lock);
+       target = btrfs_get_restripe_target(fs_info, flags);
+       if (target) {
+               /* Pick target profile only if it's already available */
+               if ((flags & target) & BTRFS_EXTENDED_PROFILE_MASK) {
+                       spin_unlock(&fs_info->balance_lock);
+                       return extended_to_chunk(target);
+               }
+       }
+       spin_unlock(&fs_info->balance_lock);
+
+       /* First, mask out the RAID levels which aren't possible */
+       for (raid_type = 0; raid_type < BTRFS_NR_RAID_TYPES; raid_type++) {
+               if (num_devices >= btrfs_raid_array[raid_type].devs_min)
+                       allowed |= btrfs_raid_array[raid_type].bg_flag;
+       }
+       allowed &= flags;
+
+       if (allowed & BTRFS_BLOCK_GROUP_RAID6)
+               allowed = BTRFS_BLOCK_GROUP_RAID6;
+       else if (allowed & BTRFS_BLOCK_GROUP_RAID5)
+               allowed = BTRFS_BLOCK_GROUP_RAID5;
+       else if (allowed & BTRFS_BLOCK_GROUP_RAID10)
+               allowed = BTRFS_BLOCK_GROUP_RAID10;
+       else if (allowed & BTRFS_BLOCK_GROUP_RAID1)
+               allowed = BTRFS_BLOCK_GROUP_RAID1;
+       else if (allowed & BTRFS_BLOCK_GROUP_RAID0)
+               allowed = BTRFS_BLOCK_GROUP_RAID0;
+
+       flags &= ~BTRFS_BLOCK_GROUP_PROFILE_MASK;
+
+       return extended_to_chunk(flags | allowed);
+}
+
+static u64 get_alloc_profile(struct btrfs_fs_info *fs_info, u64 orig_flags)
+{
+       unsigned seq;
+       u64 flags;
+
+       do {
+               flags = orig_flags;
+               seq = read_seqbegin(&fs_info->profiles_lock);
+
+               if (flags & BTRFS_BLOCK_GROUP_DATA)
+                       flags |= fs_info->avail_data_alloc_bits;
+               else if (flags & BTRFS_BLOCK_GROUP_SYSTEM)
+                       flags |= fs_info->avail_system_alloc_bits;
+               else if (flags & BTRFS_BLOCK_GROUP_METADATA)
+                       flags |= fs_info->avail_metadata_alloc_bits;
+       } while (read_seqretry(&fs_info->profiles_lock, seq));
+
+       return btrfs_reduce_alloc_profile(fs_info, flags);
+}
+
+u64 btrfs_get_alloc_profile(struct btrfs_fs_info *fs_info, u64 orig_flags)
+{
+       return get_alloc_profile(fs_info, orig_flags);
+}
+
 void btrfs_get_block_group(struct btrfs_block_group_cache *cache)
 {
        atomic_inc(&cache->count);
index de90f7311574109873a26ee086c5aca50e9cc515..34a0098eadfc4a2311a1f4d9dcdb20d37042cbae 100644 (file)
@@ -219,6 +219,22 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags,
                      enum btrfs_chunk_alloc_enum force);
 int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, u64 type);
 void check_system_chunk(struct btrfs_trans_handle *trans, const u64 type);
+u64 btrfs_get_alloc_profile(struct btrfs_fs_info *fs_info, u64 orig_flags);
+
+static inline u64 btrfs_data_alloc_profile(struct btrfs_fs_info *fs_info)
+{
+       return btrfs_get_alloc_profile(fs_info, BTRFS_BLOCK_GROUP_DATA);
+}
+
+static inline u64 btrfs_metadata_alloc_profile(struct btrfs_fs_info *fs_info)
+{
+       return btrfs_get_alloc_profile(fs_info, BTRFS_BLOCK_GROUP_METADATA);
+}
+
+static inline u64 btrfs_system_alloc_profile(struct btrfs_fs_info *fs_info)
+{
+       return btrfs_get_alloc_profile(fs_info, BTRFS_BLOCK_GROUP_SYSTEM);
+}
 
 static inline int btrfs_block_group_cache_done(
                struct btrfs_block_group_cache *cache)
index fe25b7211f2d7d1be24d6143b625214114413c70..e1ad681b9e1a75cd4cf9237e95c3ec09b6b47c98 100644 (file)
@@ -2527,10 +2527,6 @@ int btrfs_extent_readonly(struct btrfs_fs_info *fs_info, u64 bytenr);
 int btrfs_free_block_groups(struct btrfs_fs_info *info);
 void btrfs_get_block_group_trimming(struct btrfs_block_group_cache *cache);
 void btrfs_put_block_group_trimming(struct btrfs_block_group_cache *cache);
-u64 btrfs_data_alloc_profile(struct btrfs_fs_info *fs_info);
-u64 btrfs_metadata_alloc_profile(struct btrfs_fs_info *fs_info);
-u64 btrfs_system_alloc_profile(struct btrfs_fs_info *fs_info);
-u64 btrfs_get_alloc_profile(struct btrfs_fs_info *fs_info, u64 orig_flags);
 void btrfs_clear_space_info_full(struct btrfs_fs_info *info);
 
 enum btrfs_reserve_flush_enum {
index 9dd8b08e46159a61f924fda88b7978906ad74cc9..4021992485498f9e9398f085506e476312150cb8 100644 (file)
@@ -2524,111 +2524,6 @@ int btrfs_extent_readonly(struct btrfs_fs_info *fs_info, u64 bytenr)
        return readonly;
 }
 
-/*
- * returns target flags in extended format or 0 if restripe for this
- * chunk_type is not in progress
- *
- * should be called with balance_lock held
- */
-u64 btrfs_get_restripe_target(struct btrfs_fs_info *fs_info, u64 flags)
-{
-       struct btrfs_balance_control *bctl = fs_info->balance_ctl;
-       u64 target = 0;
-
-       if (!bctl)
-               return 0;
-
-       if (flags & BTRFS_BLOCK_GROUP_DATA &&
-           bctl->data.flags & BTRFS_BALANCE_ARGS_CONVERT) {
-               target = BTRFS_BLOCK_GROUP_DATA | bctl->data.target;
-       } else if (flags & BTRFS_BLOCK_GROUP_SYSTEM &&
-                  bctl->sys.flags & BTRFS_BALANCE_ARGS_CONVERT) {
-               target = BTRFS_BLOCK_GROUP_SYSTEM | bctl->sys.target;
-       } else if (flags & BTRFS_BLOCK_GROUP_METADATA &&
-                  bctl->meta.flags & BTRFS_BALANCE_ARGS_CONVERT) {
-               target = BTRFS_BLOCK_GROUP_METADATA | bctl->meta.target;
-       }
-
-       return target;
-}
-
-/*
- * @flags: available profiles in extended format (see ctree.h)
- *
- * Returns reduced profile in chunk format.  If profile changing is in
- * progress (either running or paused) picks the target profile (if it's
- * already available), otherwise falls back to plain reducing.
- */
-static u64 btrfs_reduce_alloc_profile(struct btrfs_fs_info *fs_info, u64 flags)
-{
-       u64 num_devices = fs_info->fs_devices->rw_devices;
-       u64 target;
-       u64 raid_type;
-       u64 allowed = 0;
-
-       /*
-        * see if restripe for this chunk_type is in progress, if so
-        * try to reduce to the target profile
-        */
-       spin_lock(&fs_info->balance_lock);
-       target = btrfs_get_restripe_target(fs_info, flags);
-       if (target) {
-               /* pick target profile only if it's already available */
-               if ((flags & target) & BTRFS_EXTENDED_PROFILE_MASK) {
-                       spin_unlock(&fs_info->balance_lock);
-                       return extended_to_chunk(target);
-               }
-       }
-       spin_unlock(&fs_info->balance_lock);
-
-       /* First, mask out the RAID levels which aren't possible */
-       for (raid_type = 0; raid_type < BTRFS_NR_RAID_TYPES; raid_type++) {
-               if (num_devices >= btrfs_raid_array[raid_type].devs_min)
-                       allowed |= btrfs_raid_array[raid_type].bg_flag;
-       }
-       allowed &= flags;
-
-       if (allowed & BTRFS_BLOCK_GROUP_RAID6)
-               allowed = BTRFS_BLOCK_GROUP_RAID6;
-       else if (allowed & BTRFS_BLOCK_GROUP_RAID5)
-               allowed = BTRFS_BLOCK_GROUP_RAID5;
-       else if (allowed & BTRFS_BLOCK_GROUP_RAID10)
-               allowed = BTRFS_BLOCK_GROUP_RAID10;
-       else if (allowed & BTRFS_BLOCK_GROUP_RAID1)
-               allowed = BTRFS_BLOCK_GROUP_RAID1;
-       else if (allowed & BTRFS_BLOCK_GROUP_RAID0)
-               allowed = BTRFS_BLOCK_GROUP_RAID0;
-
-       flags &= ~BTRFS_BLOCK_GROUP_PROFILE_MASK;
-
-       return extended_to_chunk(flags | allowed);
-}
-
-static u64 get_alloc_profile(struct btrfs_fs_info *fs_info, u64 orig_flags)
-{
-       unsigned seq;
-       u64 flags;
-
-       do {
-               flags = orig_flags;
-               seq = read_seqbegin(&fs_info->profiles_lock);
-
-               if (flags & BTRFS_BLOCK_GROUP_DATA)
-                       flags |= fs_info->avail_data_alloc_bits;
-               else if (flags & BTRFS_BLOCK_GROUP_SYSTEM)
-                       flags |= fs_info->avail_system_alloc_bits;
-               else if (flags & BTRFS_BLOCK_GROUP_METADATA)
-                       flags |= fs_info->avail_metadata_alloc_bits;
-       } while (read_seqretry(&fs_info->profiles_lock, seq));
-
-       return btrfs_reduce_alloc_profile(fs_info, flags);
-}
-
-u64 btrfs_get_alloc_profile(struct btrfs_fs_info *fs_info, u64 orig_flags)
-{
-       return get_alloc_profile(fs_info, orig_flags);
-}
-
 static u64 get_alloc_profile_by_root(struct btrfs_root *root, int data)
 {
        struct btrfs_fs_info *fs_info = root->fs_info;
@@ -2642,25 +2537,10 @@ static u64 get_alloc_profile_by_root(struct btrfs_root *root, int data)
        else
                flags = BTRFS_BLOCK_GROUP_METADATA;
 
-       ret = get_alloc_profile(fs_info, flags);
+       ret = btrfs_get_alloc_profile(fs_info, flags);
        return ret;
 }
 
-u64 btrfs_data_alloc_profile(struct btrfs_fs_info *fs_info)
-{
-       return get_alloc_profile(fs_info, BTRFS_BLOCK_GROUP_DATA);
-}
-
-u64 btrfs_metadata_alloc_profile(struct btrfs_fs_info *fs_info)
-{
-       return get_alloc_profile(fs_info, BTRFS_BLOCK_GROUP_METADATA);
-}
-
-u64 btrfs_system_alloc_profile(struct btrfs_fs_info *fs_info)
-{
-       return get_alloc_profile(fs_info, BTRFS_BLOCK_GROUP_SYSTEM);
-}
-
 static u64 first_logical_byte(struct btrfs_fs_info *fs_info, u64 search_start)
 {
        struct btrfs_block_group_cache *cache;