All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 07/21] btrfs: zoned: move btrfs_finish_block_group_to_copy to zoned code
  2021-11-24  9:30 [PATCH 00/21] btrfs: first batch of zoned cleanups Johannes Thumshirn
@ 2021-11-24  9:30 ` Johannes Thumshirn
  0 siblings, 0 replies; 2+ messages in thread
From: Johannes Thumshirn @ 2021-11-24  9:30 UTC (permalink / raw)
  To: David Sterba
  Cc: Johannes Thumshirn, linux-btrfs, Nikolay Borisov, Naohiro Aota

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(-)

diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 7572d80bff2ac..1fcc5d57e96ef 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -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)
diff --git a/fs/btrfs/dev-replace.h b/fs/btrfs/dev-replace.h
index 3911049a5f231..60b70dacc299b 100644
--- a/fs/btrfs/dev-replace.h
+++ b/fs/btrfs/dev-replace.h
@@ -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
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 73bfe30691b01..893d025069275 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -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;
+}
diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h
index e2309e3b3d7b8..bc9482cceadc4 100644
--- a/fs/btrfs/zoned.h
+++ b/fs/btrfs/zoned.h
@@ -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)
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 07/21] btrfs: zoned: move btrfs_finish_block_group_to_copy to zoned code
@ 2021-11-26  2:38 kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2021-11-26  2:38 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 3968 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <1482f3cd38ca134c23c8969a27191a828fc2f64d.1637745470.git.johannes.thumshirn@wdc.com>
References: <1482f3cd38ca134c23c8969a27191a828fc2f64d.1637745470.git.johannes.thumshirn@wdc.com>
TO: Johannes Thumshirn <johannes.thumshirn@wdc.com>
TO: David Sterba <dsterba@suse.com>
CC: Johannes Thumshirn <johannes.thumshirn@wdc.com>
CC: linux-btrfs(a)vger.kernel.org
CC: Nikolay Borisov <nborisov@suse.com>
CC: Naohiro Aota <Naohiro.Aota@wdc.com>

Hi Johannes,

I love your patch! Perhaps something to improve:

[auto build test WARNING on kdave/for-next]
[also build test WARNING on next-20211125]
[cannot apply to v5.16-rc2]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Johannes-Thumshirn/btrfs-first-batch-of-zoned-cleanups/20211124-173329
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: i386-randconfig-m021-20211124 (https://download.01.org/0day-ci/archive/20211126/202111261027.3kJDKpBC-lkp(a)intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

New smatch warnings:
fs/btrfs/zoned.c:2187 btrfs_finish_block_group_to_copy() error: 'em' dereferencing possible ERR_PTR()

Old smatch warnings:
fs/btrfs/zoned.c:169 sb_zone_number() error: uninitialized symbol 'zone'.
fs/btrfs/zoned.c:1456 btrfs_load_block_group_zone_info() error: uninitialized symbol 'ret'.

vim +/em +2187 fs/btrfs/zoned.c

1a4c69dc517089 Johannes Thumshirn 2021-11-24  2162  
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2163  bool btrfs_finish_block_group_to_copy(struct btrfs_device *srcdev,
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2164  				      struct btrfs_block_group *cache,
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2165  				      u64 physical)
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2166  {
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2167  	struct btrfs_fs_info *fs_info = cache->fs_info;
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2168  	struct extent_map *em;
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2169  	struct map_lookup *map;
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2170  	u64 chunk_offset = cache->start;
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2171  	int num_extents, cur_extent;
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2172  	int i;
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2173  
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2174  	/* Do not use "to_copy" on non zoned filesystem for now */
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2175  	if (!btrfs_is_zoned(fs_info))
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2176  		return true;
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2177  
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2178  	spin_lock(&cache->lock);
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2179  	if (cache->removed) {
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2180  		spin_unlock(&cache->lock);
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2181  		return true;
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2182  	}
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2183  	spin_unlock(&cache->lock);
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2184  
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2185  	em = btrfs_get_chunk_map(fs_info, chunk_offset, 1);
1a4c69dc517089 Johannes Thumshirn 2021-11-24  2186  	ASSERT(!IS_ERR(em));
1a4c69dc517089 Johannes Thumshirn 2021-11-24 @2187  	map = em->map_lookup;

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-26  2:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-26  2:38 [PATCH 07/21] btrfs: zoned: move btrfs_finish_block_group_to_copy to zoned code kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2021-11-24  9:30 [PATCH 00/21] btrfs: first batch of zoned cleanups Johannes Thumshirn
2021-11-24  9:30 ` [PATCH 07/21] btrfs: zoned: move btrfs_finish_block_group_to_copy to zoned code Johannes Thumshirn

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.