All of lore.kernel.org
 help / color / mirror / Atom feed
* minor sb clearing improvements
@ 2022-11-21 17:47 Christoph Hellwig
  2022-11-21 17:47 ` [PATCH 1/2] btrfs: don't read the disk superblock for zoned devices in btrfs_scratch_superblocks Christoph Hellwig
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Christoph Hellwig @ 2022-11-21 17:47 UTC (permalink / raw)
  To: Chris Mason, Josef Bacik, David Sterba; +Cc: linux-btrfs

Hi all,

this series moves btrfs off the deprecated write_one_page API that
requires ->writepage to be implemented (in this case on the block
device inode), and while doing so also avoids a pointless sb read
for zoned file systems.

Diffstat:
 volumes.c |   50 +++++++++++++++++++++++++-------------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

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

* [PATCH 1/2] btrfs: don't read the disk superblock for zoned devices in btrfs_scratch_superblocks
  2022-11-21 17:47 minor sb clearing improvements Christoph Hellwig
@ 2022-11-21 17:47 ` Christoph Hellwig
  2022-11-22 11:39   ` Johannes Thumshirn
  2022-11-21 17:47 ` [PATCH 2/2] btrfs: stop using write_one_page in btrfs_scratch_superblock Christoph Hellwig
  2023-01-09 20:15 ` minor sb clearing improvements David Sterba
  2 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2022-11-21 17:47 UTC (permalink / raw)
  To: Chris Mason, Josef Bacik, David Sterba; +Cc: linux-btrfs

For zoned devices, btrfs_scratch_superblocks just resets the sb zones,
which means there is no need to even read the previous superblock.
Split the code to read, zero and write the superblock for convention
devices into a separate helper so that it isn't called for zoned
devices.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/btrfs/volumes.c | 51 +++++++++++++++++++++++-----------------------
 1 file changed, 26 insertions(+), 25 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index b386cb4b9aaa1..2dd7d2c5b0d80 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2005,42 +2005,43 @@ static u64 btrfs_num_devices(struct btrfs_fs_info *fs_info)
 	return num_devices;
 }
 
+static void btrfs_scratch_superblock(struct btrfs_fs_info *fs_info,
+				     struct block_device *bdev, int copy_num)
+{
+	struct btrfs_super_block *disk_super;
+	struct page *page;
+	int ret;
+
+	disk_super = btrfs_read_dev_one_super(bdev, copy_num, false);
+	if (IS_ERR(disk_super))
+		return;
+	memset(&disk_super->magic, 0, sizeof(disk_super->magic));
+	page = virt_to_page(disk_super);
+	set_page_dirty(page);
+	lock_page(page);
+	/* write_on_page() unlocks the page */
+	ret = write_one_page(page);
+	if (ret)
+		btrfs_warn(fs_info,
+			"error clearing superblock number %d (%d)",
+			copy_num, ret);
+	btrfs_release_disk_super(disk_super);
+}
+
 void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info,
 			       struct block_device *bdev,
 			       const char *device_path)
 {
-	struct btrfs_super_block *disk_super;
 	int copy_num;
 
 	if (!bdev)
 		return;
 
 	for (copy_num = 0; copy_num < BTRFS_SUPER_MIRROR_MAX; copy_num++) {
-		struct page *page;
-		int ret;
-
-		disk_super = btrfs_read_dev_one_super(bdev, copy_num, false);
-		if (IS_ERR(disk_super))
-			continue;
-
-		if (bdev_is_zoned(bdev)) {
+		if (bdev_is_zoned(bdev))
 			btrfs_reset_sb_log_zones(bdev, copy_num);
-			continue;
-		}
-
-		memset(&disk_super->magic, 0, sizeof(disk_super->magic));
-
-		page = virt_to_page(disk_super);
-		set_page_dirty(page);
-		lock_page(page);
-		/* write_on_page() unlocks the page */
-		ret = write_one_page(page);
-		if (ret)
-			btrfs_warn(fs_info,
-				"error clearing superblock number %d (%d)",
-				copy_num, ret);
-		btrfs_release_disk_super(disk_super);
-
+		else
+			btrfs_scratch_superblock(fs_info, bdev, copy_num);
 	}
 
 	/* Notify udev that device has changed */
-- 
2.30.2


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

* [PATCH 2/2] btrfs: stop using write_one_page in btrfs_scratch_superblock
  2022-11-21 17:47 minor sb clearing improvements Christoph Hellwig
  2022-11-21 17:47 ` [PATCH 1/2] btrfs: don't read the disk superblock for zoned devices in btrfs_scratch_superblocks Christoph Hellwig
@ 2022-11-21 17:47 ` Christoph Hellwig
  2023-01-09 20:15 ` minor sb clearing improvements David Sterba
  2 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2022-11-21 17:47 UTC (permalink / raw)
  To: Chris Mason, Josef Bacik, David Sterba; +Cc: linux-btrfs

write_one_page is an awkward interface that expects the page locked
and ->writepage to be implemented.  Just mark the sb dirty, put
the page and then call the proper bdev helper to sync the range.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/btrfs/volumes.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 2dd7d2c5b0d80..ddf172ba67972 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2009,23 +2009,22 @@ static void btrfs_scratch_superblock(struct btrfs_fs_info *fs_info,
 				     struct block_device *bdev, int copy_num)
 {
 	struct btrfs_super_block *disk_super;
-	struct page *page;
+	const size_t len = sizeof(disk_super->magic);
+	u64 bytenr = btrfs_sb_offset(copy_num);
 	int ret;
 
-	disk_super = btrfs_read_dev_one_super(bdev, copy_num, false);
+	disk_super = btrfs_read_disk_super(bdev, bytenr, bytenr);
 	if (IS_ERR(disk_super))
 		return;
-	memset(&disk_super->magic, 0, sizeof(disk_super->magic));
-	page = virt_to_page(disk_super);
-	set_page_dirty(page);
-	lock_page(page);
-	/* write_on_page() unlocks the page */
-	ret = write_one_page(page);
+	memset(&disk_super->magic, 0, len);
+	set_page_dirty(virt_to_page(disk_super));
+	btrfs_release_disk_super(disk_super);
+
+	ret = sync_blockdev_range(bdev, bytenr, bytenr + len - 1);
 	if (ret)
 		btrfs_warn(fs_info,
 			"error clearing superblock number %d (%d)",
 			copy_num, ret);
-	btrfs_release_disk_super(disk_super);
 }
 
 void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info,
-- 
2.30.2


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

* Re: [PATCH 1/2] btrfs: don't read the disk superblock for zoned devices in btrfs_scratch_superblocks
  2022-11-21 17:47 ` [PATCH 1/2] btrfs: don't read the disk superblock for zoned devices in btrfs_scratch_superblocks Christoph Hellwig
@ 2022-11-22 11:39   ` Johannes Thumshirn
  0 siblings, 0 replies; 5+ messages in thread
From: Johannes Thumshirn @ 2022-11-22 11:39 UTC (permalink / raw)
  To: Christoph Hellwig, Chris Mason, Josef Bacik, David Sterba; +Cc: linux-btrfs

On 21.11.22 18:48, Christoph Hellwig wrote:
> Split the code to read, zero and write the superblock for convention
                                              conventional ~^

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

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

* Re: minor sb clearing improvements
  2022-11-21 17:47 minor sb clearing improvements Christoph Hellwig
  2022-11-21 17:47 ` [PATCH 1/2] btrfs: don't read the disk superblock for zoned devices in btrfs_scratch_superblocks Christoph Hellwig
  2022-11-21 17:47 ` [PATCH 2/2] btrfs: stop using write_one_page in btrfs_scratch_superblock Christoph Hellwig
@ 2023-01-09 20:15 ` David Sterba
  2 siblings, 0 replies; 5+ messages in thread
From: David Sterba @ 2023-01-09 20:15 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Chris Mason, Josef Bacik, David Sterba, linux-btrfs

On Mon, Nov 21, 2022 at 06:47:47PM +0100, Christoph Hellwig wrote:
> Hi all,
> 
> this series moves btrfs off the deprecated write_one_page API that
> requires ->writepage to be implemented (in this case on the block
> device inode), and while doing so also avoids a pointless sb read
> for zoned file systems.
> 
> Diffstat:
>  volumes.c |   50 +++++++++++++++++++++++++-------------------------
>  1 file changed, 25 insertions(+), 25 deletions(-)

Added to misc-next, thanks.

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

end of thread, other threads:[~2023-01-09 20:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-21 17:47 minor sb clearing improvements Christoph Hellwig
2022-11-21 17:47 ` [PATCH 1/2] btrfs: don't read the disk superblock for zoned devices in btrfs_scratch_superblocks Christoph Hellwig
2022-11-22 11:39   ` Johannes Thumshirn
2022-11-21 17:47 ` [PATCH 2/2] btrfs: stop using write_one_page in btrfs_scratch_superblock Christoph Hellwig
2023-01-09 20:15 ` minor sb clearing improvements David Sterba

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.