@@ -460,61 +460,6 @@ static char* btrfs_dev_name(struct btrfs_device *device)
return rcu_str_deref(device->name);
}
-bool btrfs_finish_block_group_to_copy(struct btrfs_device *srcdev,
- struct btrfs_block_group *cache,
- u64 physical)
-{
- struct btrfs_fs_info *fs_info = cache->fs_info;
- struct extent_map *em;
- struct map_lookup *map;
- u64 chunk_offset = cache->start;
- int num_extents, cur_extent;
- int i;
-
- /* Do not use "to_copy" on non zoned filesystem for now */
- if (!btrfs_is_zoned(fs_info))
- return true;
-
- spin_lock(&cache->lock);
- if (cache->removed) {
- spin_unlock(&cache->lock);
- return true;
- }
- spin_unlock(&cache->lock);
-
- em = btrfs_get_chunk_map(fs_info, chunk_offset, 1);
- ASSERT(!IS_ERR(em));
- map = em->map_lookup;
-
- num_extents = cur_extent = 0;
- for (i = 0; i < map->num_stripes; i++) {
- /* We have more device extent to copy */
- if (srcdev != map->stripes[i].dev)
- continue;
-
- num_extents++;
- if (physical == map->stripes[i].physical)
- cur_extent = i;
- }
-
- free_extent_map(em);
-
- if (num_extents > 1 && cur_extent < num_extents - 1) {
- /*
- * Has more stripes on this device. Keep this block group
- * readonly until we finish all the stripes.
- */
- return false;
- }
-
- /* Last stripe on this device */
- spin_lock(&cache->lock);
- cache->to_copy = 0;
- spin_unlock(&cache->lock);
-
- return true;
-}
-
static int btrfs_dev_replace_start(struct btrfs_fs_info *fs_info,
const char *tgtdev_name, u64 srcdevid, const char *srcdev_name,
int read_src)
@@ -18,8 +18,5 @@ int btrfs_dev_replace_cancel(struct btrfs_fs_info *fs_info);
void btrfs_dev_replace_suspend_for_unmount(struct btrfs_fs_info *fs_info);
int btrfs_resume_dev_replace_async(struct btrfs_fs_info *fs_info);
int __pure btrfs_dev_replace_is_ongoing(struct btrfs_dev_replace *dev_replace);
-bool btrfs_finish_block_group_to_copy(struct btrfs_device *srcdev,
- struct btrfs_block_group *cache,
- u64 physical);
#endif
@@ -2159,3 +2159,58 @@ int btrfs_mark_block_group_to_copy(struct btrfs_fs_info *fs_info,
return ret;
}
+
+bool btrfs_finish_block_group_to_copy(struct btrfs_device *srcdev,
+ struct btrfs_block_group *cache,
+ u64 physical)
+{
+ struct btrfs_fs_info *fs_info = cache->fs_info;
+ struct extent_map *em;
+ struct map_lookup *map;
+ u64 chunk_offset = cache->start;
+ int num_extents, cur_extent;
+ int i;
+
+ /* Do not use "to_copy" on non zoned filesystem for now */
+ if (!btrfs_is_zoned(fs_info))
+ return true;
+
+ spin_lock(&cache->lock);
+ if (cache->removed) {
+ spin_unlock(&cache->lock);
+ return true;
+ }
+ spin_unlock(&cache->lock);
+
+ em = btrfs_get_chunk_map(fs_info, chunk_offset, 1);
+ ASSERT(!IS_ERR(em));
+ map = em->map_lookup;
+
+ num_extents = cur_extent = 0;
+ for (i = 0; i < map->num_stripes; i++) {
+ /* We have more device extent to copy */
+ if (srcdev != map->stripes[i].dev)
+ continue;
+
+ num_extents++;
+ if (physical == map->stripes[i].physical)
+ cur_extent = i;
+ }
+
+ free_extent_map(em);
+
+ if (num_extents > 1 && cur_extent < num_extents - 1) {
+ /*
+ * Has more stripes on this device. Keep this block group
+ * readonly until we finish all the stripes.
+ */
+ return false;
+ }
+
+ /* Last stripe on this device */
+ spin_lock(&cache->lock);
+ cache->to_copy = 0;
+ spin_unlock(&cache->lock);
+
+ return true;
+}
@@ -81,6 +81,9 @@ void btrfs_clear_data_reloc_bg(struct btrfs_block_group *bg);
void btrfs_free_zone_cache(struct btrfs_fs_info *fs_info);
int btrfs_mark_block_group_to_copy(struct btrfs_fs_info *fs_info,
struct btrfs_device *src_dev);
+bool btrfs_finish_block_group_to_copy(struct btrfs_device *srcdev,
+ struct btrfs_block_group *cache,
+ u64 physical);
#else /* CONFIG_BLK_DEV_ZONED */
static inline int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos,
struct blk_zone *zone)
@@ -245,6 +248,13 @@ static inline int btrfs_mark_block_group_to_copy(struct btrfs_fs_info *fs_info,
{
return 0;
}
+
+static inline bool btrfs_finish_block_group_to_copy(struct btrfs_device *srcdev,
+ struct btrfs_block_group *cache,
+ u64 physical)
+{
+ return true;
+}
#endif
static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos)
btrfs_finish_block_group_to_copy is only used in a zoned filesystem so move the code to zoned code. Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> --- fs/btrfs/dev-replace.c | 55 ------------------------------------------ fs/btrfs/dev-replace.h | 3 --- fs/btrfs/zoned.c | 55 ++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/zoned.h | 10 ++++++++ 4 files changed, 65 insertions(+), 58 deletions(-)