diff mbox series

[12/18] libxfs: use uncached buffers for initial mkfs writes

Message ID 158216302984.602314.15196666031325406487.stgit@magnolia (mailing list archive)
State Superseded, archived
Headers show
Series xfsprogs: refactor buffer function names | expand

Commit Message

Darrick J. Wong Feb. 20, 2020, 1:43 a.m. UTC
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>
---
 libxfs/libxfs_io.h |    1 -
 libxfs/rdwr.c      |   12 ------------
 mkfs/xfs_mkfs.c    |   34 +++++++++++++++++++++++-----------
 3 files changed, 23 insertions(+), 24 deletions(-)

Comments

Christoph Hellwig Feb. 21, 2020, 2:51 p.m. UTC | #1
On Wed, Feb 19, 2020 at 05:43:49PM -0800, Darrick J. Wong wrote:
> +/* Prepare an uncached buffer, ready to write something out. */
> +static inline struct xfs_buf *
> +get_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;
> +}

I'd call this alloc_write_buf.

But the patch itself looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
Darrick J. Wong Feb. 21, 2020, 3:52 p.m. UTC | #2
On Fri, Feb 21, 2020 at 06:51:01AM -0800, Christoph Hellwig wrote:
> On Wed, Feb 19, 2020 at 05:43:49PM -0800, Darrick J. Wong wrote:
> > +/* Prepare an uncached buffer, ready to write something out. */
> > +static inline struct xfs_buf *
> > +get_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;
> > +}
> 
> I'd call this alloc_write_buf.

Agreed, will fix.

--D

> But the patch itself looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h
index 546b7710..6598dba7 100644
--- a/libxfs/libxfs_io.h
+++ b/libxfs/libxfs_io.h
@@ -213,7 +213,6 @@  struct xfs_buf *libxfs_getsb(struct xfs_mount *);
 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 ada20dd9..20a8b0ce 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -869,18 +869,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 9ca4cb1a..f58f235d 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 *
+get_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 = get_write_buf(mp->m_ddev_targp, (xi->dsize - whack_blks),
+			whack_blks);
 	memset(buf->b_addr, 0, WHACK_SIZE);
 	libxfs_writebuf(buf, LIBXFS_WRITEBUF_FAIL_EXIT);
-	libxfs_purgebuf(buf);
 
 	/*
 	 * Now zero out the beginning of the device, to obliterate any old
@@ -3456,18 +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 = get_write_buf(mp->m_ddev_targp, 0, whack_blks);
 	memset(buf->b_addr, 0, WHACK_SIZE);
 	libxfs_writebuf(buf, LIBXFS_WRITEBUF_FAIL_EXIT);
-	libxfs_purgebuf(buf);
 
 	/* OK, now write the superblock... */
-	buf = libxfs_buf_get(mp->m_ddev_targp, XFS_SB_DADDR, XFS_FSS_TO_BB(mp, 1));
+	buf = get_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, LIBXFS_WRITEBUF_FAIL_EXIT);
-	libxfs_purgebuf(buf);
 
 	/* ...and zero the log.... */
 	lsunit = sbp->sb_logsunit;
@@ -3482,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 = get_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, LIBXFS_WRITEBUF_FAIL_EXIT);
-		libxfs_purgebuf(buf);
 	}
 
 }