]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs_db: use uncached buffer reads to get the superblock
authorDarrick J. Wong <darrick.wong@oracle.com>
Sun, 1 Mar 2020 17:34:10 +0000 (12:34 -0500)
committerEric Sandeen <sandeen@sandeen.net>
Sun, 1 Mar 2020 17:34:10 +0000 (12:34 -0500)
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>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
db/init.c

index 8bad7e53d2ff66f9933e606799bfeb4125789091..61eea111f017c65bfc9fd1ae7750ec8894ca766a 100644 (file)
--- 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) {