linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/25] xfsprogs: refactor buffer function names
@ 2020-02-25  0:11 Darrick J. Wong
  2020-02-25  0:11 ` [PATCH 01/25] libxfs: open-code "exit on buffer read failure" in upper level callers Darrick J. Wong
                   ` (24 more replies)
  0 siblings, 25 replies; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:11 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

Hi all,

This series cleans up several messes in the libxfs buffer handling code.
First, we get rid of the overloaded (and in some places hidden usages)
of LIBXFS_EXIT_ON_FAIL flag that is sprinkled throughout the buffer
callers.  Next, we rename the buffer get/read/put/write functions to
match their kernel counterparts, which enables us to remove a bunch of
ugly #defines.  Then, we replace the open-coded uncached buffer logic in
the callers with the same uncached buffer API as the kernel has.
Finally, we move as many callers as we feasibly can to use the
xfs_buf_(get|read) interfaces so that we don't have multiple entry
points to the same functionality.

For v2, move the "exit on io error" functionality directly into the
callers.

If you're going to start using this mess, you probably ought to just
pull from my git trees, which are linked below.

This is an extraordinary way to destroy everything.  Enjoy!
Comments and questions are, as always, welcome.

--D

xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=libxfs-refactor-buffer-funcs

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [PATCH 01/25] libxfs: open-code "exit on buffer read failure" in upper level callers
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
@ 2020-02-25  0:11 ` Darrick J. Wong
  2020-02-25 17:42   ` Christoph Hellwig
  2020-02-25 19:26   ` [PATCH v2 " Darrick J. Wong
  2020-02-25  0:11 ` [PATCH 02/25] libxfs: remove LIBXFS_EXIT_ON_FAILURE Darrick J. Wong
                   ` (23 subsequent siblings)
  24 siblings, 2 replies; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:11 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Make all functions that use LIBXFS_EXIT_ON_FAILURE to abort on buffer
read errors implement that logic themselves.  This also removes places
where libxfs can abort the program with no warning.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 libxfs/init.c   |   40 ++++++++++++++++++++--------------------
 libxfs/rdwr.c   |    4 ----
 mkfs/xfs_mkfs.c |   16 ++++++++++++----
 3 files changed, 32 insertions(+), 28 deletions(-)


diff --git a/libxfs/init.c b/libxfs/init.c
index 913f546f..485ab8f8 100644
--- a/libxfs/init.c
+++ b/libxfs/init.c
@@ -639,19 +639,20 @@ libxfs_buftarg_init(
  * such that the numerous XFS_* macros can be used.  If dev is zero,
  * no IO will be performed (no size checks, read root inodes).
  */
-xfs_mount_t *
+struct xfs_mount *
 libxfs_mount(
-	xfs_mount_t	*mp,
-	xfs_sb_t	*sb,
-	dev_t		dev,
-	dev_t		logdev,
-	dev_t		rtdev,
-	int		flags)
+	struct xfs_mount	*mp,
+	struct xfs_sb		*sb,
+	dev_t			dev,
+	dev_t			logdev,
+	dev_t			rtdev,
+	int			flags)
 {
-	xfs_daddr_t	d;
-	xfs_buf_t	*bp;
-	xfs_sb_t	*sbp;
-	int		error;
+	struct xfs_buf		*bp;
+	struct xfs_sb		*sbp;
+	xfs_daddr_t		d;
+	bool			debugger = (flags & LIBXFS_MOUNT_DEBUGGER);
+	int			error;
 
 	libxfs_buftarg_init(mp, dev, logdev, rtdev);
 
@@ -728,12 +729,12 @@ libxfs_mount(
 	if (dev == 0)	/* maxtrres, we have no device so leave now */
 		return mp;
 
-	bp = libxfs_readbuf(mp->m_dev,
-			d - XFS_FSS_TO_BB(mp, 1), XFS_FSS_TO_BB(mp, 1),
-			!(flags & LIBXFS_MOUNT_DEBUGGER), NULL);
+	/* device size checks must pass unless we're a debugger. */
+	bp = libxfs_readbuf(mp->m_dev, d - XFS_FSS_TO_BB(mp, 1),
+			XFS_FSS_TO_BB(mp, 1), 0, NULL);
 	if (!bp) {
 		fprintf(stderr, _("%s: data size check failed\n"), progname);
-		if (!(flags & LIBXFS_MOUNT_DEBUGGER))
+		if (!debugger)
 			return NULL;
 	} else
 		libxfs_putbuf(bp);
@@ -744,11 +745,10 @@ libxfs_mount(
 		if ( (XFS_BB_TO_FSB(mp, d) != mp->m_sb.sb_logblocks) ||
 		     (!(bp = libxfs_readbuf(mp->m_logdev_targp,
 					d - XFS_FSB_TO_BB(mp, 1),
-					XFS_FSB_TO_BB(mp, 1),
-					!(flags & LIBXFS_MOUNT_DEBUGGER), NULL))) ) {
+					XFS_FSB_TO_BB(mp, 1), 0, NULL)))) {
 			fprintf(stderr, _("%s: log size checks failed\n"),
 					progname);
-			if (!(flags & LIBXFS_MOUNT_DEBUGGER))
+			if (!debugger)
 				return NULL;
 		}
 		if (bp)
@@ -772,11 +772,11 @@ libxfs_mount(
 	if (sbp->sb_agcount > 1000000) {
 		bp = libxfs_readbuf(mp->m_dev,
 				XFS_AG_DADDR(mp, sbp->sb_agcount - 1, 0), 1,
-				!(flags & LIBXFS_MOUNT_DEBUGGER), NULL);
+				0, NULL);
 		if (bp->b_error) {
 			fprintf(stderr, _("%s: read of AG %u failed\n"),
 						progname, sbp->sb_agcount);
-			if (!(flags & LIBXFS_MOUNT_DEBUGGER))
+			if (!debugger)
 				return NULL;
 			fprintf(stderr, _("%s: limiting reads to AG 0\n"),
 								progname);
diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index 4253b890..474fceb0 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -911,14 +911,10 @@ __read_buf(int fd, void *buf, int len, off64_t offset, int flags)
 		int error = errno;
 		fprintf(stderr, _("%s: read failed: %s\n"),
 			progname, strerror(error));
-		if (flags & LIBXFS_EXIT_ON_FAILURE)
-			exit(1);
 		return -error;
 	} else if (sts != len) {
 		fprintf(stderr, _("%s: error - read only %d of %d bytes\n"),
 			progname, sts, len);
-		if (flags & LIBXFS_EXIT_ON_FAILURE)
-			exit(1);
 		return -EIO;
 	}
 	return 0;
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 7f315d8a..3de73fc6 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -3576,8 +3576,12 @@ rewrite_secondary_superblocks(
 	buf = libxfs_readbuf(mp->m_dev,
 			XFS_AGB_TO_DADDR(mp, mp->m_sb.sb_agcount - 1,
 				XFS_SB_DADDR),
-			XFS_FSS_TO_BB(mp, 1),
-			LIBXFS_EXIT_ON_FAILURE, &xfs_sb_buf_ops);
+			XFS_FSS_TO_BB(mp, 1), 0, &xfs_sb_buf_ops);
+	if (!buf) {
+		fprintf(stderr, _("%s: could not re-read AG %u superblock\n"),
+				progname, mp->m_sb.sb_agcount - 1);
+		exit(1);
+	}
 	XFS_BUF_TO_SBP(buf)->sb_rootino = cpu_to_be64(mp->m_sb.sb_rootino);
 	libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
 
@@ -3588,8 +3592,12 @@ rewrite_secondary_superblocks(
 	buf = libxfs_readbuf(mp->m_dev,
 			XFS_AGB_TO_DADDR(mp, (mp->m_sb.sb_agcount - 1) / 2,
 				XFS_SB_DADDR),
-			XFS_FSS_TO_BB(mp, 1),
-			LIBXFS_EXIT_ON_FAILURE, &xfs_sb_buf_ops);
+			XFS_FSS_TO_BB(mp, 1), 0, &xfs_sb_buf_ops);
+	if (!buf) {
+		fprintf(stderr, _("%s: could not re-read AG %u superblock\n"),
+				progname, (mp->m_sb.sb_agcount - 1) / 2);
+		exit(1);
+	}
 	XFS_BUF_TO_SBP(buf)->sb_rootino = cpu_to_be64(mp->m_sb.sb_rootino);
 	libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
 }


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 02/25] libxfs: remove LIBXFS_EXIT_ON_FAILURE
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
  2020-02-25  0:11 ` [PATCH 01/25] libxfs: open-code "exit on buffer read failure" in upper level callers Darrick J. Wong
@ 2020-02-25  0:11 ` Darrick J. Wong
  2020-02-25 17:43   ` Christoph Hellwig
  2020-02-25  0:11 ` [PATCH 03/25] libxfs: remove LIBXFS_B_EXIT Darrick J. Wong
                   ` (22 subsequent siblings)
  24 siblings, 1 reply; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:11 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Now that the read-side users of LIBXFS_EXIT_ON_FAILURE are gone and the
only write-side callers are in mkfs which now checks for buffer write
failures, get rid of LIBXFS_EXIT_ON_FAILURE.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 include/libxfs.h   |    1 -
 libxfs/libxfs_io.h |    2 +-
 libxfs/rdwr.c      |    2 +-
 mkfs/proto.c       |    2 +-
 mkfs/xfs_mkfs.c    |   14 +++++++-------
 5 files changed, 10 insertions(+), 11 deletions(-)


diff --git a/include/libxfs.h b/include/libxfs.h
index 504f6e9c..12447835 100644
--- a/include/libxfs.h
+++ b/include/libxfs.h
@@ -126,7 +126,6 @@ typedef struct libxfs_xinit {
 	int		bcache_flags;	/* cache init flags */
 } libxfs_init_t;
 
-#define LIBXFS_EXIT_ON_FAILURE	0x0001	/* exit the program if a call fails */
 #define LIBXFS_ISREADONLY	0x0002	/* disallow all mounted filesystems */
 #define LIBXFS_ISINACTIVE	0x0004	/* allow mounted only if mounted ro */
 #define LIBXFS_DANGEROUSLY	0x0008	/* repairing a device mounted ro    */
diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h
index 6bb75a67..87c6ea3e 100644
--- a/libxfs/libxfs_io.h
+++ b/libxfs/libxfs_io.h
@@ -91,7 +91,7 @@ bool xfs_verify_magic(struct xfs_buf *bp, __be32 dmagic);
 bool xfs_verify_magic16(struct xfs_buf *bp, __be16 dmagic);
 
 /* b_flags bits */
-#define LIBXFS_B_EXIT		0x0001	/* ==LIBXFS_EXIT_ON_FAILURE */
+#define LIBXFS_B_EXIT		0x0001	/* exit if write fails */
 #define LIBXFS_B_DIRTY		0x0002	/* buffer has been modified */
 #define LIBXFS_B_STALE		0x0004	/* buffer marked as invalid */
 #define LIBXFS_B_UPTODATE	0x0008	/* buffer is sync'd to disk */
diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index 474fceb0..011b449d 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -19,7 +19,7 @@
 #include "xfs_trans.h"
 #include "libfrog/platform.h"
 
-#include "libxfs.h"		/* for LIBXFS_EXIT_ON_FAILURE */
+#include "libxfs.h"
 
 /*
  * Important design/architecture note:
diff --git a/mkfs/proto.c b/mkfs/proto.c
index 2ece593e..c3813ea2 100644
--- a/mkfs/proto.c
+++ b/mkfs/proto.c
@@ -262,7 +262,7 @@ newfile(
 		if (logit)
 			libxfs_trans_log_buf(tp, bp, 0, bp->b_bcount - 1);
 		else
-			libxfs_writebuf(bp, LIBXFS_EXIT_ON_FAILURE);
+			libxfs_writebuf(bp, 0);
 	}
 	ip->i_d.di_size = len;
 	return flags;
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 3de73fc6..fbf2b7f2 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -3447,7 +3447,7 @@ prepare_devices(
 	buf = libxfs_getbuf(mp->m_ddev_targp, (xi->dsize - whack_blks),
 			    whack_blks);
 	memset(buf->b_addr, 0, WHACK_SIZE);
-	libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
+	libxfs_writebuf(buf, 0);
 	libxfs_purgebuf(buf);
 
 	/*
@@ -3458,7 +3458,7 @@ prepare_devices(
 	 */
 	buf = libxfs_getbuf(mp->m_ddev_targp, 0, whack_blks);
 	memset(buf->b_addr, 0, WHACK_SIZE);
-	libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
+	libxfs_writebuf(buf, 0);
 	libxfs_purgebuf(buf);
 
 	/* OK, now write the superblock... */
@@ -3466,7 +3466,7 @@ prepare_devices(
 	buf->b_ops = &xfs_sb_buf_ops;
 	memset(buf->b_addr, 0, cfg->sectorsize);
 	libxfs_sb_to_disk(buf->b_addr, sbp);
-	libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
+	libxfs_writebuf(buf, 0);
 	libxfs_purgebuf(buf);
 
 	/* ...and zero the log.... */
@@ -3486,7 +3486,7 @@ prepare_devices(
 				    XFS_FSB_TO_BB(mp, cfg->rtblocks - 1LL),
 				    BTOBB(cfg->blocksize));
 		memset(buf->b_addr, 0, cfg->blocksize);
-		libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
+		libxfs_writebuf(buf, 0);
 		libxfs_purgebuf(buf);
 	}
 
@@ -3583,7 +3583,7 @@ rewrite_secondary_superblocks(
 		exit(1);
 	}
 	XFS_BUF_TO_SBP(buf)->sb_rootino = cpu_to_be64(mp->m_sb.sb_rootino);
-	libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
+	libxfs_writebuf(buf, 0);
 
 	/* and one in the middle for luck if there's enough AGs for that */
 	if (mp->m_sb.sb_agcount <= 2)
@@ -3599,7 +3599,7 @@ rewrite_secondary_superblocks(
 		exit(1);
 	}
 	XFS_BUF_TO_SBP(buf)->sb_rootino = cpu_to_be64(mp->m_sb.sb_rootino);
-	libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
+	libxfs_writebuf(buf, 0);
 }
 
 static void
@@ -3946,7 +3946,7 @@ main(
 	if (!buf || buf->b_error)
 		exit(1);
 	(XFS_BUF_TO_SBP(buf))->sb_inprogress = 0;
-	libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
+	libxfs_writebuf(buf, 0);
 
 	/* Report failure if anything failed to get written to our new fs. */
 	error = -libxfs_umount(mp);


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 03/25] libxfs: remove LIBXFS_B_EXIT
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
  2020-02-25  0:11 ` [PATCH 01/25] libxfs: open-code "exit on buffer read failure" in upper level callers Darrick J. Wong
  2020-02-25  0:11 ` [PATCH 02/25] libxfs: remove LIBXFS_EXIT_ON_FAILURE Darrick J. Wong
@ 2020-02-25  0:11 ` Darrick J. Wong
  2020-02-25 17:43   ` Christoph Hellwig
  2020-02-25  0:11 ` [PATCH 04/25] libxfs: replace libxfs_putbuf with libxfs_buf_relse Darrick J. Wong
                   ` (21 subsequent siblings)
  24 siblings, 1 reply; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:11 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Now that we've removed all users of LIBXFS_B_EXIT, remove it as well.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 libxfs/libxfs_io.h |    1 -
 libxfs/rdwr.c      |    7 +------
 2 files changed, 1 insertion(+), 7 deletions(-)


diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h
index 87c6ea3e..716db553 100644
--- a/libxfs/libxfs_io.h
+++ b/libxfs/libxfs_io.h
@@ -91,7 +91,6 @@ bool xfs_verify_magic(struct xfs_buf *bp, __be32 dmagic);
 bool xfs_verify_magic16(struct xfs_buf *bp, __be16 dmagic);
 
 /* b_flags bits */
-#define LIBXFS_B_EXIT		0x0001	/* exit if write fails */
 #define LIBXFS_B_DIRTY		0x0002	/* buffer has been modified */
 #define LIBXFS_B_STALE		0x0004	/* buffer marked as invalid */
 #define LIBXFS_B_UPTODATE	0x0008	/* buffer is sync'd to disk */
diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index 011b449d..45b535e4 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -1075,14 +1075,10 @@ __write_buf(int fd, void *buf, int len, off64_t offset, int flags)
 		int error = errno;
 		fprintf(stderr, _("%s: pwrite failed: %s\n"),
 			progname, strerror(error));
-		if (flags & LIBXFS_B_EXIT)
-			exit(1);
 		return -error;
 	} else if (sts != len) {
 		fprintf(stderr, _("%s: error - pwrite only %d of %d bytes\n"),
 			progname, sts, len);
-		if (flags & LIBXFS_B_EXIT)
-			exit(1);
 		return -EIO;
 	}
 	return 0;
@@ -1153,8 +1149,7 @@ libxfs_writebufr(xfs_buf_t *bp)
 			(long long)bp->b_bn, bp->b_bcount, -bp->b_error);
 	} else {
 		bp->b_flags |= LIBXFS_B_UPTODATE;
-		bp->b_flags &= ~(LIBXFS_B_DIRTY | LIBXFS_B_EXIT |
-				 LIBXFS_B_UNCHECKED);
+		bp->b_flags &= ~(LIBXFS_B_DIRTY | LIBXFS_B_UNCHECKED);
 	}
 	return bp->b_error;
 }


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 04/25] libxfs: replace libxfs_putbuf with libxfs_buf_relse
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
                   ` (2 preceding siblings ...)
  2020-02-25  0:11 ` [PATCH 03/25] libxfs: remove LIBXFS_B_EXIT Darrick J. Wong
@ 2020-02-25  0:11 ` Darrick J. Wong
  2020-02-25  0:12 ` [PATCH 05/25] libxfs: replace libxfs_getbuf with libxfs_buf_get Darrick J. Wong
                   ` (20 subsequent siblings)
  24 siblings, 0 replies; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:11 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs, Christoph Hellwig

From: Darrick J. Wong <darrick.wong@oracle.com>

Change all the libxfs_putbuf calls to libxfs_buf_relse to match the
kernel interface, since one is a #define of the other.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 copy/xfs_copy.c          |    4 ++--
 db/fsmap.c               |    6 +++---
 db/info.c                |    2 +-
 db/init.c                |    2 +-
 db/io.c                  |    2 +-
 libxfs/init.c            |    8 ++++----
 libxfs/libxfs_api_defs.h |    1 +
 libxfs/libxfs_io.h       |    4 ++--
 libxfs/libxfs_priv.h     |    1 -
 libxfs/rdwr.c            |   14 +++++++-------
 libxfs/trans.c           |   10 +++++-----
 repair/attr_repair.c     |   24 ++++++++++++------------
 repair/da_util.c         |   22 +++++++++++-----------
 repair/dino_chunks.c     |    8 ++++----
 repair/dinode.c          |    8 ++++----
 repair/dir2.c            |   14 +++++++-------
 repair/phase3.c          |    2 +-
 repair/phase6.c          |   36 ++++++++++++++++++------------------
 repair/prefetch.c        |   10 +++++-----
 repair/rmap.c            |    8 ++++----
 repair/rt.c              |    4 ++--
 repair/scan.c            |   18 +++++++++---------
 repair/xfs_repair.c      |    2 +-
 23 files changed, 105 insertions(+), 105 deletions(-)


diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c
index 7f4615ac..3e519471 100644
--- a/copy/xfs_copy.c
+++ b/copy/xfs_copy.c
@@ -716,12 +716,12 @@ main(int argc, char **argv)
 	libxfs_sb_from_disk(sb, XFS_BUF_TO_SBP(sbp));
 
 	/* Do it again, now with proper length and verifier */
-	libxfs_putbuf(sbp);
+	libxfs_buf_relse(sbp);
 	libxfs_purgebuf(sbp);
 	sbp = libxfs_readbuf(mbuf.m_ddev_targp, XFS_SB_DADDR,
 			     1 << (sb->sb_sectlog - BBSHIFT),
 			     0, &xfs_sb_buf_ops);
-	libxfs_putbuf(sbp);
+	libxfs_buf_relse(sbp);
 
 	mp = libxfs_mount(&mbuf, sb, xargs.ddev, xargs.logdev, xargs.rtdev, 0);
 	if (mp == NULL) {
diff --git a/db/fsmap.c b/db/fsmap.c
index 29f3827c..a6e61962 100644
--- a/db/fsmap.c
+++ b/db/fsmap.c
@@ -75,7 +75,7 @@ fsmap(
 
 		bt_cur = libxfs_rmapbt_init_cursor(mp, NULL, agbp, agno);
 		if (!bt_cur) {
-			libxfs_putbuf(agbp);
+			libxfs_buf_relse(agbp);
 			dbprintf(_("Not enough memory.\n"));
 			return;
 		}
@@ -85,14 +85,14 @@ fsmap(
 				fsmap_fn, &info);
 		if (error) {
 			libxfs_btree_del_cursor(bt_cur, XFS_BTREE_ERROR);
-			libxfs_putbuf(agbp);
+			libxfs_buf_relse(agbp);
 			dbprintf(_("Error %d while querying fsmap btree.\n"),
 				error);
 			return;
 		}
 
 		libxfs_btree_del_cursor(bt_cur, XFS_BTREE_NOERROR);
-		libxfs_putbuf(agbp);
+		libxfs_buf_relse(agbp);
 
 		if (agno == start_ag)
 			low.rm_startblock = 0;
diff --git a/db/info.c b/db/info.c
index fc5ccfe7..5c941dc4 100644
--- a/db/info.c
+++ b/db/info.c
@@ -89,7 +89,7 @@ print_agresv_info(
 	length = be32_to_cpu(agf->agf_length);
 	free = be32_to_cpu(agf->agf_freeblks) +
 	       be32_to_cpu(agf->agf_flcount);
-	libxfs_putbuf(bp);
+	libxfs_buf_relse(bp);
 
 	printf("AG %d: length: %u free: %u reserved: %u used: %u",
 			agno, length, free, ask, used);
diff --git a/db/init.c b/db/init.c
index e5450d2b..15b4ec0c 100644
--- a/db/init.c
+++ b/db/init.c
@@ -123,7 +123,7 @@ 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_putbuf(bp);
+	libxfs_buf_relse(bp);
 	libxfs_purgebuf(bp);
 
 	sbp = &xmount.m_sb;
diff --git a/db/io.c b/db/io.c
index 6b66472e..a11b7bb1 100644
--- a/db/io.c
+++ b/db/io.c
@@ -96,7 +96,7 @@ pop_cur(void)
 		return;
 	}
 	if (iocur_top->bp) {
-		libxfs_putbuf(iocur_top->bp);
+		libxfs_buf_relse(iocur_top->bp);
 		iocur_top->bp = NULL;
 	}
 	if (iocur_top->bbmap) {
diff --git a/libxfs/init.c b/libxfs/init.c
index 485ab8f8..4efe1099 100644
--- a/libxfs/init.c
+++ b/libxfs/init.c
@@ -457,7 +457,7 @@ rtmount_init(
 			progname);
 		return -1;
 	}
-	libxfs_putbuf(bp);
+	libxfs_buf_relse(bp);
 	return 0;
 }
 
@@ -737,7 +737,7 @@ libxfs_mount(
 		if (!debugger)
 			return NULL;
 	} else
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 
 	if (mp->m_logdev_targp->dev &&
 	    mp->m_logdev_targp->dev != mp->m_ddev_targp->dev) {
@@ -752,7 +752,7 @@ libxfs_mount(
 				return NULL;
 		}
 		if (bp)
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 	}
 
 	/* Initialize realtime fields in the mount structure */
@@ -782,7 +782,7 @@ libxfs_mount(
 								progname);
 			sbp->sb_agcount = 1;
 		}
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 	}
 
 	error = libxfs_initialize_perag(mp, sbp->sb_agcount, &mp->m_maxagi);
diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h
index 1a438e58..8bca7ddf 100644
--- a/libxfs/libxfs_api_defs.h
+++ b/libxfs/libxfs_api_defs.h
@@ -44,6 +44,7 @@
 #define xfs_btree_del_cursor		libxfs_btree_del_cursor
 #define xfs_btree_init_block		libxfs_btree_init_block
 #define xfs_buf_delwri_submit		libxfs_buf_delwri_submit
+#define xfs_buf_relse			libxfs_buf_relse
 #define xfs_bunmapi			libxfs_bunmapi
 #define xfs_calc_dquots_per_chunk	libxfs_calc_dquots_per_chunk
 #define xfs_da3_node_hdr_from_disk	libxfs_da3_node_hdr_from_disk
diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h
index 716db553..3ddfc0c8 100644
--- a/libxfs/libxfs_io.h
+++ b/libxfs/libxfs_io.h
@@ -148,7 +148,7 @@ extern struct cache_operations	libxfs_bcache_operations;
 #define libxfs_getbuf_flags(dev, daddr, len, flags) \
 	libxfs_trace_getbuf_flags(__FUNCTION__, __FILE__, __LINE__, \
 			    (dev), (daddr), (len), (flags))
-#define libxfs_putbuf(buf) \
+#define libxfs_buf_relse(buf) \
 	libxfs_trace_putbuf(__FUNCTION__, __FILE__, __LINE__, (buf))
 
 extern xfs_buf_t *libxfs_trace_readbuf(const char *, const char *, int,
@@ -180,7 +180,7 @@ extern xfs_buf_t *libxfs_getbuf_map(struct xfs_buftarg *,
 			struct xfs_buf_map *, int, int);
 extern xfs_buf_t *libxfs_getbuf_flags(struct xfs_buftarg *, xfs_daddr_t,
 			int, unsigned int);
-extern void	libxfs_putbuf (xfs_buf_t *);
+void	libxfs_buf_relse(struct xfs_buf *bp);
 
 #endif
 
diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h
index fe08f96b..4bd3c462 100644
--- a/libxfs/libxfs_priv.h
+++ b/libxfs/libxfs_priv.h
@@ -377,7 +377,6 @@ roundup_64(uint64_t x, uint32_t y)
 	(len) = __bar; /* no set-but-unused warning */	\
 	NULL;						\
 })
-#define xfs_buf_relse(bp)		libxfs_putbuf(bp)
 #define xfs_buf_get(devp,blkno,len)	(libxfs_getbuf((devp), (blkno), (len)))
 #define xfs_bwrite(bp)			libxfs_writebuf((bp), 0)
 #define xfs_buf_oneshot(bp)		((void) 0)
diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index 45b535e4..02e19e1c 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -48,7 +48,7 @@
  *
  * The result of this is that until the userspace code outside libxfs is cleaned
  * up, functions that release buffers from userspace control (i.e
- * libxfs_writebuf/libxfs_putbuf) need to zero bp->b_error to prevent
+ * libxfs_writebuf/libxfs_buf_relse) need to zero bp->b_error to prevent
  * propagation of stale errors into future buffer operations.
  */
 
@@ -387,7 +387,6 @@ libxfs_log_header(
 #undef libxfs_getbuf
 #undef libxfs_getbuf_map
 #undef libxfs_getbuf_flags
-#undef libxfs_putbuf
 
 xfs_buf_t	*libxfs_readbuf(struct xfs_buftarg *, xfs_daddr_t, int, int,
 				const struct xfs_buf_ops *);
@@ -399,7 +398,7 @@ xfs_buf_t	*libxfs_getbuf_map(struct xfs_buftarg *, struct xfs_buf_map *,
 				int, int);
 xfs_buf_t	*libxfs_getbuf_flags(struct xfs_buftarg *, xfs_daddr_t, int,
 				unsigned int);
-void		libxfs_putbuf (xfs_buf_t *);
+void		libxfs_buf_relse(struct xfs_buf *bp);
 
 #define	__add_trace(bp, func, file, line)	\
 do {						\
@@ -469,7 +468,7 @@ void
 libxfs_trace_putbuf(const char *func, const char *file, int line, xfs_buf_t *bp)
 {
 	__add_trace(bp, func, file, line);
-	libxfs_putbuf(bp);
+	libxfs_buf_relse(bp);
 }
 
 
@@ -844,7 +843,8 @@ libxfs_getbuf_map(struct xfs_buftarg *btp, struct xfs_buf_map *map,
 }
 
 void
-libxfs_putbuf(xfs_buf_t *bp)
+libxfs_buf_relse(
+	struct xfs_buf	*bp)
 {
 	/*
 	 * ensure that any errors on this use of the buffer don't carry
@@ -1183,7 +1183,7 @@ libxfs_writebuf(xfs_buf_t *bp, int flags)
 	bp->b_error = 0;
 	bp->b_flags &= ~LIBXFS_B_STALE;
 	bp->b_flags |= (LIBXFS_B_DIRTY | flags);
-	libxfs_putbuf(bp);
+	libxfs_buf_relse(bp);
 	return 0;
 }
 
@@ -1520,7 +1520,7 @@ xfs_buf_delwri_submit(
 		error2 = libxfs_writebufr(bp);
 		if (!error)
 			error = error2;
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 	}
 
 	return error;
diff --git a/libxfs/trans.c b/libxfs/trans.c
index 18b87d70..59cb897f 100644
--- a/libxfs/trans.c
+++ b/libxfs/trans.c
@@ -566,7 +566,7 @@ libxfs_trans_brelse(
 	ASSERT(bp->b_transp == tp);
 
 	if (!tp) {
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 		return;
 	}
 
@@ -602,7 +602,7 @@ libxfs_trans_brelse(
 	xfs_buf_item_put(bip);
 
 	bp->b_transp = NULL;
-	libxfs_putbuf(bp);
+	libxfs_buf_relse(bp);
 }
 
 /*
@@ -839,7 +839,7 @@ inode_item_done(
 	if (error) {
 		fprintf(stderr, _("%s: warning - iflush_int failed (%d)\n"),
 			progname, error);
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 		goto free;
 	}
 
@@ -868,7 +868,7 @@ buf_item_done(
 	xfs_buf_item_put(bip);
 	if (hold)
 		return;
-	libxfs_putbuf(bp);
+	libxfs_buf_relse(bp);
 }
 
 static void
@@ -906,7 +906,7 @@ buf_item_unlock(
 	bip->bli_flags &= ~XFS_BLI_HOLD;
 	xfs_buf_item_put(bip);
 	if (!hold)
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 }
 
 static void
diff --git a/repair/attr_repair.c b/repair/attr_repair.c
index 535fcfbb..ec068ba2 100644
--- a/repair/attr_repair.c
+++ b/repair/attr_repair.c
@@ -418,7 +418,7 @@ rmtval_get(xfs_mount_t *mp, xfs_ino_t ino, blkmap_t *blkmap,
 		if (bp->b_error == -EFSBADCRC || bp->b_error == -EFSCORRUPTED) {
 			do_warn(
 	_("Corrupt remote block for attributes of inode %" PRIu64 "\n"), ino);
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 			clearit = 1;
 			break;
 		}
@@ -430,7 +430,7 @@ rmtval_get(xfs_mount_t *mp, xfs_ino_t ino, blkmap_t *blkmap,
 		amountdone += length;
 		value += length;
 		i++;
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 	}
 	return (clearit);
 }
@@ -782,7 +782,7 @@ process_leaf_attr_level(xfs_mount_t	*mp,
 			do_warn(
 	_("bad attribute leaf magic %#x for inode %" PRIu64 "\n"),
 				 leafhdr.magic, ino);
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 			goto error_out;
 		}
 
@@ -793,7 +793,7 @@ process_leaf_attr_level(xfs_mount_t	*mp,
 		if (process_leaf_attr_block(mp, leaf, da_bno, ino,
 				da_cursor->blkmap, current_hashval,
 				&greatest_hashval, &repair))  {
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 			goto error_out;
 		}
 
@@ -813,7 +813,7 @@ process_leaf_attr_level(xfs_mount_t	*mp,
 			do_warn(
 	_("bad sibling back pointer for block %u in attribute fork for inode %" PRIu64 "\n"),
 				da_bno, ino);
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 			goto error_out;
 		}
 
@@ -822,7 +822,7 @@ process_leaf_attr_level(xfs_mount_t	*mp,
 
 		if (da_bno != 0) {
 			if (verify_da_path(mp, da_cursor, 0, XFS_ATTR_FORK)) {
-				libxfs_putbuf(bp);
+				libxfs_buf_relse(bp);
 				goto error_out;
 			}
 		}
@@ -838,7 +838,7 @@ process_leaf_attr_level(xfs_mount_t	*mp,
 		if (repair && !no_modify)
 			libxfs_writebuf(bp, 0);
 		else
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 	} while (da_bno != 0);
 
 	if (verify_final_da_path(mp, da_cursor, 0, XFS_ATTR_FORK))  {
@@ -992,7 +992,7 @@ _("would clear forw/back pointers in block 0 for attributes in inode %" PRIu64 "
 	if (badness) {
 		*repair = 0;
 		/* the block is bad.  lose the attribute fork. */
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 		return 1;
 	}
 
@@ -1001,7 +1001,7 @@ _("would clear forw/back pointers in block 0 for attributes in inode %" PRIu64 "
 	if (*repair && !no_modify)
 		libxfs_writebuf(bp, 0);
 	else
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 
 	return 0;
 }
@@ -1045,7 +1045,7 @@ _("would clear forw/back pointers in block 0 for attributes in inode %" PRIu64 "
 		*repair = 1;
 		libxfs_writebuf(bp, 0);
 	} else
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 	error = process_node_attr(mp, ino, dip, blkmap); /* + repair */
 	if (error)
 		*repair = 0;
@@ -1107,7 +1107,7 @@ process_longform_attr(
 	/* is this block sane? */
 	if (__check_attr_header(mp, bp, ino)) {
 		*repair = 0;
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 		return 1;
 	}
 
@@ -1130,7 +1130,7 @@ process_longform_attr(
 		do_warn(
 	_("bad attribute leaf magic # %#x for dir ino %" PRIu64 "\n"),
 			be16_to_cpu(info->magic), ino);
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 		*repair = 0;
 		return 1;
 	}
diff --git a/repair/da_util.c b/repair/da_util.c
index bf25f7f2..c02d621c 100644
--- a/repair/da_util.c
+++ b/repair/da_util.c
@@ -145,7 +145,7 @@ _("found non-root LEAFN node in inode %" PRIu64 " bno = %u\n"),
 					da_cursor->ino, bno);
 			}
 			*rbno = 0;
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 			return 1;
 		}
 
@@ -155,13 +155,13 @@ _("found non-root LEAFN node in inode %" PRIu64 " bno = %u\n"),
 _("bad %s magic number 0x%x in inode %" PRIu64 " bno = %u\n"),
 					FORKNAME(whichfork), nodehdr.magic,
 					da_cursor->ino, bno);
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 			goto error_out;
 		}
 
 		/* corrupt node; rebuild the dir. */
 		if (bp->b_error == -EFSBADCRC || bp->b_error == -EFSCORRUPTED) {
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 			do_warn(
 _("corrupt %s tree block %u for inode %" PRIu64 "\n"),
 				FORKNAME(whichfork), bno, da_cursor->ino);
@@ -173,7 +173,7 @@ _("corrupt %s tree block %u for inode %" PRIu64 "\n"),
 _("bad %s record count in inode %" PRIu64 ", count = %d, max = %d\n"),
 				FORKNAME(whichfork), da_cursor->ino,
 				nodehdr.count, geo->node_ents);
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 			goto error_out;
 		}
 
@@ -186,7 +186,7 @@ _("bad %s record count in inode %" PRIu64 ", count = %d, max = %d\n"),
 				do_warn(
 _("bad header depth for directory inode %" PRIu64 "\n"),
 					da_cursor->ino);
-				libxfs_putbuf(bp);
+				libxfs_buf_relse(bp);
 				i = -1;
 				goto error_out;
 			}
@@ -197,7 +197,7 @@ _("bad header depth for directory inode %" PRIu64 "\n"),
 				do_warn(
 _("bad %s btree for inode %" PRIu64 "\n"),
 					FORKNAME(whichfork), da_cursor->ino);
-				libxfs_putbuf(bp);
+				libxfs_buf_relse(bp);
 				goto error_out;
 			}
 		}
@@ -222,7 +222,7 @@ _("bad %s btree for inode %" PRIu64 "\n"),
 
 error_out:
 	while (i > 1 && i <= da_cursor->active) {
-		libxfs_putbuf(da_cursor->level[i].bp);
+		libxfs_buf_relse(da_cursor->level[i].bp);
 		i++;
 	}
 
@@ -252,7 +252,7 @@ release_da_cursor_int(
 		}
 		ASSERT(error != 0);
 
-		libxfs_putbuf(cursor->level[level].bp);
+		libxfs_buf_relse(cursor->level[level].bp);
 		cursor->level[level].bp = NULL;
 	}
 
@@ -406,7 +406,7 @@ _("would correct bad hashval in non-leaf %s block\n"
 	if (cursor->level[this_level].dirty && !no_modify)
 		libxfs_writebuf(cursor->level[this_level].bp, 0);
 	else
-		libxfs_putbuf(cursor->level[this_level].bp);
+		libxfs_buf_relse(cursor->level[this_level].bp);
 
 	cursor->level[this_level].bp = NULL;
 
@@ -600,7 +600,7 @@ _("bad level %d in %s block %u for inode %" PRIu64 "\n"),
 #ifdef XR_DIR_TRACE
 			fprintf(stderr, "verify_da_path returns 1 (bad) #4\n");
 #endif
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 			return 1;
 		}
 
@@ -622,7 +622,7 @@ _("bad level %d in %s block %u for inode %" PRIu64 "\n"),
 		if (cursor->level[this_level].dirty && !no_modify)
 			libxfs_writebuf(cursor->level[this_level].bp, 0);
 		else
-			libxfs_putbuf(cursor->level[this_level].bp);
+			libxfs_buf_relse(cursor->level[this_level].bp);
 
 		/* switch cursor to point at the new buffer we just read */
 		cursor->level[this_level].bp = bp;
diff --git a/repair/dino_chunks.c b/repair/dino_chunks.c
index dbf3d37a..863c4531 100644
--- a/repair/dino_chunks.c
+++ b/repair/dino_chunks.c
@@ -56,7 +56,7 @@ check_aginode_block(xfs_mount_t	*mp,
 	if (cnt)
 		bp->b_ops = &xfs_inode_buf_ops;
 
-	libxfs_putbuf(bp);
+	libxfs_buf_relse(bp);
 	return(cnt);
 }
 
@@ -670,7 +670,7 @@ process_inode_chunk(
 					M_IGEO(mp)->blocks_per_cluster));
 			while (bp_index > 0) {
 				bp_index--;
-				libxfs_putbuf(bplist[bp_index]);
+				libxfs_buf_relse(bplist[bp_index]);
 			}
 			free(bplist);
 			return(1);
@@ -759,7 +759,7 @@ process_inode_chunk(
 			*bogus = 1;
 			for (bp_index = 0; bp_index < cluster_count; bp_index++)
 				if (bplist[bp_index])
-					libxfs_putbuf(bplist[bp_index]);
+					libxfs_buf_relse(bplist[bp_index]);
 			free(bplist);
 			return(0);
 		}
@@ -942,7 +942,7 @@ process_inode_chunk(
 				if (dirty && !no_modify)
 					libxfs_writebuf(bplist[bp_index], 0);
 				else
-					libxfs_putbuf(bplist[bp_index]);
+					libxfs_buf_relse(bplist[bp_index]);
 			}
 			free(bplist);
 			break;
diff --git a/repair/dinode.c b/repair/dinode.c
index 0d9c96be..928698cb 100644
--- a/repair/dinode.c
+++ b/repair/dinode.c
@@ -1234,7 +1234,7 @@ _("cannot read inode %" PRIu64 ", file block %" PRIu64 ", disk block %" PRIu64 "
 		if (writebuf && !no_modify)
 			libxfs_writebuf(bp, 0);
 		else
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 	}
 	return 0;
 }
@@ -1296,7 +1296,7 @@ _("cannot read inode %" PRIu64 ", file block %d, disk block %" PRIu64 "\n"),
 			do_warn(
 _("Corrupt symlink remote block %" PRIu64 ", inode %" PRIu64 ".\n"),
 				fsbno, lino);
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 			return 1;
 		}
 		if (bp->b_error == -EFSBADCRC) {
@@ -1316,7 +1316,7 @@ _("Bad symlink buffer CRC, block %" PRIu64 ", inode %" PRIu64 ".\n"
 				do_warn(
 _("bad symlink header ino %" PRIu64 ", file block %d, disk block %" PRIu64 "\n"),
 					lino, i, fsbno);
-				libxfs_putbuf(bp);
+				libxfs_buf_relse(bp);
 				return 1;
 			}
 			src += sizeof(struct xfs_dsymlink_hdr);
@@ -1331,7 +1331,7 @@ _("bad symlink header ino %" PRIu64 ", file block %d, disk block %" PRIu64 "\n")
 		if (badcrc && !no_modify)
 			libxfs_writebuf(bp, 0);
 		else
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 	}
 	return 0;
 }
diff --git a/repair/dir2.c b/repair/dir2.c
index 723aee1f..769e341c 100644
--- a/repair/dir2.c
+++ b/repair/dir2.c
@@ -1012,7 +1012,7 @@ _("bad directory block magic # %#x in block %u for directory inode %" PRIu64 "\n
 		*repair = 1;
 		libxfs_writebuf(bp, 0);
 	} else
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 	return rval;
 }
 
@@ -1131,7 +1131,7 @@ _("can't read file block %u for directory inode %" PRIu64 "\n"),
 			do_warn(
 _("bad directory leaf magic # %#x for directory inode %" PRIu64 " block %u\n"),
 				leafhdr.magic, ino, da_bno);
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 			goto error_out;
 		}
 		buf_dirty = 0;
@@ -1141,7 +1141,7 @@ _("bad directory leaf magic # %#x for directory inode %" PRIu64 " block %u\n"),
 		 */
 		if (process_leaf_block_dir2(mp, leaf, da_bno, ino,
 				current_hashval, &greatest_hashval)) {
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 			goto error_out;
 		}
 		/*
@@ -1159,14 +1159,14 @@ _("bad directory leaf magic # %#x for directory inode %" PRIu64 " block %u\n"),
 			do_warn(
 _("bad sibling back pointer for block %u in directory inode %" PRIu64 "\n"),
 				da_bno, ino);
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 			goto error_out;
 		}
 		prev_bno = da_bno;
 		da_bno = leafhdr.forw;
 		if (da_bno != 0) {
 			if (verify_da_path(mp, da_cursor, 0, XFS_DATA_FORK)) {
-				libxfs_putbuf(bp);
+				libxfs_buf_relse(bp);
 				goto error_out;
 			}
 		}
@@ -1182,7 +1182,7 @@ _("bad sibling back pointer for block %u in directory inode %" PRIu64 "\n"),
 			*repair = 1;
 			libxfs_writebuf(bp, 0);
 		} else
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 	} while (da_bno != 0);
 	if (verify_final_da_path(mp, da_cursor, 0, XFS_DATA_FORK)) {
 		/*
@@ -1341,7 +1341,7 @@ _("bad directory block magic # %#x in block %" PRIu64 " for directory inode %" P
 			*repair = 1;
 			libxfs_writebuf(bp, 0);
 		} else
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 	}
 	if (good == 0)
 		return 1;
diff --git a/repair/phase3.c b/repair/phase3.c
index 161852e0..1c6929ac 100644
--- a/repair/phase3.c
+++ b/repair/phase3.c
@@ -49,7 +49,7 @@ process_agi_unlinked(
 	if (agi_dirty)
 		libxfs_writebuf(bp, 0);
 	else
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 }
 
 static void
diff --git a/repair/phase6.c b/repair/phase6.c
index 70135694..2464fe1a 100644
--- a/repair/phase6.c
+++ b/repair/phase6.c
@@ -1624,7 +1624,7 @@ longform_dir2_entry_check_data(
 			dir2_kill_block(mp, ip, da_bno, bp);
 		} else {
 			do_warn(_("would junk block\n"));
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 		}
 		freetab->ents[db].v = NULLDATAOFF;
 		*bpp = NULL;
@@ -2063,21 +2063,21 @@ longform_dir2_check_leaf(
 		do_warn(
 	_("leaf block %u for directory inode %" PRIu64 " bad header\n"),
 			da_bno, ip->i_ino);
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 		return 1;
 	}
 
 	if (leafhdr.magic == XFS_DIR3_LEAF1_MAGIC) {
 		error = check_da3_header(mp, bp, ip->i_ino);
 		if (error) {
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 			return error;
 		}
 	}
 
 	seeval = dir_hash_see_all(hashtab, ents, leafhdr.count, leafhdr.stale);
 	if (dir_hash_check(hashtab, ip, seeval)) {
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 		return 1;
 	}
 	badtail = freetab->nents != be32_to_cpu(ltp->bestcount);
@@ -2089,10 +2089,10 @@ longform_dir2_check_leaf(
 		do_warn(
 	_("leaf block %u for directory inode %" PRIu64 " bad tail\n"),
 			da_bno, ip->i_ino);
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 		return 1;
 	}
-	libxfs_putbuf(bp);
+	libxfs_buf_relse(bp);
 	return fixit;
 }
 
@@ -2155,7 +2155,7 @@ longform_dir2_check_node(
 			do_warn(
 	_("unknown magic number %#x for block %u in directory inode %" PRIu64 "\n"),
 				leafhdr.magic, da_bno, ip->i_ino);
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 			return 1;
 		}
 
@@ -2164,7 +2164,7 @@ longform_dir2_check_node(
 		    leafhdr.magic == XFS_DA3_NODE_MAGIC) {
 			error = check_da3_header(mp, bp, ip->i_ino);
 			if (error) {
-				libxfs_putbuf(bp);
+				libxfs_buf_relse(bp);
 				return error;
 			}
 		}
@@ -2172,7 +2172,7 @@ longform_dir2_check_node(
 		/* ignore nodes */
 		if (leafhdr.magic == XFS_DA_NODE_MAGIC ||
 		    leafhdr.magic == XFS_DA3_NODE_MAGIC) {
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 			continue;
 		}
 
@@ -2186,12 +2186,12 @@ longform_dir2_check_node(
 			do_warn(
 	_("leaf block %u for directory inode %" PRIu64 " bad header\n"),
 				da_bno, ip->i_ino);
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 			return 1;
 		}
 		seeval = dir_hash_see_all(hashtab, ents,
 					leafhdr.count, leafhdr.stale);
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 		if (seeval != DIR_HASH_CK_OK)
 			return 1;
 	}
@@ -2226,14 +2226,14 @@ longform_dir2_check_node(
 			do_warn(
 	_("free block %u for directory inode %" PRIu64 " bad header\n"),
 				da_bno, ip->i_ino);
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 			return 1;
 		}
 
 		if (freehdr.magic == XFS_DIR3_FREE_MAGIC) {
 			error = check_dir3_header(mp, bp, ip->i_ino);
 			if (error) {
-				libxfs_putbuf(bp);
+				libxfs_buf_relse(bp);
 				return error;
 			}
 		}
@@ -2244,7 +2244,7 @@ longform_dir2_check_node(
 				do_warn(
 	_("free block %u entry %i for directory ino %" PRIu64 " bad\n"),
 					da_bno, i, ip->i_ino);
-				libxfs_putbuf(bp);
+				libxfs_buf_relse(bp);
 				return 1;
 			}
 			used += be16_to_cpu(bests[i]) != NULLDATAOFF;
@@ -2254,10 +2254,10 @@ longform_dir2_check_node(
 			do_warn(
 	_("free block %u for directory inode %" PRIu64 " bad nused\n"),
 				da_bno, ip->i_ino);
-			libxfs_putbuf(bp);
+			libxfs_buf_relse(bp);
 			return 1;
 		}
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 	}
 	for (i = 0; i < freetab->nents; i++) {
 		if ((freetab->ents[i].s == 0) &&
@@ -2433,14 +2433,14 @@ longform_dir2_entry_check(xfs_mount_t	*mp,
 		dir_hash_dup_names(hashtab);
 		for (i = 0; i < num_bps; i++)
 			if (bplist[i])
-				libxfs_putbuf(bplist[i]);
+				libxfs_buf_relse(bplist[i]);
 		longform_dir2_rebuild(mp, ino, ip, irec, ino_offset, hashtab);
 		*num_illegal = 0;
 		*need_dot = 0;
 	} else {
 		for (i = 0; i < num_bps; i++)
 			if (bplist[i])
-				libxfs_putbuf(bplist[i]);
+				libxfs_buf_relse(bplist[i]);
 	}
 
 	free(bplist);
diff --git a/repair/prefetch.c b/repair/prefetch.c
index 8e3772ed..f7ea9c8f 100644
--- a/repair/prefetch.c
+++ b/repair/prefetch.c
@@ -129,7 +129,7 @@ pf_queue_io(
 			pf_read_inode_dirs(args, bp);
 		XFS_BUF_SET_PRIORITY(bp, XFS_BUF_PRIORITY(bp) +
 						CACHE_PREFETCH_PRIORITY);
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 		return;
 	}
 	XFS_BUF_SET_PRIORITY(bp, flag);
@@ -286,13 +286,13 @@ pf_scan_lbtree(
 	 */
 	if (bp->b_error) {
 		bp->b_flags |= LIBXFS_B_UNCHECKED;
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 		return 0;
 	}
 
 	rc = (*func)(XFS_BUF_TO_BLOCK(bp), level - 1, isadir, args);
 
-	libxfs_putbuf(bp);
+	libxfs_buf_relse(bp);
 
 	return rc;
 }
@@ -578,7 +578,7 @@ pf_batch_read(
 		if ((bplist[num - 1]->b_flags & LIBXFS_B_DISCONTIG)) {
 			libxfs_readbufr_map(mp->m_ddev_targp, bplist[num - 1], 0);
 			bplist[num - 1]->b_flags |= LIBXFS_B_UNCHECKED;
-			libxfs_putbuf(bplist[num - 1]);
+			libxfs_buf_relse(bplist[num - 1]);
 			num--;
 		}
 
@@ -612,7 +612,7 @@ pf_batch_read(
 				B_IS_INODE(XFS_BUF_PRIORITY(bplist[i])) ? 'I' : 'M',
 				bplist[i], (long long)XFS_BUF_ADDR(bplist[i]),
 				args->agno);
-			libxfs_putbuf(bplist[i]);
+			libxfs_buf_relse(bplist[i]);
 		}
 		pthread_mutex_lock(&args->lock);
 		if (which != PF_SECONDARY) {
diff --git a/repair/rmap.c b/repair/rmap.c
index 2f99d35d..bc53e6c0 100644
--- a/repair/rmap.c
+++ b/repair/rmap.c
@@ -527,7 +527,7 @@ rmap_store_ag_btree_rec(
 		}
 		b++;
 	}
-	libxfs_putbuf(agflbp);
+	libxfs_buf_relse(agflbp);
 	agflbp = NULL;
 	bitmap_free(&own_ag_bitmap);
 
@@ -579,7 +579,7 @@ rmap_store_ag_btree_rec(
 	free_slab_cursor(&rm_cur);
 err:
 	if (agflbp)
-		libxfs_putbuf(agflbp);
+		libxfs_buf_relse(agflbp);
 	if (own_ag_bitmap)
 		bitmap_free(&own_ag_bitmap);
 	return error;
@@ -1082,7 +1082,7 @@ _("Incorrect reverse-mapping: saw (%u/%u) %slen %u owner %"PRId64" %s%soff \
 	if (bt_cur)
 		libxfs_btree_del_cursor(bt_cur, XFS_BTREE_NOERROR);
 	if (agbp)
-		libxfs_putbuf(agbp);
+		libxfs_buf_relse(agbp);
 	free_slab_cursor(&rm_cur);
 	return 0;
 }
@@ -1417,7 +1417,7 @@ _("Incorrect reference count: saw (%u/%u) len %u nlinks %u; should be (%u/%u) le
 		libxfs_btree_del_cursor(bt_cur, error ? XFS_BTREE_ERROR :
 							XFS_BTREE_NOERROR);
 	if (agbp)
-		libxfs_putbuf(agbp);
+		libxfs_buf_relse(agbp);
 	free_slab_cursor(&rl_cur);
 	return 0;
 }
diff --git a/repair/rt.c b/repair/rt.c
index 7108e3d5..3319829c 100644
--- a/repair/rt.c
+++ b/repair/rt.c
@@ -222,7 +222,7 @@ process_rtbitmap(xfs_mount_t	*mp,
 				prevbit = 0;
 			}
 		}
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 		if (extno == mp->m_sb.sb_rextents)
 			break;
 	}
@@ -266,7 +266,7 @@ process_rtsummary(xfs_mount_t	*mp,
 		bytes = bp->b_un.b_addr;
 		memmove((char *)sumfile + sumbno * mp->m_sb.sb_blocksize, bytes,
 			mp->m_sb.sb_blocksize);
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 	}
 }
 #endif
diff --git a/repair/scan.c b/repair/scan.c
index 05707dd2..c961e843 100644
--- a/repair/scan.c
+++ b/repair/scan.c
@@ -82,7 +82,7 @@ scan_sbtree(
 
 	(*func)(XFS_BUF_TO_BLOCK(bp), nlevels - 1, root, agno, suspect,
 			isroot, magic, priv, ops);
-	libxfs_putbuf(bp);
+	libxfs_buf_relse(bp);
 }
 
 /*
@@ -154,7 +154,7 @@ scan_lbtree(
 	if ((dirty || badcrc) && !no_modify)
 		libxfs_writebuf(bp, 0);
 	else
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 
 	return(err);
 }
@@ -2142,7 +2142,7 @@ scan_freelist(
 
 	agcnts->fdblocks += state.count;
 
-	libxfs_putbuf(agflbuf);
+	libxfs_buf_relse(agflbuf);
 }
 
 static void
@@ -2432,12 +2432,12 @@ scan_ag(
 	if (agi_dirty && !no_modify)
 		libxfs_writebuf(agibuf, 0);
 	else
-		libxfs_putbuf(agibuf);
+		libxfs_buf_relse(agibuf);
 
 	if (agf_dirty && !no_modify)
 		libxfs_writebuf(agfbuf, 0);
 	else
-		libxfs_putbuf(agfbuf);
+		libxfs_buf_relse(agfbuf);
 
 	if (sb_dirty && !no_modify) {
 		if (agno == 0)
@@ -2445,7 +2445,7 @@ scan_ag(
 		libxfs_sb_to_disk(XFS_BUF_TO_SBP(sbbuf), sb);
 		libxfs_writebuf(sbbuf, 0);
 	} else
-		libxfs_putbuf(sbbuf);
+		libxfs_buf_relse(sbbuf);
 	free(sb);
 	PROG_RPT_INC(prog_rpt_done[agno], 1);
 
@@ -2455,11 +2455,11 @@ scan_ag(
 	return;
 
 out_free_agibuf:
-	libxfs_putbuf(agibuf);
+	libxfs_buf_relse(agibuf);
 out_free_agfbuf:
-	libxfs_putbuf(agfbuf);
+	libxfs_buf_relse(agfbuf);
 out_free_sbbuf:
-	libxfs_putbuf(sbbuf);
+	libxfs_buf_relse(sbbuf);
 out_free_sb:
 	free(sb);
 
diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c
index 38578121..a97f2803 100644
--- a/repair/xfs_repair.c
+++ b/repair/xfs_repair.c
@@ -479,7 +479,7 @@ guess_correct_sunit(
 		if (error)
 			continue;
 		libxfs_sb_from_disk(&sb, XFS_BUF_TO_SBP(bp));
-		libxfs_putbuf(bp);
+		libxfs_buf_relse(bp);
 
 		calc_rootino = libxfs_ialloc_calc_rootino(mp, sb.sb_unit);
 		if (calc_rootino == mp->m_sb.sb_rootino)


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 05/25] libxfs: replace libxfs_getbuf with libxfs_buf_get
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
                   ` (3 preceding siblings ...)
  2020-02-25  0:11 ` [PATCH 04/25] libxfs: replace libxfs_putbuf with libxfs_buf_relse Darrick J. Wong
@ 2020-02-25  0:12 ` Darrick J. Wong
  2020-02-25  0:12 ` [PATCH 06/25] libxfs: replace libxfs_readbuf with libxfs_buf_read Darrick J. Wong
                   ` (19 subsequent siblings)
  24 siblings, 0 replies; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:12 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs, Christoph Hellwig

From: Darrick J. Wong <darrick.wong@oracle.com>

Change all the libxfs_getbuf calls to libxfs_buf_get to match the
kernel interface, since one is a #define of the other.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 include/cache.h          |    2 +-
 libxfs/libxfs_api_defs.h |    1 +
 libxfs/libxfs_io.h       |   21 ++++++++++++++++-----
 libxfs/libxfs_priv.h     |    1 -
 libxfs/rdwr.c            |   34 ++++++++++++++++------------------
 mkfs/xfs_mkfs.c          |    9 +++++----
 repair/phase5.c          |   30 +++++++++++++++---------------
 7 files changed, 54 insertions(+), 44 deletions(-)


diff --git a/include/cache.h b/include/cache.h
index 552b9248..334ad263 100644
--- a/include/cache.h
+++ b/include/cache.h
@@ -33,7 +33,7 @@ enum {
  * For prefetch support, the top half of the range starts at
  * CACHE_PREFETCH_PRIORITY and everytime the buffer is fetched and is at or
  * above this priority level, it is reduced to below this level (refer to
- * libxfs_getbuf).
+ * libxfs_buf_get).
  *
  * If we have dirty nodes, we can't recycle them until they've been cleaned. To
  * keep these out of the reclaimable lists (as there can be lots of them) give
diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h
index 8bca7ddf..6d86774f 100644
--- a/libxfs/libxfs_api_defs.h
+++ b/libxfs/libxfs_api_defs.h
@@ -44,6 +44,7 @@
 #define xfs_btree_del_cursor		libxfs_btree_del_cursor
 #define xfs_btree_init_block		libxfs_btree_init_block
 #define xfs_buf_delwri_submit		libxfs_buf_delwri_submit
+#define xfs_buf_get			libxfs_buf_get
 #define xfs_buf_relse			libxfs_buf_relse
 #define xfs_bunmapi			libxfs_bunmapi
 #define xfs_calc_dquots_per_chunk	libxfs_calc_dquots_per_chunk
diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h
index 3ddfc0c8..50b7cef8 100644
--- a/libxfs/libxfs_io.h
+++ b/libxfs/libxfs_io.h
@@ -139,7 +139,7 @@ extern struct cache_operations	libxfs_bcache_operations;
 #define libxfs_writebuf(buf, flags) \
 	libxfs_trace_writebuf(__FUNCTION__, __FILE__, __LINE__, \
 			      (buf), (flags))
-#define libxfs_getbuf(dev, daddr, len) \
+#define libxfs_buf_get(dev, daddr, len) \
 	libxfs_trace_getbuf(__FUNCTION__, __FILE__, __LINE__, \
 			    (dev), (daddr), (len))
 #define libxfs_getbuf_map(dev, map, nmaps, flags) \
@@ -159,8 +159,9 @@ extern xfs_buf_t *libxfs_trace_readbuf_map(const char *, const char *, int,
 			const struct xfs_buf_ops *);
 extern int	libxfs_trace_writebuf(const char *, const char *, int,
 			xfs_buf_t *, int);
-extern xfs_buf_t *libxfs_trace_getbuf(const char *, const char *, int,
-			struct xfs_buftarg *, xfs_daddr_t, int);
+struct xfs_buf *libxfs_trace_getbuf(const char *func, const char *file,
+			int line, struct xfs_buftarg *btp, xfs_daddr_t daddr,
+			size_t len);
 extern xfs_buf_t *libxfs_trace_getbuf_map(const char *, const char *, int,
 			struct xfs_buftarg *, struct xfs_buf_map *, int, int);
 extern xfs_buf_t *libxfs_trace_getbuf_flags(const char *, const char *, int,
@@ -175,14 +176,24 @@ extern xfs_buf_t *libxfs_readbuf(struct xfs_buftarg *, xfs_daddr_t, int, int,
 extern xfs_buf_t *libxfs_readbuf_map(struct xfs_buftarg *, struct xfs_buf_map *,
 			int, int, const struct xfs_buf_ops *);
 extern int	libxfs_writebuf(xfs_buf_t *, int);
-extern xfs_buf_t *libxfs_getbuf(struct xfs_buftarg *, xfs_daddr_t, int);
 extern xfs_buf_t *libxfs_getbuf_map(struct xfs_buftarg *,
 			struct xfs_buf_map *, int, int);
 extern xfs_buf_t *libxfs_getbuf_flags(struct xfs_buftarg *, xfs_daddr_t,
 			int, unsigned int);
 void	libxfs_buf_relse(struct xfs_buf *bp);
 
-#endif
+static inline struct xfs_buf*
+libxfs_buf_get(
+	struct xfs_buftarg	*target,
+	xfs_daddr_t		blkno,
+	size_t			numblks)
+{
+	DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
+
+	return libxfs_getbuf_map(target, &map, 1, 0);
+}
+
+#endif /* XFS_BUF_TRACING */
 
 extern void	libxfs_readbuf_verify(struct xfs_buf *bp,
 			const struct xfs_buf_ops *ops);
diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h
index 4bd3c462..0f26120f 100644
--- a/libxfs/libxfs_priv.h
+++ b/libxfs/libxfs_priv.h
@@ -377,7 +377,6 @@ roundup_64(uint64_t x, uint32_t y)
 	(len) = __bar; /* no set-but-unused warning */	\
 	NULL;						\
 })
-#define xfs_buf_get(devp,blkno,len)	(libxfs_getbuf((devp), (blkno), (len)))
 #define xfs_bwrite(bp)			libxfs_writebuf((bp), 0)
 #define xfs_buf_oneshot(bp)		((void) 0)
 
diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index 02e19e1c..99b48db2 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -30,7 +30,7 @@
  * outside libxfs clears bp->b_error - very little code even checks it - so the
  * libxfs code is tripping on stale errors left by the userspace code.
  *
- * We can't clear errors or zero buffer contents in libxfs_getbuf-* like we do
+ * We can't clear errors or zero buffer contents in libxfs_buf_get-* like we do
  * in the kernel, because those functions are used by the libxfs_readbuf_*
  * functions and hence need to leave the buffers unchanged on cache hits. This
  * is actually the only way to gather a write error from a libxfs_writebuf()
@@ -44,7 +44,7 @@
  *
  * IOWs, userspace is behaving quite differently to the kernel and as a result
  * it leaks errors from reads, invalidations and writes through
- * libxfs_getbuf/libxfs_readbuf.
+ * libxfs_buf_get/libxfs_readbuf.
  *
  * The result of this is that until the userspace code outside libxfs is cleaned
  * up, functions that release buffers from userspace control (i.e
@@ -384,7 +384,6 @@ libxfs_log_header(
 #undef libxfs_readbuf
 #undef libxfs_readbuf_map
 #undef libxfs_writebuf
-#undef libxfs_getbuf
 #undef libxfs_getbuf_map
 #undef libxfs_getbuf_flags
 
@@ -393,7 +392,8 @@ xfs_buf_t	*libxfs_readbuf(struct xfs_buftarg *, xfs_daddr_t, int, int,
 xfs_buf_t	*libxfs_readbuf_map(struct xfs_buftarg *, struct xfs_buf_map *,
 				int, int, const struct xfs_buf_ops *);
 int		libxfs_writebuf(xfs_buf_t *, int);
-xfs_buf_t	*libxfs_getbuf(struct xfs_buftarg *, xfs_daddr_t, int);
+struct xfs_buf *libxfs_buf_get(struct xfs_buftarg *btp, xfs_daddr_t daddr,
+				size_t len);
 xfs_buf_t	*libxfs_getbuf_map(struct xfs_buftarg *, struct xfs_buf_map *,
 				int, int);
 xfs_buf_t	*libxfs_getbuf_flags(struct xfs_buftarg *, xfs_daddr_t, int,
@@ -436,11 +436,19 @@ libxfs_trace_writebuf(const char *func, const char *file, int line, xfs_buf_t *b
 	return libxfs_writebuf(bp, flags);
 }
 
-xfs_buf_t *
-libxfs_trace_getbuf(const char *func, const char *file, int line,
-		struct xfs_buftarg *btp, xfs_daddr_t blkno, int len)
+struct xfs_buf *
+libxfs_trace_getbuf(
+	const char		*func,
+	const char		*file,
+	int			line,
+	struct xfs_buftarg	*btp,
+	xfs_daddr_t		blkno,
+	size_t			len)
 {
-	xfs_buf_t	*bp = libxfs_getbuf(btp, blkno, len);
+	struct xfs_buf		*bp;
+	DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
+
+	bp = libxfs_getbuf_map(target, &map, 1, 0);
 	__add_trace(bp, func, file, line);
 	return bp;
 }
@@ -799,16 +807,6 @@ reset_buf_state(
 				LIBXFS_B_UPTODATE);
 }
 
-struct xfs_buf *
-libxfs_getbuf(struct xfs_buftarg *btp, xfs_daddr_t blkno, int len)
-{
-	struct xfs_buf	*bp;
-
-	bp = libxfs_getbuf_flags(btp, blkno, len, 0);
-	reset_buf_state(bp);
-	return bp;
-}
-
 static struct xfs_buf *
 __libxfs_getbuf_map(struct xfs_buftarg *btp, struct xfs_buf_map *map,
 		    int nmaps, int flags)
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index fbf2b7f2..4e757ee1 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -3444,7 +3444,7 @@ prepare_devices(
 	 * the end of the device.  (MD sb is ~64k from the end, take out a wider
 	 * swath to be sure)
 	 */
-	buf = libxfs_getbuf(mp->m_ddev_targp, (xi->dsize - whack_blks),
+	buf = libxfs_buf_get(mp->m_ddev_targp, (xi->dsize - whack_blks),
 			    whack_blks);
 	memset(buf->b_addr, 0, WHACK_SIZE);
 	libxfs_writebuf(buf, 0);
@@ -3456,13 +3456,14 @@ prepare_devices(
 	 * swap (somewhere around the page size), jfs (32k),
 	 * ext[2,3] and reiserfs (64k) - and hopefully all else.
 	 */
-	buf = libxfs_getbuf(mp->m_ddev_targp, 0, whack_blks);
+	buf = libxfs_buf_get(mp->m_ddev_targp, 0, whack_blks);
 	memset(buf->b_addr, 0, WHACK_SIZE);
 	libxfs_writebuf(buf, 0);
 	libxfs_purgebuf(buf);
 
 	/* OK, now write the superblock... */
-	buf = libxfs_getbuf(mp->m_ddev_targp, XFS_SB_DADDR, XFS_FSS_TO_BB(mp, 1));
+	buf = libxfs_buf_get(mp->m_ddev_targp, XFS_SB_DADDR,
+			XFS_FSS_TO_BB(mp, 1));
 	buf->b_ops = &xfs_sb_buf_ops;
 	memset(buf->b_addr, 0, cfg->sectorsize);
 	libxfs_sb_to_disk(buf->b_addr, sbp);
@@ -3482,7 +3483,7 @@ prepare_devices(
 
 	/* finally, check we can write the last block in the realtime area */
 	if (mp->m_rtdev_targp->dev && cfg->rtblocks > 0) {
-		buf = libxfs_getbuf(mp->m_rtdev_targp,
+		buf = libxfs_buf_get(mp->m_rtdev_targp,
 				    XFS_FSB_TO_BB(mp, cfg->rtblocks - 1LL),
 				    BTOBB(cfg->blocksize));
 		memset(buf->b_addr, 0, cfg->blocksize);
diff --git a/repair/phase5.c b/repair/phase5.c
index 7f7d3d18..cdbf6697 100644
--- a/repair/phase5.c
+++ b/repair/phase5.c
@@ -689,7 +689,7 @@ prop_freespace_cursor(xfs_mount_t *mp, xfs_agnumber_t agno,
 
 		bt_hdr->bb_u.s.bb_rightsib = cpu_to_be32(agbno);
 
-		lptr->buf_p = libxfs_getbuf(mp->m_dev,
+		lptr->buf_p = libxfs_buf_get(mp->m_dev,
 					XFS_AGB_TO_DADDR(mp, agno, agbno),
 					XFS_FSB_TO_BB(mp, 1));
 		lptr->agbno = agbno;
@@ -767,7 +767,7 @@ build_freespace_tree(xfs_mount_t *mp, xfs_agnumber_t agno,
 		lptr = &btree_curs->level[i];
 
 		agbno = get_next_blockaddr(agno, i, btree_curs);
-		lptr->buf_p = libxfs_getbuf(mp->m_dev,
+		lptr->buf_p = libxfs_buf_get(mp->m_dev,
 					XFS_AGB_TO_DADDR(mp, agno, agbno),
 					XFS_FSB_TO_BB(mp, 1));
 
@@ -877,7 +877,7 @@ build_freespace_tree(xfs_mount_t *mp, xfs_agnumber_t agno,
 			lptr->agbno = get_next_blockaddr(agno, 0, btree_curs);
 			bt_hdr->bb_u.s.bb_rightsib = cpu_to_be32(lptr->agbno);
 
-			lptr->buf_p = libxfs_getbuf(mp->m_dev,
+			lptr->buf_p = libxfs_buf_get(mp->m_dev,
 					XFS_AGB_TO_DADDR(mp, agno, lptr->agbno),
 					XFS_FSB_TO_BB(mp, 1));
 		}
@@ -1054,7 +1054,7 @@ prop_ino_cursor(xfs_mount_t *mp, xfs_agnumber_t agno, bt_status_t *btree_curs,
 
 		bt_hdr->bb_u.s.bb_rightsib = cpu_to_be32(agbno);
 
-		lptr->buf_p = libxfs_getbuf(mp->m_dev,
+		lptr->buf_p = libxfs_buf_get(mp->m_dev,
 					XFS_AGB_TO_DADDR(mp, agno, agbno),
 					XFS_FSB_TO_BB(mp, 1));
 		lptr->agbno = agbno;
@@ -1104,7 +1104,7 @@ build_agi(xfs_mount_t *mp, xfs_agnumber_t agno, bt_status_t *btree_curs,
 	xfs_agi_t	*agi;
 	int		i;
 
-	agi_buf = libxfs_getbuf(mp->m_dev,
+	agi_buf = libxfs_buf_get(mp->m_dev,
 			XFS_AG_DADDR(mp, agno, XFS_AGI_DADDR(mp)),
 			mp->m_sb.sb_sectsize/BBSIZE);
 	agi_buf->b_ops = &xfs_agi_buf_ops;
@@ -1174,7 +1174,7 @@ build_ino_tree(xfs_mount_t *mp, xfs_agnumber_t agno,
 		lptr = &btree_curs->level[i];
 
 		agbno = get_next_blockaddr(agno, i, btree_curs);
-		lptr->buf_p = libxfs_getbuf(mp->m_dev,
+		lptr->buf_p = libxfs_buf_get(mp->m_dev,
 					XFS_AGB_TO_DADDR(mp, agno, agbno),
 					XFS_FSB_TO_BB(mp, 1));
 
@@ -1306,7 +1306,7 @@ build_ino_tree(xfs_mount_t *mp, xfs_agnumber_t agno,
 			lptr->agbno = get_next_blockaddr(agno, 0, btree_curs);
 			bt_hdr->bb_u.s.bb_rightsib = cpu_to_be32(lptr->agbno);
 
-			lptr->buf_p = libxfs_getbuf(mp->m_dev,
+			lptr->buf_p = libxfs_buf_get(mp->m_dev,
 					XFS_AGB_TO_DADDR(mp, agno, lptr->agbno),
 					XFS_FSB_TO_BB(mp, 1));
 		}
@@ -1459,7 +1459,7 @@ prop_rmap_cursor(
 
 		bt_hdr->bb_u.s.bb_rightsib = cpu_to_be32(agbno);
 
-		lptr->buf_p = libxfs_getbuf(mp->m_dev,
+		lptr->buf_p = libxfs_buf_get(mp->m_dev,
 					XFS_AGB_TO_DADDR(mp, agno, agbno),
 					XFS_FSB_TO_BB(mp, 1));
 		lptr->agbno = agbno;
@@ -1569,7 +1569,7 @@ build_rmap_tree(
 		lptr = &btree_curs->level[i];
 
 		agbno = get_next_blockaddr(agno, i, btree_curs);
-		lptr->buf_p = libxfs_getbuf(mp->m_dev,
+		lptr->buf_p = libxfs_buf_get(mp->m_dev,
 					XFS_AGB_TO_DADDR(mp, agno, agbno),
 					XFS_FSB_TO_BB(mp, 1));
 
@@ -1668,7 +1668,7 @@ _("Insufficient memory to construct reverse-map cursor."));
 			lptr->agbno = get_next_blockaddr(agno, 0, btree_curs);
 			bt_hdr->bb_u.s.bb_rightsib = cpu_to_be32(lptr->agbno);
 
-			lptr->buf_p = libxfs_getbuf(mp->m_dev,
+			lptr->buf_p = libxfs_buf_get(mp->m_dev,
 					XFS_AGB_TO_DADDR(mp, agno, lptr->agbno),
 					XFS_FSB_TO_BB(mp, 1));
 		}
@@ -1809,7 +1809,7 @@ prop_refc_cursor(
 
 		bt_hdr->bb_u.s.bb_rightsib = cpu_to_be32(agbno);
 
-		lptr->buf_p = libxfs_getbuf(mp->m_dev,
+		lptr->buf_p = libxfs_buf_get(mp->m_dev,
 					XFS_AGB_TO_DADDR(mp, agno, agbno),
 					XFS_FSB_TO_BB(mp, 1));
 		lptr->agbno = agbno;
@@ -1874,7 +1874,7 @@ build_refcount_tree(
 		lptr = &btree_curs->level[i];
 
 		agbno = get_next_blockaddr(agno, i, btree_curs);
-		lptr->buf_p = libxfs_getbuf(mp->m_dev,
+		lptr->buf_p = libxfs_buf_get(mp->m_dev,
 					XFS_AGB_TO_DADDR(mp, agno, agbno),
 					XFS_FSB_TO_BB(mp, 1));
 
@@ -1961,7 +1961,7 @@ _("Insufficient memory to construct refcount cursor."));
 			lptr->agbno = get_next_blockaddr(agno, 0, btree_curs);
 			bt_hdr->bb_u.s.bb_rightsib = cpu_to_be32(lptr->agbno);
 
-			lptr->buf_p = libxfs_getbuf(mp->m_dev,
+			lptr->buf_p = libxfs_buf_get(mp->m_dev,
 					XFS_AGB_TO_DADDR(mp, agno, lptr->agbno),
 					XFS_FSB_TO_BB(mp, 1));
 		}
@@ -1996,7 +1996,7 @@ build_agf_agfl(
 	__be32			*freelist;
 	int			error;
 
-	agf_buf = libxfs_getbuf(mp->m_dev,
+	agf_buf = libxfs_buf_get(mp->m_dev,
 			XFS_AG_DADDR(mp, agno, XFS_AGF_DADDR(mp)),
 			mp->m_sb.sb_sectsize/BBSIZE);
 	agf_buf->b_ops = &xfs_agf_buf_ops;
@@ -2068,7 +2068,7 @@ build_agf_agfl(
 		platform_uuid_copy(&agf->agf_uuid, &mp->m_sb.sb_meta_uuid);
 
 	/* initialise the AGFL, then fill it if there are blocks left over. */
-	agfl_buf = libxfs_getbuf(mp->m_dev,
+	agfl_buf = libxfs_buf_get(mp->m_dev,
 			XFS_AG_DADDR(mp, agno, XFS_AGFL_DADDR(mp)),
 			mp->m_sb.sb_sectsize/BBSIZE);
 	agfl_buf->b_ops = &xfs_agfl_buf_ops;


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 06/25] libxfs: replace libxfs_readbuf with libxfs_buf_read
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
                   ` (4 preceding siblings ...)
  2020-02-25  0:12 ` [PATCH 05/25] libxfs: replace libxfs_getbuf with libxfs_buf_get Darrick J. Wong
@ 2020-02-25  0:12 ` Darrick J. Wong
  2020-02-25  0:12 ` [PATCH 07/25] libxfs: rename libxfs_writebufr to libxfs_bwrite Darrick J. Wong
                   ` (18 subsequent siblings)
  24 siblings, 0 replies; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:12 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs, Christoph Hellwig

From: Darrick J. Wong <darrick.wong@oracle.com>

Change all the libxfs_readbuf calls to libxfs_buf_read to match the
kernel interface.  This enables us to hide libxfs_readbuf and simplify
the userspace buffer interface further.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 copy/xfs_copy.c          |    4 ++-
 db/init.c                |    2 +-
 db/io.c                  |    2 +-
 libxfs/init.c            |    8 +++----
 libxfs/libxfs_api_defs.h |    1 +
 libxfs/libxfs_io.h       |   25 +++++++++++++++------
 libxfs/rdwr.c            |   56 +++++++++++++++++++++++-----------------------
 mkfs/xfs_mkfs.c          |    4 ++-
 repair/attr_repair.c     |    6 ++---
 repair/dino_chunks.c     |    4 ++-
 repair/dinode.c          |    6 ++---
 repair/phase3.c          |    2 +-
 repair/prefetch.c        |    2 +-
 repair/rt.c              |    4 ++-
 repair/scan.c            |   12 +++++-----
 15 files changed, 75 insertions(+), 63 deletions(-)


diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c
index 3e519471..9e9719a0 100644
--- a/copy/xfs_copy.c
+++ b/copy/xfs_copy.c
@@ -710,7 +710,7 @@ 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_readbuf(mbuf.m_ddev_targp, XFS_SB_DADDR,
+	sbp = libxfs_buf_read(mbuf.m_ddev_targp, XFS_SB_DADDR,
 			     1 << (XFS_MAX_SECTORSIZE_LOG - BBSHIFT), 0, NULL);
 	sb = &mbuf.m_sb;
 	libxfs_sb_from_disk(sb, XFS_BUF_TO_SBP(sbp));
@@ -718,7 +718,7 @@ main(int argc, char **argv)
 	/* Do it again, now with proper length and verifier */
 	libxfs_buf_relse(sbp);
 	libxfs_purgebuf(sbp);
-	sbp = libxfs_readbuf(mbuf.m_ddev_targp, XFS_SB_DADDR,
+	sbp = libxfs_buf_read(mbuf.m_ddev_targp, XFS_SB_DADDR,
 			     1 << (sb->sb_sectlog - BBSHIFT),
 			     0, &xfs_sb_buf_ops);
 	libxfs_buf_relse(sbp);
diff --git a/db/init.c b/db/init.c
index 15b4ec0c..8bad7e53 100644
--- a/db/init.c
+++ b/db/init.c
@@ -112,7 +112,7 @@ init(
 	 */
 	memset(&xmount, 0, sizeof(struct xfs_mount));
 	libxfs_buftarg_init(&xmount, x.ddev, x.logdev, x.rtdev);
-	bp = libxfs_readbuf(xmount.m_ddev_targp, XFS_SB_DADDR,
+	bp = libxfs_buf_read(xmount.m_ddev_targp, XFS_SB_DADDR,
 			    1 << (XFS_MAX_SECTORSIZE_LOG - BBSHIFT), 0, NULL);
 
 	if (!bp || bp->b_error) {
diff --git a/db/io.c b/db/io.c
index a11b7bb1..163ccc89 100644
--- a/db/io.c
+++ b/db/io.c
@@ -545,7 +545,7 @@ set_cur(
 		bp = libxfs_readbuf_map(mp->m_ddev_targp, bbmap->b,
 					bbmap->nmaps, 0, ops);
 	} else {
-		bp = libxfs_readbuf(mp->m_ddev_targp, blknum, len, 0, ops);
+		bp = libxfs_buf_read(mp->m_ddev_targp, blknum, len, 0, ops);
 		iocur_top->bbmap = NULL;
 	}
 
diff --git a/libxfs/init.c b/libxfs/init.c
index 4efe1099..328f46ac 100644
--- a/libxfs/init.c
+++ b/libxfs/init.c
@@ -450,7 +450,7 @@ rtmount_init(
 			(unsigned long long) mp->m_sb.sb_rblocks);
 		return -1;
 	}
-	bp = libxfs_readbuf(mp->m_rtdev,
+	bp = libxfs_buf_read(mp->m_rtdev,
 			d - XFS_FSB_TO_BB(mp, 1), XFS_FSB_TO_BB(mp, 1), 0, NULL);
 	if (bp == NULL) {
 		fprintf(stderr, _("%s: realtime size check failed\n"),
@@ -730,7 +730,7 @@ libxfs_mount(
 		return mp;
 
 	/* device size checks must pass unless we're a debugger. */
-	bp = libxfs_readbuf(mp->m_dev, d - XFS_FSS_TO_BB(mp, 1),
+	bp = libxfs_buf_read(mp->m_dev, d - XFS_FSS_TO_BB(mp, 1),
 			XFS_FSS_TO_BB(mp, 1), 0, NULL);
 	if (!bp) {
 		fprintf(stderr, _("%s: data size check failed\n"), progname);
@@ -743,7 +743,7 @@ libxfs_mount(
 	    mp->m_logdev_targp->dev != mp->m_ddev_targp->dev) {
 		d = (xfs_daddr_t) XFS_FSB_TO_BB(mp, mp->m_sb.sb_logblocks);
 		if ( (XFS_BB_TO_FSB(mp, d) != mp->m_sb.sb_logblocks) ||
-		     (!(bp = libxfs_readbuf(mp->m_logdev_targp,
+		     (!(bp = libxfs_buf_read(mp->m_logdev_targp,
 					d - XFS_FSB_TO_BB(mp, 1),
 					XFS_FSB_TO_BB(mp, 1), 0, NULL)))) {
 			fprintf(stderr, _("%s: log size checks failed\n"),
@@ -770,7 +770,7 @@ libxfs_mount(
 	 * read the first one and let the user know to check the geometry.
 	 */
 	if (sbp->sb_agcount > 1000000) {
-		bp = libxfs_readbuf(mp->m_dev,
+		bp = libxfs_buf_read(mp->m_dev,
 				XFS_AG_DADDR(mp, sbp->sb_agcount - 1, 0), 1,
 				0, NULL);
 		if (bp->b_error) {
diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h
index 6d86774f..57cf5f83 100644
--- a/libxfs/libxfs_api_defs.h
+++ b/libxfs/libxfs_api_defs.h
@@ -45,6 +45,7 @@
 #define xfs_btree_init_block		libxfs_btree_init_block
 #define xfs_buf_delwri_submit		libxfs_buf_delwri_submit
 #define xfs_buf_get			libxfs_buf_get
+#define xfs_buf_read			libxfs_buf_read
 #define xfs_buf_relse			libxfs_buf_relse
 #define xfs_bunmapi			libxfs_bunmapi
 #define xfs_calc_dquots_per_chunk	libxfs_calc_dquots_per_chunk
diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h
index 50b7cef8..1b8318af 100644
--- a/libxfs/libxfs_io.h
+++ b/libxfs/libxfs_io.h
@@ -130,7 +130,7 @@ extern struct cache_operations	libxfs_bcache_operations;
 
 #ifdef XFS_BUF_TRACING
 
-#define libxfs_readbuf(dev, daddr, len, flags, ops) \
+#define libxfs_buf_read(dev, daddr, len, flags, ops) \
 	libxfs_trace_readbuf(__FUNCTION__, __FILE__, __LINE__, \
 			    (dev), (daddr), (len), (flags), (ops))
 #define libxfs_readbuf_map(dev, map, nmaps, flags, ops) \
@@ -151,9 +151,9 @@ extern struct cache_operations	libxfs_bcache_operations;
 #define libxfs_buf_relse(buf) \
 	libxfs_trace_putbuf(__FUNCTION__, __FILE__, __LINE__, (buf))
 
-extern xfs_buf_t *libxfs_trace_readbuf(const char *, const char *, int,
-			struct xfs_buftarg *, xfs_daddr_t, int, int,
-			const struct xfs_buf_ops *);
+struct xfs_buf *libxfs_trace_readbuf(const char *func, const char *file,
+			int line, struct xfs_buftarg *btp, xfs_daddr_t daddr,
+			size_t len, int flags, const struct xfs_buf_ops *ops);
 extern xfs_buf_t *libxfs_trace_readbuf_map(const char *, const char *, int,
 			struct xfs_buftarg *, struct xfs_buf_map *, int, int,
 			const struct xfs_buf_ops *);
@@ -171,8 +171,6 @@ extern void	libxfs_trace_putbuf (const char *, const char *, int,
 
 #else
 
-extern xfs_buf_t *libxfs_readbuf(struct xfs_buftarg *, xfs_daddr_t, int, int,
-			const struct xfs_buf_ops *);
 extern xfs_buf_t *libxfs_readbuf_map(struct xfs_buftarg *, struct xfs_buf_map *,
 			int, int, const struct xfs_buf_ops *);
 extern int	libxfs_writebuf(xfs_buf_t *, int);
@@ -193,11 +191,24 @@ libxfs_buf_get(
 	return libxfs_getbuf_map(target, &map, 1, 0);
 }
 
+static inline struct xfs_buf*
+libxfs_buf_read(
+	struct xfs_buftarg	*target,
+	xfs_daddr_t		blkno,
+	size_t			numblks,
+	xfs_buf_flags_t		flags,
+	const struct xfs_buf_ops *ops)
+{
+	DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
+
+	return libxfs_readbuf_map(target, &map, 1, flags, ops);
+}
+
 #endif /* XFS_BUF_TRACING */
 
 extern void	libxfs_readbuf_verify(struct xfs_buf *bp,
 			const struct xfs_buf_ops *ops);
-extern xfs_buf_t *libxfs_getsb(struct xfs_mount *);
+struct xfs_buf *libxfs_getsb(struct xfs_mount *mp);
 extern void	libxfs_bcache_purge(void);
 extern void	libxfs_bcache_free(void);
 extern void	libxfs_bcache_flush(void);
diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index 99b48db2..fbd6f322 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -44,7 +44,7 @@
  *
  * IOWs, userspace is behaving quite differently to the kernel and as a result
  * it leaks errors from reads, invalidations and writes through
- * libxfs_buf_get/libxfs_readbuf.
+ * libxfs_buf_get/libxfs_buf_read.
  *
  * The result of this is that until the userspace code outside libxfs is cleaned
  * up, functions that release buffers from userspace control (i.e
@@ -381,14 +381,11 @@ libxfs_log_header(
 
 #ifdef XFS_BUF_TRACING
 
-#undef libxfs_readbuf
 #undef libxfs_readbuf_map
 #undef libxfs_writebuf
 #undef libxfs_getbuf_map
 #undef libxfs_getbuf_flags
 
-xfs_buf_t	*libxfs_readbuf(struct xfs_buftarg *, xfs_daddr_t, int, int,
-				const struct xfs_buf_ops *);
 xfs_buf_t	*libxfs_readbuf_map(struct xfs_buftarg *, struct xfs_buf_map *,
 				int, int, const struct xfs_buf_ops *);
 int		libxfs_writebuf(xfs_buf_t *, int);
@@ -409,22 +406,21 @@ do {						\
 	}					\
 } while (0)
 
-xfs_buf_t *
-libxfs_trace_readbuf(const char *func, const char *file, int line,
-		struct xfs_buftarg *btp, xfs_daddr_t blkno, int len, int flags,
-		const struct xfs_buf_ops *ops)
+struct xfs_buf *
+libxfs_trace_readbuf(
+	const char		*func,
+	const char		*file,
+	int			line,
+	struct xfs_buftarg	*btp,
+	xfs_daddr_t		blkno,
+	size_t			len,
+	int			flags,
+	const struct xfs_buf_ops *ops)
 {
-	xfs_buf_t	*bp = libxfs_readbuf(btp, blkno, len, flags, ops);
-	__add_trace(bp, func, file, line);
-	return bp;
-}
+	struct xfs_buf		*bp;
+	DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
 
-xfs_buf_t *
-libxfs_trace_readbuf_map(const char *func, const char *file, int line,
-		struct xfs_buftarg *btp, struct xfs_buf_map *map, int nmaps, int flags,
-		const struct xfs_buf_ops *ops)
-{
-	xfs_buf_t	*bp = libxfs_readbuf_map(btp, map, nmaps, flags, ops);
+	bp = libxfs_readbuf_map(btp, &map, 1, flags, ops);
 	__add_trace(bp, func, file, line);
 	return bp;
 }
@@ -483,11 +479,12 @@ libxfs_trace_putbuf(const char *func, const char *file, int line, xfs_buf_t *bp)
 #endif
 
 
-xfs_buf_t *
-libxfs_getsb(xfs_mount_t *mp)
+struct xfs_buf *
+libxfs_getsb(
+	struct xfs_mount	*mp)
 {
-	return libxfs_readbuf(mp->m_ddev_targp, XFS_SB_DADDR,
-				XFS_FSS_TO_BB(mp, 1), 0, &xfs_sb_buf_ops);
+	return libxfs_buf_read(mp->m_ddev_targp, XFS_SB_DADDR,
+			XFS_FSS_TO_BB(mp, 1), 0, &xfs_sb_buf_ops);
 }
 
 kmem_zone_t			*xfs_buf_zone;
@@ -952,13 +949,16 @@ libxfs_readbuf_verify(struct xfs_buf *bp, const struct xfs_buf_ops *ops)
 	bp->b_flags &= ~LIBXFS_B_UNCHECKED;
 }
 
-
-xfs_buf_t *
-libxfs_readbuf(struct xfs_buftarg *btp, xfs_daddr_t blkno, int len, int flags,
-		const struct xfs_buf_ops *ops)
+static struct xfs_buf *
+libxfs_readbuf(
+	struct xfs_buftarg	*btp,
+	xfs_daddr_t		blkno,
+	size_t			len,
+	int			flags,
+	const struct xfs_buf_ops *ops)
 {
-	xfs_buf_t	*bp;
-	int		error;
+	struct xfs_buf		*bp;
+	int			error;
 
 	bp = libxfs_getbuf_flags(btp, blkno, len, 0);
 	if (!bp)
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 4e757ee1..3827b410 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -3574,7 +3574,7 @@ rewrite_secondary_superblocks(
 	struct xfs_buf		*buf;
 
 	/* rewrite the last superblock */
-	buf = libxfs_readbuf(mp->m_dev,
+	buf = libxfs_buf_read(mp->m_dev,
 			XFS_AGB_TO_DADDR(mp, mp->m_sb.sb_agcount - 1,
 				XFS_SB_DADDR),
 			XFS_FSS_TO_BB(mp, 1), 0, &xfs_sb_buf_ops);
@@ -3590,7 +3590,7 @@ rewrite_secondary_superblocks(
 	if (mp->m_sb.sb_agcount <= 2)
 		return;
 
-	buf = libxfs_readbuf(mp->m_dev,
+	buf = libxfs_buf_read(mp->m_dev,
 			XFS_AGB_TO_DADDR(mp, (mp->m_sb.sb_agcount - 1) / 2,
 				XFS_SB_DADDR),
 			XFS_FSS_TO_BB(mp, 1), 0, &xfs_sb_buf_ops);
diff --git a/repair/attr_repair.c b/repair/attr_repair.c
index ec068ba2..cc20b1a1 100644
--- a/repair/attr_repair.c
+++ b/repair/attr_repair.c
@@ -405,7 +405,7 @@ rmtval_get(xfs_mount_t *mp, xfs_ino_t ino, blkmap_t *blkmap,
 			clearit = 1;
 			break;
 		}
-		bp = libxfs_readbuf(mp->m_dev, XFS_FSB_TO_DADDR(mp, bno),
+		bp = libxfs_buf_read(mp->m_dev, XFS_FSB_TO_DADDR(mp, bno),
 				    XFS_FSB_TO_BB(mp, 1), 0,
 				    &xfs_attr3_rmt_buf_ops);
 		if (!bp) {
@@ -763,7 +763,7 @@ process_leaf_attr_level(xfs_mount_t	*mp,
 			goto error_out;
 		}
 
-		bp = libxfs_readbuf(mp->m_dev, XFS_FSB_TO_DADDR(mp, dev_bno),
+		bp = libxfs_buf_read(mp->m_dev, XFS_FSB_TO_DADDR(mp, dev_bno),
 				    XFS_FSB_TO_BB(mp, 1), 0,
 				    &xfs_attr3_leaf_buf_ops);
 		if (!bp) {
@@ -1093,7 +1093,7 @@ process_longform_attr(
 		return 1;
 	}
 
-	bp = libxfs_readbuf(mp->m_dev, XFS_FSB_TO_DADDR(mp, bno),
+	bp = libxfs_buf_read(mp->m_dev, XFS_FSB_TO_DADDR(mp, bno),
 				XFS_FSB_TO_BB(mp, 1), 0, &xfs_da3_node_buf_ops);
 	if (!bp) {
 		do_warn(
diff --git a/repair/dino_chunks.c b/repair/dino_chunks.c
index 863c4531..76e9f773 100644
--- a/repair/dino_chunks.c
+++ b/repair/dino_chunks.c
@@ -39,7 +39,7 @@ check_aginode_block(xfs_mount_t	*mp,
 	 * tree and we wouldn't be here and we stale the buffers out
 	 * so no one else will overlap them.
 	 */
-	bp = libxfs_readbuf(mp->m_dev, XFS_AGB_TO_DADDR(mp, agno, agbno),
+	bp = libxfs_buf_read(mp->m_dev, XFS_AGB_TO_DADDR(mp, agno, agbno),
 			XFS_FSB_TO_BB(mp, 1), 0, NULL);
 	if (!bp) {
 		do_warn(_("cannot read agbno (%u/%u), disk block %" PRId64 "\n"),
@@ -656,7 +656,7 @@ process_inode_chunk(
 		pftrace("about to read off %llu in AG %d",
 			XFS_AGB_TO_DADDR(mp, agno, agbno), agno);
 
-		bplist[bp_index] = libxfs_readbuf(mp->m_dev,
+		bplist[bp_index] = libxfs_buf_read(mp->m_dev,
 					XFS_AGB_TO_DADDR(mp, agno, agbno),
 					XFS_FSB_TO_BB(mp,
 						M_IGEO(mp)->blocks_per_cluster),
diff --git a/repair/dinode.c b/repair/dinode.c
index 928698cb..848eac09 100644
--- a/repair/dinode.c
+++ b/repair/dinode.c
@@ -748,7 +748,7 @@ get_agino_buf(
 		cluster_agino, cluster_daddr, cluster_blks);
 #endif
 
-	bp = libxfs_readbuf(mp->m_dev, cluster_daddr, cluster_blks,
+	bp = libxfs_buf_read(mp->m_dev, cluster_daddr, cluster_blks,
 			0, &xfs_inode_buf_ops);
 	if (!bp) {
 		do_warn(_("cannot read inode (%u/%u), disk block %" PRIu64 "\n"),
@@ -1179,7 +1179,7 @@ process_quota_inode(
 		fsbno = blkmap_get(blkmap, qbno);
 		dqid = (xfs_dqid_t)qbno * dqperchunk;
 
-		bp = libxfs_readbuf(mp->m_dev, XFS_FSB_TO_DADDR(mp, fsbno),
+		bp = libxfs_buf_read(mp->m_dev, XFS_FSB_TO_DADDR(mp, fsbno),
 				    dqchunklen, 0, &xfs_dquot_buf_ops);
 		if (!bp) {
 			do_warn(
@@ -1284,7 +1284,7 @@ _("cannot read inode %" PRIu64 ", file block %d, NULL disk block\n"),
 
 		byte_cnt = XFS_FSB_TO_B(mp, blk_cnt);
 
-		bp = libxfs_readbuf(mp->m_dev, XFS_FSB_TO_DADDR(mp, fsbno),
+		bp = libxfs_buf_read(mp->m_dev, XFS_FSB_TO_DADDR(mp, fsbno),
 				    BTOBB(byte_cnt), 0, &xfs_symlink_buf_ops);
 		if (!bp) {
 			do_warn(
diff --git a/repair/phase3.c b/repair/phase3.c
index 1c6929ac..886acd1f 100644
--- a/repair/phase3.c
+++ b/repair/phase3.c
@@ -28,7 +28,7 @@ process_agi_unlinked(
 	xfs_agnumber_t		i;
 	int			agi_dirty = 0;
 
-	bp = libxfs_readbuf(mp->m_dev,
+	bp = libxfs_buf_read(mp->m_dev,
 			XFS_AG_DADDR(mp, agno, XFS_AGI_DADDR(mp)),
 			mp->m_sb.sb_sectsize/BBSIZE, 0, &xfs_agi_buf_ops);
 	if (!bp)
diff --git a/repair/prefetch.c b/repair/prefetch.c
index f7ea9c8f..12272932 100644
--- a/repair/prefetch.c
+++ b/repair/prefetch.c
@@ -271,7 +271,7 @@ pf_scan_lbtree(
 	xfs_buf_t		*bp;
 	int			rc;
 
-	bp = libxfs_readbuf(mp->m_dev, XFS_FSB_TO_DADDR(mp, dbno),
+	bp = libxfs_buf_read(mp->m_dev, XFS_FSB_TO_DADDR(mp, dbno),
 			XFS_FSB_TO_BB(mp, 1), 0, &xfs_bmbt_buf_ops);
 	if (!bp)
 		return 0;
diff --git a/repair/rt.c b/repair/rt.c
index 3319829c..b514998d 100644
--- a/repair/rt.c
+++ b/repair/rt.c
@@ -193,7 +193,7 @@ process_rtbitmap(xfs_mount_t	*mp,
 			error = 1;
 			continue;
 		}
-		bp = libxfs_readbuf(mp->m_dev, XFS_FSB_TO_DADDR(mp, bno),
+		bp = libxfs_buf_read(mp->m_dev, XFS_FSB_TO_DADDR(mp, bno),
 				XFS_FSB_TO_BB(mp, 1), NULL);
 		if (!bp) {
 			do_warn(_("can't read block %d for rtbitmap inode\n"),
@@ -255,7 +255,7 @@ process_rtsummary(xfs_mount_t	*mp,
 			error++;
 			continue;
 		}
-		bp = libxfs_readbuf(mp->m_dev, XFS_FSB_TO_DADDR(mp, bno),
+		bp = libxfs_buf_read(mp->m_dev, XFS_FSB_TO_DADDR(mp, bno),
 				XFS_FSB_TO_BB(mp, 1), NULL);
 		if (!bp) {
 			do_warn(_("can't read block %d for rtsummary inode\n"),
diff --git a/repair/scan.c b/repair/scan.c
index c961e843..f4e4fef5 100644
--- a/repair/scan.c
+++ b/repair/scan.c
@@ -68,7 +68,7 @@ scan_sbtree(
 {
 	xfs_buf_t	*bp;
 
-	bp = libxfs_readbuf(mp->m_dev, XFS_AGB_TO_DADDR(mp, agno, root),
+	bp = libxfs_buf_read(mp->m_dev, XFS_AGB_TO_DADDR(mp, agno, root),
 			XFS_FSB_TO_BB(mp, 1), 0, ops);
 	if (!bp) {
 		do_error(_("can't read btree block %d/%d\n"), agno, root);
@@ -123,7 +123,7 @@ scan_lbtree(
 	int		dirty = 0;
 	bool		badcrc = false;
 
-	bp = libxfs_readbuf(mp->m_dev, XFS_FSB_TO_DADDR(mp, root),
+	bp = libxfs_buf_read(mp->m_dev, XFS_FSB_TO_DADDR(mp, root),
 		      XFS_FSB_TO_BB(mp, 1), 0, ops);
 	if (!bp)  {
 		do_error(_("can't read btree block %d/%d\n"),
@@ -2111,7 +2111,7 @@ scan_freelist(
 	if (be32_to_cpu(agf->agf_flcount) == 0)
 		return;
 
-	agflbuf = libxfs_readbuf(mp->m_dev,
+	agflbuf = libxfs_buf_read(mp->m_dev,
 				 XFS_AG_DADDR(mp, agno, XFS_AGFL_DADDR(mp)),
 				 XFS_FSS_TO_BB(mp, 1), 0, &xfs_agfl_buf_ops);
 	if (!agflbuf)  {
@@ -2335,7 +2335,7 @@ scan_ag(
 		return;
 	}
 
-	sbbuf = libxfs_readbuf(mp->m_dev, XFS_AG_DADDR(mp, agno, XFS_SB_DADDR),
+	sbbuf = libxfs_buf_read(mp->m_dev, XFS_AG_DADDR(mp, agno, XFS_SB_DADDR),
 				XFS_FSS_TO_BB(mp, 1), 0, &xfs_sb_buf_ops);
 	if (!sbbuf)  {
 		objname = _("root superblock");
@@ -2343,7 +2343,7 @@ scan_ag(
 	}
 	libxfs_sb_from_disk(sb, XFS_BUF_TO_SBP(sbbuf));
 
-	agfbuf = libxfs_readbuf(mp->m_dev,
+	agfbuf = libxfs_buf_read(mp->m_dev,
 			XFS_AG_DADDR(mp, agno, XFS_AGF_DADDR(mp)),
 			XFS_FSS_TO_BB(mp, 1), 0, &xfs_agf_buf_ops);
 	if (!agfbuf)  {
@@ -2352,7 +2352,7 @@ scan_ag(
 	}
 	agf = XFS_BUF_TO_AGF(agfbuf);
 
-	agibuf = libxfs_readbuf(mp->m_dev,
+	agibuf = libxfs_buf_read(mp->m_dev,
 			XFS_AG_DADDR(mp, agno, XFS_AGI_DADDR(mp)),
 			XFS_FSS_TO_BB(mp, 1), 0, &xfs_agi_buf_ops);
 	if (!agibuf)  {


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 07/25] libxfs: rename libxfs_writebufr to libxfs_bwrite
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
                   ` (5 preceding siblings ...)
  2020-02-25  0:12 ` [PATCH 06/25] libxfs: replace libxfs_readbuf with libxfs_buf_read Darrick J. Wong
@ 2020-02-25  0:12 ` Darrick J. Wong
  2020-02-25 17:44   ` Christoph Hellwig
  2020-02-25  0:12 ` [PATCH 08/25] libxfs: make libxfs_readbuf_verify return an error code Darrick J. Wong
                   ` (17 subsequent siblings)
  24 siblings, 1 reply; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:12 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Rename this function so that we have an API that matches the kernel
without a #define.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 db/io.c                  |    4 ++--
 libxfs/libxfs_api_defs.h |    1 +
 libxfs/libxfs_io.h       |    2 +-
 libxfs/libxfs_priv.h     |    1 -
 libxfs/rdwr.c            |   11 ++++++-----
 5 files changed, 10 insertions(+), 9 deletions(-)


diff --git a/db/io.c b/db/io.c
index 163ccc89..7c7a4624 100644
--- a/db/io.c
+++ b/db/io.c
@@ -426,7 +426,7 @@ write_cur_buf(void)
 {
 	int ret;
 
-	ret = -libxfs_writebufr(iocur_top->bp);
+	ret = -libxfs_bwrite(iocur_top->bp);
 	if (ret != 0)
 		dbprintf(_("write error: %s\n"), strerror(ret));
 
@@ -442,7 +442,7 @@ write_cur_bbs(void)
 {
 	int ret;
 
-	ret = -libxfs_writebufr(iocur_top->bp);
+	ret = -libxfs_bwrite(iocur_top->bp);
 	if (ret != 0)
 		dbprintf(_("write error: %s\n"), strerror(ret));
 
diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h
index 57cf5f83..df267c98 100644
--- a/libxfs/libxfs_api_defs.h
+++ b/libxfs/libxfs_api_defs.h
@@ -48,6 +48,7 @@
 #define xfs_buf_read			libxfs_buf_read
 #define xfs_buf_relse			libxfs_buf_relse
 #define xfs_bunmapi			libxfs_bunmapi
+#define xfs_bwrite			libxfs_bwrite
 #define xfs_calc_dquots_per_chunk	libxfs_calc_dquots_per_chunk
 #define xfs_da3_node_hdr_from_disk	libxfs_da3_node_hdr_from_disk
 #define xfs_da_get_buf			libxfs_da_get_buf
diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h
index 1b8318af..0370d685 100644
--- a/libxfs/libxfs_io.h
+++ b/libxfs/libxfs_io.h
@@ -220,7 +220,7 @@ extern xfs_buf_t *libxfs_getbufr(struct xfs_buftarg *, xfs_daddr_t, int);
 extern void	libxfs_putbufr(xfs_buf_t *);
 
 extern int	libxfs_writebuf_int(xfs_buf_t *, int);
-extern int	libxfs_writebufr(struct xfs_buf *);
+int		libxfs_bwrite(struct xfs_buf *bp);
 extern int	libxfs_readbufr(struct xfs_buftarg *, xfs_daddr_t, xfs_buf_t *, int, int);
 extern int	libxfs_readbufr_map(struct xfs_buftarg *, struct xfs_buf *, int);
 
diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h
index 0f26120f..5d6dd063 100644
--- a/libxfs/libxfs_priv.h
+++ b/libxfs/libxfs_priv.h
@@ -377,7 +377,6 @@ roundup_64(uint64_t x, uint32_t y)
 	(len) = __bar; /* no set-but-unused warning */	\
 	NULL;						\
 })
-#define xfs_bwrite(bp)			libxfs_writebuf((bp), 0)
 #define xfs_buf_oneshot(bp)		((void) 0)
 
 #define XBRW_READ			LIBXFS_BREAD
diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index fbd6f322..7100d4df 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -1083,9 +1083,10 @@ __write_buf(int fd, void *buf, int len, off64_t offset, int flags)
 }
 
 int
-libxfs_writebufr(xfs_buf_t *bp)
+libxfs_bwrite(
+	struct xfs_buf	*bp)
 {
-	int	fd = libxfs_device_to_fd(bp->b_target->dev);
+	int		fd = libxfs_device_to_fd(bp->b_target->dev);
 
 	/*
 	 * we never write buffers that are marked stale. This indicates they
@@ -1294,7 +1295,7 @@ libxfs_bflush(
 	struct xfs_buf		*bp = (struct xfs_buf *)node;
 
 	if (!bp->b_error && bp->b_flags & LIBXFS_B_DIRTY)
-		return libxfs_writebufr(bp);
+		return libxfs_bwrite(bp);
 	return bp->b_error;
 }
 
@@ -1302,7 +1303,7 @@ void
 libxfs_putbufr(xfs_buf_t *bp)
 {
 	if (bp->b_flags & LIBXFS_B_DIRTY)
-		libxfs_writebufr(bp);
+		libxfs_bwrite(bp);
 	libxfs_brelse((struct cache_node *)bp);
 }
 
@@ -1515,7 +1516,7 @@ xfs_buf_delwri_submit(
 
 	list_for_each_entry_safe(bp, n, buffer_list, b_list) {
 		list_del_init(&bp->b_list);
-		error2 = libxfs_writebufr(bp);
+		error2 = libxfs_bwrite(bp);
 		if (!error)
 			error = error2;
 		libxfs_buf_relse(bp);


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 08/25] libxfs: make libxfs_readbuf_verify return an error code
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
                   ` (6 preceding siblings ...)
  2020-02-25  0:12 ` [PATCH 07/25] libxfs: rename libxfs_writebufr to libxfs_bwrite Darrick J. Wong
@ 2020-02-25  0:12 ` Darrick J. Wong
  2020-02-25  0:12 ` [PATCH 09/25] libxfs: make libxfs_readbufr stash the error value in b_error Darrick J. Wong
                   ` (16 subsequent siblings)
  24 siblings, 0 replies; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:12 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs, Christoph Hellwig

From: Darrick J. Wong <darrick.wong@oracle.com>

Return the bp->b_error from libxfs_readbuf_verify instead of making
callers check it.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 libxfs/libxfs_io.h |    3 +--
 libxfs/rdwr.c      |   10 +++++++---
 repair/prefetch.c  |    5 +++--
 3 files changed, 11 insertions(+), 7 deletions(-)


diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h
index 0370d685..d96b5318 100644
--- a/libxfs/libxfs_io.h
+++ b/libxfs/libxfs_io.h
@@ -206,8 +206,7 @@ libxfs_buf_read(
 
 #endif /* XFS_BUF_TRACING */
 
-extern void	libxfs_readbuf_verify(struct xfs_buf *bp,
-			const struct xfs_buf_ops *ops);
+int libxfs_readbuf_verify(struct xfs_buf *bp, const struct xfs_buf_ops *ops);
 struct xfs_buf *libxfs_getsb(struct xfs_mount *mp);
 extern void	libxfs_bcache_purge(void);
 extern void	libxfs_bcache_free(void);
diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index 7100d4df..fb22c118 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -939,14 +939,18 @@ libxfs_readbufr(struct xfs_buftarg *btp, xfs_daddr_t blkno, xfs_buf_t *bp,
 	return error;
 }
 
-void
-libxfs_readbuf_verify(struct xfs_buf *bp, const struct xfs_buf_ops *ops)
+int
+libxfs_readbuf_verify(
+	struct xfs_buf		*bp,
+	const struct xfs_buf_ops *ops)
 {
 	if (!ops)
-		return;
+		return bp->b_error;
+
 	bp->b_ops = ops;
 	bp->b_ops->verify_read(bp);
 	bp->b_flags &= ~LIBXFS_B_UNCHECKED;
+	return bp->b_error;
 }
 
 static struct xfs_buf *
diff --git a/repair/prefetch.c b/repair/prefetch.c
index 12272932..a3858f9a 100644
--- a/repair/prefetch.c
+++ b/repair/prefetch.c
@@ -400,9 +400,10 @@ pf_read_inode_dirs(
 	int			icnt = 0;
 	int			hasdir = 0;
 	int			isadir;
+	int			error;
 
-	libxfs_readbuf_verify(bp, &xfs_inode_buf_ops);
-	if (bp->b_error)
+	error = -libxfs_readbuf_verify(bp, &xfs_inode_buf_ops);
+	if (error)
 		return;
 
 	for (icnt = 0; icnt < (bp->b_bcount >> mp->m_sb.sb_inodelog); icnt++) {


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 09/25] libxfs: make libxfs_readbufr stash the error value in b_error
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
                   ` (7 preceding siblings ...)
  2020-02-25  0:12 ` [PATCH 08/25] libxfs: make libxfs_readbuf_verify return an error code Darrick J. Wong
@ 2020-02-25  0:12 ` Darrick J. Wong
  2020-02-25  0:12 ` [PATCH 10/25] libxfs: introduce libxfs_buf_read_uncached Darrick J. Wong
                   ` (15 subsequent siblings)
  24 siblings, 0 replies; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:12 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs, Christoph Hellwig

From: Darrick J. Wong <darrick.wong@oracle.com>

Make libxfs_readbufr stash the error value in b_error, which will make
the behavior consistent between regular and multi-mapping buffers.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 libxfs/rdwr.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)


diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index fb22c118..9ee9d557 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -936,6 +936,7 @@ libxfs_readbufr(struct xfs_buftarg *btp, xfs_daddr_t blkno, xfs_buf_t *bp,
 		pthread_self(), __FUNCTION__, bytes, error,
 		(long long)LIBXFS_BBTOOFF64(blkno), (long long)blkno, bp);
 #endif
+	bp->b_error = error;
 	return error;
 }
 
@@ -995,9 +996,7 @@ libxfs_readbuf(
 	 * contents. *cough* xfs_da_node_buf_ops *cough*.
 	 */
 	error = libxfs_readbufr(btp, blkno, bp, len, flags);
-	if (error)
-		bp->b_error = error;
-	else
+	if (!error)
 		libxfs_readbuf_verify(bp, ops);
 	return bp;
 }


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 10/25] libxfs: introduce libxfs_buf_read_uncached
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
                   ` (8 preceding siblings ...)
  2020-02-25  0:12 ` [PATCH 09/25] libxfs: make libxfs_readbufr stash the error value in b_error Darrick J. Wong
@ 2020-02-25  0:12 ` Darrick J. Wong
  2020-02-25 17:44   ` Christoph Hellwig
  2020-02-25  0:12 ` [PATCH 11/25] xfs_db: use uncached buffer reads to get the superblock Darrick J. Wong
                   ` (14 subsequent siblings)
  24 siblings, 1 reply; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:12 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Introduce an uncached read function so that userspace can handle them in
the same way as the kernel.  This also eliminates the need for some of
the libxfs_purgebuf calls (and two trips into the cache code).

Refactor the get/read uncached buffer functions to hide the details of
uncached buffer-ism in rdwr.c.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 libxfs/libxfs_api_defs.h |    2 +
 libxfs/libxfs_io.h       |   22 +++------------
 libxfs/rdwr.c            |   67 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+), 17 deletions(-)


diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h
index df267c98..1149e301 100644
--- a/libxfs/libxfs_api_defs.h
+++ b/libxfs/libxfs_api_defs.h
@@ -45,7 +45,9 @@
 #define xfs_btree_init_block		libxfs_btree_init_block
 #define xfs_buf_delwri_submit		libxfs_buf_delwri_submit
 #define xfs_buf_get			libxfs_buf_get
+#define xfs_buf_get_uncached		libxfs_buf_get_uncached
 #define xfs_buf_read			libxfs_buf_read
+#define xfs_buf_read_uncached		libxfs_buf_read_uncached
 #define xfs_buf_relse			libxfs_buf_relse
 #define xfs_bunmapi			libxfs_bunmapi
 #define xfs_bwrite			libxfs_bwrite
diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h
index d96b5318..21afc99c 100644
--- a/libxfs/libxfs_io.h
+++ b/libxfs/libxfs_io.h
@@ -255,23 +255,11 @@ xfs_buf_associate_memory(struct xfs_buf *bp, void *mem, size_t len)
 	return 0;
 }
 
-/*
- * Allocate an uncached buffer that points nowhere.  The refcount will be 1,
- * and the cache node hash list will be empty to indicate that it's uncached.
- */
-static inline struct xfs_buf *
-xfs_buf_get_uncached(struct xfs_buftarg *targ, size_t bblen, int flags)
-{
-	struct xfs_buf	*bp;
-
-	bp = libxfs_getbufr(targ, XFS_BUF_DADDR_NULL, bblen);
-	if (!bp)
-		return NULL;
-
-	INIT_LIST_HEAD(&bp->b_node.cn_hash);
-	bp->b_node.cn_count = 1;
-	return bp;
-}
+struct xfs_buf *libxfs_buf_get_uncached(struct xfs_buftarg *targ, size_t bblen,
+		int flags);
+int libxfs_buf_read_uncached(struct xfs_buftarg *targ, xfs_daddr_t daddr,
+		size_t bblen, int flags, struct xfs_buf **bpp,
+		const struct xfs_buf_ops *ops);
 
 /* Push a single buffer on a delwri queue. */
 static inline void
diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index 9ee9d557..9324ee1c 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -1066,6 +1066,73 @@ libxfs_readbuf_map(struct xfs_buftarg *btp, struct xfs_buf_map *map, int nmaps,
 	return bp;
 }
 
+/* Allocate a raw uncached buffer. */
+static inline struct xfs_buf *
+libxfs_getbufr_uncached(
+	struct xfs_buftarg	*targ,
+	xfs_daddr_t		daddr,
+	size_t			bblen)
+{
+	struct xfs_buf		*bp;
+
+	bp = libxfs_getbufr(targ, daddr, bblen);
+	if (!bp)
+		return NULL;
+
+	INIT_LIST_HEAD(&bp->b_node.cn_hash);
+	bp->b_node.cn_count = 1;
+	return bp;
+}
+
+/*
+ * Allocate an uncached buffer that points nowhere.  The refcount will be 1,
+ * and the cache node hash list will be empty to indicate that it's uncached.
+ */
+struct xfs_buf *
+libxfs_buf_get_uncached(
+	struct xfs_buftarg	*targ,
+	size_t			bblen,
+	int			flags)
+{
+	return libxfs_getbufr_uncached(targ, XFS_BUF_DADDR_NULL, bblen);
+}
+
+/*
+ * Allocate and read an uncached buffer.  The refcount will be 1, and the cache
+ * node hash list will be empty to indicate that it's uncached.
+ */
+int
+libxfs_buf_read_uncached(
+	struct xfs_buftarg	*targ,
+	xfs_daddr_t		daddr,
+	size_t			bblen,
+	int			flags,
+	struct xfs_buf		**bpp,
+	const struct xfs_buf_ops *ops)
+{
+	struct xfs_buf		*bp;
+	int			error;
+
+	*bpp = NULL;
+	bp = libxfs_getbufr_uncached(targ, daddr, bblen);
+	if (!bp)
+		return -ENOMEM;
+
+	error = libxfs_readbufr(targ, daddr, bp, bblen, flags);
+	if (error)
+		goto err;
+
+	error = libxfs_readbuf_verify(bp, ops);
+	if (error)
+		goto err;
+
+	*bpp = bp;
+	return 0;
+err:
+	libxfs_buf_relse(bp);
+	return error;
+}
+
 static int
 __write_buf(int fd, void *buf, int len, off64_t offset, int flags)
 {


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 11/25] xfs_db: use uncached buffer reads to get the superblock
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
                   ` (9 preceding siblings ...)
  2020-02-25  0:12 ` [PATCH 10/25] libxfs: introduce libxfs_buf_read_uncached Darrick J. Wong
@ 2020-02-25  0:12 ` Darrick J. Wong
  2020-02-25 17:45   ` Christoph Hellwig
  2020-02-25  0:12 ` [PATCH 12/25] xfs_copy: " Darrick J. Wong
                   ` (13 subsequent siblings)
  24 siblings, 1 reply; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:12 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

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(-)


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) {


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 12/25] xfs_copy: use uncached buffer reads to get the superblock
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
                   ` (10 preceding siblings ...)
  2020-02-25  0:12 ` [PATCH 11/25] xfs_db: use uncached buffer reads to get the superblock Darrick J. Wong
@ 2020-02-25  0:12 ` Darrick J. Wong
  2020-02-25 17:45   ` Christoph Hellwig
  2020-02-25  0:12 ` [PATCH 13/25] libxfs: move log functions for convenience Darrick J. Wong
                   ` (12 subsequent siblings)
  24 siblings, 1 reply; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:12 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

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>
---
 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 9e9719a0..5cab1a5f 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);


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 13/25] libxfs: move log functions for convenience
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
                   ` (11 preceding siblings ...)
  2020-02-25  0:12 ` [PATCH 12/25] xfs_copy: " Darrick J. Wong
@ 2020-02-25  0:12 ` Darrick J. Wong
  2020-02-25 17:47   ` Christoph Hellwig
  2020-02-25  0:12 ` [PATCH 14/25] libxfs: convert libxfs_log_clear to use uncached buffers Darrick J. Wong
                   ` (11 subsequent siblings)
  24 siblings, 1 reply; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:12 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Move libxfs_log_clear and libxfs_log_header to the bottom of the file so
that we avoid having to create advance declarations of static functions
in the next patch.  No functional changes.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 libxfs/rdwr.c |  473 +++++++++++++++++++++++++++++----------------------------
 1 file changed, 237 insertions(+), 236 deletions(-)


diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index 9324ee1c..d607a565 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -138,242 +138,6 @@ static char *next(
 	return ptr + offset;
 }
 
-/*
- * Format the log. The caller provides either a buftarg which is used to access
- * the log via buffers or a direct pointer to a buffer that encapsulates the
- * entire log.
- */
-int
-libxfs_log_clear(
-	struct xfs_buftarg	*btp,
-	char			*dptr,
-	xfs_daddr_t		start,
-	uint			length,		/* basic blocks */
-	uuid_t			*fs_uuid,
-	int			version,
-	int			sunit,		/* bytes */
-	int			fmt,
-	int			cycle,
-	bool			max)
-{
-	struct xfs_buf		*bp = NULL;
-	int			len;
-	xfs_lsn_t		lsn;
-	xfs_lsn_t		tail_lsn;
-	xfs_daddr_t		blk;
-	xfs_daddr_t		end_blk;
-	char			*ptr;
-
-	if (((btp && dptr) || (!btp && !dptr)) ||
-	    (btp && !btp->dev) || !fs_uuid)
-		return -EINVAL;
-
-	/* first zero the log */
-	if (btp)
-		libxfs_device_zero(btp, start, length);
-	else
-		memset(dptr, 0, BBTOB(length));
-
-	/*
-	 * Initialize the log record length and LSNs. XLOG_INIT_CYCLE is a
-	 * special reset case where we only write a single record where the lsn
-	 * and tail_lsn match. Otherwise, the record lsn starts at block 0 of
-	 * the specified cycle and points tail_lsn at the last record of the
-	 * previous cycle.
-	 */
-	len = ((version == 2) && sunit) ? BTOBB(sunit) : 2;
-	len = max(len, 2);
-	lsn = xlog_assign_lsn(cycle, 0);
-	if (cycle == XLOG_INIT_CYCLE)
-		tail_lsn = lsn;
-	else
-		tail_lsn = xlog_assign_lsn(cycle - 1, length - len);
-
-	/* write out the first log record */
-	ptr = dptr;
-	if (btp) {
-		bp = libxfs_getbufr(btp, start, len);
-		ptr = bp->b_addr;
-	}
-	libxfs_log_header(ptr, fs_uuid, version, sunit, fmt, lsn, tail_lsn,
-			  next, bp);
-	if (bp) {
-		bp->b_flags |= LIBXFS_B_DIRTY;
-		libxfs_putbufr(bp);
-	}
-
-	/*
-	 * There's nothing else to do if this is a log reset. The kernel detects
-	 * the rest of the log is zeroed and starts at cycle 1.
-	 */
-	if (cycle == XLOG_INIT_CYCLE)
-		return 0;
-
-	/*
-	 * Bump the record size for a full log format if the caller allows it.
-	 * This is primarily for performance reasons and most callers don't care
-	 * about record size since the log is clean after we're done.
-	 */
-	if (max)
-		len = BTOBB(BDSTRAT_SIZE);
-
-	/*
-	 * Otherwise, fill everything beyond the initial record with records of
-	 * the previous cycle so the kernel head/tail detection works correctly.
-	 *
-	 * We don't particularly care about the record size or content here.
-	 * It's only important that the headers are in place such that the
-	 * kernel finds 1.) a clean log and 2.) the correct current cycle value.
-	 * Therefore, bump up the record size to the max to use larger I/Os and
-	 * improve performance.
-	 */
-	cycle--;
-	blk = start + len;
-	if (dptr)
-		dptr += BBTOB(len);
-	end_blk = start + length;
-
-	len = min(end_blk - blk, len);
-	while (blk < end_blk) {
-		lsn = xlog_assign_lsn(cycle, blk - start);
-		tail_lsn = xlog_assign_lsn(cycle, blk - start - len);
-
-		ptr = dptr;
-		if (btp) {
-			bp = libxfs_getbufr(btp, blk, len);
-			ptr = bp->b_addr;
-		}
-		/*
-		 * Note: pass the full buffer length as the sunit to initialize
-		 * the entire buffer.
-		 */
-		libxfs_log_header(ptr, fs_uuid, version, BBTOB(len), fmt, lsn,
-				  tail_lsn, next, bp);
-		if (bp) {
-			bp->b_flags |= LIBXFS_B_DIRTY;
-			libxfs_putbufr(bp);
-		}
-
-		blk += len;
-		if (dptr)
-			dptr += BBTOB(len);
-		len = min(end_blk - blk, len);
-	}
-
-	return 0;
-}
-
-int
-libxfs_log_header(
-	char			*caddr,
-	uuid_t			*fs_uuid,
-	int			version,
-	int			sunit,
-	int			fmt,
-	xfs_lsn_t		lsn,
-	xfs_lsn_t		tail_lsn,
-	libxfs_get_block_t	*nextfunc,
-	void			*private)
-{
-	xlog_rec_header_t	*head = (xlog_rec_header_t *)caddr;
-	char			*p = caddr;
-	__be32			cycle_lsn;
-	int			i, len;
-	int			hdrs = 1;
-
-	if (lsn == NULLCOMMITLSN)
-		lsn = xlog_assign_lsn(XLOG_INIT_CYCLE, 0);
-	if (tail_lsn == NULLCOMMITLSN)
-		tail_lsn = lsn;
-
-	len = ((version == 2) && sunit) ? BTOBB(sunit) : 1;
-
-	memset(p, 0, BBSIZE);
-	head->h_magicno = cpu_to_be32(XLOG_HEADER_MAGIC_NUM);
-	head->h_cycle = cpu_to_be32(CYCLE_LSN(lsn));
-	head->h_version = cpu_to_be32(version);
-	head->h_crc = cpu_to_le32(0);
-	head->h_prev_block = cpu_to_be32(-1);
-	head->h_num_logops = cpu_to_be32(1);
-	head->h_fmt = cpu_to_be32(fmt);
-	head->h_size = cpu_to_be32(max(sunit, XLOG_BIG_RECORD_BSIZE));
-
-	head->h_lsn = cpu_to_be64(lsn);
-	head->h_tail_lsn = cpu_to_be64(tail_lsn);
-
-	memcpy(&head->h_fs_uuid, fs_uuid, sizeof(uuid_t));
-
-	/*
-	 * The kernel expects to see either a log record header magic value or
-	 * the LSN cycle at the top of every log block. The first word of each
-	 * non-header block is copied to the record headers and replaced with
-	 * the cycle value (see xlog_[un]pack_data() and xlog_get_cycle() for
-	 * details).
-	 *
-	 * Even though we only ever write an unmount record (one block), we
-	 * support writing log records up to the max log buffer size of 256k to
-	 * improve log format performance. This means a record can require up
-	 * to 8 headers (1 rec. header + 7 ext. headers) for the packed cycle
-	 * data (each header supports 32k of data).
-	 */
-	cycle_lsn = CYCLE_LSN_DISK(head->h_lsn);
-	if (version == 2 && sunit > XLOG_HEADER_CYCLE_SIZE) {
-		hdrs = sunit / XLOG_HEADER_CYCLE_SIZE;
-		if (sunit % XLOG_HEADER_CYCLE_SIZE)
-			hdrs++;
-	}
-
-	/*
-	 * A fixed number of extended headers is expected based on h_size. If
-	 * required, format those now so the unmount record is located
-	 * correctly.
-	 *
-	 * Since we only write an unmount record, we only need one h_cycle_data
-	 * entry for the unmount record block. The subsequent record data
-	 * blocks are zeroed, which means we can stamp them directly with the
-	 * cycle and zero the rest of the cycle data in the extended headers.
-	 */
-	if (hdrs > 1) {
-		for (i = 1; i < hdrs; i++) {
-			p = nextfunc(p, BBSIZE, private);
-			memset(p, 0, BBSIZE);
-			/* xlog_rec_ext_header.xh_cycle */
-			*(__be32 *)p = cycle_lsn;
-		}
-	}
-
-	/*
-	 * The total length is the max of the stripe unit or 2 basic block
-	 * minimum (1 hdr blk + 1 data blk). The record length is the total
-	 * minus however many header blocks are required.
-	 */
-	head->h_len = cpu_to_be32(max(BBTOB(2), sunit) - hdrs * BBSIZE);
-
-	/*
-	 * Write out the unmount record, pack the first word into the record
-	 * header and stamp the block with the cycle.
-	 */
-	p = nextfunc(p, BBSIZE, private);
-	unmount_record(p);
-
-	head->h_cycle_data[0] = *(__be32 *)p;
-	*(__be32 *)p = cycle_lsn;
-
-	/*
-	 * Finally, zero all remaining blocks in the record and stamp each with
-	 * the cycle. We don't need to pack any of these blocks because the
-	 * cycle data in the headers has already been zeroed.
-	 */
-	len = max(len, hdrs + 1);
-	for (i = hdrs + 1; i < len; i++) {
-		p = nextfunc(p, BBSIZE, private);
-		memset(p, 0, BBSIZE);
-		*(__be32 *)p = cycle_lsn;
-	}
-
-	return BBTOB(len);
-}
-
 /*
  * Simple I/O (buffer cache) interface
  */
@@ -1594,3 +1358,240 @@ xfs_buf_delwri_submit(
 
 	return error;
 }
+
+/*
+ * Format the log. The caller provides either a buftarg which is used to access
+ * the log via buffers or a direct pointer to a buffer that encapsulates the
+ * entire log.
+ */
+int
+libxfs_log_clear(
+	struct xfs_buftarg	*btp,
+	char			*dptr,
+	xfs_daddr_t		start,
+	uint			length,		/* basic blocks */
+	uuid_t			*fs_uuid,
+	int			version,
+	int			sunit,		/* bytes */
+	int			fmt,
+	int			cycle,
+	bool			max)
+{
+	struct xfs_buf		*bp = NULL;
+	int			len;
+	xfs_lsn_t		lsn;
+	xfs_lsn_t		tail_lsn;
+	xfs_daddr_t		blk;
+	xfs_daddr_t		end_blk;
+	char			*ptr;
+
+	if (((btp && dptr) || (!btp && !dptr)) ||
+	    (btp && !btp->dev) || !fs_uuid)
+		return -EINVAL;
+
+	/* first zero the log */
+	if (btp)
+		libxfs_device_zero(btp, start, length);
+	else
+		memset(dptr, 0, BBTOB(length));
+
+	/*
+	 * Initialize the log record length and LSNs. XLOG_INIT_CYCLE is a
+	 * special reset case where we only write a single record where the lsn
+	 * and tail_lsn match. Otherwise, the record lsn starts at block 0 of
+	 * the specified cycle and points tail_lsn at the last record of the
+	 * previous cycle.
+	 */
+	len = ((version == 2) && sunit) ? BTOBB(sunit) : 2;
+	len = max(len, 2);
+	lsn = xlog_assign_lsn(cycle, 0);
+	if (cycle == XLOG_INIT_CYCLE)
+		tail_lsn = lsn;
+	else
+		tail_lsn = xlog_assign_lsn(cycle - 1, length - len);
+
+	/* write out the first log record */
+	ptr = dptr;
+	if (btp) {
+		bp = libxfs_getbufr(btp, start, len);
+		ptr = bp->b_addr;
+	}
+	libxfs_log_header(ptr, fs_uuid, version, sunit, fmt, lsn, tail_lsn,
+			  next, bp);
+	if (bp) {
+		bp->b_flags |= LIBXFS_B_DIRTY;
+		libxfs_putbufr(bp);
+	}
+
+	/*
+	 * There's nothing else to do if this is a log reset. The kernel detects
+	 * the rest of the log is zeroed and starts at cycle 1.
+	 */
+	if (cycle == XLOG_INIT_CYCLE)
+		return 0;
+
+	/*
+	 * Bump the record size for a full log format if the caller allows it.
+	 * This is primarily for performance reasons and most callers don't care
+	 * about record size since the log is clean after we're done.
+	 */
+	if (max)
+		len = BTOBB(BDSTRAT_SIZE);
+
+	/*
+	 * Otherwise, fill everything beyond the initial record with records of
+	 * the previous cycle so the kernel head/tail detection works correctly.
+	 *
+	 * We don't particularly care about the record size or content here.
+	 * It's only important that the headers are in place such that the
+	 * kernel finds 1.) a clean log and 2.) the correct current cycle value.
+	 * Therefore, bump up the record size to the max to use larger I/Os and
+	 * improve performance.
+	 */
+	cycle--;
+	blk = start + len;
+	if (dptr)
+		dptr += BBTOB(len);
+	end_blk = start + length;
+
+	len = min(end_blk - blk, len);
+	while (blk < end_blk) {
+		lsn = xlog_assign_lsn(cycle, blk - start);
+		tail_lsn = xlog_assign_lsn(cycle, blk - start - len);
+
+		ptr = dptr;
+		if (btp) {
+			bp = libxfs_getbufr(btp, blk, len);
+			ptr = bp->b_addr;
+		}
+		/*
+		 * Note: pass the full buffer length as the sunit to initialize
+		 * the entire buffer.
+		 */
+		libxfs_log_header(ptr, fs_uuid, version, BBTOB(len), fmt, lsn,
+				  tail_lsn, next, bp);
+		if (bp) {
+			bp->b_flags |= LIBXFS_B_DIRTY;
+			libxfs_putbufr(bp);
+		}
+
+		blk += len;
+		if (dptr)
+			dptr += BBTOB(len);
+		len = min(end_blk - blk, len);
+	}
+
+	return 0;
+}
+
+int
+libxfs_log_header(
+	char			*caddr,
+	uuid_t			*fs_uuid,
+	int			version,
+	int			sunit,
+	int			fmt,
+	xfs_lsn_t		lsn,
+	xfs_lsn_t		tail_lsn,
+	libxfs_get_block_t	*nextfunc,
+	void			*private)
+{
+	xlog_rec_header_t	*head = (xlog_rec_header_t *)caddr;
+	char			*p = caddr;
+	__be32			cycle_lsn;
+	int			i, len;
+	int			hdrs = 1;
+
+	if (lsn == NULLCOMMITLSN)
+		lsn = xlog_assign_lsn(XLOG_INIT_CYCLE, 0);
+	if (tail_lsn == NULLCOMMITLSN)
+		tail_lsn = lsn;
+
+	len = ((version == 2) && sunit) ? BTOBB(sunit) : 1;
+
+	memset(p, 0, BBSIZE);
+	head->h_magicno = cpu_to_be32(XLOG_HEADER_MAGIC_NUM);
+	head->h_cycle = cpu_to_be32(CYCLE_LSN(lsn));
+	head->h_version = cpu_to_be32(version);
+	head->h_crc = cpu_to_le32(0);
+	head->h_prev_block = cpu_to_be32(-1);
+	head->h_num_logops = cpu_to_be32(1);
+	head->h_fmt = cpu_to_be32(fmt);
+	head->h_size = cpu_to_be32(max(sunit, XLOG_BIG_RECORD_BSIZE));
+
+	head->h_lsn = cpu_to_be64(lsn);
+	head->h_tail_lsn = cpu_to_be64(tail_lsn);
+
+	memcpy(&head->h_fs_uuid, fs_uuid, sizeof(uuid_t));
+
+	/*
+	 * The kernel expects to see either a log record header magic value or
+	 * the LSN cycle at the top of every log block. The first word of each
+	 * non-header block is copied to the record headers and replaced with
+	 * the cycle value (see xlog_[un]pack_data() and xlog_get_cycle() for
+	 * details).
+	 *
+	 * Even though we only ever write an unmount record (one block), we
+	 * support writing log records up to the max log buffer size of 256k to
+	 * improve log format performance. This means a record can require up
+	 * to 8 headers (1 rec. header + 7 ext. headers) for the packed cycle
+	 * data (each header supports 32k of data).
+	 */
+	cycle_lsn = CYCLE_LSN_DISK(head->h_lsn);
+	if (version == 2 && sunit > XLOG_HEADER_CYCLE_SIZE) {
+		hdrs = sunit / XLOG_HEADER_CYCLE_SIZE;
+		if (sunit % XLOG_HEADER_CYCLE_SIZE)
+			hdrs++;
+	}
+
+	/*
+	 * A fixed number of extended headers is expected based on h_size. If
+	 * required, format those now so the unmount record is located
+	 * correctly.
+	 *
+	 * Since we only write an unmount record, we only need one h_cycle_data
+	 * entry for the unmount record block. The subsequent record data
+	 * blocks are zeroed, which means we can stamp them directly with the
+	 * cycle and zero the rest of the cycle data in the extended headers.
+	 */
+	if (hdrs > 1) {
+		for (i = 1; i < hdrs; i++) {
+			p = nextfunc(p, BBSIZE, private);
+			memset(p, 0, BBSIZE);
+			/* xlog_rec_ext_header.xh_cycle */
+			*(__be32 *)p = cycle_lsn;
+		}
+	}
+
+	/*
+	 * The total length is the max of the stripe unit or 2 basic block
+	 * minimum (1 hdr blk + 1 data blk). The record length is the total
+	 * minus however many header blocks are required.
+	 */
+	head->h_len = cpu_to_be32(max(BBTOB(2), sunit) - hdrs * BBSIZE);
+
+	/*
+	 * Write out the unmount record, pack the first word into the record
+	 * header and stamp the block with the cycle.
+	 */
+	p = nextfunc(p, BBSIZE, private);
+	unmount_record(p);
+
+	head->h_cycle_data[0] = *(__be32 *)p;
+	*(__be32 *)p = cycle_lsn;
+
+	/*
+	 * Finally, zero all remaining blocks in the record and stamp each with
+	 * the cycle. We don't need to pack any of these blocks because the
+	 * cycle data in the headers has already been zeroed.
+	 */
+	len = max(len, hdrs + 1);
+	for (i = hdrs + 1; i < len; i++) {
+		p = nextfunc(p, BBSIZE, private);
+		memset(p, 0, BBSIZE);
+		*(__be32 *)p = cycle_lsn;
+	}
+
+	return BBTOB(len);
+}
+


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 14/25] libxfs: convert libxfs_log_clear to use uncached buffers
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
                   ` (12 preceding siblings ...)
  2020-02-25  0:12 ` [PATCH 13/25] libxfs: move log functions for convenience Darrick J. Wong
@ 2020-02-25  0:12 ` Darrick J. Wong
  2020-02-25 17:49   ` Christoph Hellwig
  2020-02-25  0:13 ` [PATCH 15/25] libxlog: use uncached buffers instead of open-coding them Darrick J. Wong
                   ` (10 subsequent siblings)
  24 siblings, 1 reply; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:12 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Convert the log clearing function to use uncached buffers like
everything else, instead of using the raw buffer get/put functions.
This will eventually enable us to hide them more effectively.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 libxfs/rdwr.c |   16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)


diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index d607a565..739f4aed 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -1413,15 +1413,13 @@ libxfs_log_clear(
 	/* write out the first log record */
 	ptr = dptr;
 	if (btp) {
-		bp = libxfs_getbufr(btp, start, len);
+		bp = libxfs_getbufr_uncached(btp, start, len);
 		ptr = bp->b_addr;
 	}
 	libxfs_log_header(ptr, fs_uuid, version, sunit, fmt, lsn, tail_lsn,
 			  next, bp);
-	if (bp) {
-		bp->b_flags |= LIBXFS_B_DIRTY;
-		libxfs_putbufr(bp);
-	}
+	if (bp)
+		libxfs_writebuf(bp, 0);
 
 	/*
 	 * There's nothing else to do if this is a log reset. The kernel detects
@@ -1461,7 +1459,7 @@ libxfs_log_clear(
 
 		ptr = dptr;
 		if (btp) {
-			bp = libxfs_getbufr(btp, blk, len);
+			bp = libxfs_getbufr_uncached(btp, blk, len);
 			ptr = bp->b_addr;
 		}
 		/*
@@ -1470,10 +1468,8 @@ libxfs_log_clear(
 		 */
 		libxfs_log_header(ptr, fs_uuid, version, BBTOB(len), fmt, lsn,
 				  tail_lsn, next, bp);
-		if (bp) {
-			bp->b_flags |= LIBXFS_B_DIRTY;
-			libxfs_putbufr(bp);
-		}
+		if (bp)
+			libxfs_writebuf(bp, 0);
 
 		blk += len;
 		if (dptr)


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 15/25] libxlog: use uncached buffers instead of open-coding them
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
                   ` (13 preceding siblings ...)
  2020-02-25  0:12 ` [PATCH 14/25] libxfs: convert libxfs_log_clear to use uncached buffers Darrick J. Wong
@ 2020-02-25  0:13 ` Darrick J. Wong
  2020-02-25 17:50   ` Christoph Hellwig
  2020-02-25  0:13 ` [PATCH 16/25] libxfs: use uncached buffers for initial mkfs writes Darrick J. Wong
                   ` (9 subsequent siblings)
  24 siblings, 1 reply; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:13 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Use the new uncached buffer functions to manage buffers instead of
open-coding the logic.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 include/libxlog.h         |    1 -
 libxlog/xfs_log_recover.c |   35 ++++++++++++++---------------------
 logprint/log_print_all.c  |    2 +-
 3 files changed, 15 insertions(+), 23 deletions(-)


diff --git a/include/libxlog.h b/include/libxlog.h
index 4b785507..5e94fa1e 100644
--- a/include/libxlog.h
+++ b/include/libxlog.h
@@ -75,7 +75,6 @@ extern libxfs_init_t	x;
 extern int xlog_is_dirty(struct xfs_mount *, struct xlog *, libxfs_init_t *,
 			 int);
 extern struct xfs_buf *xlog_get_bp(struct xlog *, int);
-extern void	xlog_put_bp(struct xfs_buf *);
 extern int	xlog_bread(struct xlog *log, xfs_daddr_t blk_no, int nbblks,
 				xfs_buf_t *bp, char **offset);
 extern int	xlog_bread_noalign(struct xlog *log, xfs_daddr_t blk_no,
diff --git a/libxlog/xfs_log_recover.c b/libxlog/xfs_log_recover.c
index 9324a213..e7e57bd2 100644
--- a/libxlog/xfs_log_recover.c
+++ b/libxlog/xfs_log_recover.c
@@ -67,14 +67,7 @@ xlog_get_bp(
 		nbblks += log->l_sectBBsize;
 	nbblks = round_up(nbblks, log->l_sectBBsize);
 
-	return libxfs_getbufr(log->l_dev, (xfs_daddr_t)-1, nbblks);
-}
-
-void
-xlog_put_bp(
-	xfs_buf_t	*bp)
-{
-	libxfs_putbufr(bp);
+	return libxfs_buf_get_uncached(log->l_dev, nbblks, 0);
 }
 
 /*
@@ -274,7 +267,7 @@ xlog_find_verify_cycle(
 	*new_blk = -1;
 
 out:
-	xlog_put_bp(bp);
+	libxfs_buf_relse(bp);
 	return error;
 }
 
@@ -383,7 +376,7 @@ xlog_find_verify_log_record(
 		*last_blk = i;
 
 out:
-	xlog_put_bp(bp);
+	libxfs_buf_relse(bp);
 	return error;
 }
 
@@ -634,7 +627,7 @@ xlog_find_head(
 			goto bp_err;
 	}
 
-	xlog_put_bp(bp);
+	libxfs_buf_relse(bp);
 	if (head_blk == log_bbnum)
 		*return_head_blk = 0;
 	else
@@ -648,7 +641,7 @@ xlog_find_head(
 	return 0;
 
  bp_err:
-	xlog_put_bp(bp);
+	libxfs_buf_relse(bp);
 
 	if (error)
 		xfs_warn(log->l_mp, "failed to find log head");
@@ -745,7 +738,7 @@ xlog_find_tail(
 	}
 	if (!found) {
 		xfs_warn(log->l_mp, "%s: couldn't find sync record", __func__);
-		xlog_put_bp(bp);
+		libxfs_buf_relse(bp);
 		ASSERT(0);
 		return XFS_ERROR(EIO);
 	}
@@ -858,7 +851,7 @@ xlog_find_tail(
 		error = xlog_clear_stale_blocks(log, tail_lsn);
 
 done:
-	xlog_put_bp(bp);
+	libxfs_buf_relse(bp);
 
 	if (error)
 		xfs_warn(log->l_mp, "failed to locate log tail");
@@ -906,7 +899,7 @@ xlog_find_zeroed(
 	first_cycle = xlog_get_cycle(offset);
 	if (first_cycle == 0) {		/* completely zeroed log */
 		*blk_no = 0;
-		xlog_put_bp(bp);
+		libxfs_buf_relse(bp);
 		return -1;
 	}
 
@@ -917,7 +910,7 @@ xlog_find_zeroed(
 
 	last_cycle = xlog_get_cycle(offset);
 	if (last_cycle != 0) {		/* log completely written to */
-		xlog_put_bp(bp);
+		libxfs_buf_relse(bp);
 		return 0;
 	} else if (first_cycle != 1) {
 		/*
@@ -974,7 +967,7 @@ xlog_find_zeroed(
 
 	*blk_no = last_blk;
 bp_err:
-	xlog_put_bp(bp);
+	libxfs_buf_relse(bp);
 	if (error)
 		return error;
 	return -1;
@@ -1457,7 +1450,7 @@ xlog_do_recovery_pass(
 			hblks = h_size / XLOG_HEADER_CYCLE_SIZE;
 			if (h_size % XLOG_HEADER_CYCLE_SIZE)
 				hblks++;
-			xlog_put_bp(hbp);
+			libxfs_buf_relse(hbp);
 			hbp = xlog_get_bp(log, hblks);
 		} else {
 			hblks = 1;
@@ -1473,7 +1466,7 @@ xlog_do_recovery_pass(
 		return ENOMEM;
 	dbp = xlog_get_bp(log, BTOBB(h_size));
 	if (!dbp) {
-		xlog_put_bp(hbp);
+		libxfs_buf_relse(hbp);
 		return ENOMEM;
 	}
 
@@ -1657,8 +1650,8 @@ xlog_do_recovery_pass(
 	}
 
  bread_err2:
-	xlog_put_bp(dbp);
+	libxfs_buf_relse(dbp);
  bread_err1:
-	xlog_put_bp(hbp);
+	libxfs_buf_relse(hbp);
 	return error;
 }
diff --git a/logprint/log_print_all.c b/logprint/log_print_all.c
index d3d4c07b..32d13719 100644
--- a/logprint/log_print_all.c
+++ b/logprint/log_print_all.c
@@ -39,7 +39,7 @@ xlog_print_find_oldest(
 		error = xlog_find_cycle_start(log, bp, first_blk,
 					      last_blk, last_half_cycle);
 
-	xlog_put_bp(bp);
+	libxfs_buf_relse(bp);
 	return error;
 }
 


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 16/25] libxfs: use uncached buffers for initial mkfs writes
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
                   ` (14 preceding siblings ...)
  2020-02-25  0:13 ` [PATCH 15/25] libxlog: use uncached buffers instead of open-coding them Darrick J. Wong
@ 2020-02-25  0:13 ` Darrick J. Wong
  2020-02-25  0:13 ` [PATCH 17/25] libxfs: straighten out libxfs_writebuf naming confusion Darrick J. Wong
                   ` (8 subsequent siblings)
  24 siblings, 0 replies; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:13 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs, Christoph Hellwig

From: Darrick J. Wong <darrick.wong@oracle.com>

Teach mkfs to use uncached buffers to write the start and end of the
data device, the initial superblock, and the end of the realtime device
instead of open-coding uncached buffers.  This means we can get rid of
libxfs_purgebuf since we handle the state from the start now.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 libxfs/libxfs_io.h |    1 -
 libxfs/rdwr.c      |   12 ------------
 mkfs/xfs_mkfs.c    |   33 ++++++++++++++++++++++-----------
 3 files changed, 22 insertions(+), 24 deletions(-)


diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h
index 21afc99c..1d30039a 100644
--- a/libxfs/libxfs_io.h
+++ b/libxfs/libxfs_io.h
@@ -211,7 +211,6 @@ struct xfs_buf *libxfs_getsb(struct xfs_mount *mp);
 extern void	libxfs_bcache_purge(void);
 extern void	libxfs_bcache_free(void);
 extern void	libxfs_bcache_flush(void);
-extern void	libxfs_purgebuf(xfs_buf_t *);
 extern int	libxfs_bcache_overflowed(void);
 
 /* Buffer (Raw) Interfaces */
diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index 739f4aed..e19b4c51 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -633,18 +633,6 @@ libxfs_buf_relse(
 		libxfs_putbufr(bp);
 }
 
-void
-libxfs_purgebuf(xfs_buf_t *bp)
-{
-	struct xfs_bufkey key = {NULL};
-
-	key.buftarg = bp->b_target;
-	key.blkno = bp->b_bn;
-	key.bblen = bp->b_length;
-
-	cache_node_purge(libxfs_bcache, &key, (struct cache_node *)bp);
-}
-
 static struct cache_node *
 libxfs_balloc(cache_key_t key)
 {
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 3827b410..b80bbd75 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -3396,6 +3396,21 @@ finish_superblock_setup(
 
 }
 
+/* Prepare an uncached buffer, ready to write something out. */
+static inline struct xfs_buf *
+alloc_write_buf(
+	struct xfs_buftarg	*btp,
+	xfs_daddr_t		daddr,
+	int			bblen)
+{
+	struct xfs_buf		*bp;
+
+	bp = libxfs_buf_get_uncached(btp, bblen, 0);
+	bp->b_bn = daddr;
+	bp->b_maps[0].bm_bn = daddr;
+	return bp;
+}
+
 /*
  * Sanitise the data and log devices and prepare them so libxfs can mount the
  * device successfully. Also check we can access the rt device if configured.
@@ -3444,11 +3459,10 @@ prepare_devices(
 	 * the end of the device.  (MD sb is ~64k from the end, take out a wider
 	 * swath to be sure)
 	 */
-	buf = libxfs_buf_get(mp->m_ddev_targp, (xi->dsize - whack_blks),
-			    whack_blks);
+	buf = alloc_write_buf(mp->m_ddev_targp, (xi->dsize - whack_blks),
+			whack_blks);
 	memset(buf->b_addr, 0, WHACK_SIZE);
 	libxfs_writebuf(buf, 0);
-	libxfs_purgebuf(buf);
 
 	/*
 	 * Now zero out the beginning of the device, to obliterate any old
@@ -3456,19 +3470,17 @@ prepare_devices(
 	 * swap (somewhere around the page size), jfs (32k),
 	 * ext[2,3] and reiserfs (64k) - and hopefully all else.
 	 */
-	buf = libxfs_buf_get(mp->m_ddev_targp, 0, whack_blks);
+	buf = alloc_write_buf(mp->m_ddev_targp, 0, whack_blks);
 	memset(buf->b_addr, 0, WHACK_SIZE);
 	libxfs_writebuf(buf, 0);
-	libxfs_purgebuf(buf);
 
 	/* OK, now write the superblock... */
-	buf = libxfs_buf_get(mp->m_ddev_targp, XFS_SB_DADDR,
+	buf = alloc_write_buf(mp->m_ddev_targp, XFS_SB_DADDR,
 			XFS_FSS_TO_BB(mp, 1));
 	buf->b_ops = &xfs_sb_buf_ops;
 	memset(buf->b_addr, 0, cfg->sectorsize);
 	libxfs_sb_to_disk(buf->b_addr, sbp);
 	libxfs_writebuf(buf, 0);
-	libxfs_purgebuf(buf);
 
 	/* ...and zero the log.... */
 	lsunit = sbp->sb_logsunit;
@@ -3483,12 +3495,11 @@ prepare_devices(
 
 	/* finally, check we can write the last block in the realtime area */
 	if (mp->m_rtdev_targp->dev && cfg->rtblocks > 0) {
-		buf = libxfs_buf_get(mp->m_rtdev_targp,
-				    XFS_FSB_TO_BB(mp, cfg->rtblocks - 1LL),
-				    BTOBB(cfg->blocksize));
+		buf = alloc_write_buf(mp->m_rtdev_targp,
+				XFS_FSB_TO_BB(mp, cfg->rtblocks - 1LL),
+				BTOBB(cfg->blocksize));
 		memset(buf->b_addr, 0, cfg->blocksize);
 		libxfs_writebuf(buf, 0);
-		libxfs_purgebuf(buf);
 	}
 
 }


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 17/25] libxfs: straighten out libxfs_writebuf naming confusion
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
                   ` (15 preceding siblings ...)
  2020-02-25  0:13 ` [PATCH 16/25] libxfs: use uncached buffers for initial mkfs writes Darrick J. Wong
@ 2020-02-25  0:13 ` Darrick J. Wong
  2020-02-25 17:50   ` Christoph Hellwig
  2020-02-25  0:13 ` [PATCH 18/25] libxfs: remove unused flags parameter to libxfs_buf_mark_dirty Darrick J. Wong
                   ` (7 subsequent siblings)
  24 siblings, 1 reply; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:13 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

libxfs_writebuf is not a well named function -- it marks the buffer
dirty and then releases the caller's reference.  The actual write comes
when the cache is flushed, either because someone explicitly told the
cache to flush or because we started buffer reclaim.

Make the buffer release explicit in the callers and rename the function
to say what it actually does -- it marks the buffer dirty outside of
transaction context.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 libxfs/libxfs_io.h   |   10 +++++-----
 libxfs/rdwr.c        |   35 ++++++++++++++++++++++++-----------
 libxfs/trans.c       |    3 ++-
 mkfs/proto.c         |    6 ++++--
 mkfs/xfs_mkfs.c      |   21 ++++++++++++++-------
 repair/attr_repair.c |   17 +++++++++--------
 repair/da_util.c     |   12 ++++++++----
 repair/dino_chunks.c |    7 +++++--
 repair/dinode.c      |   12 ++++++++----
 repair/dir2.c        |    9 ++++++---
 repair/phase3.c      |    6 ++++--
 repair/phase5.c      |   42 ++++++++++++++++++++++++++++--------------
 repair/rmap.c        |    3 ++-
 repair/scan.c        |   21 ++++++++++++++-------
 repair/xfs_repair.c  |    3 ++-
 15 files changed, 135 insertions(+), 72 deletions(-)


diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h
index 1d30039a..51b1dc15 100644
--- a/libxfs/libxfs_io.h
+++ b/libxfs/libxfs_io.h
@@ -136,8 +136,8 @@ extern struct cache_operations	libxfs_bcache_operations;
 #define libxfs_readbuf_map(dev, map, nmaps, flags, ops) \
 	libxfs_trace_readbuf_map(__FUNCTION__, __FILE__, __LINE__, \
 			    (dev), (map), (nmaps), (flags), (ops))
-#define libxfs_writebuf(buf, flags) \
-	libxfs_trace_writebuf(__FUNCTION__, __FILE__, __LINE__, \
+#define libxfs_buf_mark_dirty(buf, flags) \
+	libxfs_trace_dirtybuf(__FUNCTION__, __FILE__, __LINE__, \
 			      (buf), (flags))
 #define libxfs_buf_get(dev, daddr, len) \
 	libxfs_trace_getbuf(__FUNCTION__, __FILE__, __LINE__, \
@@ -157,8 +157,8 @@ struct xfs_buf *libxfs_trace_readbuf(const char *func, const char *file,
 extern xfs_buf_t *libxfs_trace_readbuf_map(const char *, const char *, int,
 			struct xfs_buftarg *, struct xfs_buf_map *, int, int,
 			const struct xfs_buf_ops *);
-extern int	libxfs_trace_writebuf(const char *, const char *, int,
-			xfs_buf_t *, int);
+void libxfs_trace_dirtybuf(const char *func, const char *file, int line,
+			struct xfs_buf *bp, int flags);
 struct xfs_buf *libxfs_trace_getbuf(const char *func, const char *file,
 			int line, struct xfs_buftarg *btp, xfs_daddr_t daddr,
 			size_t len);
@@ -173,7 +173,7 @@ extern void	libxfs_trace_putbuf (const char *, const char *, int,
 
 extern xfs_buf_t *libxfs_readbuf_map(struct xfs_buftarg *, struct xfs_buf_map *,
 			int, int, const struct xfs_buf_ops *);
-extern int	libxfs_writebuf(xfs_buf_t *, int);
+void libxfs_buf_mark_dirty(struct xfs_buf *bp, int flags);
 extern xfs_buf_t *libxfs_getbuf_map(struct xfs_buftarg *,
 			struct xfs_buf_map *, int, int);
 extern xfs_buf_t *libxfs_getbuf_flags(struct xfs_buftarg *, xfs_daddr_t,
diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index e19b4c51..16701bba 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -189,11 +189,16 @@ libxfs_trace_readbuf(
 	return bp;
 }
 
-int
-libxfs_trace_writebuf(const char *func, const char *file, int line, xfs_buf_t *bp, int flags)
+void
+libxfs_trace_dirtybuf(
+	const char		*func,
+	const char		*file,
+	int			line,
+	struct xfs_buf		*bp,
+	int			flags)
 {
 	__add_trace(bp, func, file, line);
-	return libxfs_writebuf(bp, flags);
+	libxfs_buf_mark_dirty(bp, flags);
 }
 
 struct xfs_buf *
@@ -988,8 +993,14 @@ libxfs_writebuf_int(xfs_buf_t *bp, int flags)
 	return 0;
 }
 
-int
-libxfs_writebuf(xfs_buf_t *bp, int flags)
+/*
+ * Mark a buffer dirty.  The dirty data will be written out when the cache
+ * is flushed (or at release time if the buffer is uncached).
+ */
+void
+libxfs_buf_mark_dirty(
+	struct xfs_buf	*bp,
+	int		flags)
 {
 #ifdef IO_DEBUG
 	printf("%lx: %s: dirty blkno=%llu(%llu)\n",
@@ -1004,8 +1015,6 @@ libxfs_writebuf(xfs_buf_t *bp, int flags)
 	bp->b_error = 0;
 	bp->b_flags &= ~LIBXFS_B_STALE;
 	bp->b_flags |= (LIBXFS_B_DIRTY | flags);
-	libxfs_buf_relse(bp);
-	return 0;
 }
 
 void
@@ -1406,8 +1415,10 @@ libxfs_log_clear(
 	}
 	libxfs_log_header(ptr, fs_uuid, version, sunit, fmt, lsn, tail_lsn,
 			  next, bp);
-	if (bp)
-		libxfs_writebuf(bp, 0);
+	if (bp) {
+		libxfs_buf_mark_dirty(bp, 0);
+		libxfs_buf_relse(bp);
+	}
 
 	/*
 	 * There's nothing else to do if this is a log reset. The kernel detects
@@ -1456,8 +1467,10 @@ libxfs_log_clear(
 		 */
 		libxfs_log_header(ptr, fs_uuid, version, BBTOB(len), fmt, lsn,
 				  tail_lsn, next, bp);
-		if (bp)
-			libxfs_writebuf(bp, 0);
+		if (bp) {
+			libxfs_buf_mark_dirty(bp, 0);
+			libxfs_buf_relse(bp);
+		}
 
 		blk += len;
 		if (dptr)
diff --git a/libxfs/trans.c b/libxfs/trans.c
index 59cb897f..91001a93 100644
--- a/libxfs/trans.c
+++ b/libxfs/trans.c
@@ -843,7 +843,8 @@ inode_item_done(
 		goto free;
 	}
 
-	libxfs_writebuf(bp, 0);
+	libxfs_buf_mark_dirty(bp, 0);
+	libxfs_buf_relse(bp);
 free:
 	xfs_inode_item_put(iip);
 }
diff --git a/mkfs/proto.c b/mkfs/proto.c
index c3813ea2..7de76ca4 100644
--- a/mkfs/proto.c
+++ b/mkfs/proto.c
@@ -261,8 +261,10 @@ newfile(
 			memset((char *)bp->b_addr + len, 0, bp->b_bcount - len);
 		if (logit)
 			libxfs_trans_log_buf(tp, bp, 0, bp->b_bcount - 1);
-		else
-			libxfs_writebuf(bp, 0);
+		else {
+			libxfs_buf_mark_dirty(bp, 0);
+			libxfs_buf_relse(bp);
+		}
 	}
 	ip->i_d.di_size = len;
 	return flags;
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index b80bbd75..75a90f3a 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -3462,7 +3462,8 @@ prepare_devices(
 	buf = alloc_write_buf(mp->m_ddev_targp, (xi->dsize - whack_blks),
 			whack_blks);
 	memset(buf->b_addr, 0, WHACK_SIZE);
-	libxfs_writebuf(buf, 0);
+	libxfs_buf_mark_dirty(buf, 0);
+	libxfs_buf_relse(buf);
 
 	/*
 	 * Now zero out the beginning of the device, to obliterate any old
@@ -3472,7 +3473,8 @@ prepare_devices(
 	 */
 	buf = alloc_write_buf(mp->m_ddev_targp, 0, whack_blks);
 	memset(buf->b_addr, 0, WHACK_SIZE);
-	libxfs_writebuf(buf, 0);
+	libxfs_buf_mark_dirty(buf, 0);
+	libxfs_buf_relse(buf);
 
 	/* OK, now write the superblock... */
 	buf = alloc_write_buf(mp->m_ddev_targp, XFS_SB_DADDR,
@@ -3480,7 +3482,8 @@ prepare_devices(
 	buf->b_ops = &xfs_sb_buf_ops;
 	memset(buf->b_addr, 0, cfg->sectorsize);
 	libxfs_sb_to_disk(buf->b_addr, sbp);
-	libxfs_writebuf(buf, 0);
+	libxfs_buf_mark_dirty(buf, 0);
+	libxfs_buf_relse(buf);
 
 	/* ...and zero the log.... */
 	lsunit = sbp->sb_logsunit;
@@ -3499,7 +3502,8 @@ prepare_devices(
 				XFS_FSB_TO_BB(mp, cfg->rtblocks - 1LL),
 				BTOBB(cfg->blocksize));
 		memset(buf->b_addr, 0, cfg->blocksize);
-		libxfs_writebuf(buf, 0);
+		libxfs_buf_mark_dirty(buf, 0);
+		libxfs_buf_relse(buf);
 	}
 
 }
@@ -3595,7 +3599,8 @@ rewrite_secondary_superblocks(
 		exit(1);
 	}
 	XFS_BUF_TO_SBP(buf)->sb_rootino = cpu_to_be64(mp->m_sb.sb_rootino);
-	libxfs_writebuf(buf, 0);
+	libxfs_buf_mark_dirty(buf, 0);
+	libxfs_buf_relse(buf);
 
 	/* and one in the middle for luck if there's enough AGs for that */
 	if (mp->m_sb.sb_agcount <= 2)
@@ -3611,7 +3616,8 @@ rewrite_secondary_superblocks(
 		exit(1);
 	}
 	XFS_BUF_TO_SBP(buf)->sb_rootino = cpu_to_be64(mp->m_sb.sb_rootino);
-	libxfs_writebuf(buf, 0);
+	libxfs_buf_mark_dirty(buf, 0);
+	libxfs_buf_relse(buf);
 }
 
 static void
@@ -3958,7 +3964,8 @@ main(
 	if (!buf || buf->b_error)
 		exit(1);
 	(XFS_BUF_TO_SBP(buf))->sb_inprogress = 0;
-	libxfs_writebuf(buf, 0);
+	libxfs_buf_mark_dirty(buf, 0);
+	libxfs_buf_relse(buf);
 
 	/* Report failure if anything failed to get written to our new fs. */
 	error = -libxfs_umount(mp);
diff --git a/repair/attr_repair.c b/repair/attr_repair.c
index cc20b1a1..476998eb 100644
--- a/repair/attr_repair.c
+++ b/repair/attr_repair.c
@@ -835,8 +835,10 @@ process_leaf_attr_level(xfs_mount_t	*mp,
 		if (!no_modify && bp->b_error == -EFSBADCRC)
 			repair++;
 
-		if (repair && !no_modify)
-			libxfs_writebuf(bp, 0);
+		if (repair && !no_modify) {
+			libxfs_buf_mark_dirty(bp, 0);
+			libxfs_buf_relse(bp);
+		}
 		else
 			libxfs_buf_relse(bp);
 	} while (da_bno != 0);
@@ -999,9 +1001,8 @@ _("would clear forw/back pointers in block 0 for attributes in inode %" PRIu64 "
 	*repair = *repair || repairlinks;
 
 	if (*repair && !no_modify)
-		libxfs_writebuf(bp, 0);
-	else
-		libxfs_buf_relse(bp);
+		libxfs_buf_mark_dirty(bp, 0);
+	libxfs_buf_relse(bp);
 
 	return 0;
 }
@@ -1043,9 +1044,9 @@ _("would clear forw/back pointers in block 0 for attributes in inode %" PRIu64 "
 	/* must do this now, to release block 0 before the traversal */
 	if ((*repair || repairlinks) && !no_modify) {
 		*repair = 1;
-		libxfs_writebuf(bp, 0);
-	} else
-		libxfs_buf_relse(bp);
+		libxfs_buf_mark_dirty(bp, 0);
+	}
+	libxfs_buf_relse(bp);
 	error = process_node_attr(mp, ino, dip, blkmap); /* + repair */
 	if (error)
 		*repair = 0;
diff --git a/repair/da_util.c b/repair/da_util.c
index c02d621c..6a0e28a3 100644
--- a/repair/da_util.c
+++ b/repair/da_util.c
@@ -403,8 +403,10 @@ _("would correct bad hashval in non-leaf %s block\n"
 	ASSERT(cursor->level[this_level].dirty == 0 ||
 		(cursor->level[this_level].dirty && !no_modify));
 
-	if (cursor->level[this_level].dirty && !no_modify)
-		libxfs_writebuf(cursor->level[this_level].bp, 0);
+	if (cursor->level[this_level].dirty && !no_modify) {
+		libxfs_buf_mark_dirty(cursor->level[this_level].bp, 0);
+		libxfs_buf_relse(cursor->level[this_level].bp);
+	}
 	else
 		libxfs_buf_relse(cursor->level[this_level].bp);
 
@@ -619,8 +621,10 @@ _("bad level %d in %s block %u for inode %" PRIu64 "\n"),
 		    cursor->level[this_level].bp->b_error == -EFSBADCRC)
 			cursor->level[this_level].dirty = 1;
 
-		if (cursor->level[this_level].dirty && !no_modify)
-			libxfs_writebuf(cursor->level[this_level].bp, 0);
+		if (cursor->level[this_level].dirty && !no_modify) {
+			libxfs_buf_mark_dirty(cursor->level[this_level].bp, 0);
+			libxfs_buf_relse(cursor->level[this_level].bp);
+		}
 		else
 			libxfs_buf_relse(cursor->level[this_level].bp);
 
diff --git a/repair/dino_chunks.c b/repair/dino_chunks.c
index 76e9f773..5b6f7fca 100644
--- a/repair/dino_chunks.c
+++ b/repair/dino_chunks.c
@@ -939,8 +939,11 @@ process_inode_chunk(
 					bplist[bp_index], (long long)
 					XFS_BUF_ADDR(bplist[bp_index]), agno);
 
-				if (dirty && !no_modify)
-					libxfs_writebuf(bplist[bp_index], 0);
+				if (dirty && !no_modify) {
+					libxfs_buf_mark_dirty(bplist[bp_index],
+							0);
+					libxfs_buf_relse(bplist[bp_index]);
+				}
 				else
 					libxfs_buf_relse(bplist[bp_index]);
 			}
diff --git a/repair/dinode.c b/repair/dinode.c
index 848eac09..39210f27 100644
--- a/repair/dinode.c
+++ b/repair/dinode.c
@@ -1231,8 +1231,10 @@ _("cannot read inode %" PRIu64 ", file block %" PRIu64 ", disk block %" PRIu64 "
 			}
 		}
 
-		if (writebuf && !no_modify)
-			libxfs_writebuf(bp, 0);
+		if (writebuf && !no_modify) {
+			libxfs_buf_mark_dirty(bp, 0);
+			libxfs_buf_relse(bp);
+		}
 		else
 			libxfs_buf_relse(bp);
 	}
@@ -1328,8 +1330,10 @@ _("bad symlink header ino %" PRIu64 ", file block %d, disk block %" PRIu64 "\n")
 		offset += byte_cnt;
 		i++;
 
-		if (badcrc && !no_modify)
-			libxfs_writebuf(bp, 0);
+		if (badcrc && !no_modify) {
+			libxfs_buf_mark_dirty(bp, 0);
+			libxfs_buf_relse(bp);
+		}
 		else
 			libxfs_buf_relse(bp);
 	}
diff --git a/repair/dir2.c b/repair/dir2.c
index 769e341c..1384011b 100644
--- a/repair/dir2.c
+++ b/repair/dir2.c
@@ -1010,7 +1010,8 @@ _("bad directory block magic # %#x in block %u for directory inode %" PRIu64 "\n
 		dirty = 1;
 	if (dirty && !no_modify) {
 		*repair = 1;
-		libxfs_writebuf(bp, 0);
+		libxfs_buf_mark_dirty(bp, 0);
+		libxfs_buf_relse(bp);
 	} else
 		libxfs_buf_relse(bp);
 	return rval;
@@ -1180,7 +1181,8 @@ _("bad sibling back pointer for block %u in directory inode %" PRIu64 "\n"),
 		ASSERT(buf_dirty == 0 || (buf_dirty && !no_modify));
 		if (buf_dirty && !no_modify) {
 			*repair = 1;
-			libxfs_writebuf(bp, 0);
+			libxfs_buf_mark_dirty(bp, 0);
+			libxfs_buf_relse(bp);
 		} else
 			libxfs_buf_relse(bp);
 	} while (da_bno != 0);
@@ -1339,7 +1341,8 @@ _("bad directory block magic # %#x in block %" PRIu64 " for directory inode %" P
 		}
 		if (dirty && !no_modify) {
 			*repair = 1;
-			libxfs_writebuf(bp, 0);
+			libxfs_buf_mark_dirty(bp, 0);
+			libxfs_buf_relse(bp);
 		} else
 			libxfs_buf_relse(bp);
 	}
diff --git a/repair/phase3.c b/repair/phase3.c
index 886acd1f..4e7fe964 100644
--- a/repair/phase3.c
+++ b/repair/phase3.c
@@ -46,8 +46,10 @@ process_agi_unlinked(
 		}
 	}
 
-	if (agi_dirty)
-		libxfs_writebuf(bp, 0);
+	if (agi_dirty) {
+		libxfs_buf_mark_dirty(bp, 0);
+		libxfs_buf_relse(bp);
+	}
 	else
 		libxfs_buf_relse(bp);
 }
diff --git a/repair/phase5.c b/repair/phase5.c
index cdbf6697..e31dedca 100644
--- a/repair/phase5.c
+++ b/repair/phase5.c
@@ -321,9 +321,11 @@ write_cursor(bt_status_t *curs)
 			fprintf(stderr, "writing bt prev block %u\n",
 						curs->level[i].prev_agbno);
 #endif
-			libxfs_writebuf(curs->level[i].prev_buf_p, 0);
+			libxfs_buf_mark_dirty(curs->level[i].prev_buf_p, 0);
+			libxfs_buf_relse(curs->level[i].prev_buf_p);
 		}
-		libxfs_writebuf(curs->level[i].buf_p, 0);
+		libxfs_buf_mark_dirty(curs->level[i].buf_p, 0);
+		libxfs_buf_relse(curs->level[i].buf_p);
 	}
 }
 
@@ -681,7 +683,8 @@ prop_freespace_cursor(xfs_mount_t *mp, xfs_agnumber_t agno,
 #endif
 		if (lptr->prev_agbno != NULLAGBLOCK) {
 			ASSERT(lptr->prev_buf_p != NULL);
-			libxfs_writebuf(lptr->prev_buf_p, 0);
+			libxfs_buf_mark_dirty(lptr->prev_buf_p, 0);
+			libxfs_buf_relse(lptr->prev_buf_p);
 		}
 		lptr->prev_agbno = lptr->agbno;;
 		lptr->prev_buf_p = lptr->buf_p;
@@ -870,7 +873,8 @@ build_freespace_tree(xfs_mount_t *mp, xfs_agnumber_t agno,
 					lptr->prev_agbno);
 #endif
 				ASSERT(lptr->prev_agbno != NULLAGBLOCK);
-				libxfs_writebuf(lptr->prev_buf_p, 0);
+				libxfs_buf_mark_dirty(lptr->prev_buf_p, 0);
+				libxfs_buf_relse(lptr->prev_buf_p);
 			}
 			lptr->prev_buf_p = lptr->buf_p;
 			lptr->prev_agbno = lptr->agbno;
@@ -1046,7 +1050,8 @@ prop_ino_cursor(xfs_mount_t *mp, xfs_agnumber_t agno, bt_status_t *btree_curs,
 #endif
 		if (lptr->prev_agbno != NULLAGBLOCK)  {
 			ASSERT(lptr->prev_buf_p != NULL);
-			libxfs_writebuf(lptr->prev_buf_p, 0);
+			libxfs_buf_mark_dirty(lptr->prev_buf_p, 0);
+			libxfs_buf_relse(lptr->prev_buf_p);
 		}
 		lptr->prev_agbno = lptr->agbno;;
 		lptr->prev_buf_p = lptr->buf_p;
@@ -1137,7 +1142,8 @@ build_agi(xfs_mount_t *mp, xfs_agnumber_t agno, bt_status_t *btree_curs,
 		agi->agi_free_level = cpu_to_be32(finobt_curs->num_levels);
 	}
 
-	libxfs_writebuf(agi_buf, 0);
+	libxfs_buf_mark_dirty(agi_buf, 0);
+	libxfs_buf_relse(agi_buf);
 }
 
 /*
@@ -1299,7 +1305,8 @@ build_ino_tree(xfs_mount_t *mp, xfs_agnumber_t agno,
 					lptr->prev_agbno);
 #endif
 				ASSERT(lptr->prev_agbno != NULLAGBLOCK);
-				libxfs_writebuf(lptr->prev_buf_p, 0);
+				libxfs_buf_mark_dirty(lptr->prev_buf_p, 0);
+				libxfs_buf_relse(lptr->prev_buf_p);
 			}
 			lptr->prev_buf_p = lptr->buf_p;
 			lptr->prev_agbno = lptr->agbno;
@@ -1451,7 +1458,8 @@ prop_rmap_cursor(
 #endif
 		if (lptr->prev_agbno != NULLAGBLOCK)  {
 			ASSERT(lptr->prev_buf_p != NULL);
-			libxfs_writebuf(lptr->prev_buf_p, 0);
+			libxfs_buf_mark_dirty(lptr->prev_buf_p, 0);
+			libxfs_buf_relse(lptr->prev_buf_p);
 		}
 		lptr->prev_agbno = lptr->agbno;
 		lptr->prev_buf_p = lptr->buf_p;
@@ -1661,7 +1669,8 @@ _("Insufficient memory to construct reverse-map cursor."));
 					lptr->prev_agbno);
 #endif
 				ASSERT(lptr->prev_agbno != NULLAGBLOCK);
-				libxfs_writebuf(lptr->prev_buf_p, 0);
+				libxfs_buf_mark_dirty(lptr->prev_buf_p, 0);
+				libxfs_buf_relse(lptr->prev_buf_p);
 			}
 			lptr->prev_buf_p = lptr->buf_p;
 			lptr->prev_agbno = lptr->agbno;
@@ -1801,7 +1810,8 @@ prop_refc_cursor(
 #endif
 		if (lptr->prev_agbno != NULLAGBLOCK)  {
 			ASSERT(lptr->prev_buf_p != NULL);
-			libxfs_writebuf(lptr->prev_buf_p, 0);
+			libxfs_buf_mark_dirty(lptr->prev_buf_p, 0);
+			libxfs_buf_relse(lptr->prev_buf_p);
 		}
 		lptr->prev_agbno = lptr->agbno;
 		lptr->prev_buf_p = lptr->buf_p;
@@ -1954,7 +1964,8 @@ _("Insufficient memory to construct refcount cursor."));
 					lptr->prev_agbno);
 #endif
 				ASSERT(lptr->prev_agbno != NULLAGBLOCK);
-				libxfs_writebuf(lptr->prev_buf_p, 0);
+				libxfs_buf_mark_dirty(lptr->prev_buf_p, 0);
+				libxfs_buf_relse(lptr->prev_buf_p);
 			}
 			lptr->prev_buf_p = lptr->buf_p;
 			lptr->prev_agbno = lptr->agbno;
@@ -2142,7 +2153,8 @@ _("Insufficient memory saving lost blocks.\n"));
 		agf->agf_flcount = 0;
 	}
 
-	libxfs_writebuf(agfl_buf, 0);
+	libxfs_buf_mark_dirty(agfl_buf, 0);
+	libxfs_buf_relse(agfl_buf);
 
 	ext_ptr = findbiggest_bcnt_extent(agno);
 	agf->agf_longest = cpu_to_be32((ext_ptr != NULL) ?
@@ -2155,7 +2167,8 @@ _("Insufficient memory saving lost blocks.\n"));
 	ASSERT(be32_to_cpu(agf->agf_refcount_root) !=
 		be32_to_cpu(agf->agf_roots[XFS_BTNUM_CNTi]));
 
-	libxfs_writebuf(agf_buf, 0);
+	libxfs_buf_mark_dirty(agf_buf, 0);
+	libxfs_buf_relse(agf_buf);
 
 	/*
 	 * now fix up the free list appropriately
@@ -2189,7 +2202,8 @@ sync_sb(xfs_mount_t *mp)
 	update_sb_version(mp);
 
 	libxfs_sb_to_disk(XFS_BUF_TO_SBP(bp), &mp->m_sb);
-	libxfs_writebuf(bp, 0);
+	libxfs_buf_mark_dirty(bp, 0);
+	libxfs_buf_relse(bp);
 }
 
 /*
diff --git a/repair/rmap.c b/repair/rmap.c
index bc53e6c0..b0b9874e 100644
--- a/repair/rmap.c
+++ b/repair/rmap.c
@@ -1231,7 +1231,8 @@ _("setting reflink flag on inode %"PRIu64"\n"),
 	else
 		dino->di_flags2 &= cpu_to_be64(~XFS_DIFLAG2_REFLINK);
 	libxfs_dinode_calc_crc(mp, dino);
-	libxfs_writebuf(buf, 0);
+	libxfs_buf_mark_dirty(buf, 0);
+	libxfs_buf_relse(buf);
 
 	return 0;
 }
diff --git a/repair/scan.c b/repair/scan.c
index f4e4fef5..00c25bed 100644
--- a/repair/scan.c
+++ b/repair/scan.c
@@ -151,8 +151,10 @@ scan_lbtree(
 
 	ASSERT(dirty == 0 || (dirty && !no_modify));
 
-	if ((dirty || badcrc) && !no_modify)
-		libxfs_writebuf(bp, 0);
+	if ((dirty || badcrc) && !no_modify) {
+		libxfs_buf_mark_dirty(bp, 0);
+		libxfs_buf_relse(bp);
+	}
 	else
 		libxfs_buf_relse(bp);
 
@@ -2429,13 +2431,17 @@ scan_ag(
 		sb_dirty += (sbbuf->b_error == -EFSBADCRC);
 	}
 
-	if (agi_dirty && !no_modify)
-		libxfs_writebuf(agibuf, 0);
+	if (agi_dirty && !no_modify) {
+		libxfs_buf_mark_dirty(agibuf, 0);
+		libxfs_buf_relse(agibuf);
+	}
 	else
 		libxfs_buf_relse(agibuf);
 
-	if (agf_dirty && !no_modify)
-		libxfs_writebuf(agfbuf, 0);
+	if (agf_dirty && !no_modify) {
+		libxfs_buf_mark_dirty(agfbuf, 0);
+		libxfs_buf_relse(agfbuf);
+	}
 	else
 		libxfs_buf_relse(agfbuf);
 
@@ -2443,7 +2449,8 @@ scan_ag(
 		if (agno == 0)
 			memcpy(&mp->m_sb, sb, sizeof(xfs_sb_t));
 		libxfs_sb_to_disk(XFS_BUF_TO_SBP(sbbuf), sb);
-		libxfs_writebuf(sbbuf, 0);
+		libxfs_buf_mark_dirty(sbbuf, 0);
+		libxfs_buf_relse(sbbuf);
 	} else
 		libxfs_buf_relse(sbbuf);
 	free(sb);
diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c
index a97f2803..c0b48407 100644
--- a/repair/xfs_repair.c
+++ b/repair/xfs_repair.c
@@ -1096,7 +1096,8 @@ _("Note - stripe unit (%d) and width (%d) were copied from a backup superblock.\
 			be32_to_cpu(dsb->sb_unit), be32_to_cpu(dsb->sb_width));
 	}
 
-	libxfs_writebuf(sbp, 0);
+	libxfs_buf_mark_dirty(sbp, 0);
+	libxfs_buf_relse(sbp);
 
 	/*
 	 * Done. Flush all cached buffers and inodes first to ensure all


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 18/25] libxfs: remove unused flags parameter to libxfs_buf_mark_dirty
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
                   ` (16 preceding siblings ...)
  2020-02-25  0:13 ` [PATCH 17/25] libxfs: straighten out libxfs_writebuf naming confusion Darrick J. Wong
@ 2020-02-25  0:13 ` Darrick J. Wong
  2020-02-25 17:51   ` Christoph Hellwig
  2020-02-25  0:13 ` [PATCH 19/25] libxfs: remove libxfs_writebuf_int Darrick J. Wong
                   ` (6 subsequent siblings)
  24 siblings, 1 reply; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:13 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Nobody uses the flags parameter, so get rid of it.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 libxfs/libxfs_io.h   |    8 ++++----
 libxfs/rdwr.c        |   14 ++++++--------
 libxfs/trans.c       |    2 +-
 mkfs/proto.c         |    2 +-
 mkfs/xfs_mkfs.c      |   14 +++++++-------
 repair/attr_repair.c |    6 +++---
 repair/da_util.c     |    4 ++--
 repair/dino_chunks.c |    3 +--
 repair/dinode.c      |    4 ++--
 repair/dir2.c        |    6 +++---
 repair/phase3.c      |    2 +-
 repair/phase5.c      |   28 ++++++++++++++--------------
 repair/rmap.c        |    2 +-
 repair/scan.c        |    8 ++++----
 repair/xfs_repair.c  |    2 +-
 15 files changed, 51 insertions(+), 54 deletions(-)


diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h
index 51b1dc15..78ce989c 100644
--- a/libxfs/libxfs_io.h
+++ b/libxfs/libxfs_io.h
@@ -136,9 +136,9 @@ extern struct cache_operations	libxfs_bcache_operations;
 #define libxfs_readbuf_map(dev, map, nmaps, flags, ops) \
 	libxfs_trace_readbuf_map(__FUNCTION__, __FILE__, __LINE__, \
 			    (dev), (map), (nmaps), (flags), (ops))
-#define libxfs_buf_mark_dirty(buf, flags) \
+#define libxfs_buf_mark_dirty(buf) \
 	libxfs_trace_dirtybuf(__FUNCTION__, __FILE__, __LINE__, \
-			      (buf), (flags))
+			      (buf))
 #define libxfs_buf_get(dev, daddr, len) \
 	libxfs_trace_getbuf(__FUNCTION__, __FILE__, __LINE__, \
 			    (dev), (daddr), (len))
@@ -158,7 +158,7 @@ extern xfs_buf_t *libxfs_trace_readbuf_map(const char *, const char *, int,
 			struct xfs_buftarg *, struct xfs_buf_map *, int, int,
 			const struct xfs_buf_ops *);
 void libxfs_trace_dirtybuf(const char *func, const char *file, int line,
-			struct xfs_buf *bp, int flags);
+			struct xfs_buf *bp);
 struct xfs_buf *libxfs_trace_getbuf(const char *func, const char *file,
 			int line, struct xfs_buftarg *btp, xfs_daddr_t daddr,
 			size_t len);
@@ -173,7 +173,7 @@ extern void	libxfs_trace_putbuf (const char *, const char *, int,
 
 extern xfs_buf_t *libxfs_readbuf_map(struct xfs_buftarg *, struct xfs_buf_map *,
 			int, int, const struct xfs_buf_ops *);
-void libxfs_buf_mark_dirty(struct xfs_buf *bp, int flags);
+void libxfs_buf_mark_dirty(struct xfs_buf *bp);
 extern xfs_buf_t *libxfs_getbuf_map(struct xfs_buftarg *,
 			struct xfs_buf_map *, int, int);
 extern xfs_buf_t *libxfs_getbuf_flags(struct xfs_buftarg *, xfs_daddr_t,
diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index 16701bba..34693725 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -194,11 +194,10 @@ libxfs_trace_dirtybuf(
 	const char		*func,
 	const char		*file,
 	int			line,
-	struct xfs_buf		*bp,
-	int			flags)
+	struct xfs_buf		*bp)
 {
 	__add_trace(bp, func, file, line);
-	libxfs_buf_mark_dirty(bp, flags);
+	libxfs_buf_mark_dirty(bp);
 }
 
 struct xfs_buf *
@@ -999,8 +998,7 @@ libxfs_writebuf_int(xfs_buf_t *bp, int flags)
  */
 void
 libxfs_buf_mark_dirty(
-	struct xfs_buf	*bp,
-	int		flags)
+	struct xfs_buf	*bp)
 {
 #ifdef IO_DEBUG
 	printf("%lx: %s: dirty blkno=%llu(%llu)\n",
@@ -1014,7 +1012,7 @@ libxfs_buf_mark_dirty(
 	 */
 	bp->b_error = 0;
 	bp->b_flags &= ~LIBXFS_B_STALE;
-	bp->b_flags |= (LIBXFS_B_DIRTY | flags);
+	bp->b_flags |= LIBXFS_B_DIRTY;
 }
 
 void
@@ -1416,7 +1414,7 @@ libxfs_log_clear(
 	libxfs_log_header(ptr, fs_uuid, version, sunit, fmt, lsn, tail_lsn,
 			  next, bp);
 	if (bp) {
-		libxfs_buf_mark_dirty(bp, 0);
+		libxfs_buf_mark_dirty(bp);
 		libxfs_buf_relse(bp);
 	}
 
@@ -1468,7 +1466,7 @@ libxfs_log_clear(
 		libxfs_log_header(ptr, fs_uuid, version, BBTOB(len), fmt, lsn,
 				  tail_lsn, next, bp);
 		if (bp) {
-			libxfs_buf_mark_dirty(bp, 0);
+			libxfs_buf_mark_dirty(bp);
 			libxfs_buf_relse(bp);
 		}
 
diff --git a/libxfs/trans.c b/libxfs/trans.c
index 91001a93..ca1166ed 100644
--- a/libxfs/trans.c
+++ b/libxfs/trans.c
@@ -843,7 +843,7 @@ inode_item_done(
 		goto free;
 	}
 
-	libxfs_buf_mark_dirty(bp, 0);
+	libxfs_buf_mark_dirty(bp);
 	libxfs_buf_relse(bp);
 free:
 	xfs_inode_item_put(iip);
diff --git a/mkfs/proto.c b/mkfs/proto.c
index 7de76ca4..26a613fe 100644
--- a/mkfs/proto.c
+++ b/mkfs/proto.c
@@ -262,7 +262,7 @@ newfile(
 		if (logit)
 			libxfs_trans_log_buf(tp, bp, 0, bp->b_bcount - 1);
 		else {
-			libxfs_buf_mark_dirty(bp, 0);
+			libxfs_buf_mark_dirty(bp);
 			libxfs_buf_relse(bp);
 		}
 	}
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 75a90f3a..295deb86 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -3462,7 +3462,7 @@ prepare_devices(
 	buf = alloc_write_buf(mp->m_ddev_targp, (xi->dsize - whack_blks),
 			whack_blks);
 	memset(buf->b_addr, 0, WHACK_SIZE);
-	libxfs_buf_mark_dirty(buf, 0);
+	libxfs_buf_mark_dirty(buf);
 	libxfs_buf_relse(buf);
 
 	/*
@@ -3473,7 +3473,7 @@ prepare_devices(
 	 */
 	buf = alloc_write_buf(mp->m_ddev_targp, 0, whack_blks);
 	memset(buf->b_addr, 0, WHACK_SIZE);
-	libxfs_buf_mark_dirty(buf, 0);
+	libxfs_buf_mark_dirty(buf);
 	libxfs_buf_relse(buf);
 
 	/* OK, now write the superblock... */
@@ -3482,7 +3482,7 @@ prepare_devices(
 	buf->b_ops = &xfs_sb_buf_ops;
 	memset(buf->b_addr, 0, cfg->sectorsize);
 	libxfs_sb_to_disk(buf->b_addr, sbp);
-	libxfs_buf_mark_dirty(buf, 0);
+	libxfs_buf_mark_dirty(buf);
 	libxfs_buf_relse(buf);
 
 	/* ...and zero the log.... */
@@ -3502,7 +3502,7 @@ prepare_devices(
 				XFS_FSB_TO_BB(mp, cfg->rtblocks - 1LL),
 				BTOBB(cfg->blocksize));
 		memset(buf->b_addr, 0, cfg->blocksize);
-		libxfs_buf_mark_dirty(buf, 0);
+		libxfs_buf_mark_dirty(buf);
 		libxfs_buf_relse(buf);
 	}
 
@@ -3599,7 +3599,7 @@ rewrite_secondary_superblocks(
 		exit(1);
 	}
 	XFS_BUF_TO_SBP(buf)->sb_rootino = cpu_to_be64(mp->m_sb.sb_rootino);
-	libxfs_buf_mark_dirty(buf, 0);
+	libxfs_buf_mark_dirty(buf);
 	libxfs_buf_relse(buf);
 
 	/* and one in the middle for luck if there's enough AGs for that */
@@ -3616,7 +3616,7 @@ rewrite_secondary_superblocks(
 		exit(1);
 	}
 	XFS_BUF_TO_SBP(buf)->sb_rootino = cpu_to_be64(mp->m_sb.sb_rootino);
-	libxfs_buf_mark_dirty(buf, 0);
+	libxfs_buf_mark_dirty(buf);
 	libxfs_buf_relse(buf);
 }
 
@@ -3964,7 +3964,7 @@ main(
 	if (!buf || buf->b_error)
 		exit(1);
 	(XFS_BUF_TO_SBP(buf))->sb_inprogress = 0;
-	libxfs_buf_mark_dirty(buf, 0);
+	libxfs_buf_mark_dirty(buf);
 	libxfs_buf_relse(buf);
 
 	/* Report failure if anything failed to get written to our new fs. */
diff --git a/repair/attr_repair.c b/repair/attr_repair.c
index 476998eb..3cef3004 100644
--- a/repair/attr_repair.c
+++ b/repair/attr_repair.c
@@ -836,7 +836,7 @@ process_leaf_attr_level(xfs_mount_t	*mp,
 			repair++;
 
 		if (repair && !no_modify) {
-			libxfs_buf_mark_dirty(bp, 0);
+			libxfs_buf_mark_dirty(bp);
 			libxfs_buf_relse(bp);
 		}
 		else
@@ -1001,7 +1001,7 @@ _("would clear forw/back pointers in block 0 for attributes in inode %" PRIu64 "
 	*repair = *repair || repairlinks;
 
 	if (*repair && !no_modify)
-		libxfs_buf_mark_dirty(bp, 0);
+		libxfs_buf_mark_dirty(bp);
 	libxfs_buf_relse(bp);
 
 	return 0;
@@ -1044,7 +1044,7 @@ _("would clear forw/back pointers in block 0 for attributes in inode %" PRIu64 "
 	/* must do this now, to release block 0 before the traversal */
 	if ((*repair || repairlinks) && !no_modify) {
 		*repair = 1;
-		libxfs_buf_mark_dirty(bp, 0);
+		libxfs_buf_mark_dirty(bp);
 	}
 	libxfs_buf_relse(bp);
 	error = process_node_attr(mp, ino, dip, blkmap); /* + repair */
diff --git a/repair/da_util.c b/repair/da_util.c
index 6a0e28a3..dc1e5bfe 100644
--- a/repair/da_util.c
+++ b/repair/da_util.c
@@ -404,7 +404,7 @@ _("would correct bad hashval in non-leaf %s block\n"
 		(cursor->level[this_level].dirty && !no_modify));
 
 	if (cursor->level[this_level].dirty && !no_modify) {
-		libxfs_buf_mark_dirty(cursor->level[this_level].bp, 0);
+		libxfs_buf_mark_dirty(cursor->level[this_level].bp);
 		libxfs_buf_relse(cursor->level[this_level].bp);
 	}
 	else
@@ -622,7 +622,7 @@ _("bad level %d in %s block %u for inode %" PRIu64 "\n"),
 			cursor->level[this_level].dirty = 1;
 
 		if (cursor->level[this_level].dirty && !no_modify) {
-			libxfs_buf_mark_dirty(cursor->level[this_level].bp, 0);
+			libxfs_buf_mark_dirty(cursor->level[this_level].bp);
 			libxfs_buf_relse(cursor->level[this_level].bp);
 		}
 		else
diff --git a/repair/dino_chunks.c b/repair/dino_chunks.c
index 5b6f7fca..b2ed1112 100644
--- a/repair/dino_chunks.c
+++ b/repair/dino_chunks.c
@@ -940,8 +940,7 @@ process_inode_chunk(
 					XFS_BUF_ADDR(bplist[bp_index]), agno);
 
 				if (dirty && !no_modify) {
-					libxfs_buf_mark_dirty(bplist[bp_index],
-							0);
+					libxfs_buf_mark_dirty(bplist[bp_index]);
 					libxfs_buf_relse(bplist[bp_index]);
 				}
 				else
diff --git a/repair/dinode.c b/repair/dinode.c
index 39210f27..08521ac8 100644
--- a/repair/dinode.c
+++ b/repair/dinode.c
@@ -1232,7 +1232,7 @@ _("cannot read inode %" PRIu64 ", file block %" PRIu64 ", disk block %" PRIu64 "
 		}
 
 		if (writebuf && !no_modify) {
-			libxfs_buf_mark_dirty(bp, 0);
+			libxfs_buf_mark_dirty(bp);
 			libxfs_buf_relse(bp);
 		}
 		else
@@ -1331,7 +1331,7 @@ _("bad symlink header ino %" PRIu64 ", file block %d, disk block %" PRIu64 "\n")
 		i++;
 
 		if (badcrc && !no_modify) {
-			libxfs_buf_mark_dirty(bp, 0);
+			libxfs_buf_mark_dirty(bp);
 			libxfs_buf_relse(bp);
 		}
 		else
diff --git a/repair/dir2.c b/repair/dir2.c
index 1384011b..cbbce601 100644
--- a/repair/dir2.c
+++ b/repair/dir2.c
@@ -1010,7 +1010,7 @@ _("bad directory block magic # %#x in block %u for directory inode %" PRIu64 "\n
 		dirty = 1;
 	if (dirty && !no_modify) {
 		*repair = 1;
-		libxfs_buf_mark_dirty(bp, 0);
+		libxfs_buf_mark_dirty(bp);
 		libxfs_buf_relse(bp);
 	} else
 		libxfs_buf_relse(bp);
@@ -1181,7 +1181,7 @@ _("bad sibling back pointer for block %u in directory inode %" PRIu64 "\n"),
 		ASSERT(buf_dirty == 0 || (buf_dirty && !no_modify));
 		if (buf_dirty && !no_modify) {
 			*repair = 1;
-			libxfs_buf_mark_dirty(bp, 0);
+			libxfs_buf_mark_dirty(bp);
 			libxfs_buf_relse(bp);
 		} else
 			libxfs_buf_relse(bp);
@@ -1341,7 +1341,7 @@ _("bad directory block magic # %#x in block %" PRIu64 " for directory inode %" P
 		}
 		if (dirty && !no_modify) {
 			*repair = 1;
-			libxfs_buf_mark_dirty(bp, 0);
+			libxfs_buf_mark_dirty(bp);
 			libxfs_buf_relse(bp);
 		} else
 			libxfs_buf_relse(bp);
diff --git a/repair/phase3.c b/repair/phase3.c
index 4e7fe964..79dc65f8 100644
--- a/repair/phase3.c
+++ b/repair/phase3.c
@@ -47,7 +47,7 @@ process_agi_unlinked(
 	}
 
 	if (agi_dirty) {
-		libxfs_buf_mark_dirty(bp, 0);
+		libxfs_buf_mark_dirty(bp);
 		libxfs_buf_relse(bp);
 	}
 	else
diff --git a/repair/phase5.c b/repair/phase5.c
index e31dedca..7ec58f88 100644
--- a/repair/phase5.c
+++ b/repair/phase5.c
@@ -321,10 +321,10 @@ write_cursor(bt_status_t *curs)
 			fprintf(stderr, "writing bt prev block %u\n",
 						curs->level[i].prev_agbno);
 #endif
-			libxfs_buf_mark_dirty(curs->level[i].prev_buf_p, 0);
+			libxfs_buf_mark_dirty(curs->level[i].prev_buf_p);
 			libxfs_buf_relse(curs->level[i].prev_buf_p);
 		}
-		libxfs_buf_mark_dirty(curs->level[i].buf_p, 0);
+		libxfs_buf_mark_dirty(curs->level[i].buf_p);
 		libxfs_buf_relse(curs->level[i].buf_p);
 	}
 }
@@ -683,7 +683,7 @@ prop_freespace_cursor(xfs_mount_t *mp, xfs_agnumber_t agno,
 #endif
 		if (lptr->prev_agbno != NULLAGBLOCK) {
 			ASSERT(lptr->prev_buf_p != NULL);
-			libxfs_buf_mark_dirty(lptr->prev_buf_p, 0);
+			libxfs_buf_mark_dirty(lptr->prev_buf_p);
 			libxfs_buf_relse(lptr->prev_buf_p);
 		}
 		lptr->prev_agbno = lptr->agbno;;
@@ -873,7 +873,7 @@ build_freespace_tree(xfs_mount_t *mp, xfs_agnumber_t agno,
 					lptr->prev_agbno);
 #endif
 				ASSERT(lptr->prev_agbno != NULLAGBLOCK);
-				libxfs_buf_mark_dirty(lptr->prev_buf_p, 0);
+				libxfs_buf_mark_dirty(lptr->prev_buf_p);
 				libxfs_buf_relse(lptr->prev_buf_p);
 			}
 			lptr->prev_buf_p = lptr->buf_p;
@@ -1050,7 +1050,7 @@ prop_ino_cursor(xfs_mount_t *mp, xfs_agnumber_t agno, bt_status_t *btree_curs,
 #endif
 		if (lptr->prev_agbno != NULLAGBLOCK)  {
 			ASSERT(lptr->prev_buf_p != NULL);
-			libxfs_buf_mark_dirty(lptr->prev_buf_p, 0);
+			libxfs_buf_mark_dirty(lptr->prev_buf_p);
 			libxfs_buf_relse(lptr->prev_buf_p);
 		}
 		lptr->prev_agbno = lptr->agbno;;
@@ -1142,7 +1142,7 @@ build_agi(xfs_mount_t *mp, xfs_agnumber_t agno, bt_status_t *btree_curs,
 		agi->agi_free_level = cpu_to_be32(finobt_curs->num_levels);
 	}
 
-	libxfs_buf_mark_dirty(agi_buf, 0);
+	libxfs_buf_mark_dirty(agi_buf);
 	libxfs_buf_relse(agi_buf);
 }
 
@@ -1305,7 +1305,7 @@ build_ino_tree(xfs_mount_t *mp, xfs_agnumber_t agno,
 					lptr->prev_agbno);
 #endif
 				ASSERT(lptr->prev_agbno != NULLAGBLOCK);
-				libxfs_buf_mark_dirty(lptr->prev_buf_p, 0);
+				libxfs_buf_mark_dirty(lptr->prev_buf_p);
 				libxfs_buf_relse(lptr->prev_buf_p);
 			}
 			lptr->prev_buf_p = lptr->buf_p;
@@ -1458,7 +1458,7 @@ prop_rmap_cursor(
 #endif
 		if (lptr->prev_agbno != NULLAGBLOCK)  {
 			ASSERT(lptr->prev_buf_p != NULL);
-			libxfs_buf_mark_dirty(lptr->prev_buf_p, 0);
+			libxfs_buf_mark_dirty(lptr->prev_buf_p);
 			libxfs_buf_relse(lptr->prev_buf_p);
 		}
 		lptr->prev_agbno = lptr->agbno;
@@ -1669,7 +1669,7 @@ _("Insufficient memory to construct reverse-map cursor."));
 					lptr->prev_agbno);
 #endif
 				ASSERT(lptr->prev_agbno != NULLAGBLOCK);
-				libxfs_buf_mark_dirty(lptr->prev_buf_p, 0);
+				libxfs_buf_mark_dirty(lptr->prev_buf_p);
 				libxfs_buf_relse(lptr->prev_buf_p);
 			}
 			lptr->prev_buf_p = lptr->buf_p;
@@ -1810,7 +1810,7 @@ prop_refc_cursor(
 #endif
 		if (lptr->prev_agbno != NULLAGBLOCK)  {
 			ASSERT(lptr->prev_buf_p != NULL);
-			libxfs_buf_mark_dirty(lptr->prev_buf_p, 0);
+			libxfs_buf_mark_dirty(lptr->prev_buf_p);
 			libxfs_buf_relse(lptr->prev_buf_p);
 		}
 		lptr->prev_agbno = lptr->agbno;
@@ -1964,7 +1964,7 @@ _("Insufficient memory to construct refcount cursor."));
 					lptr->prev_agbno);
 #endif
 				ASSERT(lptr->prev_agbno != NULLAGBLOCK);
-				libxfs_buf_mark_dirty(lptr->prev_buf_p, 0);
+				libxfs_buf_mark_dirty(lptr->prev_buf_p);
 				libxfs_buf_relse(lptr->prev_buf_p);
 			}
 			lptr->prev_buf_p = lptr->buf_p;
@@ -2153,7 +2153,7 @@ _("Insufficient memory saving lost blocks.\n"));
 		agf->agf_flcount = 0;
 	}
 
-	libxfs_buf_mark_dirty(agfl_buf, 0);
+	libxfs_buf_mark_dirty(agfl_buf);
 	libxfs_buf_relse(agfl_buf);
 
 	ext_ptr = findbiggest_bcnt_extent(agno);
@@ -2167,7 +2167,7 @@ _("Insufficient memory saving lost blocks.\n"));
 	ASSERT(be32_to_cpu(agf->agf_refcount_root) !=
 		be32_to_cpu(agf->agf_roots[XFS_BTNUM_CNTi]));
 
-	libxfs_buf_mark_dirty(agf_buf, 0);
+	libxfs_buf_mark_dirty(agf_buf);
 	libxfs_buf_relse(agf_buf);
 
 	/*
@@ -2202,7 +2202,7 @@ sync_sb(xfs_mount_t *mp)
 	update_sb_version(mp);
 
 	libxfs_sb_to_disk(XFS_BUF_TO_SBP(bp), &mp->m_sb);
-	libxfs_buf_mark_dirty(bp, 0);
+	libxfs_buf_mark_dirty(bp);
 	libxfs_buf_relse(bp);
 }
 
diff --git a/repair/rmap.c b/repair/rmap.c
index b0b9874e..a37efbe7 100644
--- a/repair/rmap.c
+++ b/repair/rmap.c
@@ -1231,7 +1231,7 @@ _("setting reflink flag on inode %"PRIu64"\n"),
 	else
 		dino->di_flags2 &= cpu_to_be64(~XFS_DIFLAG2_REFLINK);
 	libxfs_dinode_calc_crc(mp, dino);
-	libxfs_buf_mark_dirty(buf, 0);
+	libxfs_buf_mark_dirty(buf);
 	libxfs_buf_relse(buf);
 
 	return 0;
diff --git a/repair/scan.c b/repair/scan.c
index 00c25bed..66b596db 100644
--- a/repair/scan.c
+++ b/repair/scan.c
@@ -152,7 +152,7 @@ scan_lbtree(
 	ASSERT(dirty == 0 || (dirty && !no_modify));
 
 	if ((dirty || badcrc) && !no_modify) {
-		libxfs_buf_mark_dirty(bp, 0);
+		libxfs_buf_mark_dirty(bp);
 		libxfs_buf_relse(bp);
 	}
 	else
@@ -2432,14 +2432,14 @@ scan_ag(
 	}
 
 	if (agi_dirty && !no_modify) {
-		libxfs_buf_mark_dirty(agibuf, 0);
+		libxfs_buf_mark_dirty(agibuf);
 		libxfs_buf_relse(agibuf);
 	}
 	else
 		libxfs_buf_relse(agibuf);
 
 	if (agf_dirty && !no_modify) {
-		libxfs_buf_mark_dirty(agfbuf, 0);
+		libxfs_buf_mark_dirty(agfbuf);
 		libxfs_buf_relse(agfbuf);
 	}
 	else
@@ -2449,7 +2449,7 @@ scan_ag(
 		if (agno == 0)
 			memcpy(&mp->m_sb, sb, sizeof(xfs_sb_t));
 		libxfs_sb_to_disk(XFS_BUF_TO_SBP(sbbuf), sb);
-		libxfs_buf_mark_dirty(sbbuf, 0);
+		libxfs_buf_mark_dirty(sbbuf);
 		libxfs_buf_relse(sbbuf);
 	} else
 		libxfs_buf_relse(sbbuf);
diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c
index c0b48407..425c6751 100644
--- a/repair/xfs_repair.c
+++ b/repair/xfs_repair.c
@@ -1096,7 +1096,7 @@ _("Note - stripe unit (%d) and width (%d) were copied from a backup superblock.\
 			be32_to_cpu(dsb->sb_unit), be32_to_cpu(dsb->sb_width));
 	}
 
-	libxfs_buf_mark_dirty(sbp, 0);
+	libxfs_buf_mark_dirty(sbp);
 	libxfs_buf_relse(sbp);
 
 	/*


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 19/25] libxfs: remove libxfs_writebuf_int
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
                   ` (17 preceding siblings ...)
  2020-02-25  0:13 ` [PATCH 18/25] libxfs: remove unused flags parameter to libxfs_buf_mark_dirty Darrick J. Wong
@ 2020-02-25  0:13 ` Darrick J. Wong
  2020-02-25  0:13 ` [PATCH 20/25] libxfs: remove dangerous casting between xfs_buf and cache_node Darrick J. Wong
                   ` (5 subsequent siblings)
  24 siblings, 0 replies; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:13 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs, Christoph Hellwig

From: Darrick J. Wong <darrick.wong@oracle.com>

This function is the same as libxfs_buf_dirty so use that instead.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 libxfs/libxfs_io.h |    1 -
 libxfs/rdwr.c      |   13 -------------
 libxfs/trans.c     |    2 +-
 3 files changed, 1 insertion(+), 15 deletions(-)


diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h
index 78ce989c..646e340b 100644
--- a/libxfs/libxfs_io.h
+++ b/libxfs/libxfs_io.h
@@ -217,7 +217,6 @@ extern int	libxfs_bcache_overflowed(void);
 extern xfs_buf_t *libxfs_getbufr(struct xfs_buftarg *, xfs_daddr_t, int);
 extern void	libxfs_putbufr(xfs_buf_t *);
 
-extern int	libxfs_writebuf_int(xfs_buf_t *, int);
 int		libxfs_bwrite(struct xfs_buf *bp);
 extern int	libxfs_readbufr(struct xfs_buftarg *, xfs_daddr_t, xfs_buf_t *, int, int);
 extern int	libxfs_readbufr_map(struct xfs_buftarg *, struct xfs_buf *, int);
diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index 34693725..5285abd5 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -979,19 +979,6 @@ libxfs_bwrite(
 	return bp->b_error;
 }
 
-int
-libxfs_writebuf_int(xfs_buf_t *bp, int flags)
-{
-	/*
-	 * Clear any error hanging over from reading the buffer. This prevents
-	 * subsequent reads after this write from seeing stale errors.
-	 */
-	bp->b_error = 0;
-	bp->b_flags &= ~LIBXFS_B_STALE;
-	bp->b_flags |= (LIBXFS_B_DIRTY | flags);
-	return 0;
-}
-
 /*
  * Mark a buffer dirty.  The dirty data will be written out when the cache
  * is flushed (or at release time if the buffer is uncached).
diff --git a/libxfs/trans.c b/libxfs/trans.c
index ca1166ed..df1ec90b 100644
--- a/libxfs/trans.c
+++ b/libxfs/trans.c
@@ -863,7 +863,7 @@ buf_item_done(
 
 	hold = (bip->bli_flags & XFS_BLI_HOLD);
 	if (bip->bli_flags & XFS_BLI_DIRTY)
-		libxfs_writebuf_int(bp, 0);
+		libxfs_buf_mark_dirty(bp);
 
 	bip->bli_flags &= ~XFS_BLI_HOLD;
 	xfs_buf_item_put(bip);


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 20/25] libxfs: remove dangerous casting between xfs_buf and cache_node
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
                   ` (18 preceding siblings ...)
  2020-02-25  0:13 ` [PATCH 19/25] libxfs: remove libxfs_writebuf_int Darrick J. Wong
@ 2020-02-25  0:13 ` Darrick J. Wong
  2020-02-25 17:52   ` Christoph Hellwig
  2020-02-25  0:13 ` [PATCH 21/25] libxfs: remove dangerous casting between cache_node and xfs_buf Darrick J. Wong
                   ` (4 subsequent siblings)
  24 siblings, 1 reply; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:13 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Get rid of all the dangerous casting between xfs_buf and cache_node
since we can dereference directly.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 libxfs/libxfs_io.h |    5 ++---
 libxfs/rdwr.c      |   28 +++++++++++++++-------------
 2 files changed, 17 insertions(+), 16 deletions(-)


diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h
index 646e340b..cd159881 100644
--- a/libxfs/libxfs_io.h
+++ b/libxfs/libxfs_io.h
@@ -109,10 +109,9 @@ typedef unsigned int xfs_buf_flags_t;
 
 #define XFS_BUF_SET_PRIORITY(bp,pri)	cache_node_set_priority( \
 						libxfs_bcache, \
-						(struct cache_node *)(bp), \
+						&(bp)->b_node, \
 						(pri))
-#define XFS_BUF_PRIORITY(bp)		(cache_node_get_priority( \
-						(struct cache_node *)(bp)))
+#define XFS_BUF_PRIORITY(bp)		(cache_node_get_priority(&(bp)->b_node))
 #define xfs_buf_set_ref(bp,ref)		((void) 0)
 #define xfs_buf_ioerror(bp,err)		((bp)->b_error = (err))
 
diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index 5285abd5..09a2a716 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -518,8 +518,8 @@ __cache_lookup(struct xfs_bufkey *key, unsigned int flags)
 		bp->b_holder = pthread_self();
 	}
 
-	cache_node_set_priority(libxfs_bcache, (struct cache_node *)bp,
-		cache_node_get_priority((struct cache_node *)bp) -
+	cache_node_set_priority(libxfs_bcache, &bp->b_node,
+			cache_node_get_priority(&bp->b_node) -
 						CACHE_PREFETCH_PRIORITY);
 #ifdef XFS_BUF_TRACING
 	pthread_mutex_lock(&libxfs_bcache->c_mutex);
@@ -535,7 +535,7 @@ __cache_lookup(struct xfs_bufkey *key, unsigned int flags)
 
 	return bp;
 out_put:
-	cache_node_put(libxfs_bcache, (struct cache_node *)bp);
+	cache_node_put(libxfs_bcache, &bp->b_node);
 	return NULL;
 }
 
@@ -632,23 +632,25 @@ libxfs_buf_relse(
 	}
 
 	if (!list_empty(&bp->b_node.cn_hash))
-		cache_node_put(libxfs_bcache, (struct cache_node *)bp);
+		cache_node_put(libxfs_bcache, &bp->b_node);
 	else if (--bp->b_node.cn_count == 0)
 		libxfs_putbufr(bp);
 }
 
 static struct cache_node *
-libxfs_balloc(cache_key_t key)
+libxfs_balloc(
+	cache_key_t		key)
 {
-	struct xfs_bufkey *bufkey = (struct xfs_bufkey *)key;
+	struct xfs_bufkey	*bufkey = (struct xfs_bufkey *)key;
+	struct xfs_buf		*bp;
 
 	if (bufkey->map)
-		return (struct cache_node *)
-		       libxfs_getbufr_map(bufkey->buftarg,
-					  bufkey->blkno, bufkey->bblen,
-					  bufkey->map, bufkey->nmaps);
-	return (struct cache_node *)libxfs_getbufr(bufkey->buftarg,
-					  bufkey->blkno, bufkey->bblen);
+		bp = libxfs_getbufr_map(bufkey->buftarg, bufkey->blkno,
+				bufkey->bblen, bufkey->map, bufkey->nmaps);
+	else
+		bp = libxfs_getbufr(bufkey->buftarg, bufkey->blkno,
+				bufkey->bblen);
+	return &bp->b_node;
 }
 
 
@@ -1120,7 +1122,7 @@ libxfs_putbufr(xfs_buf_t *bp)
 {
 	if (bp->b_flags & LIBXFS_B_DIRTY)
 		libxfs_bwrite(bp);
-	libxfs_brelse((struct cache_node *)bp);
+	libxfs_brelse(&bp->b_node);
 }
 
 


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 21/25] libxfs: remove dangerous casting between cache_node and xfs_buf
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
                   ` (19 preceding siblings ...)
  2020-02-25  0:13 ` [PATCH 20/25] libxfs: remove dangerous casting between xfs_buf and cache_node Darrick J. Wong
@ 2020-02-25  0:13 ` Darrick J. Wong
  2020-02-25 17:52   ` Christoph Hellwig
  2020-02-25  0:13 ` [PATCH 22/25] libxfs: remove the libxfs_{get,put}bufr APIs Darrick J. Wong
                   ` (3 subsequent siblings)
  24 siblings, 1 reply; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:13 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Get rid of all the dangerous casting between cache_node and xfs_buf
since we can use container_of now.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 libxfs/rdwr.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)


diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index 09a2a716..29c9dd68 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -294,8 +294,9 @@ libxfs_bhash(cache_key_t key, unsigned int hashsize, unsigned int hashshift)
 static int
 libxfs_bcompare(struct cache_node *node, cache_key_t key)
 {
-	struct xfs_buf	*bp = (struct xfs_buf *)node;
-	struct xfs_bufkey *bkey = (struct xfs_bufkey *)key;
+	struct xfs_buf		*bp = container_of(node, struct xfs_buf,
+						   b_node);
+	struct xfs_bufkey	*bkey = (struct xfs_bufkey *)key;
 
 	if (bp->b_target->dev == bkey->buftarg->dev &&
 	    bp->b_bn == bkey->blkno) {
@@ -1045,7 +1046,8 @@ static void
 libxfs_brelse(
 	struct cache_node	*node)
 {
-	struct xfs_buf		*bp = (struct xfs_buf *)node;
+	struct xfs_buf		*bp = container_of(node, struct xfs_buf,
+						   b_node);
 
 	if (!bp)
 		return;
@@ -1110,7 +1112,8 @@ static int
 libxfs_bflush(
 	struct cache_node	*node)
 {
-	struct xfs_buf		*bp = (struct xfs_buf *)node;
+	struct xfs_buf		*bp = container_of(node, struct xfs_buf,
+						   b_node);
 
 	if (!bp->b_error && bp->b_flags & LIBXFS_B_DIRTY)
 		return libxfs_bwrite(bp);


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 22/25] libxfs: remove the libxfs_{get,put}bufr APIs
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
                   ` (20 preceding siblings ...)
  2020-02-25  0:13 ` [PATCH 21/25] libxfs: remove dangerous casting between cache_node and xfs_buf Darrick J. Wong
@ 2020-02-25  0:13 ` Darrick J. Wong
  2020-02-25 17:52   ` Christoph Hellwig
  2020-02-25  0:13 ` [PATCH 23/25] libxfs: hide libxfs_getbuf_flags Darrick J. Wong
                   ` (2 subsequent siblings)
  24 siblings, 1 reply; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:13 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Hide libxfs_getbufr since nobody should be using the internal function,
and fold libxfs_putbufr into its only caller.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 libxfs/libxfs_io.h |    3 ---
 libxfs/rdwr.c      |   20 ++++++++------------
 2 files changed, 8 insertions(+), 15 deletions(-)


diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h
index cd159881..c69eea97 100644
--- a/libxfs/libxfs_io.h
+++ b/libxfs/libxfs_io.h
@@ -213,9 +213,6 @@ extern void	libxfs_bcache_flush(void);
 extern int	libxfs_bcache_overflowed(void);
 
 /* Buffer (Raw) Interfaces */
-extern xfs_buf_t *libxfs_getbufr(struct xfs_buftarg *, xfs_daddr_t, int);
-extern void	libxfs_putbufr(xfs_buf_t *);
-
 int		libxfs_bwrite(struct xfs_buf *bp);
 extern int	libxfs_readbufr(struct xfs_buftarg *, xfs_daddr_t, xfs_buf_t *, int, int);
 extern int	libxfs_readbufr_map(struct xfs_buftarg *, struct xfs_buf *, int);
diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index 29c9dd68..e46f749c 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -21,6 +21,8 @@
 
 #include "libxfs.h"
 
+static void libxfs_brelse(struct cache_node *node);
+
 /*
  * Important design/architecture note:
  *
@@ -430,7 +432,7 @@ __libxfs_getbufr(int blen)
 	return bp;
 }
 
-xfs_buf_t *
+static xfs_buf_t *
 libxfs_getbufr(struct xfs_buftarg *btp, xfs_daddr_t blkno, int bblen)
 {
 	xfs_buf_t	*bp;
@@ -634,8 +636,11 @@ libxfs_buf_relse(
 
 	if (!list_empty(&bp->b_node.cn_hash))
 		cache_node_put(libxfs_bcache, &bp->b_node);
-	else if (--bp->b_node.cn_count == 0)
-		libxfs_putbufr(bp);
+	else if (--bp->b_node.cn_count == 0) {
+		if (bp->b_flags & LIBXFS_B_DIRTY)
+			libxfs_bwrite(bp);
+		libxfs_brelse(&bp->b_node);
+	}
 }
 
 static struct cache_node *
@@ -1120,15 +1125,6 @@ libxfs_bflush(
 	return bp->b_error;
 }
 
-void
-libxfs_putbufr(xfs_buf_t *bp)
-{
-	if (bp->b_flags & LIBXFS_B_DIRTY)
-		libxfs_bwrite(bp);
-	libxfs_brelse(&bp->b_node);
-}
-
-
 void
 libxfs_bcache_purge(void)
 {


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 23/25] libxfs: hide libxfs_getbuf_flags
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
                   ` (21 preceding siblings ...)
  2020-02-25  0:13 ` [PATCH 22/25] libxfs: remove the libxfs_{get,put}bufr APIs Darrick J. Wong
@ 2020-02-25  0:13 ` Darrick J. Wong
  2020-02-25  0:14 ` [PATCH 24/25] libxfs: rename libxfs_readbuf_map to libxfs_buf_read_map Darrick J. Wong
  2020-02-25  0:14 ` [PATCH 25/25] libxfs: rename libxfs_getbuf_map to libxfs_buf_get_map Darrick J. Wong
  24 siblings, 0 replies; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:13 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs, Christoph Hellwig

From: Darrick J. Wong <darrick.wong@oracle.com>

Hide this function since it's internal to rdwr.c.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 libxfs/libxfs_io.h |    7 -------
 libxfs/rdwr.c      |   21 ++++++---------------
 2 files changed, 6 insertions(+), 22 deletions(-)


diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h
index c69eea97..7f513d86 100644
--- a/libxfs/libxfs_io.h
+++ b/libxfs/libxfs_io.h
@@ -144,9 +144,6 @@ extern struct cache_operations	libxfs_bcache_operations;
 #define libxfs_getbuf_map(dev, map, nmaps, flags) \
 	libxfs_trace_getbuf_map(__FUNCTION__, __FILE__, __LINE__, \
 			    (dev), (map), (nmaps), (flags))
-#define libxfs_getbuf_flags(dev, daddr, len, flags) \
-	libxfs_trace_getbuf_flags(__FUNCTION__, __FILE__, __LINE__, \
-			    (dev), (daddr), (len), (flags))
 #define libxfs_buf_relse(buf) \
 	libxfs_trace_putbuf(__FUNCTION__, __FILE__, __LINE__, (buf))
 
@@ -163,8 +160,6 @@ struct xfs_buf *libxfs_trace_getbuf(const char *func, const char *file,
 			size_t len);
 extern xfs_buf_t *libxfs_trace_getbuf_map(const char *, const char *, int,
 			struct xfs_buftarg *, struct xfs_buf_map *, int, int);
-extern xfs_buf_t *libxfs_trace_getbuf_flags(const char *, const char *, int,
-			struct xfs_buftarg *, xfs_daddr_t, int, unsigned int);
 extern void	libxfs_trace_putbuf (const char *, const char *, int,
 			xfs_buf_t *);
 
@@ -175,8 +170,6 @@ extern xfs_buf_t *libxfs_readbuf_map(struct xfs_buftarg *, struct xfs_buf_map *,
 void libxfs_buf_mark_dirty(struct xfs_buf *bp);
 extern xfs_buf_t *libxfs_getbuf_map(struct xfs_buftarg *,
 			struct xfs_buf_map *, int, int);
-extern xfs_buf_t *libxfs_getbuf_flags(struct xfs_buftarg *, xfs_daddr_t,
-			int, unsigned int);
 void	libxfs_buf_relse(struct xfs_buf *bp);
 
 static inline struct xfs_buf*
diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index e46f749c..4b33c20d 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -150,7 +150,6 @@ static char *next(
 #undef libxfs_readbuf_map
 #undef libxfs_writebuf
 #undef libxfs_getbuf_map
-#undef libxfs_getbuf_flags
 
 xfs_buf_t	*libxfs_readbuf_map(struct xfs_buftarg *, struct xfs_buf_map *,
 				int, int, const struct xfs_buf_ops *);
@@ -159,8 +158,6 @@ struct xfs_buf *libxfs_buf_get(struct xfs_buftarg *btp, xfs_daddr_t daddr,
 				size_t len);
 xfs_buf_t	*libxfs_getbuf_map(struct xfs_buftarg *, struct xfs_buf_map *,
 				int, int);
-xfs_buf_t	*libxfs_getbuf_flags(struct xfs_buftarg *, xfs_daddr_t, int,
-				unsigned int);
 void		libxfs_buf_relse(struct xfs_buf *bp);
 
 #define	__add_trace(bp, func, file, line)	\
@@ -229,15 +226,6 @@ libxfs_trace_getbuf_map(const char *func, const char *file, int line,
 	return bp;
 }
 
-xfs_buf_t *
-libxfs_trace_getbuf_flags(const char *func, const char *file, int line,
-		struct xfs_buftarg *btp, xfs_daddr_t blkno, int len, unsigned int flags)
-{
-	xfs_buf_t	*bp = libxfs_getbuf_flags(btp, blkno, len, flags);
-	__add_trace(bp, func, file, line);
-	return bp;
-}
-
 void
 libxfs_trace_putbuf(const char *func, const char *file, int line, xfs_buf_t *bp)
 {
@@ -542,9 +530,12 @@ __cache_lookup(struct xfs_bufkey *key, unsigned int flags)
 	return NULL;
 }
 
-struct xfs_buf *
-libxfs_getbuf_flags(struct xfs_buftarg *btp, xfs_daddr_t blkno, int len,
-		unsigned int flags)
+static struct xfs_buf *
+libxfs_getbuf_flags(
+	struct xfs_buftarg	*btp,
+	xfs_daddr_t		blkno,
+	int			len,
+	unsigned int		flags)
 {
 	struct xfs_bufkey key = {NULL};
 


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 24/25] libxfs: rename libxfs_readbuf_map to libxfs_buf_read_map
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
                   ` (22 preceding siblings ...)
  2020-02-25  0:13 ` [PATCH 23/25] libxfs: hide libxfs_getbuf_flags Darrick J. Wong
@ 2020-02-25  0:14 ` Darrick J. Wong
  2020-02-25  0:14 ` [PATCH 25/25] libxfs: rename libxfs_getbuf_map to libxfs_buf_get_map Darrick J. Wong
  24 siblings, 0 replies; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:14 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs, Christoph Hellwig

From: Darrick J. Wong <darrick.wong@oracle.com>

Rename this function to match the kernel function.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 db/io.c            |    2 +-
 libxfs/libxfs_io.h |    9 +++++----
 libxfs/rdwr.c      |   11 ++++++-----
 libxfs/trans.c     |    4 ++--
 repair/da_util.c   |    2 +-
 5 files changed, 15 insertions(+), 13 deletions(-)


diff --git a/db/io.c b/db/io.c
index 7c7a4624..b81e9969 100644
--- a/db/io.c
+++ b/db/io.c
@@ -542,7 +542,7 @@ set_cur(
 		if (!iocur_top->bbmap)
 			return;
 		memcpy(iocur_top->bbmap, bbmap, sizeof(struct bbmap));
-		bp = libxfs_readbuf_map(mp->m_ddev_targp, bbmap->b,
+		bp = libxfs_buf_read_map(mp->m_ddev_targp, bbmap->b,
 					bbmap->nmaps, 0, ops);
 	} else {
 		bp = libxfs_buf_read(mp->m_ddev_targp, blknum, len, 0, ops);
diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h
index 7f513d86..62b09205 100644
--- a/libxfs/libxfs_io.h
+++ b/libxfs/libxfs_io.h
@@ -132,7 +132,7 @@ extern struct cache_operations	libxfs_bcache_operations;
 #define libxfs_buf_read(dev, daddr, len, flags, ops) \
 	libxfs_trace_readbuf(__FUNCTION__, __FILE__, __LINE__, \
 			    (dev), (daddr), (len), (flags), (ops))
-#define libxfs_readbuf_map(dev, map, nmaps, flags, ops) \
+#define libxfs_buf_read_map(dev, map, nmaps, flags, ops) \
 	libxfs_trace_readbuf_map(__FUNCTION__, __FILE__, __LINE__, \
 			    (dev), (map), (nmaps), (flags), (ops))
 #define libxfs_buf_mark_dirty(buf) \
@@ -165,8 +165,9 @@ extern void	libxfs_trace_putbuf (const char *, const char *, int,
 
 #else
 
-extern xfs_buf_t *libxfs_readbuf_map(struct xfs_buftarg *, struct xfs_buf_map *,
-			int, int, const struct xfs_buf_ops *);
+struct xfs_buf *libxfs_buf_read_map(struct xfs_buftarg *btp,
+			struct xfs_buf_map *map, int nmaps, int flags,
+			const struct xfs_buf_ops *ops);
 void libxfs_buf_mark_dirty(struct xfs_buf *bp);
 extern xfs_buf_t *libxfs_getbuf_map(struct xfs_buftarg *,
 			struct xfs_buf_map *, int, int);
@@ -193,7 +194,7 @@ libxfs_buf_read(
 {
 	DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
 
-	return libxfs_readbuf_map(target, &map, 1, flags, ops);
+	return libxfs_buf_read_map(target, &map, 1, flags, ops);
 }
 
 #endif /* XFS_BUF_TRACING */
diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index 4b33c20d..7fc43743 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -147,12 +147,13 @@ static char *next(
 
 #ifdef XFS_BUF_TRACING
 
-#undef libxfs_readbuf_map
+#undef libxfs_buf_read_map
 #undef libxfs_writebuf
 #undef libxfs_getbuf_map
 
-xfs_buf_t	*libxfs_readbuf_map(struct xfs_buftarg *, struct xfs_buf_map *,
-				int, int, const struct xfs_buf_ops *);
+struct xfs_buf	*libxfs_buf_read_map(struct xfs_buftarg *btp,
+			struct xfs_buf_map *map, int nmaps, int flags,
+			const struct xfs_buf_ops *ops);
 int		libxfs_writebuf(xfs_buf_t *, int);
 struct xfs_buf *libxfs_buf_get(struct xfs_buftarg *btp, xfs_daddr_t daddr,
 				size_t len);
@@ -183,7 +184,7 @@ libxfs_trace_readbuf(
 	struct xfs_buf		*bp;
 	DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
 
-	bp = libxfs_readbuf_map(btp, &map, 1, flags, ops);
+	bp = libxfs_buf_read_map(btp, &map, 1, flags, ops);
 	__add_trace(bp, func, file, line);
 	return bp;
 }
@@ -789,7 +790,7 @@ libxfs_readbufr_map(struct xfs_buftarg *btp, struct xfs_buf *bp, int flags)
 }
 
 struct xfs_buf *
-libxfs_readbuf_map(struct xfs_buftarg *btp, struct xfs_buf_map *map, int nmaps,
+libxfs_buf_read_map(struct xfs_buftarg *btp, struct xfs_buf_map *map, int nmaps,
 		int flags, const struct xfs_buf_ops *ops)
 {
 	struct xfs_buf	*bp;
diff --git a/libxfs/trans.c b/libxfs/trans.c
index df1ec90b..ebdc73d5 100644
--- a/libxfs/trans.c
+++ b/libxfs/trans.c
@@ -507,7 +507,7 @@ libxfs_trans_read_buf_map(
 	*bpp = NULL;
 
 	if (tp == NULL) {
-		bp = libxfs_readbuf_map(target, map, nmaps, flags, ops);
+		bp = libxfs_buf_read_map(target, map, nmaps, flags, ops);
 		if (!bp) {
 			return (flags & XBF_TRYLOCK) ?  -EAGAIN : -ENOMEM;
 		}
@@ -526,7 +526,7 @@ libxfs_trans_read_buf_map(
 		goto done;
 	}
 
-	bp = libxfs_readbuf_map(target, map, nmaps, flags, ops);
+	bp = libxfs_buf_read_map(target, map, nmaps, flags, ops);
 	if (!bp) {
 		return (flags & XBF_TRYLOCK) ?  -EAGAIN : -ENOMEM;
 	}
diff --git a/repair/da_util.c b/repair/da_util.c
index dc1e5bfe..e639ecda 100644
--- a/repair/da_util.c
+++ b/repair/da_util.c
@@ -64,7 +64,7 @@ da_read_buf(
 		map[i].bm_bn = XFS_FSB_TO_DADDR(mp, bmp[i].startblock);
 		map[i].bm_len = XFS_FSB_TO_BB(mp, bmp[i].blockcount);
 	}
-	bp = libxfs_readbuf_map(mp->m_dev, map, nex, 0, ops);
+	bp = libxfs_buf_read_map(mp->m_dev, map, nex, 0, ops);
 	if (map != map_array)
 		free(map);
 	return bp;


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [PATCH 25/25] libxfs: rename libxfs_getbuf_map to libxfs_buf_get_map
  2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
                   ` (23 preceding siblings ...)
  2020-02-25  0:14 ` [PATCH 24/25] libxfs: rename libxfs_readbuf_map to libxfs_buf_read_map Darrick J. Wong
@ 2020-02-25  0:14 ` Darrick J. Wong
  24 siblings, 0 replies; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25  0:14 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs, Christoph Hellwig

From: Darrick J. Wong <darrick.wong@oracle.com>

Rename this function to match the kernel function.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 libxfs/libxfs_io.h |    8 ++++----
 libxfs/rdwr.c      |   18 +++++++++---------
 libxfs/trans.c     |    4 ++--
 repair/prefetch.c  |    2 +-
 4 files changed, 16 insertions(+), 16 deletions(-)


diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h
index 62b09205..957f0396 100644
--- a/libxfs/libxfs_io.h
+++ b/libxfs/libxfs_io.h
@@ -141,7 +141,7 @@ extern struct cache_operations	libxfs_bcache_operations;
 #define libxfs_buf_get(dev, daddr, len) \
 	libxfs_trace_getbuf(__FUNCTION__, __FILE__, __LINE__, \
 			    (dev), (daddr), (len))
-#define libxfs_getbuf_map(dev, map, nmaps, flags) \
+#define libxfs_buf_get_map(dev, map, nmaps, flags) \
 	libxfs_trace_getbuf_map(__FUNCTION__, __FILE__, __LINE__, \
 			    (dev), (map), (nmaps), (flags))
 #define libxfs_buf_relse(buf) \
@@ -169,8 +169,8 @@ struct xfs_buf *libxfs_buf_read_map(struct xfs_buftarg *btp,
 			struct xfs_buf_map *map, int nmaps, int flags,
 			const struct xfs_buf_ops *ops);
 void libxfs_buf_mark_dirty(struct xfs_buf *bp);
-extern xfs_buf_t *libxfs_getbuf_map(struct xfs_buftarg *,
-			struct xfs_buf_map *, int, int);
+struct xfs_buf *libxfs_buf_get_map(struct xfs_buftarg *btp,
+			struct xfs_buf_map *map, int nmaps, int flags);
 void	libxfs_buf_relse(struct xfs_buf *bp);
 
 static inline struct xfs_buf*
@@ -181,7 +181,7 @@ libxfs_buf_get(
 {
 	DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
 
-	return libxfs_getbuf_map(target, &map, 1, 0);
+	return libxfs_buf_get_map(target, &map, 1, 0);
 }
 
 static inline struct xfs_buf*
diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index 7fc43743..ce31e45d 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -149,7 +149,7 @@ static char *next(
 
 #undef libxfs_buf_read_map
 #undef libxfs_writebuf
-#undef libxfs_getbuf_map
+#undef libxfs_buf_get_map
 
 struct xfs_buf	*libxfs_buf_read_map(struct xfs_buftarg *btp,
 			struct xfs_buf_map *map, int nmaps, int flags,
@@ -157,8 +157,8 @@ struct xfs_buf	*libxfs_buf_read_map(struct xfs_buftarg *btp,
 int		libxfs_writebuf(xfs_buf_t *, int);
 struct xfs_buf *libxfs_buf_get(struct xfs_buftarg *btp, xfs_daddr_t daddr,
 				size_t len);
-xfs_buf_t	*libxfs_getbuf_map(struct xfs_buftarg *, struct xfs_buf_map *,
-				int, int);
+struct xfs_buf	*libxfs_buf_get_map(struct xfs_buftarg *btp,
+			struct xfs_buf_map *map, int nmaps, int flags);
 void		libxfs_buf_relse(struct xfs_buf *bp);
 
 #define	__add_trace(bp, func, file, line)	\
@@ -212,7 +212,7 @@ libxfs_trace_getbuf(
 	struct xfs_buf		*bp;
 	DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
 
-	bp = libxfs_getbuf_map(target, &map, 1, 0);
+	bp = libxfs_buf_get_map(target, &map, 1, 0);
 	__add_trace(bp, func, file, line);
 	return bp;
 }
@@ -222,7 +222,7 @@ libxfs_trace_getbuf_map(const char *func, const char *file, int line,
 		struct xfs_buftarg *btp, struct xfs_buf_map *map, int nmaps,
 		int flags)
 {
-	xfs_buf_t	*bp = libxfs_getbuf_map(btp, map, nmaps, flags);
+	xfs_buf_t	*bp = libxfs_buf_get_map(btp, map, nmaps, flags);
 	__add_trace(bp, func, file, line);
 	return bp;
 }
@@ -568,7 +568,7 @@ reset_buf_state(
 }
 
 static struct xfs_buf *
-__libxfs_getbuf_map(struct xfs_buftarg *btp, struct xfs_buf_map *map,
+__libxfs_buf_get_map(struct xfs_buftarg *btp, struct xfs_buf_map *map,
 		    int nmaps, int flags)
 {
 	struct xfs_bufkey key = {NULL};
@@ -590,12 +590,12 @@ __libxfs_getbuf_map(struct xfs_buftarg *btp, struct xfs_buf_map *map,
 }
 
 struct xfs_buf *
-libxfs_getbuf_map(struct xfs_buftarg *btp, struct xfs_buf_map *map,
+libxfs_buf_get_map(struct xfs_buftarg *btp, struct xfs_buf_map *map,
 		  int nmaps, int flags)
 {
 	struct xfs_buf	*bp;
 
-	bp = __libxfs_getbuf_map(btp, map, nmaps, flags);
+	bp = __libxfs_buf_get_map(btp, map, nmaps, flags);
 	reset_buf_state(bp);
 	return bp;
 }
@@ -800,7 +800,7 @@ libxfs_buf_read_map(struct xfs_buftarg *btp, struct xfs_buf_map *map, int nmaps,
 		return libxfs_readbuf(btp, map[0].bm_bn, map[0].bm_len,
 					flags, ops);
 
-	bp = __libxfs_getbuf_map(btp, map, nmaps, 0);
+	bp = __libxfs_buf_get_map(btp, map, nmaps, 0);
 	if (!bp)
 		return NULL;
 
diff --git a/libxfs/trans.c b/libxfs/trans.c
index ebdc73d5..b78bca86 100644
--- a/libxfs/trans.c
+++ b/libxfs/trans.c
@@ -427,7 +427,7 @@ libxfs_trans_get_buf_map(
 	struct xfs_buf_log_item	*bip;
 
 	if (!tp)
-		return libxfs_getbuf_map(target, map, nmaps, 0);
+		return libxfs_buf_get_map(target, map, nmaps, 0);
 
 	/*
 	 * If we find the buffer in the cache with this transaction
@@ -445,7 +445,7 @@ libxfs_trans_get_buf_map(
 		return bp;
 	}
 
-	bp = libxfs_getbuf_map(target, map, nmaps, 0);
+	bp = libxfs_buf_get_map(target, map, nmaps, 0);
 	if (bp == NULL) {
 		return NULL;
 	}
diff --git a/repair/prefetch.c b/repair/prefetch.c
index a3858f9a..7f705cc0 100644
--- a/repair/prefetch.c
+++ b/repair/prefetch.c
@@ -120,7 +120,7 @@ pf_queue_io(
 	 * the lock holder is either reading it from disk himself or
 	 * completely overwriting it this behaviour is perfectly fine.
 	 */
-	bp = libxfs_getbuf_map(mp->m_dev, map, nmaps, LIBXFS_GETBUF_TRYLOCK);
+	bp = libxfs_buf_get_map(mp->m_dev, map, nmaps, LIBXFS_GETBUF_TRYLOCK);
 	if (!bp)
 		return;
 


^ permalink raw reply related	[flat|nested] 49+ messages in thread

* Re: [PATCH 01/25] libxfs: open-code "exit on buffer read failure" in upper level callers
  2020-02-25  0:11 ` [PATCH 01/25] libxfs: open-code "exit on buffer read failure" in upper level callers Darrick J. Wong
@ 2020-02-25 17:42   ` Christoph Hellwig
  2020-02-25 18:40     ` Darrick J. Wong
  2020-02-25 19:26   ` [PATCH v2 " Darrick J. Wong
  1 sibling, 1 reply; 49+ messages in thread
From: Christoph Hellwig @ 2020-02-25 17:42 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: sandeen, linux-xfs

On Mon, Feb 24, 2020 at 04:11:34PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Make all functions that use LIBXFS_EXIT_ON_FAILURE to abort on buffer
> read errors implement that logic themselves.  This also removes places
> where libxfs can abort the program with no warning.

How are the libxfs_mount changes related to this commit message?

All the other bits looks fine, but those changes seem to have slipt in
without a good reason.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 02/25] libxfs: remove LIBXFS_EXIT_ON_FAILURE
  2020-02-25  0:11 ` [PATCH 02/25] libxfs: remove LIBXFS_EXIT_ON_FAILURE Darrick J. Wong
@ 2020-02-25 17:43   ` Christoph Hellwig
  0 siblings, 0 replies; 49+ messages in thread
From: Christoph Hellwig @ 2020-02-25 17:43 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: sandeen, linux-xfs

On Mon, Feb 24, 2020 at 04:11:42PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Now that the read-side users of LIBXFS_EXIT_ON_FAILURE are gone and the
> only write-side callers are in mkfs which now checks for buffer write
> failures, get rid of LIBXFS_EXIT_ON_FAILURE.

Looks good,

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

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 03/25] libxfs: remove LIBXFS_B_EXIT
  2020-02-25  0:11 ` [PATCH 03/25] libxfs: remove LIBXFS_B_EXIT Darrick J. Wong
@ 2020-02-25 17:43   ` Christoph Hellwig
  0 siblings, 0 replies; 49+ messages in thread
From: Christoph Hellwig @ 2020-02-25 17:43 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: sandeen, linux-xfs

On Mon, Feb 24, 2020 at 04:11:48PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Now that we've removed all users of LIBXFS_B_EXIT, remove it as well.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

Looks good,

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

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 07/25] libxfs: rename libxfs_writebufr to libxfs_bwrite
  2020-02-25  0:12 ` [PATCH 07/25] libxfs: rename libxfs_writebufr to libxfs_bwrite Darrick J. Wong
@ 2020-02-25 17:44   ` Christoph Hellwig
  0 siblings, 0 replies; 49+ messages in thread
From: Christoph Hellwig @ 2020-02-25 17:44 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: sandeen, linux-xfs

On Mon, Feb 24, 2020 at 04:12:13PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Rename this function so that we have an API that matches the kernel
> without a #define.

Looks good,

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

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 10/25] libxfs: introduce libxfs_buf_read_uncached
  2020-02-25  0:12 ` [PATCH 10/25] libxfs: introduce libxfs_buf_read_uncached Darrick J. Wong
@ 2020-02-25 17:44   ` Christoph Hellwig
  0 siblings, 0 replies; 49+ messages in thread
From: Christoph Hellwig @ 2020-02-25 17:44 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: sandeen, linux-xfs

On Mon, Feb 24, 2020 at 04:12:31PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Introduce an uncached read function so that userspace can handle them in
> the same way as the kernel.  This also eliminates the need for some of
> the libxfs_purgebuf calls (and two trips into the cache code).
> 
> Refactor the get/read uncached buffer functions to hide the details of
> uncached buffer-ism in rdwr.c.

Looks good,

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

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 11/25] xfs_db: use uncached buffer reads to get the superblock
  2020-02-25  0:12 ` [PATCH 11/25] xfs_db: use uncached buffer reads to get the superblock Darrick J. Wong
@ 2020-02-25 17:45   ` Christoph Hellwig
  0 siblings, 0 replies; 49+ messages in thread
From: Christoph Hellwig @ 2020-02-25 17:45 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: sandeen, linux-xfs

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>

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 12/25] xfs_copy: use uncached buffer reads to get the superblock
  2020-02-25  0:12 ` [PATCH 12/25] xfs_copy: " Darrick J. Wong
@ 2020-02-25 17:45   ` Christoph Hellwig
  0 siblings, 0 replies; 49+ messages in thread
From: Christoph Hellwig @ 2020-02-25 17:45 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: sandeen, linux-xfs

On Mon, Feb 24, 2020 at 04:12:44PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> 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>

Looks good,

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

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 13/25] libxfs: move log functions for convenience
  2020-02-25  0:12 ` [PATCH 13/25] libxfs: move log functions for convenience Darrick J. Wong
@ 2020-02-25 17:47   ` Christoph Hellwig
  2020-02-25 18:47     ` Darrick J. Wong
  0 siblings, 1 reply; 49+ messages in thread
From: Christoph Hellwig @ 2020-02-25 17:47 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: sandeen, linux-xfs

On Mon, Feb 24, 2020 at 04:12:50PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Move libxfs_log_clear and libxfs_log_header to the bottom of the file so
> that we avoid having to create advance declarations of static functions
> in the next patch.  No functional changes.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

I'd be tempted to in fact just move them into a separate file, unless
that would mean marking too many functions non-static as none of this
is related to the normal read/write code.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 14/25] libxfs: convert libxfs_log_clear to use uncached buffers
  2020-02-25  0:12 ` [PATCH 14/25] libxfs: convert libxfs_log_clear to use uncached buffers Darrick J. Wong
@ 2020-02-25 17:49   ` Christoph Hellwig
  2020-02-25 18:48     ` Darrick J. Wong
  0 siblings, 1 reply; 49+ messages in thread
From: Christoph Hellwig @ 2020-02-25 17:49 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: sandeen, linux-xfs

On Mon, Feb 24, 2020 at 04:12:56PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Convert the log clearing function to use uncached buffers like
> everything else, instead of using the raw buffer get/put functions.
> This will eventually enable us to hide them more effectively.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>  libxfs/rdwr.c |   16 ++++++----------
>  1 file changed, 6 insertions(+), 10 deletions(-)
> 
> 
> diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
> index d607a565..739f4aed 100644
> --- a/libxfs/rdwr.c
> +++ b/libxfs/rdwr.c
> @@ -1413,15 +1413,13 @@ libxfs_log_clear(
>  	/* write out the first log record */
>  	ptr = dptr;
>  	if (btp) {
> -		bp = libxfs_getbufr(btp, start, len);
> +		bp = libxfs_getbufr_uncached(btp, start, len);

Any reason this isn't using the public libxfs_buf_get_uncached
function?  Yes, that requires setting up the address, but it avoids
a dependency on internal helpers.

And I think we should add initializing the block, zeroing the buffer
and setting up ops into (lib)xfs_buf_get_uncached, basically moving
most of xfs_get_aghdr_buf into and improve the API eventually.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 15/25] libxlog: use uncached buffers instead of open-coding them
  2020-02-25  0:13 ` [PATCH 15/25] libxlog: use uncached buffers instead of open-coding them Darrick J. Wong
@ 2020-02-25 17:50   ` Christoph Hellwig
  0 siblings, 0 replies; 49+ messages in thread
From: Christoph Hellwig @ 2020-02-25 17:50 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: sandeen, linux-xfs

On Mon, Feb 24, 2020 at 04:13:04PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Use the new uncached buffer functions to manage buffers instead of
> open-coding the logic.

Looks good,

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

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 17/25] libxfs: straighten out libxfs_writebuf naming confusion
  2020-02-25  0:13 ` [PATCH 17/25] libxfs: straighten out libxfs_writebuf naming confusion Darrick J. Wong
@ 2020-02-25 17:50   ` Christoph Hellwig
  0 siblings, 0 replies; 49+ messages in thread
From: Christoph Hellwig @ 2020-02-25 17:50 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: sandeen, linux-xfs

On Mon, Feb 24, 2020 at 04:13:16PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> libxfs_writebuf is not a well named function -- it marks the buffer
> dirty and then releases the caller's reference.  The actual write comes
> when the cache is flushed, either because someone explicitly told the
> cache to flush or because we started buffer reclaim.
> 
> Make the buffer release explicit in the callers and rename the function
> to say what it actually does -- it marks the buffer dirty outside of
> transaction context.

Looks good,

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

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 18/25] libxfs: remove unused flags parameter to libxfs_buf_mark_dirty
  2020-02-25  0:13 ` [PATCH 18/25] libxfs: remove unused flags parameter to libxfs_buf_mark_dirty Darrick J. Wong
@ 2020-02-25 17:51   ` Christoph Hellwig
  2020-02-25 18:52     ` Darrick J. Wong
  0 siblings, 1 reply; 49+ messages in thread
From: Christoph Hellwig @ 2020-02-25 17:51 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: sandeen, linux-xfs

On Mon, Feb 24, 2020 at 04:13:23PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Nobody uses the flags parameter, so get rid of it.

Looks good, but wouldn't it make sense to fold this into the previous
patch instead of modifying all callers twice?

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

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 20/25] libxfs: remove dangerous casting between xfs_buf and cache_node
  2020-02-25  0:13 ` [PATCH 20/25] libxfs: remove dangerous casting between xfs_buf and cache_node Darrick J. Wong
@ 2020-02-25 17:52   ` Christoph Hellwig
  2020-02-25 18:52     ` Darrick J. Wong
  0 siblings, 1 reply; 49+ messages in thread
From: Christoph Hellwig @ 2020-02-25 17:52 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: sandeen, linux-xfs

>  #define XFS_BUF_SET_PRIORITY(bp,pri)	cache_node_set_priority( \
>  						libxfs_bcache, \
> -						(struct cache_node *)(bp), \
> +						&(bp)->b_node, \
>  						(pri))

I think this one would benefit from being turned into an inline
function..

Otherwise looks good:

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

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 21/25] libxfs: remove dangerous casting between cache_node and xfs_buf
  2020-02-25  0:13 ` [PATCH 21/25] libxfs: remove dangerous casting between cache_node and xfs_buf Darrick J. Wong
@ 2020-02-25 17:52   ` Christoph Hellwig
  0 siblings, 0 replies; 49+ messages in thread
From: Christoph Hellwig @ 2020-02-25 17:52 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: sandeen, linux-xfs

On Mon, Feb 24, 2020 at 04:13:42PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Get rid of all the dangerous casting between cache_node and xfs_buf
> since we can use container_of now.

Looks good,

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

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 22/25] libxfs: remove the libxfs_{get,put}bufr APIs
  2020-02-25  0:13 ` [PATCH 22/25] libxfs: remove the libxfs_{get,put}bufr APIs Darrick J. Wong
@ 2020-02-25 17:52   ` Christoph Hellwig
  0 siblings, 0 replies; 49+ messages in thread
From: Christoph Hellwig @ 2020-02-25 17:52 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: sandeen, linux-xfs

On Mon, Feb 24, 2020 at 04:13:48PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Hide libxfs_getbufr since nobody should be using the internal function,
> and fold libxfs_putbufr into its only caller.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

Looks good,

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

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 01/25] libxfs: open-code "exit on buffer read failure" in upper level callers
  2020-02-25 17:42   ` Christoph Hellwig
@ 2020-02-25 18:40     ` Darrick J. Wong
  2020-02-25 18:42       ` Christoph Hellwig
  0 siblings, 1 reply; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25 18:40 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: sandeen, linux-xfs

On Tue, Feb 25, 2020 at 09:42:52AM -0800, Christoph Hellwig wrote:
> On Mon, Feb 24, 2020 at 04:11:34PM -0800, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > Make all functions that use LIBXFS_EXIT_ON_FAILURE to abort on buffer
> > read errors implement that logic themselves.  This also removes places
> > where libxfs can abort the program with no warning.
> 
> How are the libxfs_mount changes related to this commit message?
> 
> All the other bits looks fine, but those changes seem to have slipt in
> without a good reason.

Prior to this patch, the "!(flags & DEBUGGER)" expressions in the call
sites evaluate to 0 or 1, and this effectively results in libxfs_mount
passing EXIT_ON_FAILURE to the buffer read functions as the flag value.
The flag value is passed all the way down to __read_buf, and when it
sees an IO failure, it exits.

After this patch, libxfs_mount passes flags==0, which means that we get
a buffer back, possibly with b_error set.  If b_error is set, we log a
warning about the screwed up filesystem and return a null mount if the
libxfs_mount caller didn't indicate that it is a debugger.  Presumably
the libxfs_mount caller will exit with error if we return a null mount.

IOWs, I'm doing exactly what the commit message says, but in a rather
subtle way.  I'll clarify that, if you'd like.

--D

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 01/25] libxfs: open-code "exit on buffer read failure" in upper level callers
  2020-02-25 18:40     ` Darrick J. Wong
@ 2020-02-25 18:42       ` Christoph Hellwig
  2020-02-25 19:19         ` Darrick J. Wong
  0 siblings, 1 reply; 49+ messages in thread
From: Christoph Hellwig @ 2020-02-25 18:42 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: Christoph Hellwig, sandeen, linux-xfs

On Tue, Feb 25, 2020 at 10:40:23AM -0800, Darrick J. Wong wrote:
> Prior to this patch, the "!(flags & DEBUGGER)" expressions in the call
> sites evaluate to 0 or 1, and this effectively results in libxfs_mount
> passing EXIT_ON_FAILURE to the buffer read functions as the flag value.
> The flag value is passed all the way down to __read_buf, and when it
> sees an IO failure, it exits.
> 
> After this patch, libxfs_mount passes flags==0, which means that we get
> a buffer back, possibly with b_error set.  If b_error is set, we log a
> warning about the screwed up filesystem and return a null mount if the
> libxfs_mount caller didn't indicate that it is a debugger.  Presumably
> the libxfs_mount caller will exit with error if we return a null mount.
> 
> IOWs, I'm doing exactly what the commit message says, but in a rather
> subtle way.  I'll clarify that, if you'd like.

Ok, with a proper commit message this looks good to me:

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

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 13/25] libxfs: move log functions for convenience
  2020-02-25 17:47   ` Christoph Hellwig
@ 2020-02-25 18:47     ` Darrick J. Wong
  0 siblings, 0 replies; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25 18:47 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: sandeen, linux-xfs

On Tue, Feb 25, 2020 at 09:47:12AM -0800, Christoph Hellwig wrote:
> On Mon, Feb 24, 2020 at 04:12:50PM -0800, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > Move libxfs_log_clear and libxfs_log_header to the bottom of the file so
> > that we avoid having to create advance declarations of static functions
> > in the next patch.  No functional changes.
> > 
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> 
> I'd be tempted to in fact just move them into a separate file, unless
> that would mean marking too many functions non-static as none of this
> is related to the normal read/write code.

<shrug> I wonder why not just move this whole thing to libxlog and
rewire it to do its own IOs (like the kernel xfs log does now) but this
series is already too long and that seems like its own neat cleanup...

--D

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 14/25] libxfs: convert libxfs_log_clear to use uncached buffers
  2020-02-25 17:49   ` Christoph Hellwig
@ 2020-02-25 18:48     ` Darrick J. Wong
  0 siblings, 0 replies; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25 18:48 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: sandeen, linux-xfs

On Tue, Feb 25, 2020 at 09:49:41AM -0800, Christoph Hellwig wrote:
> On Mon, Feb 24, 2020 at 04:12:56PM -0800, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > Convert the log clearing function to use uncached buffers like
> > everything else, instead of using the raw buffer get/put functions.
> > This will eventually enable us to hide them more effectively.
> > 
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> >  libxfs/rdwr.c |   16 ++++++----------
> >  1 file changed, 6 insertions(+), 10 deletions(-)
> > 
> > 
> > diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
> > index d607a565..739f4aed 100644
> > --- a/libxfs/rdwr.c
> > +++ b/libxfs/rdwr.c
> > @@ -1413,15 +1413,13 @@ libxfs_log_clear(
> >  	/* write out the first log record */
> >  	ptr = dptr;
> >  	if (btp) {
> > -		bp = libxfs_getbufr(btp, start, len);
> > +		bp = libxfs_getbufr_uncached(btp, start, len);
> 
> Any reason this isn't using the public libxfs_buf_get_uncached
> function?  Yes, that requires setting up the address, but it avoids
> a dependency on internal helpers.
> 
> And I think we should add initializing the block, zeroing the buffer
> and setting up ops into (lib)xfs_buf_get_uncached, basically moving
> most of xfs_get_aghdr_buf into and improve the API eventually.

We can certainly do that for kernel 5.7, but please keep in mind that
we're currently reviewing changes for xfsprogs 5.6, and it's too late in
the kernel 5.6 cycle to be messing around with core xfs apis.

--D

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 20/25] libxfs: remove dangerous casting between xfs_buf and cache_node
  2020-02-25 17:52   ` Christoph Hellwig
@ 2020-02-25 18:52     ` Darrick J. Wong
  0 siblings, 0 replies; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25 18:52 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: sandeen, linux-xfs

On Tue, Feb 25, 2020 at 09:52:16AM -0800, Christoph Hellwig wrote:
> >  #define XFS_BUF_SET_PRIORITY(bp,pri)	cache_node_set_priority( \
> >  						libxfs_bcache, \
> > -						(struct cache_node *)(bp), \
> > +						&(bp)->b_node, \
> >  						(pri))
> 
> I think this one would benefit from being turned into an inline
> function..

Yeah, probably both of those.

--D

> Otherwise looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 18/25] libxfs: remove unused flags parameter to libxfs_buf_mark_dirty
  2020-02-25 17:51   ` Christoph Hellwig
@ 2020-02-25 18:52     ` Darrick J. Wong
  0 siblings, 0 replies; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25 18:52 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: sandeen, linux-xfs

On Tue, Feb 25, 2020 at 09:51:07AM -0800, Christoph Hellwig wrote:
> On Mon, Feb 24, 2020 at 04:13:23PM -0800, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > Nobody uses the flags parameter, so get rid of it.
> 
> Looks good, but wouldn't it make sense to fold this into the previous
> patch instead of modifying all callers twice?

I'll ask Eric if he prefers it this way or combined.  Or I guess you
could, if you run into him later today. ;)

--D

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

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [PATCH 01/25] libxfs: open-code "exit on buffer read failure" in upper level callers
  2020-02-25 18:42       ` Christoph Hellwig
@ 2020-02-25 19:19         ` Darrick J. Wong
  0 siblings, 0 replies; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25 19:19 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: sandeen, linux-xfs

On Tue, Feb 25, 2020 at 10:42:40AM -0800, Christoph Hellwig wrote:
> On Tue, Feb 25, 2020 at 10:40:23AM -0800, Darrick J. Wong wrote:
> > Prior to this patch, the "!(flags & DEBUGGER)" expressions in the call
> > sites evaluate to 0 or 1, and this effectively results in libxfs_mount
> > passing EXIT_ON_FAILURE to the buffer read functions as the flag value.
> > The flag value is passed all the way down to __read_buf, and when it
> > sees an IO failure, it exits.
> > 
> > After this patch, libxfs_mount passes flags==0, which means that we get
> > a buffer back, possibly with b_error set.  If b_error is set, we log a
> > warning about the screwed up filesystem and return a null mount if the
> > libxfs_mount caller didn't indicate that it is a debugger.  Presumably
> > the libxfs_mount caller will exit with error if we return a null mount.
> > 
> > IOWs, I'm doing exactly what the commit message says, but in a rather
> > subtle way.  I'll clarify that, if you'd like.
> 
> Ok, with a proper commit message this looks good to me:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>

The new commit message reads as follows:

"libxfs: open-code "exit on buffer read failure" in upper level callers

"Make all functions that use LIBXFS_EXIT_ON_FAILURE to abort on buffer
read errors implement that logic themselves.  This also removes places
where libxfs can abort the program with no warning.

"Note that in libxfs_mount, the "!(flags & DEBUGGER)" code would
indirectly select LIBXFS_EXIT_ON_FAILURE, so we're replacing the hidden
library exit(1) with a null xfs_mount return, which should cause the
utilities to exit with an error."

--D

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [PATCH v2 01/25] libxfs: open-code "exit on buffer read failure" in upper level callers
  2020-02-25  0:11 ` [PATCH 01/25] libxfs: open-code "exit on buffer read failure" in upper level callers Darrick J. Wong
  2020-02-25 17:42   ` Christoph Hellwig
@ 2020-02-25 19:26   ` Darrick J. Wong
  1 sibling, 0 replies; 49+ messages in thread
From: Darrick J. Wong @ 2020-02-25 19:26 UTC (permalink / raw)
  To: sandeen; +Cc: linux-xfs, Christoph Hellwig

From: Darrick J. Wong <darrick.wong@oracle.com>

Make all functions that use LIBXFS_EXIT_ON_FAILURE to abort on buffer
read errors implement that logic themselves.  This also removes places
where libxfs can abort the program with no warning.

Note that in libxfs_mount, the "!(flags & DEBUGGER)" code would
indirectly select LIBXFS_EXIT_ON_FAILURE, so we're replacing the hidden
library exit(1) with a null xfs_mount return, which should cause the
utilities to exit with an error.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
v2: improve commit message
---
 libxfs/init.c   |   40 ++++++++++++++++++++--------------------
 libxfs/rdwr.c   |    4 ----
 mkfs/xfs_mkfs.c |   16 ++++++++++++----
 3 files changed, 32 insertions(+), 28 deletions(-)

diff --git a/libxfs/init.c b/libxfs/init.c
index 913f546f..485ab8f8 100644
--- a/libxfs/init.c
+++ b/libxfs/init.c
@@ -639,19 +639,20 @@ libxfs_buftarg_init(
  * such that the numerous XFS_* macros can be used.  If dev is zero,
  * no IO will be performed (no size checks, read root inodes).
  */
-xfs_mount_t *
+struct xfs_mount *
 libxfs_mount(
-	xfs_mount_t	*mp,
-	xfs_sb_t	*sb,
-	dev_t		dev,
-	dev_t		logdev,
-	dev_t		rtdev,
-	int		flags)
+	struct xfs_mount	*mp,
+	struct xfs_sb		*sb,
+	dev_t			dev,
+	dev_t			logdev,
+	dev_t			rtdev,
+	int			flags)
 {
-	xfs_daddr_t	d;
-	xfs_buf_t	*bp;
-	xfs_sb_t	*sbp;
-	int		error;
+	struct xfs_buf		*bp;
+	struct xfs_sb		*sbp;
+	xfs_daddr_t		d;
+	bool			debugger = (flags & LIBXFS_MOUNT_DEBUGGER);
+	int			error;
 
 	libxfs_buftarg_init(mp, dev, logdev, rtdev);
 
@@ -728,12 +729,12 @@ libxfs_mount(
 	if (dev == 0)	/* maxtrres, we have no device so leave now */
 		return mp;
 
-	bp = libxfs_readbuf(mp->m_dev,
-			d - XFS_FSS_TO_BB(mp, 1), XFS_FSS_TO_BB(mp, 1),
-			!(flags & LIBXFS_MOUNT_DEBUGGER), NULL);
+	/* device size checks must pass unless we're a debugger. */
+	bp = libxfs_readbuf(mp->m_dev, d - XFS_FSS_TO_BB(mp, 1),
+			XFS_FSS_TO_BB(mp, 1), 0, NULL);
 	if (!bp) {
 		fprintf(stderr, _("%s: data size check failed\n"), progname);
-		if (!(flags & LIBXFS_MOUNT_DEBUGGER))
+		if (!debugger)
 			return NULL;
 	} else
 		libxfs_putbuf(bp);
@@ -744,11 +745,10 @@ libxfs_mount(
 		if ( (XFS_BB_TO_FSB(mp, d) != mp->m_sb.sb_logblocks) ||
 		     (!(bp = libxfs_readbuf(mp->m_logdev_targp,
 					d - XFS_FSB_TO_BB(mp, 1),
-					XFS_FSB_TO_BB(mp, 1),
-					!(flags & LIBXFS_MOUNT_DEBUGGER), NULL))) ) {
+					XFS_FSB_TO_BB(mp, 1), 0, NULL)))) {
 			fprintf(stderr, _("%s: log size checks failed\n"),
 					progname);
-			if (!(flags & LIBXFS_MOUNT_DEBUGGER))
+			if (!debugger)
 				return NULL;
 		}
 		if (bp)
@@ -772,11 +772,11 @@ libxfs_mount(
 	if (sbp->sb_agcount > 1000000) {
 		bp = libxfs_readbuf(mp->m_dev,
 				XFS_AG_DADDR(mp, sbp->sb_agcount - 1, 0), 1,
-				!(flags & LIBXFS_MOUNT_DEBUGGER), NULL);
+				0, NULL);
 		if (bp->b_error) {
 			fprintf(stderr, _("%s: read of AG %u failed\n"),
 						progname, sbp->sb_agcount);
-			if (!(flags & LIBXFS_MOUNT_DEBUGGER))
+			if (!debugger)
 				return NULL;
 			fprintf(stderr, _("%s: limiting reads to AG 0\n"),
 								progname);
diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index 4253b890..474fceb0 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -911,14 +911,10 @@ __read_buf(int fd, void *buf, int len, off64_t offset, int flags)
 		int error = errno;
 		fprintf(stderr, _("%s: read failed: %s\n"),
 			progname, strerror(error));
-		if (flags & LIBXFS_EXIT_ON_FAILURE)
-			exit(1);
 		return -error;
 	} else if (sts != len) {
 		fprintf(stderr, _("%s: error - read only %d of %d bytes\n"),
 			progname, sts, len);
-		if (flags & LIBXFS_EXIT_ON_FAILURE)
-			exit(1);
 		return -EIO;
 	}
 	return 0;
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 7f315d8a..3de73fc6 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -3576,8 +3576,12 @@ rewrite_secondary_superblocks(
 	buf = libxfs_readbuf(mp->m_dev,
 			XFS_AGB_TO_DADDR(mp, mp->m_sb.sb_agcount - 1,
 				XFS_SB_DADDR),
-			XFS_FSS_TO_BB(mp, 1),
-			LIBXFS_EXIT_ON_FAILURE, &xfs_sb_buf_ops);
+			XFS_FSS_TO_BB(mp, 1), 0, &xfs_sb_buf_ops);
+	if (!buf) {
+		fprintf(stderr, _("%s: could not re-read AG %u superblock\n"),
+				progname, mp->m_sb.sb_agcount - 1);
+		exit(1);
+	}
 	XFS_BUF_TO_SBP(buf)->sb_rootino = cpu_to_be64(mp->m_sb.sb_rootino);
 	libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
 
@@ -3588,8 +3592,12 @@ rewrite_secondary_superblocks(
 	buf = libxfs_readbuf(mp->m_dev,
 			XFS_AGB_TO_DADDR(mp, (mp->m_sb.sb_agcount - 1) / 2,
 				XFS_SB_DADDR),
-			XFS_FSS_TO_BB(mp, 1),
-			LIBXFS_EXIT_ON_FAILURE, &xfs_sb_buf_ops);
+			XFS_FSS_TO_BB(mp, 1), 0, &xfs_sb_buf_ops);
+	if (!buf) {
+		fprintf(stderr, _("%s: could not re-read AG %u superblock\n"),
+				progname, (mp->m_sb.sb_agcount - 1) / 2);
+		exit(1);
+	}
 	XFS_BUF_TO_SBP(buf)->sb_rootino = cpu_to_be64(mp->m_sb.sb_rootino);
 	libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
 }

^ permalink raw reply related	[flat|nested] 49+ messages in thread

end of thread, other threads:[~2020-02-25 19:27 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-25  0:11 [PATCH v2 00/25] xfsprogs: refactor buffer function names Darrick J. Wong
2020-02-25  0:11 ` [PATCH 01/25] libxfs: open-code "exit on buffer read failure" in upper level callers Darrick J. Wong
2020-02-25 17:42   ` Christoph Hellwig
2020-02-25 18:40     ` Darrick J. Wong
2020-02-25 18:42       ` Christoph Hellwig
2020-02-25 19:19         ` Darrick J. Wong
2020-02-25 19:26   ` [PATCH v2 " Darrick J. Wong
2020-02-25  0:11 ` [PATCH 02/25] libxfs: remove LIBXFS_EXIT_ON_FAILURE Darrick J. Wong
2020-02-25 17:43   ` Christoph Hellwig
2020-02-25  0:11 ` [PATCH 03/25] libxfs: remove LIBXFS_B_EXIT Darrick J. Wong
2020-02-25 17:43   ` Christoph Hellwig
2020-02-25  0:11 ` [PATCH 04/25] libxfs: replace libxfs_putbuf with libxfs_buf_relse Darrick J. Wong
2020-02-25  0:12 ` [PATCH 05/25] libxfs: replace libxfs_getbuf with libxfs_buf_get Darrick J. Wong
2020-02-25  0:12 ` [PATCH 06/25] libxfs: replace libxfs_readbuf with libxfs_buf_read Darrick J. Wong
2020-02-25  0:12 ` [PATCH 07/25] libxfs: rename libxfs_writebufr to libxfs_bwrite Darrick J. Wong
2020-02-25 17:44   ` Christoph Hellwig
2020-02-25  0:12 ` [PATCH 08/25] libxfs: make libxfs_readbuf_verify return an error code Darrick J. Wong
2020-02-25  0:12 ` [PATCH 09/25] libxfs: make libxfs_readbufr stash the error value in b_error Darrick J. Wong
2020-02-25  0:12 ` [PATCH 10/25] libxfs: introduce libxfs_buf_read_uncached Darrick J. Wong
2020-02-25 17:44   ` Christoph Hellwig
2020-02-25  0:12 ` [PATCH 11/25] xfs_db: use uncached buffer reads to get the superblock Darrick J. Wong
2020-02-25 17:45   ` Christoph Hellwig
2020-02-25  0:12 ` [PATCH 12/25] xfs_copy: " Darrick J. Wong
2020-02-25 17:45   ` Christoph Hellwig
2020-02-25  0:12 ` [PATCH 13/25] libxfs: move log functions for convenience Darrick J. Wong
2020-02-25 17:47   ` Christoph Hellwig
2020-02-25 18:47     ` Darrick J. Wong
2020-02-25  0:12 ` [PATCH 14/25] libxfs: convert libxfs_log_clear to use uncached buffers Darrick J. Wong
2020-02-25 17:49   ` Christoph Hellwig
2020-02-25 18:48     ` Darrick J. Wong
2020-02-25  0:13 ` [PATCH 15/25] libxlog: use uncached buffers instead of open-coding them Darrick J. Wong
2020-02-25 17:50   ` Christoph Hellwig
2020-02-25  0:13 ` [PATCH 16/25] libxfs: use uncached buffers for initial mkfs writes Darrick J. Wong
2020-02-25  0:13 ` [PATCH 17/25] libxfs: straighten out libxfs_writebuf naming confusion Darrick J. Wong
2020-02-25 17:50   ` Christoph Hellwig
2020-02-25  0:13 ` [PATCH 18/25] libxfs: remove unused flags parameter to libxfs_buf_mark_dirty Darrick J. Wong
2020-02-25 17:51   ` Christoph Hellwig
2020-02-25 18:52     ` Darrick J. Wong
2020-02-25  0:13 ` [PATCH 19/25] libxfs: remove libxfs_writebuf_int Darrick J. Wong
2020-02-25  0:13 ` [PATCH 20/25] libxfs: remove dangerous casting between xfs_buf and cache_node Darrick J. Wong
2020-02-25 17:52   ` Christoph Hellwig
2020-02-25 18:52     ` Darrick J. Wong
2020-02-25  0:13 ` [PATCH 21/25] libxfs: remove dangerous casting between cache_node and xfs_buf Darrick J. Wong
2020-02-25 17:52   ` Christoph Hellwig
2020-02-25  0:13 ` [PATCH 22/25] libxfs: remove the libxfs_{get,put}bufr APIs Darrick J. Wong
2020-02-25 17:52   ` Christoph Hellwig
2020-02-25  0:13 ` [PATCH 23/25] libxfs: hide libxfs_getbuf_flags Darrick J. Wong
2020-02-25  0:14 ` [PATCH 24/25] libxfs: rename libxfs_readbuf_map to libxfs_buf_read_map Darrick J. Wong
2020-02-25  0:14 ` [PATCH 25/25] libxfs: rename libxfs_getbuf_map to libxfs_buf_get_map Darrick J. Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).