Skip to contentSkip to conversation

btrfs: clean up zoned device helpers

PATCH In review Josef Bacik 4 participants 22 messages Sep 14, 2022 – Sep 21, 2022 Btrfs file system

lore
Share & tools
lore
#0 lore raw

cover btrfs: clean up zoned device helpers

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(-)
Signature · 1 line
2.26.3
#1 lore raw

PATCH 1/10 btrfs: add a helper for opening a new device to add to the fs

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.

---
 fs/btrfs/dev-replace.c | 10 +---------
 fs/btrfs/volumes.c     | 28 +++++++++++++++++++++-------
 fs/btrfs/volumes.h     |  2 ++
 3 files changed, 24 insertions(+), 16 deletions(-)
fs/btrfs/dev-replace.c +1 -9
index c6222057f655..8f5922ba0129 100644
@@ -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) {
fs/btrfs/volumes.c +21 -7
index 09c1434c3cae..ea76458d7c70 100644
@@ -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);
fs/btrfs/volumes.h +2 -0
index 2bf7dbe739fd..60d74554edf2 100644
@@ -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
Signature · 1 line
2.26.3
#3 lore raw

Re: [PATCH 01/10] btrfs: add a helper for opening a new device to add to the fs

In reply to Josef Bacik
Quoted 12 lines
fs/btrfs/dev-replace.c +0 -0
 	list_for_each_entry(device, &fs_devices->devices, dev_list) {
fs/btrfs/volumes.c +3 -0
index 09c1434c3cae..ea76458d7c70 100644
@@ -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)
+{

fs/btrfs/volumes.c static int btrfs_finish_sprout(struct btrfs_trans_handle *trans) · line 2598

Quoted 10 lines
fs/btrfs/volumes.c +10 -0
+	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?

Quoted 17 lines
fs/btrfs/volumes.c +8 -2
+		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);
#4 lore raw

PATCH 2/10 btrfs: move btrfs_check_device_zone_type into volumes.c

In reply to Josef Bacik

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.

---
 fs/btrfs/volumes.c | 19 +++++++++++++++++++
 fs/btrfs/zoned.h   | 19 -------------------
 2 files changed, 19 insertions(+), 19 deletions(-)
fs/btrfs/volumes.c +19 -0
index ea76458d7c70..29652323ef9b 100644
@@ -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)
 {
fs/btrfs/zoned.h +0 -19
index 094f3e44c53c..20d7f35406d4 100644
@@ -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)
 {
 	/*
Signature · 1 line
2.26.3
#6 lore raw

PATCH 3/10 btrfs: move btrfs_can_zone_reset into extent-tree.c

In reply to Josef Bacik

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.

---
 fs/btrfs/extent-tree.c | 15 +++++++++++++++
 fs/btrfs/zoned.h       | 15 ---------------
 2 files changed, 15 insertions(+), 15 deletions(-)
fs/btrfs/extent-tree.c +15 -0
index 7cf7844c9dba..0785c1491313 100644
@@ -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;
fs/btrfs/zoned.h +0 -15
index 20d7f35406d4..aabdd364e889 100644
@@ -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))
Signature · 1 line
2.26.3
#8 lore raw

PATCH 4/10 btrfs: move btrfs_check_super_location into scrub.c

In reply to Josef Bacik

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.

---
 fs/btrfs/scrub.c | 9 +++++++++
 fs/btrfs/zoned.h | 9 ---------
 2 files changed, 9 insertions(+), 9 deletions(-)
fs/btrfs/scrub.c +9 -0
index d5c23faceb8e..927431217131 100644
@@ -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)
 {
fs/btrfs/zoned.h +0 -9
index aabdd364e889..0a1298afa049 100644
@@ -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))
Signature · 1 line
2.26.3
#10 lore raw

PATCH 5/10 btrfs: move btrfs_zoned_meta_io_*lock to extent_io.c

In reply to Josef Bacik

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.

---
 fs/btrfs/extent_io.c | 14 ++++++++++++++
 fs/btrfs/zoned.h     | 14 --------------
 2 files changed, 14 insertions(+), 14 deletions(-)
fs/btrfs/extent_io.c +14 -0
index f5eb6c66911c..18b60304c97a 100644
@@ -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)
 {
fs/btrfs/zoned.h +0 -14
index 0a1298afa049..af7eebe4f405 100644
@@ -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;
Signature · 1 line
2.26.3
#12 lore raw

PATCH 6/10 btrfs: move btrfs_clear_treelog_bg to extent-tree.c

In reply to Josef Bacik

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.

---
 fs/btrfs/extent-tree.c | 12 ++++++++++++
 fs/btrfs/zoned.h       | 15 ++-------------
 2 files changed, 14 insertions(+), 13 deletions(-)
fs/btrfs/extent-tree.c +12 -0
index 0785c1491313..9c4ce3c100ec 100644
@@ -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
fs/btrfs/zoned.h +2 -13
index af7eebe4f405..bd2b3fee4f2d 100644
@@ -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;
Signature · 1 line
2.26.3
#14 lore raw

PATCH 7/10 btrfs: move btrfs_zoned_data_reloc_*lock to extent_io.c

In reply to Josef Bacik

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.

---
 fs/btrfs/extent_io.c | 16 ++++++++++++++++
 fs/btrfs/zoned.h     | 16 ----------------
 2 files changed, 16 insertions(+), 16 deletions(-)
fs/btrfs/extent_io.c +16 -0
index 18b60304c97a..13c8ed8cbfc8 100644
@@ -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)
 {
fs/btrfs/zoned.h +0 -16
index bd2b3fee4f2d..de1337e462be 100644
@@ -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));
Signature · 1 line
2.26.3
#16 lore raw

PATCH 8/10 btrfs: move btrfs_zoned_bg_is_full into block-group.c

In reply to Josef Bacik

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.

---
 fs/btrfs/block-group.c | 6 ++++++
 fs/btrfs/block-group.h | 1 +
 fs/btrfs/zoned.h       | 7 -------
 3 files changed, 7 insertions(+), 7 deletions(-)
fs/btrfs/block-group.c +6 -0
index e21382a13fe4..3a5f29494d98 100644
@@ -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);
+}
fs/btrfs/block-group.h +1 -0
index 6c970a486b68..4edf5486a592 100644
@@ -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)
 {
fs/btrfs/zoned.h +0 -7
index de1337e462be..a94de42f9edb 100644
@@ -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
Signature · 1 line
2.26.3
#18 lore raw

PATCH 9/10 btrfs: make the zoned helpers take btrfs_zoned_device_info

In reply to Josef Bacik

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.

---
 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(-)
fs/btrfs/extent-tree.c +1 -1
index 9c4ce3c100ec..7dac704071b9 100644
@@ -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;
fs/btrfs/scrub.c +5 -4
index 927431217131..66f09202ba96 100644
@@ -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,
fs/btrfs/volumes.c +1 -1
index 29652323ef9b..ac3aca265a59 100644
@@ -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);
 
fs/btrfs/zoned.c +11 -9
index 4d6647925545..67751294f113 100644
@@ -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);
fs/btrfs/zoned.h +11 -12
index a94de42f9edb..eaaa4787fefb 100644
@@ -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
Signature · 1 line
2.26.3
#20 lore raw

PATCH 10/10 btrfs: delete btrfs_check_super_location helper

In reply to Josef Bacik

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.

---
 fs/btrfs/scrub.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
fs/btrfs/scrub.c +1 -11
index 66f09202ba96..9d130e13c6b9 100644
@@ -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,
Signature · 1 line
2.26.3
#21 lore raw

Re: [PATCH 10/10] btrfs: delete btrfs_check_super_location helper

Quoted 32 lines · Josef Bacik

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.

---
 fs/btrfs/scrub.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
fs/btrfs/scrub.c +0 -10
index 66f09202ba96..9d130e13c6b9 100644
@@ -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)
 {

fs/btrfs/scrub.c static noinline_for_stack int scrub_supers(struct scrub_ctx *sctx, · line 4166

Quoted 5 lines
fs/btrfs/scrub.c +1 -1
@@ -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.

Quoted 6 lines
fs/btrfs/scrub.c +0 -0
 			continue;
 
 		ret = scrub_sectors(sctx, bytenr, BTRFS_SUPER_INFO_SIZE, bytenr,
Signature · 1 line
2.26.3