]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs_copy: 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_copy needs to read the filesystem superblock to mount
the filesystem.  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>
copy/xfs_copy.c

index 9e9719a0fdeab44e2eb26b6755657c982f10cdca..5cab1a5f3c8441373978931c456859e6d25b7825 100644 (file)
@@ -562,6 +562,7 @@ main(int argc, char **argv)
        libxfs_init_t   xargs;
        thread_args     *tcarg;
        struct stat     statbuf;
+       int             error;
 
        progname = basename(argv[0]);
 
@@ -710,14 +711,20 @@ main(int argc, char **argv)
 
        /* We don't yet know the sector size, so read maximal size */
        libxfs_buftarg_init(&mbuf, xargs.ddev, xargs.logdev, xargs.rtdev);
-       sbp = libxfs_buf_read(mbuf.m_ddev_targp, XFS_SB_DADDR,
-                            1 << (XFS_MAX_SECTORSIZE_LOG - BBSHIFT), 0, NULL);
+       error = -libxfs_buf_read_uncached(mbuf.m_ddev_targp, XFS_SB_DADDR,
+                       1 << (XFS_MAX_SECTORSIZE_LOG - BBSHIFT), 0, &sbp, NULL);
+       if (error) {
+               do_log(_("%s: couldn't read superblock, error=%d\n"),
+                               progname, error);
+               exit(1);
+       }
+
        sb = &mbuf.m_sb;
        libxfs_sb_from_disk(sb, XFS_BUF_TO_SBP(sbp));
 
        /* Do it again, now with proper length and verifier */
        libxfs_buf_relse(sbp);
-       libxfs_purgebuf(sbp);
+
        sbp = libxfs_buf_read(mbuf.m_ddev_targp, XFS_SB_DADDR,
                             1 << (sb->sb_sectlog - BBSHIFT),
                             0, &xfs_sb_buf_ops);