[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250502201200.GU25675@frogsfrogsfrogs>
Date: Fri, 2 May 2025 13:12:00 -0700
From: "Darrick J. Wong" <djwong@...nel.org>
To: John Garry <john.g.garry@...cle.com>
Cc: brauner@...nel.org, hch@....de, viro@...iv.linux.org.uk, jack@...e.cz,
cem@...nel.org, linux-fsdevel@...r.kernel.org, dchinner@...hat.com,
linux-xfs@...r.kernel.org, linux-kernel@...r.kernel.org,
ojaswin@...ux.ibm.com, ritesh.list@...il.com,
martin.petersen@...cle.com, linux-ext4@...r.kernel.org,
linux-block@...r.kernel.org, catherine.hoang@...cle.com,
linux-api@...r.kernel.org
Subject: [PATCH v10.1 1.1/15] xfs: only call xfs_setsize_buftarg once per
buffer target
From: Darrick J. Wong <djwong@...nel.org>
It's silly to call xfs_setsize_buftarg from xfs_alloc_buftarg with the
block device LBA size because we don't need to ask the block layer to
validate a geometry number that it provided us. Instead, set the
preliminary bt_meta_sector* fields to the LBA size in preparation for
reading the primary super.
However, we still want to flush and invalidate the pagecache for all
three block devices before we start reading metadata from those devices.
Move the sync_blockdev calls into a separate helper function, and call
it immediately after xfs_open_devices creates the buftargs.
This will enable a subsequent patch to validate hw atomic write geometry
against the filesystem geometry.
Signed-off-by: "Darrick J. Wong" <djwong@...nel.org>
---
v10.1: call sync_blockdev on open for all the devices and move this to
immediately after the vfs change
---
fs/xfs/xfs_buf.h | 5 +++++
fs/xfs/xfs_buf.c | 14 +++++---------
fs/xfs/xfs_super.c | 33 +++++++++++++++++++++++++++++++++
3 files changed, 43 insertions(+), 9 deletions(-)
diff --git a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h
index d0b065a9a9f0d2..132210705602b4 100644
--- a/fs/xfs/xfs_buf.h
+++ b/fs/xfs/xfs_buf.h
@@ -383,6 +383,11 @@ int xfs_buf_reverify(struct xfs_buf *bp, const struct xfs_buf_ops *ops);
bool xfs_verify_magic(struct xfs_buf *bp, __be32 dmagic);
bool xfs_verify_magic16(struct xfs_buf *bp, __be16 dmagic);
+static inline int xfs_buftarg_sync(struct xfs_buftarg *btp)
+{
+ return sync_blockdev(btp->bt_bdev);
+}
+
/* for xfs_buf_mem.c only: */
int xfs_init_buftarg(struct xfs_buftarg *btp, size_t logical_sectorsize,
const char *descr);
diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index 5ae77ffdc947b1..292891d6ff69ac 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -1733,11 +1733,7 @@ xfs_setsize_buftarg(
return -EINVAL;
}
- /*
- * Flush the block device pagecache so our bios see anything dirtied
- * before mount.
- */
- return sync_blockdev(btp->bt_bdev);
+ return 0;
}
int
@@ -1810,10 +1806,10 @@ xfs_alloc_buftarg(
* When allocating the buftargs we have not yet read the super block and
* thus don't know the file system sector size yet.
*/
- if (xfs_setsize_buftarg(btp, bdev_logical_block_size(btp->bt_bdev)))
- goto error_free;
- if (xfs_init_buftarg(btp, bdev_logical_block_size(btp->bt_bdev),
- mp->m_super->s_id))
+ btp->bt_meta_sectorsize = bdev_logical_block_size(btp->bt_bdev);
+ btp->bt_meta_sectormask = btp->bt_meta_sectorsize - 1;
+
+ if (xfs_init_buftarg(btp, btp->bt_meta_sectorsize, mp->m_super->s_id))
goto error_free;
return btp;
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index b2dd0c0bf50979..83de3ac39ae53b 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -519,6 +519,35 @@ xfs_open_devices(
return error;
}
+/*
+ * Flush and invalidate all devices' pagecaches before reading any metadata
+ * because XFS doesn't use the bdev pagecache.
+ */
+STATIC int
+xfs_preflush_devices(
+ struct xfs_mount *mp)
+{
+ int error;
+
+ error = xfs_buftarg_sync(mp->m_ddev_targp);
+ if (error)
+ return error;
+
+ if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
+ error = xfs_buftarg_sync(mp->m_ddev_targp);
+ if (error)
+ return error;
+ }
+
+ if (mp->m_rtdev_targp) {
+ error = xfs_buftarg_sync(mp->m_rtdev_targp);
+ if (error)
+ return error;
+ }
+
+ return 0;
+}
+
/*
* Setup xfs_mount buffer target pointers based on superblock
*/
@@ -1671,6 +1700,10 @@ xfs_fs_fill_super(
if (error)
return error;
+ error = xfs_preflush_devices(mp);
+ if (error)
+ goto out_shutdown_devices;
+
if (xfs_debugfs) {
mp->m_debugfs = xfs_debugfs_mkdir(mp->m_super->s_id,
xfs_debugfs);
Powered by blists - more mailing lists