From 745b7e18fbd887f00d777c5f0ae08444f493b667 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Sun, 1 Mar 2020 12:34:10 -0500 Subject: [PATCH] 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 --- copy/xfs_copy.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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); -- 2.49.0