linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/10] btrfs: clean up zoned device helpers
@ 2022-09-14 23:07 Josef Bacik
  2022-09-14 23:07 ` [PATCH 01/10] btrfs: add a helper for opening a new device to add to the fs Josef Bacik
                   ` (9 more replies)
  0 siblings, 10 replies; 22+ messages in thread
From: Josef Bacik @ 2022-09-14 23:07 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

Hello,

This is in the same vein as my other cleanups, however zoned has a lot of
different patches so I'm sending them as a group, additionally so I get the
appropriate review attention from the right people.

These cleanups are aimed at making any helpers inside of zoned.h only derefence
structs that are declared inside of zoned.h, which is just
btrfs_zoned_device_info.  This means moving helpers that aren't used anywhere
else into their respective C files, reworking some of the helpers, and other
related cleanups.  Thanks,

Josef

Josef Bacik (10):
  btrfs: add a helper for opening a new device to add to the fs
  btrfs: move btrfs_check_device_zone_type into volumes.c
  btrfs: move btrfs_can_zone_reset into extent-tree.c
  btrfs: move btrfs_check_super_location into scrub.c
  btrfs: move btrfs_zoned_meta_io_*lock to extent_io.c
  btrfs: move btrfs_clear_treelog_bg to extent-tree.c
  btrfs: move btrfs_zoned_data_reloc_*lock to extent_io.c
  btrfs: move btrfs_zoned_bg_is_full into block-group.c
  btrfs: make the zoned helpers take btrfs_zoned_device_info
  btrfs: delete btrfs_check_super_location helper

 fs/btrfs/block-group.c |   6 +++
 fs/btrfs/block-group.h |   1 +
 fs/btrfs/dev-replace.c |  10 +---
 fs/btrfs/extent-tree.c |  27 ++++++++++
 fs/btrfs/extent_io.c   |  30 +++++++++++
 fs/btrfs/scrub.c       |   8 +--
 fs/btrfs/volumes.c     |  49 ++++++++++++++---
 fs/btrfs/volumes.h     |   2 +
 fs/btrfs/zoned.c       |  20 +++----
 fs/btrfs/zoned.h       | 118 +++++------------------------------------
 10 files changed, 136 insertions(+), 135 deletions(-)

-- 
2.26.3


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

* [PATCH 01/10] btrfs: add a helper for opening a new device to add to the fs
  2022-09-14 23:07 [PATCH 00/10] btrfs: clean up zoned device helpers Josef Bacik
@ 2022-09-14 23:07 ` Josef Bacik
  2022-09-15 13:54   ` Johannes Thumshirn
  2022-09-21  9:39   ` Pankaj Raghav
  2022-09-14 23:07 ` [PATCH 02/10] btrfs: move btrfs_check_device_zone_type into volumes.c Josef Bacik
                   ` (8 subsequent siblings)
  9 siblings, 2 replies; 22+ messages in thread
From: Josef Bacik @ 2022-09-14 23:07 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

We currently duplicate our device init code for adding a new device to a
file system and replacing an existing device in a file system.  These
two init functions are subtle-y different, however they both open the
disk and check it's zoned status to see if it's compatible.  Combine
this step into a single helper and use that helper from both init
functions.  The goal of this change is to move the zoned helper out of
zoned.h in order to avoid using helpers that aren't defined in zoned.h.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/dev-replace.c | 10 +---------
 fs/btrfs/volumes.c     | 28 +++++++++++++++++++++-------
 fs/btrfs/volumes.h     |  2 ++
 3 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index c6222057f655..8f5922ba0129 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -258,20 +258,12 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
 		return -EINVAL;
 	}
 
-	bdev = blkdev_get_by_path(device_path, FMODE_WRITE | FMODE_EXCL,
-				  fs_info->bdev_holder);
+	bdev = btrfs_open_device_for_adding(fs_info, device_path);
 	if (IS_ERR(bdev)) {
 		btrfs_err(fs_info, "target device %s is invalid!", device_path);
 		return PTR_ERR(bdev);
 	}
 
-	if (!btrfs_check_device_zone_type(fs_info, bdev)) {
-		btrfs_err(fs_info,
-		"dev-replace: zoned type of target device mismatch with filesystem");
-		ret = -EINVAL;
-		goto error;
-	}
-
 	sync_blockdev(bdev);
 
 	list_for_each_entry(device, &fs_devices->devices, dev_list) {
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 09c1434c3cae..ea76458d7c70 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2583,6 +2583,26 @@ static int btrfs_finish_sprout(struct btrfs_trans_handle *trans)
 	return ret;
 }
 
+struct block_device *btrfs_open_device_for_adding(struct btrfs_fs_info *fs_info,
+						  const char *device_path)
+{
+	struct block_device *bdev;
+
+	bdev = blkdev_get_by_path(device_path, FMODE_WRITE | FMODE_EXCL,
+				  fs_info->bdev_holder);
+	if (IS_ERR(bdev))
+		return bdev;
+
+	if (!btrfs_check_device_zone_type(fs_info, bdev)) {
+		btrfs_err(fs_info,
+			  "dev-replace: zoned type of target device mismatch with filesystem");
+		blkdev_put(bdev, FMODE_EXCL);
+		return ERR_PTR(-EINVAL);
+	}
+
+	return bdev;
+}
+
 int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path)
 {
 	struct btrfs_root *root = fs_info->dev_root;
@@ -2602,16 +2622,10 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
 	if (sb_rdonly(sb) && !fs_devices->seeding)
 		return -EROFS;
 
-	bdev = blkdev_get_by_path(device_path, FMODE_WRITE | FMODE_EXCL,
-				  fs_info->bdev_holder);
+	bdev = btrfs_open_device_for_adding(fs_info, device_path);
 	if (IS_ERR(bdev))
 		return PTR_ERR(bdev);
 
-	if (!btrfs_check_device_zone_type(fs_info, bdev)) {
-		ret = -EINVAL;
-		goto error;
-	}
-
 	if (fs_devices->seeding) {
 		seeding_dev = true;
 		down_write(&sb->s_umount);
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 2bf7dbe739fd..60d74554edf2 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -757,4 +757,6 @@ int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info);
 bool btrfs_repair_one_zone(struct btrfs_fs_info *fs_info, u64 logical);
 unsigned long btrfs_chunk_item_size(int num_stripes);
 bool btrfs_pinned_by_swapfile(struct btrfs_fs_info *fs_info, void *ptr);
+struct block_device *btrfs_open_device_for_adding(struct btrfs_fs_info *fs_info,
+						  const char *device_path);
 #endif
-- 
2.26.3


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

* [PATCH 02/10] btrfs: move btrfs_check_device_zone_type into volumes.c
  2022-09-14 23:07 [PATCH 00/10] btrfs: clean up zoned device helpers Josef Bacik
  2022-09-14 23:07 ` [PATCH 01/10] btrfs: add a helper for opening a new device to add to the fs Josef Bacik
@ 2022-09-14 23:07 ` Josef Bacik
  2022-09-15 13:55   ` Johannes Thumshirn
  2022-09-14 23:07 ` [PATCH 03/10] btrfs: move btrfs_can_zone_reset into extent-tree.c Josef Bacik
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Josef Bacik @ 2022-09-14 23:07 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

Now that this is only used in volumes.c move it out of zoned.h locally
to volumes.c.  This is in order to avoid having a helper that uses
functions not defined in zoned.h.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/volumes.c | 19 +++++++++++++++++++
 fs/btrfs/zoned.h   | 19 -------------------
 2 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index ea76458d7c70..29652323ef9b 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2583,6 +2583,25 @@ static int btrfs_finish_sprout(struct btrfs_trans_handle *trans)
 	return ret;
 }
 
+static inline bool btrfs_check_device_zone_type(const struct btrfs_fs_info *fs_info,
+						struct block_device *bdev)
+{
+	if (btrfs_is_zoned(fs_info)) {
+		/*
+		 * We can allow a regular device on a zoned filesystem, because
+		 * we will emulate the zoned capabilities.
+		 */
+		if (!bdev_is_zoned(bdev))
+			return true;
+
+		return fs_info->zone_size ==
+			(bdev_zone_sectors(bdev) << SECTOR_SHIFT);
+	}
+
+	/* Do not allow Host Manged zoned device */
+	return bdev_zoned_model(bdev) != BLK_ZONED_HM;
+}
+
 struct block_device *btrfs_open_device_for_adding(struct btrfs_fs_info *fs_info,
 						  const char *device_path)
 {
diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h
index 094f3e44c53c..20d7f35406d4 100644
--- a/fs/btrfs/zoned.h
+++ b/fs/btrfs/zoned.h
@@ -311,25 +311,6 @@ static inline void btrfs_dev_clear_zone_empty(struct btrfs_device *device, u64 p
 	btrfs_dev_set_empty_zone_bit(device, pos, false);
 }
 
-static inline bool btrfs_check_device_zone_type(const struct btrfs_fs_info *fs_info,
-						struct block_device *bdev)
-{
-	if (btrfs_is_zoned(fs_info)) {
-		/*
-		 * We can allow a regular device on a zoned filesystem, because
-		 * we will emulate the zoned capabilities.
-		 */
-		if (!bdev_is_zoned(bdev))
-			return true;
-
-		return fs_info->zone_size ==
-			(bdev_zone_sectors(bdev) << SECTOR_SHIFT);
-	}
-
-	/* Do not allow Host Manged zoned device */
-	return bdev_zoned_model(bdev) != BLK_ZONED_HM;
-}
-
 static inline bool btrfs_check_super_location(struct btrfs_device *device, u64 pos)
 {
 	/*
-- 
2.26.3


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

* [PATCH 03/10] btrfs: move btrfs_can_zone_reset into extent-tree.c
  2022-09-14 23:07 [PATCH 00/10] btrfs: clean up zoned device helpers Josef Bacik
  2022-09-14 23:07 ` [PATCH 01/10] btrfs: add a helper for opening a new device to add to the fs Josef Bacik
  2022-09-14 23:07 ` [PATCH 02/10] btrfs: move btrfs_check_device_zone_type into volumes.c Josef Bacik
@ 2022-09-14 23:07 ` Josef Bacik
  2022-09-15 13:56   ` Johannes Thumshirn
  2022-09-14 23:07 ` [PATCH 04/10] btrfs: move btrfs_check_super_location into scrub.c Josef Bacik
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Josef Bacik @ 2022-09-14 23:07 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

This helper is only used in extent-tree.c to decide if we need to zone
reset for a discard.  Move it out of zoned.h locally to extent-tree.c.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/extent-tree.c | 15 +++++++++++++++
 fs/btrfs/zoned.h       | 15 ---------------
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 7cf7844c9dba..0785c1491313 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -1271,6 +1271,21 @@ static int btrfs_issue_discard(struct block_device *bdev, u64 start, u64 len,
 	return ret;
 }
 
+static inline bool btrfs_can_zone_reset(struct btrfs_device *device,
+					u64 physical, u64 length)
+{
+	u64 zone_size;
+
+	if (!btrfs_dev_is_sequential(device, physical))
+		return false;
+
+	zone_size = device->zone_info->zone_size;
+	if (!IS_ALIGNED(physical, zone_size) || !IS_ALIGNED(length, zone_size))
+		return false;
+
+	return true;
+}
+
 static int do_discard_extent(struct btrfs_discard_stripe *stripe, u64 *bytes)
 {
 	struct btrfs_device *dev = stripe->dev;
diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h
index 20d7f35406d4..aabdd364e889 100644
--- a/fs/btrfs/zoned.h
+++ b/fs/btrfs/zoned.h
@@ -320,21 +320,6 @@ static inline bool btrfs_check_super_location(struct btrfs_device *device, u64 p
 	return device->zone_info == NULL || !btrfs_dev_is_sequential(device, pos);
 }
 
-static inline bool btrfs_can_zone_reset(struct btrfs_device *device,
-					u64 physical, u64 length)
-{
-	u64 zone_size;
-
-	if (!btrfs_dev_is_sequential(device, physical))
-		return false;
-
-	zone_size = device->zone_info->zone_size;
-	if (!IS_ALIGNED(physical, zone_size) || !IS_ALIGNED(length, zone_size))
-		return false;
-
-	return true;
-}
-
 static inline void btrfs_zoned_meta_io_lock(struct btrfs_fs_info *fs_info)
 {
 	if (!btrfs_is_zoned(fs_info))
-- 
2.26.3


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

* [PATCH 04/10] btrfs: move btrfs_check_super_location into scrub.c
  2022-09-14 23:07 [PATCH 00/10] btrfs: clean up zoned device helpers Josef Bacik
                   ` (2 preceding siblings ...)
  2022-09-14 23:07 ` [PATCH 03/10] btrfs: move btrfs_can_zone_reset into extent-tree.c Josef Bacik
@ 2022-09-14 23:07 ` Josef Bacik
  2022-09-15 13:57   ` Johannes Thumshirn
  2022-09-14 23:07 ` [PATCH 05/10] btrfs: move btrfs_zoned_meta_io_*lock to extent_io.c Josef Bacik
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Josef Bacik @ 2022-09-14 23:07 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

This helper is only used in scrub.c, move it out of zoned.h locally to
scrub.c to avoid using code that isn't defined in zoned.h.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/scrub.c | 9 +++++++++
 fs/btrfs/zoned.h | 9 ---------
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index d5c23faceb8e..927431217131 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -4140,6 +4140,15 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
 	return ret;
 }
 
+static inline bool btrfs_check_super_location(struct btrfs_device *device, u64 pos)
+{
+	/*
+	 * On a non-zoned device, any address is OK. On a zoned device,
+	 * non-SEQUENTIAL WRITE REQUIRED zones are capable.
+	 */
+	return device->zone_info == NULL || !btrfs_dev_is_sequential(device, pos);
+}
+
 static noinline_for_stack int scrub_supers(struct scrub_ctx *sctx,
 					   struct btrfs_device *scrub_dev)
 {
diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h
index aabdd364e889..0a1298afa049 100644
--- a/fs/btrfs/zoned.h
+++ b/fs/btrfs/zoned.h
@@ -311,15 +311,6 @@ static inline void btrfs_dev_clear_zone_empty(struct btrfs_device *device, u64 p
 	btrfs_dev_set_empty_zone_bit(device, pos, false);
 }
 
-static inline bool btrfs_check_super_location(struct btrfs_device *device, u64 pos)
-{
-	/*
-	 * On a non-zoned device, any address is OK. On a zoned device,
-	 * non-SEQUENTIAL WRITE REQUIRED zones are capable.
-	 */
-	return device->zone_info == NULL || !btrfs_dev_is_sequential(device, pos);
-}
-
 static inline void btrfs_zoned_meta_io_lock(struct btrfs_fs_info *fs_info)
 {
 	if (!btrfs_is_zoned(fs_info))
-- 
2.26.3


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

* [PATCH 05/10] btrfs: move btrfs_zoned_meta_io_*lock to extent_io.c
  2022-09-14 23:07 [PATCH 00/10] btrfs: clean up zoned device helpers Josef Bacik
                   ` (3 preceding siblings ...)
  2022-09-14 23:07 ` [PATCH 04/10] btrfs: move btrfs_check_super_location into scrub.c Josef Bacik
@ 2022-09-14 23:07 ` Josef Bacik
  2022-09-15 13:58   ` Johannes Thumshirn
  2022-09-14 23:07 ` [PATCH 06/10] btrfs: move btrfs_clear_treelog_bg to extent-tree.c Josef Bacik
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Josef Bacik @ 2022-09-14 23:07 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

This is only used in extent_io.c for locking during writeout.  Move this
out of zoned.h locally to extent_io.c, these functions use code not
defined in zoned.h so allows us to clean up the header file.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/extent_io.c | 14 ++++++++++++++
 fs/btrfs/zoned.h     | 14 --------------
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index f5eb6c66911c..18b60304c97a 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -2945,6 +2945,20 @@ static int submit_eb_page(struct page *page, struct writeback_control *wbc,
 	return 1;
 }
 
+static inline void btrfs_zoned_meta_io_lock(struct btrfs_fs_info *fs_info)
+{
+	if (!btrfs_is_zoned(fs_info))
+		return;
+	mutex_lock(&fs_info->zoned_meta_io_lock);
+}
+
+static inline void btrfs_zoned_meta_io_unlock(struct btrfs_fs_info *fs_info)
+{
+	if (!btrfs_is_zoned(fs_info))
+		return;
+	mutex_unlock(&fs_info->zoned_meta_io_lock);
+}
+
 int btree_write_cache_pages(struct address_space *mapping,
 				   struct writeback_control *wbc)
 {
diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h
index 0a1298afa049..af7eebe4f405 100644
--- a/fs/btrfs/zoned.h
+++ b/fs/btrfs/zoned.h
@@ -311,20 +311,6 @@ static inline void btrfs_dev_clear_zone_empty(struct btrfs_device *device, u64 p
 	btrfs_dev_set_empty_zone_bit(device, pos, false);
 }
 
-static inline void btrfs_zoned_meta_io_lock(struct btrfs_fs_info *fs_info)
-{
-	if (!btrfs_is_zoned(fs_info))
-		return;
-	mutex_lock(&fs_info->zoned_meta_io_lock);
-}
-
-static inline void btrfs_zoned_meta_io_unlock(struct btrfs_fs_info *fs_info)
-{
-	if (!btrfs_is_zoned(fs_info))
-		return;
-	mutex_unlock(&fs_info->zoned_meta_io_lock);
-}
-
 static inline void btrfs_clear_treelog_bg(struct btrfs_block_group *bg)
 {
 	struct btrfs_fs_info *fs_info = bg->fs_info;
-- 
2.26.3


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

* [PATCH 06/10] btrfs: move btrfs_clear_treelog_bg to extent-tree.c
  2022-09-14 23:07 [PATCH 00/10] btrfs: clean up zoned device helpers Josef Bacik
                   ` (4 preceding siblings ...)
  2022-09-14 23:07 ` [PATCH 05/10] btrfs: move btrfs_zoned_meta_io_*lock to extent_io.c Josef Bacik
@ 2022-09-14 23:07 ` Josef Bacik
  2022-09-15 14:00   ` Johannes Thumshirn
  2022-09-14 23:07 ` [PATCH 07/10] btrfs: move btrfs_zoned_data_reloc_*lock to extent_io.c Josef Bacik
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Josef Bacik @ 2022-09-14 23:07 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

This function uses a lot of code that isn't defined inside of zoned.h,
so move it to extent-tree.c where the other functions that use these
members are.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/extent-tree.c | 12 ++++++++++++
 fs/btrfs/zoned.h       | 15 ++-------------
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 0785c1491313..9c4ce3c100ec 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -3731,6 +3731,18 @@ static int do_allocation_clustered(struct btrfs_block_group *block_group,
  *   block_group::lock
  *     fs_info::treelog_bg_lock
  */
+void btrfs_clear_treelog_bg(struct btrfs_block_group *bg)
+{
+	struct btrfs_fs_info *fs_info = bg->fs_info;
+
+	if (!btrfs_is_zoned(fs_info))
+		return;
+
+	spin_lock(&fs_info->treelog_bg_lock);
+	if (fs_info->treelog_bg == bg->start)
+		fs_info->treelog_bg = 0;
+	spin_unlock(&fs_info->treelog_bg_lock);
+}
 
 /*
  * Simple allocator for sequential-only block group. It only allows sequential
diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h
index af7eebe4f405..bd2b3fee4f2d 100644
--- a/fs/btrfs/zoned.h
+++ b/fs/btrfs/zoned.h
@@ -31,6 +31,8 @@ struct btrfs_zoned_device_info {
 	struct blk_zone sb_zones[2 * BTRFS_SUPER_MIRROR_MAX];
 };
 
+void btrfs_clear_treelog_bg(struct btrfs_block_group *bg);
+
 #ifdef CONFIG_BLK_DEV_ZONED
 int btrfs_get_dev_zone(struct btrfs_device *device, u64 pos,
 		       struct blk_zone *zone);
@@ -311,19 +313,6 @@ static inline void btrfs_dev_clear_zone_empty(struct btrfs_device *device, u64 p
 	btrfs_dev_set_empty_zone_bit(device, pos, false);
 }
 
-static inline void btrfs_clear_treelog_bg(struct btrfs_block_group *bg)
-{
-	struct btrfs_fs_info *fs_info = bg->fs_info;
-
-	if (!btrfs_is_zoned(fs_info))
-		return;
-
-	spin_lock(&fs_info->treelog_bg_lock);
-	if (fs_info->treelog_bg == bg->start)
-		fs_info->treelog_bg = 0;
-	spin_unlock(&fs_info->treelog_bg_lock);
-}
-
 static inline void btrfs_zoned_data_reloc_lock(struct btrfs_inode *inode)
 {
 	struct btrfs_root *root = inode->root;
-- 
2.26.3


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

* [PATCH 07/10] btrfs: move btrfs_zoned_data_reloc_*lock to extent_io.c
  2022-09-14 23:07 [PATCH 00/10] btrfs: clean up zoned device helpers Josef Bacik
                   ` (5 preceding siblings ...)
  2022-09-14 23:07 ` [PATCH 06/10] btrfs: move btrfs_clear_treelog_bg to extent-tree.c Josef Bacik
@ 2022-09-14 23:07 ` Josef Bacik
  2022-09-15 14:01   ` Johannes Thumshirn
  2022-09-14 23:07 ` [PATCH 08/10] btrfs: move btrfs_zoned_bg_is_full into block-group.c Josef Bacik
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Josef Bacik @ 2022-09-14 23:07 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

These functions are only used to protect io in extent_io.c, move them
from zoned.h locally in extent_io.c.  These helpers use code not defined
in zoned.h, this cleans up the header file.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/extent_io.c | 16 ++++++++++++++++
 fs/btrfs/zoned.h     | 16 ----------------
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 18b60304c97a..13c8ed8cbfc8 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -3301,6 +3301,22 @@ int extent_write_locked_range(struct inode *inode, u64 start, u64 end)
 	return ret;
 }
 
+static inline void btrfs_zoned_data_reloc_lock(struct btrfs_inode *inode)
+{
+	struct btrfs_root *root = inode->root;
+
+	if (btrfs_is_data_reloc_root(root) && btrfs_is_zoned(root->fs_info))
+		mutex_lock(&root->fs_info->zoned_data_reloc_io_lock);
+}
+
+static inline void btrfs_zoned_data_reloc_unlock(struct btrfs_inode *inode)
+{
+	struct btrfs_root *root = inode->root;
+
+	if (btrfs_is_data_reloc_root(root) && btrfs_is_zoned(root->fs_info))
+		mutex_unlock(&root->fs_info->zoned_data_reloc_io_lock);
+}
+
 int extent_writepages(struct address_space *mapping,
 		      struct writeback_control *wbc)
 {
diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h
index bd2b3fee4f2d..de1337e462be 100644
--- a/fs/btrfs/zoned.h
+++ b/fs/btrfs/zoned.h
@@ -313,22 +313,6 @@ static inline void btrfs_dev_clear_zone_empty(struct btrfs_device *device, u64 p
 	btrfs_dev_set_empty_zone_bit(device, pos, false);
 }
 
-static inline void btrfs_zoned_data_reloc_lock(struct btrfs_inode *inode)
-{
-	struct btrfs_root *root = inode->root;
-
-	if (btrfs_is_data_reloc_root(root) && btrfs_is_zoned(root->fs_info))
-		mutex_lock(&root->fs_info->zoned_data_reloc_io_lock);
-}
-
-static inline void btrfs_zoned_data_reloc_unlock(struct btrfs_inode *inode)
-{
-	struct btrfs_root *root = inode->root;
-
-	if (btrfs_is_data_reloc_root(root) && btrfs_is_zoned(root->fs_info))
-		mutex_unlock(&root->fs_info->zoned_data_reloc_io_lock);
-}
-
 static inline bool btrfs_zoned_bg_is_full(const struct btrfs_block_group *bg)
 {
 	ASSERT(btrfs_is_zoned(bg->fs_info));
-- 
2.26.3


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

* [PATCH 08/10] btrfs: move btrfs_zoned_bg_is_full into block-group.c
  2022-09-14 23:07 [PATCH 00/10] btrfs: clean up zoned device helpers Josef Bacik
                   ` (6 preceding siblings ...)
  2022-09-14 23:07 ` [PATCH 07/10] btrfs: move btrfs_zoned_data_reloc_*lock to extent_io.c Josef Bacik
@ 2022-09-14 23:07 ` Josef Bacik
  2022-09-15 14:02   ` Johannes Thumshirn
  2022-09-14 23:07 ` [PATCH 09/10] btrfs: make the zoned helpers take btrfs_zoned_device_info Josef Bacik
  2022-09-14 23:07 ` [PATCH 10/10] btrfs: delete btrfs_check_super_location helper Josef Bacik
  9 siblings, 1 reply; 22+ messages in thread
From: Josef Bacik @ 2022-09-14 23:07 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

This function is completely related to block groups, as well as using
ASSERT() which isn't defined in either zoned.h or block-group.h.  Move
the code to block-group.c to make sure the headers are only using code
they define themselves.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/block-group.c | 6 ++++++
 fs/btrfs/block-group.h | 1 +
 fs/btrfs/zoned.h       | 7 -------
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index e21382a13fe4..3a5f29494d98 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -4178,3 +4178,9 @@ void btrfs_dec_block_group_swap_extents(struct btrfs_block_group *bg, int amount
 	bg->swap_extents -= amount;
 	spin_unlock(&bg->lock);
 }
+
+bool btrfs_zoned_bg_is_full(const struct btrfs_block_group *bg)
+{
+	ASSERT(btrfs_is_zoned(bg->fs_info));
+	return (bg->alloc_offset == bg->zone_capacity);
+}
diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h
index 6c970a486b68..4edf5486a592 100644
--- a/fs/btrfs/block-group.h
+++ b/fs/btrfs/block-group.h
@@ -322,6 +322,7 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info);
 int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start,
 		       struct block_device *bdev, u64 physical, u64 **logical,
 		       int *naddrs, int *stripe_len);
+bool btrfs_zoned_bg_is_full(const struct btrfs_block_group *bg);
 
 static inline u64 btrfs_data_alloc_profile(struct btrfs_fs_info *fs_info)
 {
diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h
index de1337e462be..a94de42f9edb 100644
--- a/fs/btrfs/zoned.h
+++ b/fs/btrfs/zoned.h
@@ -312,11 +312,4 @@ static inline void btrfs_dev_clear_zone_empty(struct btrfs_device *device, u64 p
 {
 	btrfs_dev_set_empty_zone_bit(device, pos, false);
 }
-
-static inline bool btrfs_zoned_bg_is_full(const struct btrfs_block_group *bg)
-{
-	ASSERT(btrfs_is_zoned(bg->fs_info));
-	return (bg->alloc_offset == bg->zone_capacity);
-}
-
 #endif
-- 
2.26.3


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

* [PATCH 09/10] btrfs: make the zoned helpers take btrfs_zoned_device_info
  2022-09-14 23:07 [PATCH 00/10] btrfs: clean up zoned device helpers Josef Bacik
                   ` (7 preceding siblings ...)
  2022-09-14 23:07 ` [PATCH 08/10] btrfs: move btrfs_zoned_bg_is_full into block-group.c Josef Bacik
@ 2022-09-14 23:07 ` Josef Bacik
  2022-09-15 14:05   ` Johannes Thumshirn
  2022-09-14 23:07 ` [PATCH 10/10] btrfs: delete btrfs_check_super_location helper Josef Bacik
  9 siblings, 1 reply; 22+ messages in thread
From: Josef Bacik @ 2022-09-14 23:07 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

These helpers are doing btrfs_device->zone_info, but btrfs_device isn't
defined in zoned.h, which forces one to include files in a specific
order.  Fix the helpers to take btrfs_zoned_device_info instead, and
make the callers pass in the zone_info.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/extent-tree.c |  2 +-
 fs/btrfs/scrub.c       |  9 +++++----
 fs/btrfs/volumes.c     |  2 +-
 fs/btrfs/zoned.c       | 20 +++++++++++---------
 fs/btrfs/zoned.h       | 23 +++++++++++------------
 5 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 9c4ce3c100ec..7dac704071b9 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -1276,7 +1276,7 @@ static inline bool btrfs_can_zone_reset(struct btrfs_device *device,
 {
 	u64 zone_size;
 
-	if (!btrfs_dev_is_sequential(device, physical))
+	if (!btrfs_dev_is_sequential(device->zone_info, physical))
 		return false;
 
 	zone_size = device->zone_info->zone_size;
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 927431217131..66f09202ba96 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -1792,7 +1792,7 @@ static int fill_writer_pointer_gap(struct scrub_ctx *sctx, u64 physical)
 	if (!btrfs_is_zoned(sctx->fs_info))
 		return 0;
 
-	if (!btrfs_dev_is_sequential(sctx->wr_tgtdev, physical))
+	if (!btrfs_dev_is_sequential(sctx->wr_tgtdev->zone_info, physical))
 		return 0;
 
 	if (sctx->write_pointer < physical) {
@@ -3367,7 +3367,7 @@ static int sync_write_pointer_for_zoned(struct scrub_ctx *sctx, u64 logical,
 				  "zoned: failed to recover write pointer");
 	}
 	mutex_unlock(&sctx->wr_lock);
-	btrfs_dev_clear_zone_empty(sctx->wr_tgtdev, physical);
+	btrfs_dev_clear_zone_empty(sctx->wr_tgtdev->zone_info, physical);
 
 	return ret;
 }
@@ -3627,7 +3627,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
 	blk_start_plug(&plug);
 
 	if (sctx->is_dev_replace &&
-	    btrfs_dev_is_sequential(sctx->wr_tgtdev, physical)) {
+	    btrfs_dev_is_sequential(sctx->wr_tgtdev->zone_info, physical)) {
 		mutex_lock(&sctx->wr_lock);
 		sctx->write_pointer = physical;
 		mutex_unlock(&sctx->wr_lock);
@@ -4146,7 +4146,8 @@ static inline bool btrfs_check_super_location(struct btrfs_device *device, u64 p
 	 * On a non-zoned device, any address is OK. On a zoned device,
 	 * non-SEQUENTIAL WRITE REQUIRED zones are capable.
 	 */
-	return device->zone_info == NULL || !btrfs_dev_is_sequential(device, pos);
+	return device->zone_info == NULL ||
+		!btrfs_dev_is_sequential(device->zone_info, pos);
 }
 
 static noinline_for_stack int scrub_supers(struct scrub_ctx *sctx,
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 29652323ef9b..ac3aca265a59 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -6853,7 +6853,7 @@ static void btrfs_submit_dev_bio(struct btrfs_device *dev, struct bio *bio)
 	if (bio_op(bio) == REQ_OP_ZONE_APPEND) {
 		u64 physical = bio->bi_iter.bi_sector << SECTOR_SHIFT;
 
-		if (btrfs_dev_is_sequential(dev, physical)) {
+		if (btrfs_dev_is_sequential(dev->zone_info, physical)) {
 			u64 zone_start = round_down(physical,
 						    dev->fs_info->zone_size);
 
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index 4d6647925545..67751294f113 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -1012,7 +1012,7 @@ u64 btrfs_find_allocatable_zones(struct btrfs_device *device, u64 hole_start,
 			return hole_end;
 
 		/* Check if zones in the region are all empty */
-		if (btrfs_dev_is_sequential(device, pos) &&
+		if (btrfs_dev_is_sequential(zinfo, pos) &&
 		    find_next_zero_bit(zinfo->empty_zones, end, begin) != end) {
 			pos += zinfo->zone_size;
 			continue;
@@ -1098,7 +1098,7 @@ int btrfs_reset_device_zone(struct btrfs_device *device, u64 physical,
 
 	*bytes = length;
 	while (length) {
-		btrfs_dev_set_zone_empty(device, physical);
+		btrfs_dev_set_zone_empty(device->zone_info, physical);
 		btrfs_dev_clear_active_zone(device, physical);
 		physical += device->zone_info->zone_size;
 		length -= device->zone_info->zone_size;
@@ -1134,8 +1134,8 @@ int btrfs_ensure_empty_zones(struct btrfs_device *device, u64 start, u64 size)
 	for (pos = start; pos < start + size; pos += zinfo->zone_size) {
 		u64 reset_bytes;
 
-		if (!btrfs_dev_is_sequential(device, pos) ||
-		    btrfs_dev_is_empty_zone(device, pos))
+		if (!btrfs_dev_is_sequential(zinfo, pos) ||
+		    btrfs_dev_is_empty_zone(zinfo, pos))
 			continue;
 
 		/* Free regions should be empty */
@@ -1315,7 +1315,8 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
 			continue;
 		}
 
-		is_sequential = btrfs_dev_is_sequential(device, physical[i]);
+		is_sequential = btrfs_dev_is_sequential(device->zone_info,
+							physical[i]);
 		if (is_sequential)
 			num_sequential++;
 		else
@@ -1337,12 +1338,13 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
 		 * This zone will be used for allocation, so mark this zone
 		 * non-empty.
 		 */
-		btrfs_dev_clear_zone_empty(device, physical[i]);
+		btrfs_dev_clear_zone_empty(device->zone_info, physical[i]);
 
 		down_read(&dev_replace->rwsem);
 		dev_replace_is_ongoing = btrfs_dev_replace_is_ongoing(dev_replace);
 		if (dev_replace_is_ongoing && dev_replace->tgtdev != NULL)
-			btrfs_dev_clear_zone_empty(dev_replace->tgtdev, physical[i]);
+			btrfs_dev_clear_zone_empty(dev_replace->tgtdev->zone_info,
+						   physical[i]);
 		up_read(&dev_replace->rwsem);
 
 		/*
@@ -1720,7 +1722,7 @@ void btrfs_revert_meta_write_pointer(struct btrfs_block_group *cache,
 
 int btrfs_zoned_issue_zeroout(struct btrfs_device *device, u64 physical, u64 length)
 {
-	if (!btrfs_dev_is_sequential(device, physical))
+	if (!btrfs_dev_is_sequential(device->zone_info, physical))
 		return -EOPNOTSUPP;
 
 	return blkdev_issue_zeroout(device->bdev, physical >> SECTOR_SHIFT,
@@ -1784,7 +1786,7 @@ int btrfs_sync_zone_write_pointer(struct btrfs_device *tgt_dev, u64 logical,
 	u64 wp;
 	int ret;
 
-	if (!btrfs_dev_is_sequential(tgt_dev, physical_pos))
+	if (!btrfs_dev_is_sequential(tgt_dev->zone_info, physical_pos))
 		return 0;
 
 	ret = read_zone_info(fs_info, logical, &zone);
diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h
index a94de42f9edb..eaaa4787fefb 100644
--- a/fs/btrfs/zoned.h
+++ b/fs/btrfs/zoned.h
@@ -267,30 +267,27 @@ static inline int btrfs_zoned_activate_one_bg(struct btrfs_fs_info *fs_info,
 
 #endif
 
-static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos)
+static inline bool btrfs_dev_is_sequential(struct btrfs_zoned_device_info *zone_info,
+					   u64 pos)
 {
-	struct btrfs_zoned_device_info *zone_info = device->zone_info;
-
 	if (!zone_info)
 		return false;
 
 	return test_bit(pos >> zone_info->zone_size_shift, zone_info->seq_zones);
 }
 
-static inline bool btrfs_dev_is_empty_zone(struct btrfs_device *device, u64 pos)
+static inline bool btrfs_dev_is_empty_zone(struct btrfs_zoned_device_info *zone_info,
+					   u64 pos)
 {
-	struct btrfs_zoned_device_info *zone_info = device->zone_info;
-
 	if (!zone_info)
 		return true;
 
 	return test_bit(pos >> zone_info->zone_size_shift, zone_info->empty_zones);
 }
 
-static inline void btrfs_dev_set_empty_zone_bit(struct btrfs_device *device,
+static inline void btrfs_dev_set_empty_zone_bit(struct btrfs_zoned_device_info *zone_info,
 						u64 pos, bool set)
 {
-	struct btrfs_zoned_device_info *zone_info = device->zone_info;
 	unsigned int zno;
 
 	if (!zone_info)
@@ -303,13 +300,15 @@ static inline void btrfs_dev_set_empty_zone_bit(struct btrfs_device *device,
 		clear_bit(zno, zone_info->empty_zones);
 }
 
-static inline void btrfs_dev_set_zone_empty(struct btrfs_device *device, u64 pos)
+static inline void btrfs_dev_set_zone_empty(struct btrfs_zoned_device_info *zone_info,
+					    u64 pos)
 {
-	btrfs_dev_set_empty_zone_bit(device, pos, true);
+	btrfs_dev_set_empty_zone_bit(zone_info, pos, true);
 }
 
-static inline void btrfs_dev_clear_zone_empty(struct btrfs_device *device, u64 pos)
+static inline void btrfs_dev_clear_zone_empty(struct btrfs_zoned_device_info *zone_info,
+					      u64 pos)
 {
-	btrfs_dev_set_empty_zone_bit(device, pos, false);
+	btrfs_dev_set_empty_zone_bit(zone_info, pos, false);
 }
 #endif
-- 
2.26.3


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

* [PATCH 10/10] btrfs: delete btrfs_check_super_location helper
  2022-09-14 23:07 [PATCH 00/10] btrfs: clean up zoned device helpers Josef Bacik
                   ` (8 preceding siblings ...)
  2022-09-14 23:07 ` [PATCH 09/10] btrfs: make the zoned helpers take btrfs_zoned_device_info Josef Bacik
@ 2022-09-14 23:07 ` Josef Bacik
  2022-09-15  7:29   ` Naohiro Aota
  9 siblings, 1 reply; 22+ messages in thread
From: Josef Bacik @ 2022-09-14 23:07 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

This checks if device->zone_info == NULL or if the bytenr falls in a
sequential range, however btrfs_dev_is_sequential already does the NULL
zone_info check, so we can replace this helper with just
!btrfs_dev_is_sequential.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/scrub.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 66f09202ba96..9d130e13c6b9 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -4140,16 +4140,6 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
 	return ret;
 }
 
-static inline bool btrfs_check_super_location(struct btrfs_device *device, u64 pos)
-{
-	/*
-	 * On a non-zoned device, any address is OK. On a zoned device,
-	 * non-SEQUENTIAL WRITE REQUIRED zones are capable.
-	 */
-	return device->zone_info == NULL ||
-		!btrfs_dev_is_sequential(device->zone_info, pos);
-}
-
 static noinline_for_stack int scrub_supers(struct scrub_ctx *sctx,
 					   struct btrfs_device *scrub_dev)
 {
@@ -4173,7 +4163,7 @@ static noinline_for_stack int scrub_supers(struct scrub_ctx *sctx,
 		if (bytenr + BTRFS_SUPER_INFO_SIZE >
 		    scrub_dev->commit_total_bytes)
 			break;
-		if (!btrfs_check_super_location(scrub_dev, bytenr))
+		if (!btrfs_dev_is_sequential(scrub_dev->zone_info, bytenr))
 			continue;
 
 		ret = scrub_sectors(sctx, bytenr, BTRFS_SUPER_INFO_SIZE, bytenr,
-- 
2.26.3


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

* Re: [PATCH 10/10] btrfs: delete btrfs_check_super_location helper
  2022-09-14 23:07 ` [PATCH 10/10] btrfs: delete btrfs_check_super_location helper Josef Bacik
@ 2022-09-15  7:29   ` Naohiro Aota
  0 siblings, 0 replies; 22+ messages in thread
From: Naohiro Aota @ 2022-09-15  7:29 UTC (permalink / raw)
  To: Josef Bacik; +Cc: linux-btrfs, kernel-team

On Wed, Sep 14, 2022 at 07:07:50PM -0400, Josef Bacik wrote:
> This checks if device->zone_info == NULL or if the bytenr falls in a
> sequential range, however btrfs_dev_is_sequential already does the NULL
> zone_info check, so we can replace this helper with just
> !btrfs_dev_is_sequential.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> ---
>  fs/btrfs/scrub.c | 12 +-----------
>  1 file changed, 1 insertion(+), 11 deletions(-)
> 
> diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
> index 66f09202ba96..9d130e13c6b9 100644
> --- a/fs/btrfs/scrub.c
> +++ b/fs/btrfs/scrub.c
> @@ -4140,16 +4140,6 @@ int scrub_enumerate_chunks(struct scrub_ctx *sctx,
>  	return ret;
>  }
>  
> -static inline bool btrfs_check_super_location(struct btrfs_device *device, u64 pos)
> -{
> -	/*
> -	 * On a non-zoned device, any address is OK. On a zoned device,
> -	 * non-SEQUENTIAL WRITE REQUIRED zones are capable.
> -	 */
> -	return device->zone_info == NULL ||
> -		!btrfs_dev_is_sequential(device->zone_info, pos);
> -}
> -
>  static noinline_for_stack int scrub_supers(struct scrub_ctx *sctx,
>  					   struct btrfs_device *scrub_dev)
>  {
> @@ -4173,7 +4163,7 @@ static noinline_for_stack int scrub_supers(struct scrub_ctx *sctx,
>  		if (bytenr + BTRFS_SUPER_INFO_SIZE >
>  		    scrub_dev->commit_total_bytes)
>  			break;
> -		if (!btrfs_check_super_location(scrub_dev, bytenr))
> +		if (!btrfs_dev_is_sequential(scrub_dev->zone_info, bytenr))

This condition is inverted. We need to skip a sequential zone as we cannot
overwrite superblock in the zone anyway.

>  			continue;
>  
>  		ret = scrub_sectors(sctx, bytenr, BTRFS_SUPER_INFO_SIZE, bytenr,
> -- 
> 2.26.3
> 

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

* Re: [PATCH 01/10] btrfs: add a helper for opening a new device to add to the fs
  2022-09-14 23:07 ` [PATCH 01/10] btrfs: add a helper for opening a new device to add to the fs Josef Bacik
@ 2022-09-15 13:54   ` Johannes Thumshirn
  2022-09-21  9:39   ` Pankaj Raghav
  1 sibling, 0 replies; 22+ messages in thread
From: Johannes Thumshirn @ 2022-09-15 13:54 UTC (permalink / raw)
  To: Josef Bacik, linux-btrfs, kernel-team

Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

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

* Re: [PATCH 02/10] btrfs: move btrfs_check_device_zone_type into volumes.c
  2022-09-14 23:07 ` [PATCH 02/10] btrfs: move btrfs_check_device_zone_type into volumes.c Josef Bacik
@ 2022-09-15 13:55   ` Johannes Thumshirn
  0 siblings, 0 replies; 22+ messages in thread
From: Johannes Thumshirn @ 2022-09-15 13:55 UTC (permalink / raw)
  To: Josef Bacik, linux-btrfs, kernel-team

Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

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

* Re: [PATCH 03/10] btrfs: move btrfs_can_zone_reset into extent-tree.c
  2022-09-14 23:07 ` [PATCH 03/10] btrfs: move btrfs_can_zone_reset into extent-tree.c Josef Bacik
@ 2022-09-15 13:56   ` Johannes Thumshirn
  0 siblings, 0 replies; 22+ messages in thread
From: Johannes Thumshirn @ 2022-09-15 13:56 UTC (permalink / raw)
  To: Josef Bacik, linux-btrfs, kernel-team

Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

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

* Re: [PATCH 04/10] btrfs: move btrfs_check_super_location into scrub.c
  2022-09-14 23:07 ` [PATCH 04/10] btrfs: move btrfs_check_super_location into scrub.c Josef Bacik
@ 2022-09-15 13:57   ` Johannes Thumshirn
  0 siblings, 0 replies; 22+ messages in thread
From: Johannes Thumshirn @ 2022-09-15 13:57 UTC (permalink / raw)
  To: Josef Bacik, linux-btrfs, kernel-team

Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

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

* Re: [PATCH 05/10] btrfs: move btrfs_zoned_meta_io_*lock to extent_io.c
  2022-09-14 23:07 ` [PATCH 05/10] btrfs: move btrfs_zoned_meta_io_*lock to extent_io.c Josef Bacik
@ 2022-09-15 13:58   ` Johannes Thumshirn
  0 siblings, 0 replies; 22+ messages in thread
From: Johannes Thumshirn @ 2022-09-15 13:58 UTC (permalink / raw)
  To: Josef Bacik, linux-btrfs, kernel-team

Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

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

* Re: [PATCH 06/10] btrfs: move btrfs_clear_treelog_bg to extent-tree.c
  2022-09-14 23:07 ` [PATCH 06/10] btrfs: move btrfs_clear_treelog_bg to extent-tree.c Josef Bacik
@ 2022-09-15 14:00   ` Johannes Thumshirn
  0 siblings, 0 replies; 22+ messages in thread
From: Johannes Thumshirn @ 2022-09-15 14:00 UTC (permalink / raw)
  To: Josef Bacik, linux-btrfs, kernel-team

Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

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

* Re: [PATCH 07/10] btrfs: move btrfs_zoned_data_reloc_*lock to extent_io.c
  2022-09-14 23:07 ` [PATCH 07/10] btrfs: move btrfs_zoned_data_reloc_*lock to extent_io.c Josef Bacik
@ 2022-09-15 14:01   ` Johannes Thumshirn
  0 siblings, 0 replies; 22+ messages in thread
From: Johannes Thumshirn @ 2022-09-15 14:01 UTC (permalink / raw)
  To: Josef Bacik, linux-btrfs, kernel-team

Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

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

* Re: [PATCH 08/10] btrfs: move btrfs_zoned_bg_is_full into block-group.c
  2022-09-14 23:07 ` [PATCH 08/10] btrfs: move btrfs_zoned_bg_is_full into block-group.c Josef Bacik
@ 2022-09-15 14:02   ` Johannes Thumshirn
  0 siblings, 0 replies; 22+ messages in thread
From: Johannes Thumshirn @ 2022-09-15 14:02 UTC (permalink / raw)
  To: Josef Bacik, linux-btrfs, kernel-team

Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

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

* Re: [PATCH 09/10] btrfs: make the zoned helpers take btrfs_zoned_device_info
  2022-09-14 23:07 ` [PATCH 09/10] btrfs: make the zoned helpers take btrfs_zoned_device_info Josef Bacik
@ 2022-09-15 14:05   ` Johannes Thumshirn
  0 siblings, 0 replies; 22+ messages in thread
From: Johannes Thumshirn @ 2022-09-15 14:05 UTC (permalink / raw)
  To: Josef Bacik, linux-btrfs, kernel-team

Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

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

* Re: [PATCH 01/10] btrfs: add a helper for opening a new device to add to the fs
  2022-09-14 23:07 ` [PATCH 01/10] btrfs: add a helper for opening a new device to add to the fs Josef Bacik
  2022-09-15 13:54   ` Johannes Thumshirn
@ 2022-09-21  9:39   ` Pankaj Raghav
  1 sibling, 0 replies; 22+ messages in thread
From: Pankaj Raghav @ 2022-09-21  9:39 UTC (permalink / raw)
  To: Josef Bacik; +Cc: linux-btrfs, kernel-team, Pankaj Raghav

>  	list_for_each_entry(device, &fs_devices->devices, dev_list) {
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 09c1434c3cae..ea76458d7c70 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -2583,6 +2583,26 @@ static int btrfs_finish_sprout(struct btrfs_trans_handle *trans)
>  	return ret;
>  }
>  
> +struct block_device *btrfs_open_device_for_adding(struct btrfs_fs_info *fs_info,
> +						  const char *device_path)
> +{
> +	struct block_device *bdev;
> +
> +	bdev = blkdev_get_by_path(device_path, FMODE_WRITE | FMODE_EXCL,
> +				  fs_info->bdev_holder);
> +	if (IS_ERR(bdev))
> +		return bdev;
> +
> +	if (!btrfs_check_device_zone_type(fs_info, bdev)) {
> +		btrfs_err(fs_info,
> +			  "dev-replace: zoned type of target device mismatch with filesystem");

Shouldn't the `dev-replace` be removed as this helper is used from
dev-replace.c and volumes.c?

> +		blkdev_put(bdev, FMODE_EXCL);
> +		return ERR_PTR(-EINVAL);
> +	}
> +
> +	return bdev;
> +}
> +
>  int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path)
>  {
>  	struct btrfs_root *root = fs_info->dev_root;
> @@ -2602,16 +2622,10 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
>  	if (sb_rdonly(sb) && !fs_devices->seeding)
>  		return -EROFS;
>  
> -	bdev = blkdev_get_by_path(device_path, FMODE_WRITE | FMODE_EXCL,
> -				  fs_info->bdev_holder);
> +	bdev = btrfs_open_device_for_adding(fs_info, device_path);

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

end of thread, other threads:[~2022-09-21  9:39 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-14 23:07 [PATCH 00/10] btrfs: clean up zoned device helpers Josef Bacik
2022-09-14 23:07 ` [PATCH 01/10] btrfs: add a helper for opening a new device to add to the fs Josef Bacik
2022-09-15 13:54   ` Johannes Thumshirn
2022-09-21  9:39   ` Pankaj Raghav
2022-09-14 23:07 ` [PATCH 02/10] btrfs: move btrfs_check_device_zone_type into volumes.c Josef Bacik
2022-09-15 13:55   ` Johannes Thumshirn
2022-09-14 23:07 ` [PATCH 03/10] btrfs: move btrfs_can_zone_reset into extent-tree.c Josef Bacik
2022-09-15 13:56   ` Johannes Thumshirn
2022-09-14 23:07 ` [PATCH 04/10] btrfs: move btrfs_check_super_location into scrub.c Josef Bacik
2022-09-15 13:57   ` Johannes Thumshirn
2022-09-14 23:07 ` [PATCH 05/10] btrfs: move btrfs_zoned_meta_io_*lock to extent_io.c Josef Bacik
2022-09-15 13:58   ` Johannes Thumshirn
2022-09-14 23:07 ` [PATCH 06/10] btrfs: move btrfs_clear_treelog_bg to extent-tree.c Josef Bacik
2022-09-15 14:00   ` Johannes Thumshirn
2022-09-14 23:07 ` [PATCH 07/10] btrfs: move btrfs_zoned_data_reloc_*lock to extent_io.c Josef Bacik
2022-09-15 14:01   ` Johannes Thumshirn
2022-09-14 23:07 ` [PATCH 08/10] btrfs: move btrfs_zoned_bg_is_full into block-group.c Josef Bacik
2022-09-15 14:02   ` Johannes Thumshirn
2022-09-14 23:07 ` [PATCH 09/10] btrfs: make the zoned helpers take btrfs_zoned_device_info Josef Bacik
2022-09-15 14:05   ` Johannes Thumshirn
2022-09-14 23:07 ` [PATCH 10/10] btrfs: delete btrfs_check_super_location helper Josef Bacik
2022-09-15  7:29   ` Naohiro Aota

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).