diff mbox series

[11/25] xfs_db: use uncached buffer reads to get the superblock

Message ID 158258955793.451378.12834800309076146911.stgit@magnolia (mailing list archive)
State Superseded
Headers show
Series xfsprogs: refactor buffer function names | expand

Commit Message

Darrick J. Wong Feb. 25, 2020, 12:12 a.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

Upon startup, xfs_db needs to check if it is even looking at an XFS
filesystem, and it needs the AG 0 superblock contents to initialize the
incore mount.  We cannot know the filesystem sector size until we read
the superblock, but we also do not want to introduce aliasing in the
buffer cache.  Convert this code to the new uncached buffer read API so
that we can stop open-coding it.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 db/init.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Comments

Christoph Hellwig Feb. 25, 2020, 5:45 p.m. UTC | #1
On Mon, Feb 24, 2020 at 04:12:37PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Upon startup, xfs_db needs to check if it is even looking at an XFS
> filesystem, and it needs the AG 0 superblock contents to initialize the
> incore mount.  We cannot know the filesystem sector size until we read
> the superblock, but we also do not want to introduce aliasing in the
> buffer cache.  Convert this code to the new uncached buffer read API so
> that we can stop open-coding it.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/db/init.c b/db/init.c
index 8bad7e53..61eea111 100644
--- a/db/init.c
+++ b/db/init.c
@@ -47,6 +47,7 @@  init(
 	struct xfs_buf	*bp;
 	unsigned int	agcount;
 	int		c;
+	int		error;
 
 	setlocale(LC_ALL, "");
 	bindtextdomain(PACKAGE, LOCALEDIR);
@@ -112,10 +113,9 @@  init(
 	 */
 	memset(&xmount, 0, sizeof(struct xfs_mount));
 	libxfs_buftarg_init(&xmount, x.ddev, x.logdev, x.rtdev);
-	bp = libxfs_buf_read(xmount.m_ddev_targp, XFS_SB_DADDR,
-			    1 << (XFS_MAX_SECTORSIZE_LOG - BBSHIFT), 0, NULL);
-
-	if (!bp || bp->b_error) {
+	error = -libxfs_buf_read_uncached(xmount.m_ddev_targp, XFS_SB_DADDR,
+			1 << (XFS_MAX_SECTORSIZE_LOG - BBSHIFT), 0, &bp, NULL);
+	if (error) {
 		fprintf(stderr, _("%s: %s is invalid (cannot read first 512 "
 			"bytes)\n"), progname, fsdevice);
 		exit(1);
@@ -124,7 +124,6 @@  init(
 	/* copy SB from buffer to in-core, converting architecture as we go */
 	libxfs_sb_from_disk(&xmount.m_sb, XFS_BUF_TO_SBP(bp));
 	libxfs_buf_relse(bp);
-	libxfs_purgebuf(bp);
 
 	sbp = &xmount.m_sb;
 	if (sbp->sb_magicnum != XFS_SB_MAGIC) {