From: Darrick J. Wong Date: Sun, 1 Mar 2020 17:34:10 +0000 (-0500) Subject: xfs_copy: use uncached buffer reads to get the superblock X-Git-Tag: v5.5.0-rc1~16 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=745b7e18fbd887f00d777c5f0ae08444f493b667;p=thirdparty%2Fxfsprogs-dev.git xfs_copy: use uncached buffer reads to get the superblock 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 Reviewed-by: Christoph Hellwig Signed-off-by: Eric Sandeen --- diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c index 9e9719a0f..5cab1a5f3 100644 --- a/copy/xfs_copy.c +++ b/copy/xfs_copy.c @@ -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);