linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: sandeen@sandeen.net
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH v2 26/36] xfs_repair: refactor buffer ops assignments during phase 5
Date: Wed, 10 Apr 2019 08:25:54 -0700	[thread overview]
Message-ID: <20190410152554.GB1019523@magnolia> (raw)
In-Reply-To: <155259758961.31886.4826767055567611572.stgit@magnolia>

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

Refactor the buffer ops assignments in phase 5 to use a helper function
to determine the correct buf_ops instead of open-coding them.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
v2: convert all the ag btree types
---
 repair/phase5.c |   54 ++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 42 insertions(+), 12 deletions(-)

diff --git a/repair/phase5.c b/repair/phase5.c
index 367c3ab9..5d9c542a 100644
--- a/repair/phase5.c
+++ b/repair/phase5.c
@@ -615,6 +615,28 @@ calculate_freespace_cursor(xfs_mount_t *mp, xfs_agnumber_t agno,
 	return(extra_blocks);
 }
 
+/* Map btnum to buffer ops for the types that need it. */
+static const struct xfs_buf_ops *
+btnum_to_ops(
+	xfs_btnum_t	btnum)
+{
+	switch (btnum) {
+	case XFS_BTNUM_BNO:
+	case XFS_BTNUM_CNT:
+		return &xfs_allocbt_buf_ops;
+	case XFS_BTNUM_INO:
+	case XFS_BTNUM_FINO:
+		return &xfs_inobt_buf_ops;
+	case XFS_BTNUM_RMAP:
+		return &xfs_rmapbt_buf_ops;
+	case XFS_BTNUM_REFC:
+		return &xfs_refcountbt_buf_ops;
+	default:
+		ASSERT(0);
+		return NULL;
+	}
+}
+
 static void
 prop_freespace_cursor(xfs_mount_t *mp, xfs_agnumber_t agno,
 		bt_status_t *btree_curs, xfs_agblock_t startblock,
@@ -625,6 +647,7 @@ prop_freespace_cursor(xfs_mount_t *mp, xfs_agnumber_t agno,
 	xfs_alloc_ptr_t		*bt_ptr;
 	xfs_agblock_t		agbno;
 	bt_stat_level_t		*lptr;
+	const struct xfs_buf_ops *ops = btnum_to_ops(btnum);
 
 	ASSERT(btnum == XFS_BTNUM_BNO || btnum == XFS_BTNUM_CNT);
 
@@ -675,7 +698,7 @@ prop_freespace_cursor(xfs_mount_t *mp, xfs_agnumber_t agno,
 		/*
 		 * initialize block header
 		 */
-		lptr->buf_p->b_ops = &xfs_allocbt_buf_ops;
+		lptr->buf_p->b_ops = ops;
 		bt_hdr = XFS_BUF_TO_BLOCK(lptr->buf_p);
 		memset(bt_hdr, 0, mp->m_sb.sb_blocksize);
 		libxfs_btree_init_block(mp, lptr->buf_p, btnum, level,
@@ -723,6 +746,7 @@ build_freespace_tree(xfs_mount_t *mp, xfs_agnumber_t agno,
 	extent_tree_node_t	*ext_ptr;
 	bt_stat_level_t		*lptr;
 	xfs_extlen_t		freeblks;
+	const struct xfs_buf_ops *ops = btnum_to_ops(btnum);
 
 	ASSERT(btnum == XFS_BTNUM_BNO || btnum == XFS_BTNUM_CNT);
 
@@ -754,7 +778,7 @@ build_freespace_tree(xfs_mount_t *mp, xfs_agnumber_t agno,
 		/*
 		 * initialize block header
 		 */
-		lptr->buf_p->b_ops = &xfs_allocbt_buf_ops;
+		lptr->buf_p->b_ops = ops;
 		bt_hdr = XFS_BUF_TO_BLOCK(lptr->buf_p);
 		memset(bt_hdr, 0, mp->m_sb.sb_blocksize);
 		libxfs_btree_init_block(mp, lptr->buf_p, btnum, i, 0, agno, 0);
@@ -781,7 +805,7 @@ build_freespace_tree(xfs_mount_t *mp, xfs_agnumber_t agno,
 		/*
 		 * block initialization, lay in block header
 		 */
-		lptr->buf_p->b_ops = &xfs_allocbt_buf_ops;
+		lptr->buf_p->b_ops = ops;
 		bt_hdr = XFS_BUF_TO_BLOCK(lptr->buf_p);
 		memset(bt_hdr, 0, mp->m_sb.sb_blocksize);
 		libxfs_btree_init_block(mp, lptr->buf_p, btnum, 0, 0, agno, 0);
@@ -990,6 +1014,7 @@ prop_ino_cursor(xfs_mount_t *mp, xfs_agnumber_t agno, bt_status_t *btree_curs,
 	xfs_inobt_ptr_t		*bt_ptr;
 	xfs_agblock_t		agbno;
 	bt_stat_level_t		*lptr;
+	const struct xfs_buf_ops *ops = btnum_to_ops(btnum);
 
 	level++;
 
@@ -1038,7 +1063,7 @@ prop_ino_cursor(xfs_mount_t *mp, xfs_agnumber_t agno, bt_status_t *btree_curs,
 		/*
 		 * initialize block header
 		 */
-		lptr->buf_p->b_ops = &xfs_inobt_buf_ops;
+		lptr->buf_p->b_ops = ops;
 		bt_hdr = XFS_BUF_TO_BLOCK(lptr->buf_p);
 		memset(bt_hdr, 0, mp->m_sb.sb_blocksize);
 		libxfs_btree_init_block(mp, lptr->buf_p, btnum,
@@ -1130,6 +1155,7 @@ build_ino_tree(xfs_mount_t *mp, xfs_agnumber_t agno,
 	xfs_inobt_rec_t		*bt_rec;
 	ino_tree_node_t		*ino_rec;
 	bt_stat_level_t		*lptr;
+	const struct xfs_buf_ops *ops = btnum_to_ops(btnum);
 	xfs_agino_t		count = 0;
 	xfs_agino_t		freecount = 0;
 	int			inocnt;
@@ -1160,7 +1186,7 @@ build_ino_tree(xfs_mount_t *mp, xfs_agnumber_t agno,
 		 * initialize block header
 		 */
 
-		lptr->buf_p->b_ops = &xfs_inobt_buf_ops;
+		lptr->buf_p->b_ops = ops;
 		bt_hdr = XFS_BUF_TO_BLOCK(lptr->buf_p);
 		memset(bt_hdr, 0, mp->m_sb.sb_blocksize);
 		libxfs_btree_init_block(mp, lptr->buf_p, btnum, i, 0, agno, 0);
@@ -1188,7 +1214,7 @@ build_ino_tree(xfs_mount_t *mp, xfs_agnumber_t agno,
 		/*
 		 * block initialization, lay in block header
 		 */
-		lptr->buf_p->b_ops = &xfs_inobt_buf_ops;
+		lptr->buf_p->b_ops = ops;
 		bt_hdr = XFS_BUF_TO_BLOCK(lptr->buf_p);
 		memset(bt_hdr, 0, mp->m_sb.sb_blocksize);
 		libxfs_btree_init_block(mp, lptr->buf_p, btnum, 0, 0, agno, 0);
@@ -1393,6 +1419,7 @@ prop_rmap_cursor(
 	xfs_rmap_ptr_t		*bt_ptr;
 	xfs_agblock_t		agbno;
 	struct bt_stat_level	*lptr;
+	const struct xfs_buf_ops *ops = btnum_to_ops(XFS_BTNUM_RMAP);
 
 	level++;
 
@@ -1441,7 +1468,7 @@ prop_rmap_cursor(
 		/*
 		 * initialize block header
 		 */
-		lptr->buf_p->b_ops = &xfs_rmapbt_buf_ops;
+		lptr->buf_p->b_ops = ops;
 		bt_hdr = XFS_BUF_TO_BLOCK(lptr->buf_p);
 		memset(bt_hdr, 0, mp->m_sb.sb_blocksize);
 		libxfs_btree_init_block(mp, lptr->buf_p, XFS_BTNUM_RMAP,
@@ -1530,6 +1557,7 @@ build_rmap_tree(
 	struct xfs_rmap_irec	highest_key = {0};
 	struct xfs_rmap_irec	hi_key = {0};
 	struct bt_stat_level	*lptr;
+	const struct xfs_buf_ops *ops = btnum_to_ops(XFS_BTNUM_RMAP);
 	int			numrecs;
 	int			level = btree_curs->num_levels;
 	int			error;
@@ -1553,7 +1581,7 @@ build_rmap_tree(
 		 * initialize block header
 		 */
 
-		lptr->buf_p->b_ops = &xfs_rmapbt_buf_ops;
+		lptr->buf_p->b_ops = ops;
 		bt_hdr = XFS_BUF_TO_BLOCK(lptr->buf_p);
 		memset(bt_hdr, 0, mp->m_sb.sb_blocksize);
 		libxfs_btree_init_block(mp, lptr->buf_p, XFS_BTNUM_RMAP,
@@ -1580,7 +1608,7 @@ _("Insufficient memory to construct reverse-map cursor."));
 		/*
 		 * block initialization, lay in block header
 		 */
-		lptr->buf_p->b_ops = &xfs_rmapbt_buf_ops;
+		lptr->buf_p->b_ops = ops;
 		bt_hdr = XFS_BUF_TO_BLOCK(lptr->buf_p);
 		memset(bt_hdr, 0, mp->m_sb.sb_blocksize);
 		libxfs_btree_init_block(mp, lptr->buf_p, XFS_BTNUM_RMAP,
@@ -1741,6 +1769,7 @@ prop_refc_cursor(
 	xfs_refcount_ptr_t	*bt_ptr;
 	xfs_agblock_t		agbno;
 	struct bt_stat_level	*lptr;
+	const struct xfs_buf_ops *ops = btnum_to_ops(XFS_BTNUM_REFC);
 
 	level++;
 
@@ -1789,7 +1818,7 @@ prop_refc_cursor(
 		/*
 		 * initialize block header
 		 */
-		lptr->buf_p->b_ops = &xfs_refcountbt_buf_ops;
+		lptr->buf_p->b_ops = ops;
 		bt_hdr = XFS_BUF_TO_BLOCK(lptr->buf_p);
 		memset(bt_hdr, 0, mp->m_sb.sb_blocksize);
 		libxfs_btree_init_block(mp, lptr->buf_p, XFS_BTNUM_REFC,
@@ -1834,6 +1863,7 @@ build_refcount_tree(
 	struct xfs_slab_cursor	*refc_cur;
 	struct xfs_refcount_rec	*bt_rec;
 	struct bt_stat_level	*lptr;
+	const struct xfs_buf_ops *ops = btnum_to_ops(XFS_BTNUM_REFC);
 	int			numrecs;
 	int			level = btree_curs->num_levels;
 	int			error;
@@ -1856,7 +1886,7 @@ build_refcount_tree(
 		 * initialize block header
 		 */
 
-		lptr->buf_p->b_ops = &xfs_refcountbt_buf_ops;
+		lptr->buf_p->b_ops = ops;
 		bt_hdr = XFS_BUF_TO_BLOCK(lptr->buf_p);
 		memset(bt_hdr, 0, mp->m_sb.sb_blocksize);
 		libxfs_btree_init_block(mp, lptr->buf_p, XFS_BTNUM_REFC,
@@ -1883,7 +1913,7 @@ _("Insufficient memory to construct refcount cursor."));
 		/*
 		 * block initialization, lay in block header
 		 */
-		lptr->buf_p->b_ops = &xfs_refcountbt_buf_ops;
+		lptr->buf_p->b_ops = ops;
 		bt_hdr = XFS_BUF_TO_BLOCK(lptr->buf_p);
 		memset(bt_hdr, 0, mp->m_sb.sb_blocksize);
 		libxfs_btree_init_block(mp, lptr->buf_p, XFS_BTNUM_REFC,

  parent reply	other threads:[~2019-04-10 15:26 UTC|newest]

Thread overview: 135+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-14 21:03 [PATCH v2 00/36] xfsprogs-5.0: fix various problems Darrick J. Wong
2019-03-14 21:03 ` [PATCH 01/36] libxfs: fix repair deadlock due to failed inode flushes Darrick J. Wong
2019-03-15 22:01   ` Allison Henderson
2019-03-14 21:03 ` [PATCH 02/36] configure: use sys/xattr.h for fsetxattr detection Darrick J. Wong
2019-03-15 22:01   ` Allison Henderson
2019-03-14 21:04 ` [PATCH 03/36] configure.ac: fix alignment of features Darrick J. Wong
2019-03-14 23:46   ` Eric Sandeen
2019-03-15 22:02   ` Allison Henderson
2019-03-14 21:04 ` [PATCH 04/36] debian: drop dangling libhandle.a symlinks in xfslibs-dev Darrick J. Wong
2019-03-15  0:14   ` Nathan Scott
2019-03-15 22:02   ` Allison Henderson
2019-03-14 21:04 ` [PATCH 05/36] debian: don't bypass top level Makefile when building subdirs Darrick J. Wong
2019-03-15  0:16   ` Nathan Scott
2019-03-15 22:02   ` Allison Henderson
2019-03-14 21:04 ` [PATCH 06/36] debian: enable parallel make Darrick J. Wong
2019-03-15  0:18   ` Nathan Scott
2019-03-15  1:01     ` Darrick J. Wong
2019-03-15  5:30       ` Darrick J. Wong
2019-03-14 21:04 ` [PATCH 07/36] xfs_io: actually check copy file range helper return values Darrick J. Wong
2019-03-15  2:12   ` Eric Sandeen
2019-03-15  2:56     ` Darrick J. Wong
2019-03-15 16:51       ` Eric Sandeen
2019-03-17 22:45         ` Dave Chinner
2019-03-14 21:04 ` [PATCH 08/36] xfs_io: statx -r should print attributes_mask Darrick J. Wong
2019-04-03 16:31   ` Eric Sandeen
2019-03-14 21:04 ` [PATCH 09/36] xfs_io: don't walk off the end of argv in fzero_f Darrick J. Wong
2019-03-15  0:25   ` [PATCH 09.5/36] xfs_io: document fzero_f -k option in manpage Eric Sandeen
2019-03-15  0:31     ` Darrick J. Wong
2019-03-15  3:06   ` [PATCH 09/36] xfs_io: don't walk off the end of argv in fzero_f Eric Sandeen
2019-03-14 21:04 ` [PATCH 10/36] xfs_scrub_all: walk the lsblk device/fs hierarchy correctly Darrick J. Wong
2019-03-15  2:46   ` Eric Sandeen
2019-03-15  2:55     ` Darrick J. Wong
2019-03-14 21:04 ` [PATCH 11/36] xfs_scrub_all.timer: activate after most of the system is up Darrick J. Wong
2019-03-15  2:56   ` Eric Sandeen
2019-03-15  2:59     ` Darrick J. Wong
2019-03-15  3:02   ` Eric Sandeen
2019-03-14 21:05 ` [PATCH 12/36] xfs_scrub: rename the global nr_threads Darrick J. Wong
2019-03-15  3:09   ` Eric Sandeen
2019-03-14 21:05 ` [PATCH 13/36] xfs_scrub: use datadev parallelization estimates for thread count Darrick J. Wong
2019-03-15 17:36   ` Eric Sandeen
2019-03-15 17:41     ` Darrick J. Wong
2019-03-14 21:05 ` [PATCH 14/36] xfs_scrub: don't expose internal pool state Darrick J. Wong
2019-03-15 17:49   ` Eric Sandeen
2019-03-14 21:05 ` [PATCH 15/36] xfs_scrub: one read/verify pool per disk Darrick J. Wong
2019-03-20 20:03   ` Eric Sandeen
2019-03-20 20:06   ` [PATCH v2 " Darrick J. Wong
2019-03-28 22:57     ` Eric Sandeen
2019-03-14 21:05 ` [PATCH 16/36] xfs_scrub: don't close mnt_fd when mnt_fd open fails Darrick J. Wong
2019-03-20 20:06   ` Eric Sandeen
2019-03-14 21:05 ` [PATCH 17/36] xfs_scrub: check label for misleading characters Darrick J. Wong
2019-03-20 20:09   ` Eric Sandeen
2019-03-20 20:13     ` Darrick J. Wong
2019-03-28 23:00   ` Eric Sandeen
2019-03-14 21:05 ` [PATCH 18/36] scrub: fix Makefile targets which depend on builddefs Darrick J. Wong
2019-03-20 20:23   ` Eric Sandeen
2019-03-21 20:39     ` Darrick J. Wong
2019-03-14 21:05 ` [PATCH 19/36] mkfs: validate extent size hint parameters Darrick J. Wong
2019-03-26 16:59   ` Eric Sandeen
2019-03-26 17:56     ` Darrick J. Wong
2019-04-12 19:31   ` [PATCH v2 " Darrick J. Wong
2019-03-14 21:05 ` [PATCH 20/36] xfs_db: fix finobt record decoding when sparse inodes enabled Darrick J. Wong
2019-03-26 17:05   ` Eric Sandeen
2019-03-26 17:08     ` Darrick J. Wong
2019-03-14 21:05 ` [PATCH 21/36] xfs_db: use TYP_FINOBT for finobt metadump Darrick J. Wong
2019-03-26 17:11   ` Eric Sandeen
2019-03-14 21:06 ` [PATCH 22/36] xfs_info: use findmnt to handle mounted block devices Darrick J. Wong
2019-03-26 17:28   ` Eric Sandeen
2019-04-18 19:12     ` Darrick J. Wong
2019-03-14 21:06 ` [PATCH 23/36] xfs_repair: reinitialize the root directory nlink correctly Darrick J. Wong
2019-04-09 20:44   ` Eric Sandeen
2019-03-14 21:06 ` [PATCH 24/36] xfs_repair: bump the irec on-disk nlink when adding lost+found Darrick J. Wong
2019-04-09 20:46   ` Eric Sandeen
2019-03-14 21:06 ` [PATCH 25/36] xfs_repair: fix uninitialized variable warnings Darrick J. Wong
2019-03-26 19:56   ` Eric Sandeen
2019-03-26 21:21     ` Darrick J. Wong
2019-04-09 20:40   ` Eric Sandeen
2019-03-14 21:06 ` [PATCH 26/36] xfs_repair: refactor buffer ops assignments during phase 5 Darrick J. Wong
2019-04-09 21:11   ` Eric Sandeen
2019-04-10 15:25   ` Darrick J. Wong [this message]
2019-04-12 20:29     ` [PATCH v2 " Eric Sandeen
2019-03-14 21:06 ` [PATCH 27/36] xfs_repair: pass ops through during scan Darrick J. Wong
2019-04-12 20:30   ` Eric Sandeen
2019-03-14 21:06 ` [PATCH 28/36] libfrog: hoist bitmap out of scrub Darrick J. Wong
2019-04-03 18:33   ` Eric Sandeen
2019-03-14 21:06 ` [PATCH 29/36] xfs_repair: correctly account for free space btree shrinks when fixing freelist Darrick J. Wong
2019-03-14 21:06 ` [PATCH 30/36] libxfs: retain ifork_ops when flushing inode Darrick J. Wong
2019-04-05 18:17   ` Eric Sandeen
2019-04-05 18:19     ` Eric Sandeen
2019-04-05 20:06       ` Darrick J. Wong
2019-03-14 21:07 ` [PATCH 31/36] libxfs: refactor the open-coded libxfs_trans_bjoin calls Darrick J. Wong
2019-04-05 18:39   ` Eric Sandeen
2019-03-14 21:07 ` [PATCH 32/36] libxfs: refactor buffer item release code Darrick J. Wong
2019-03-14 21:07 ` [PATCH 33/36] libxfs: don't touch buffer log item pointer when flushing inode log item Darrick J. Wong
2019-03-14 21:07 ` [PATCH 34/36] libxfs: fix buffer log item lifetime weirdness Darrick J. Wong
2019-03-14 21:07 ` [PATCH 35/36] libxfs: shorten inode item lifetime Darrick J. Wong
2019-03-14 21:07 ` [PATCH 36/36] libxfs: remove libxfs_trans_iget Darrick J. Wong
2019-04-05 19:28   ` Eric Sandeen
2019-03-20 19:34 ` [PATCH 37/36] xfs_scrub: include unicrash.h in unicrash.c Darrick J. Wong
2019-04-04 21:07   ` Eric Sandeen
2019-03-20 19:34 ` [PATCH 38/36] xfs_io: don't read garbage stack contents if INUMBERS goes nuts Darrick J. Wong
2019-04-04 21:12   ` Eric Sandeen
2019-04-04 21:39     ` Darrick J. Wong
2019-03-20 19:35 ` [PATCH 39/36] misc: fix strncpy length complaints Darrick J. Wong
2019-04-04 21:30   ` Eric Sandeen
2019-04-18 18:51     ` Darrick J. Wong
2019-03-20 19:36 ` [PATCH 40/36] xfs_io: fix label parsing and validation Darrick J. Wong
2019-04-04 21:51   ` Eric Sandeen
2019-03-20 19:36 ` [PATCH 41/36] xfs_repair: better cli option parameter checking Darrick J. Wong
2019-04-04 22:08   ` Eric Sandeen
2019-03-20 19:36 ` [PATCH 42/36] xfs_db: refactor metadump handling of multi-fsb objects Darrick J. Wong
2019-04-04 22:17   ` Eric Sandeen
2019-03-20 19:37 ` [PATCH 43/36] xfs_db: refactor multi-fsb object detection decision making Darrick J. Wong
2019-04-04 23:49   ` Eric Sandeen
2019-04-05  0:01     ` Darrick J. Wong
2019-04-05  0:09   ` [PATCH v2 " Darrick J. Wong
2019-04-05 20:31     ` Eric Sandeen
2019-03-20 19:37 ` [PATCH 44/36] xfs_db: metadump should handle symlinks properly Darrick J. Wong
2019-04-05 14:18   ` Eric Sandeen
2019-04-05 14:44     ` Darrick J. Wong
2019-03-20 20:03 ` [PATCH 45/36] xfs_scrub: rename confusing structure Darrick J. Wong
2019-04-04 16:40   ` Eric Sandeen
2019-04-04 16:56     ` Darrick J. Wong
2019-04-04 17:10   ` [PATCH v2 " Darrick J. Wong
2019-04-12 19:22     ` Eric Sandeen
2019-03-20 20:04 ` [PATCH 46/36] xfs_scrub: remove pointless xfs_verify_error_info struct Darrick J. Wong
2019-04-04 16:47   ` Eric Sandeen
2019-04-04 17:10   ` [PATCH v2 " Darrick J. Wong
2019-04-12 19:23     ` Eric Sandeen
2019-04-12 19:32       ` Darrick J. Wong
2019-03-20 20:05 ` [PATCH 47/36] xfs_scrub: remove xfs_ prefixes from structure names Darrick J. Wong
2019-04-04 16:49   ` Eric Sandeen
2019-03-26 17:18 ` [PATCH 48/36] mkfs: don't use DIFLAG values for fsx_xflags Darrick J. Wong
2019-04-04 16:38   ` Eric Sandeen
2019-04-01 16:43 ` [PATCH 49/36] xfs_scrub: remove redundant function declarations Darrick J. Wong
2019-04-04 16:33   ` Eric Sandeen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190410152554.GB1019523@magnolia \
    --to=darrick.wong@oracle.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@sandeen.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).