All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] xfsprogs: reverse mapping fixes
@ 2016-08-24  2:24 Darrick J. Wong
  2016-08-24  2:24 ` [PATCH 1/7] xfs: don't perform lookups on zero-height btrees Darrick J. Wong
                   ` (7 more replies)
  0 siblings, 8 replies; 16+ messages in thread
From: Darrick J. Wong @ 2016-08-24  2:24 UTC (permalink / raw)
  To: david, darrick.wong; +Cc: linux-xfs, xfs

Hi all,

This is a roll-up of a few fixes[1] for reverse-mapping in xfsprogs 4.8.

The patches have been xfstested with the 'auto' group on x64
and (afaict) don't cause any regressions.

This is an extraordinary way to eat your data.  Enjoy! 
Comments and questions are, as always, welcome.

--D

[1] https://github.com/djwong/xfsprogs/tree/for-dave-for-4.8-6

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 1/7] xfs: don't perform lookups on zero-height btrees
  2016-08-24  2:24 [PATCH 0/7] xfsprogs: reverse mapping fixes Darrick J. Wong
@ 2016-08-24  2:24 ` Darrick J. Wong
  2016-08-25  9:11   ` Christoph Hellwig
  2016-08-24  2:24 ` [PATCH 2/7] xfs: fix some key handling problems in _btree_simple_query_range Darrick J. Wong
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Darrick J. Wong @ 2016-08-24  2:24 UTC (permalink / raw)
  To: david, darrick.wong; +Cc: linux-xfs, xfs

If the caller passes in a cursor to a zero-height btree (which is
impossible), we never set block to anything but NULL, which causes the
later dereference of it to crash.  Instead, just return -EFSCORRUPTED.

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


diff --git a/libxfs/xfs_btree.c b/libxfs/xfs_btree.c
index 8391078..cb671f6 100644
--- a/libxfs/xfs_btree.c
+++ b/libxfs/xfs_btree.c
@@ -1810,6 +1810,10 @@ xfs_btree_lookup(
 
 	XFS_BTREE_STATS_INC(cur, lookup);
 
+	/* No such thing as a zero-level tree. */
+	if (cur->bc_nlevels == 0)
+		return -EFSCORRUPTED;
+
 	block = NULL;
 	keyno = 0;
 

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 2/7] xfs: fix some key handling problems in _btree_simple_query_range
  2016-08-24  2:24 [PATCH 0/7] xfsprogs: reverse mapping fixes Darrick J. Wong
  2016-08-24  2:24 ` [PATCH 1/7] xfs: don't perform lookups on zero-height btrees Darrick J. Wong
@ 2016-08-24  2:24 ` Darrick J. Wong
  2016-08-25  9:11   ` Christoph Hellwig
  2016-08-24  2:24 ` [PATCH 3/7] xfs: simple btree query range should look right if LE lookup fails Darrick J. Wong
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Darrick J. Wong @ 2016-08-24  2:24 UTC (permalink / raw)
  To: david, darrick.wong; +Cc: linux-xfs, xfs

We only need the record's high key for the first record that we look
at; for all records, we /definitely/ need the regular record key.
Therefore, fix how the simple range query function gets its keys.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 libxfs/xfs_btree.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)


diff --git a/libxfs/xfs_btree.c b/libxfs/xfs_btree.c
index cb671f6..b69c8d2 100644
--- a/libxfs/xfs_btree.c
+++ b/libxfs/xfs_btree.c
@@ -4563,10 +4563,10 @@ xfs_btree_simple_query_range(
 		error = xfs_btree_get_rec(cur, &recp, &stat);
 		if (error || !stat)
 			break;
-		cur->bc_ops->init_high_key_from_rec(&rec_key, recp);
 
 		/* Skip if high_key(rec) < low_key. */
 		if (firstrec) {
+			cur->bc_ops->init_high_key_from_rec(&rec_key, recp);
 			firstrec = false;
 			diff = cur->bc_ops->diff_two_keys(cur, low_key,
 					&rec_key);
@@ -4575,6 +4575,7 @@ xfs_btree_simple_query_range(
 		}
 
 		/* Stop if high_key < low_key(rec). */
+		cur->bc_ops->init_key_from_rec(&rec_key, recp);
 		diff = cur->bc_ops->diff_two_keys(cur, &rec_key, high_key);
 		if (diff > 0)
 			break;

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 3/7] xfs: simple btree query range should look right if LE lookup fails
  2016-08-24  2:24 [PATCH 0/7] xfsprogs: reverse mapping fixes Darrick J. Wong
  2016-08-24  2:24 ` [PATCH 1/7] xfs: don't perform lookups on zero-height btrees Darrick J. Wong
  2016-08-24  2:24 ` [PATCH 2/7] xfs: fix some key handling problems in _btree_simple_query_range Darrick J. Wong
@ 2016-08-24  2:24 ` Darrick J. Wong
  2016-08-25  9:11   ` Christoph Hellwig
  2016-08-24  2:24 ` [PATCH 4/7] libxcmd: fix mount option parsing to find rt/log devices Darrick J. Wong
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Darrick J. Wong @ 2016-08-24  2:24 UTC (permalink / raw)
  To: david, darrick.wong; +Cc: linux-xfs, xfs

If the initial LOOKUP_LE in the simple query range fails to find
anything, we should attempt to increment the btree cursor to see
if there actually /are/ records for what we're trying to find.
Without this patch, a bnobt range query of (0, $agsize) returns
no results because the leftmost record never has a startblock
of zero.

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


diff --git a/libxfs/xfs_btree.c b/libxfs/xfs_btree.c
index b69c8d2..8e928ea 100644
--- a/libxfs/xfs_btree.c
+++ b/libxfs/xfs_btree.c
@@ -4558,6 +4558,13 @@ xfs_btree_simple_query_range(
 	if (error)
 		goto out;
 
+	/* Nothing?  See if there's anything to the right. */
+	if (!stat) {
+		error = xfs_btree_increment(cur, 0, &stat);
+		if (error)
+			goto out;
+	}
+
 	while (stat) {
 		/* Find the record. */
 		error = xfs_btree_get_rec(cur, &recp, &stat);

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 4/7] libxcmd: fix mount option parsing to find rt/log devices
  2016-08-24  2:24 [PATCH 0/7] xfsprogs: reverse mapping fixes Darrick J. Wong
                   ` (2 preceding siblings ...)
  2016-08-24  2:24 ` [PATCH 3/7] xfs: simple btree query range should look right if LE lookup fails Darrick J. Wong
@ 2016-08-24  2:24 ` Darrick J. Wong
  2016-08-25  9:12   ` Christoph Hellwig
  2016-08-24  2:24 ` [PATCH 5/7] misc: fix Coverity errors Darrick J. Wong
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 16+ messages in thread
From: Darrick J. Wong @ 2016-08-24  2:24 UTC (permalink / raw)
  To: david, darrick.wong; +Cc: linux-xfs, xfs

It turns out that glibc's hasmntopt implementation returns NULL
if the opt parameter ends with an equals ('=').  Therefore, we
cannot directly search for the option 'rtdev='; we must instead
have hasmntopt look for 'rtdev' and look for the trailing equals
sign ourselves.  This fixes xfs_info's reporting of external
log and realtime device paths, and xfs_scrub will need it for
data block scrubbing of realtime extents.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 libxcmd/paths.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)


diff --git a/libxcmd/paths.c b/libxcmd/paths.c
index 71af25f..b08985f 100644
--- a/libxcmd/paths.c
+++ b/libxcmd/paths.c
@@ -234,10 +234,17 @@ fs_extract_mount_options(
 {
 	char		*fslog, *fsrt;
 
-	/* Extract log device and realtime device from mount options */
-	if ((fslog = hasmntopt(mnt, "logdev=")))
+	/*
+	 * Extract log device and realtime device from mount options.
+	 *
+	 * Note: the glibc hasmntopt implementation requires that the
+	 * character in mnt_opts immediately after the search string
+	 * must be a NULL ('\0'), a comma (','), or an equals ('=').
+	 * Therefore we cannot search for 'logdev=' directly.
+	 */
+	if ((fslog = hasmntopt(mnt, "logdev")) && fslog[6] == '=')
 		fslog += 7;
-	if ((fsrt = hasmntopt(mnt, "rtdev=")))
+	if ((fsrt = hasmntopt(mnt, "rtdev")) && fsrt[5] == '=')
 		fsrt += 6;
 
 	/* Do this only after we've finished processing mount options */

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 5/7] misc: fix Coverity errors
  2016-08-24  2:24 [PATCH 0/7] xfsprogs: reverse mapping fixes Darrick J. Wong
                   ` (3 preceding siblings ...)
  2016-08-24  2:24 ` [PATCH 4/7] libxcmd: fix mount option parsing to find rt/log devices Darrick J. Wong
@ 2016-08-24  2:24 ` Darrick J. Wong
  2016-08-25  9:14   ` Christoph Hellwig
  2016-08-25 21:02   ` [PATCH v2 " Darrick J. Wong
  2016-08-24  2:25 ` [PATCH 6/7] misc: fix libxfs api violations Darrick J. Wong
                   ` (2 subsequent siblings)
  7 siblings, 2 replies; 16+ messages in thread
From: Darrick J. Wong @ 2016-08-24  2:24 UTC (permalink / raw)
  To: david, darrick.wong; +Cc: linux-xfs, xfs

Fix various code sloppinesses pointed out by Coverity.

Coverity-id: 1371628 - 1371638
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 db/fsmap.c      |    1 +
 repair/phase5.c |   12 ++++++++----
 repair/rmap.c   |    5 +++--
 repair/scan.c   |    1 +
 4 files changed, 13 insertions(+), 6 deletions(-)


diff --git a/db/fsmap.c b/db/fsmap.c
index b2ba55d..4b245b9 100644
--- a/db/fsmap.c
+++ b/db/fsmap.c
@@ -75,6 +75,7 @@ fsmap(
 	high.rm_owner = ULLONG_MAX;
 	high.rm_offset = ULLONG_MAX;
 	high.rm_flags = XFS_RMAP_ATTR_FORK | XFS_RMAP_BMBT_BLOCK | XFS_RMAP_UNWRITTEN;
+	high.rm_blockcount = low.rm_blockcount = 0;
 
 	start_ag = XFS_FSB_TO_AGNO(mp, start_fsb);
 	end_ag = XFS_FSB_TO_AGNO(mp, end_fsb);
diff --git a/repair/phase5.c b/repair/phase5.c
index e583879..5a7185c 100644
--- a/repair/phase5.c
+++ b/repair/phase5.c
@@ -1464,7 +1464,7 @@ prop_rmap_cursor(
 		 * and set the rightsib pointer of current block
 		 */
 #ifdef XR_BLD_INO_TRACE
-		fprintf(stderr, " ino prop agbno %d ", lptr->prev_agbno);
+		fprintf(stderr, " rmap prop agbno %d ", lptr->prev_agbno);
 #endif
 		if (lptr->prev_agbno != NULLAGBLOCK)  {
 			ASSERT(lptr->prev_buf_p != NULL);
@@ -1502,7 +1502,7 @@ prop_rmap_cursor(
 		prop_rmap_cursor(mp, agno, btree_curs, rm_rec, level);
 	}
 	/*
-	 * add inode info to current block
+	 * add rmap info to current block
 	 */
 	be16_add_cpu(&bt_hdr->bb_numrecs, 1);
 
@@ -1548,6 +1548,7 @@ prop_rmap_highkey(
 		bt_key->rm_offset = cpu_to_be64(
 				libxfs_rmap_irec_offset_pack(&high_key));
 
+		key.rm_blockcount = 0;
 		for (i = 1; i < numrecs - 1; i++) {
 			bt_key = XFS_RMAP_HIGH_KEY_ADDR(bt_hdr, i);
 			key.rm_startblock = be32_to_cpu(bt_key->rm_startblock);
@@ -1621,7 +1622,7 @@ _("Insufficient memory to construct reverse-map cursor."));
 	rm_rec = pop_slab_cursor(rmap_cur);
 	lptr = &btree_curs->level[0];
 
-	for (i = 0; i < lptr->num_blocks; i++)  {
+	for (i = 0; i < lptr->num_blocks && rm_rec != NULL; i++)  {
 		/*
 		 * block initialization, lay in block header
 		 */
@@ -1639,14 +1640,17 @@ _("Insufficient memory to construct reverse-map cursor."));
 		if (lptr->modulo > 0)
 			lptr->modulo--;
 
-		if (lptr->num_recs_pb > 0)
+		if (lptr->num_recs_pb > 0) {
+			ASSERT(rm_rec != NULL);
 			prop_rmap_cursor(mp, agno, btree_curs, rm_rec, 0);
+		}
 
 		bt_rec = (struct xfs_rmap_rec *)
 			  ((char *)bt_hdr + XFS_RMAP_BLOCK_LEN);
 		highest_key.rm_startblock = 0;
 		highest_key.rm_owner = 0;
 		highest_key.rm_offset = 0;
+		highest_key.rm_blockcount = 0;
 		for (j = 0; j < be16_to_cpu(bt_hdr->bb_numrecs); j++) {
 			ASSERT(rm_rec != NULL);
 			bt_rec[j].rm_startblock =
diff --git a/repair/rmap.c b/repair/rmap.c
index f22f4f0..b3d4c25 100644
--- a/repair/rmap.c
+++ b/repair/rmap.c
@@ -316,7 +316,7 @@ fold_raw_rmaps(
 	struct xfs_slab_cursor	*cur = NULL;
 	struct xfs_rmap_irec	*prev, *rec;
 	size_t			old_sz;
-	int			error;
+	int			error = 0;
 
 	old_sz = slab_count(ag_rmaps[agno].ar_rmaps);
 	if (slab_count(ag_rmaps[agno].ar_raw_rmaps) == 0)
@@ -329,7 +329,7 @@ fold_raw_rmaps(
 
 	prev = pop_slab_cursor(cur);
 	rec = pop_slab_cursor(cur);
-	while (rec) {
+	while (prev && rec) {
 		if (mergeable_rmaps(prev, rec)) {
 			prev->rm_blockcount += rec->rm_blockcount;
 			rec = pop_slab_cursor(cur);
@@ -843,6 +843,7 @@ rmap_high_key_from_rec(
 	    (rec->rm_flags & XFS_RMAP_BMBT_BLOCK))
 		return;
 	key->rm_offset += adj;
+	key->rm_blockcount = 0;
 }
 
 /*
diff --git a/repair/scan.c b/repair/scan.c
index 9a46dd0..253e3de 100644
--- a/repair/scan.c
+++ b/repair/scan.c
@@ -1109,6 +1109,7 @@ advance:
 		key.rm_flags = 0;
 		key.rm_startblock = be32_to_cpu(kp->rm_startblock);
 		key.rm_owner = be64_to_cpu(kp->rm_owner);
+		key.rm_blockcount = 0;
 		if (libxfs_rmap_irec_offset_unpack(be64_to_cpu(kp->rm_offset),
 				&key)) {
 			/* Look for impossible flags. */

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 6/7] misc: fix libxfs api violations
  2016-08-24  2:24 [PATCH 0/7] xfsprogs: reverse mapping fixes Darrick J. Wong
                   ` (4 preceding siblings ...)
  2016-08-24  2:24 ` [PATCH 5/7] misc: fix Coverity errors Darrick J. Wong
@ 2016-08-24  2:25 ` Darrick J. Wong
  2016-08-24  2:25 ` [PATCH 7/7] xfs_repair: fix naming problems in repair/rmap.c Darrick J. Wong
  2016-08-25 21:03 ` [PATCH 0/7] xfsprogs: reverse mapping fixes Darrick J. Wong
  7 siblings, 0 replies; 16+ messages in thread
From: Darrick J. Wong @ 2016-08-24  2:25 UTC (permalink / raw)
  To: david, darrick.wong; +Cc: linux-xfs, xfs

Fix all the client programs to use 'libxfs_' prefixes for non-inline
function calls and to negate integer return codes.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 db/bmap.c                    |    4 ++-
 db/bmroot.c                  |    4 ++-
 db/check.c                   |    6 +++--
 db/frag.c                    |    2 +-
 db/fsmap.c                   |    8 +++----
 db/init.c                    |    2 +-
 db/logformat.c               |    2 +-
 db/metadump.c                |    4 ++-
 io/open.c                    |    2 +-
 libxfs/libxfs_api_defs.h     |   15 +++++++++++++
 mkfs/maxtrres.c              |    2 +-
 mkfs/xfs_mkfs.c              |   46 +++++++++++++++++++--------------------
 repair/dinode.c              |    8 +++----
 repair/phase5.c              |   50 +++++++++++++++++++++---------------------
 repair/phase6.c              |    6 +++--
 repair/prefetch.c            |    4 ++-
 repair/rmap.c                |   24 ++++++++++----------
 repair/sb.c                  |    2 +-
 tools/find-api-violations.sh |   38 ++++++++++++++++++++++++++++++++
 19 files changed, 141 insertions(+), 88 deletions(-)
 create mode 100755 tools/find-api-violations.sh


diff --git a/db/bmap.c b/db/bmap.c
index c71b6b4..58833f7 100644
--- a/db/bmap.c
+++ b/db/bmap.c
@@ -90,7 +90,7 @@ bmap(
 		push_cur();
 		rblock = (xfs_bmdr_block_t *)XFS_DFORK_PTR(dip, whichfork);
 		fsize = XFS_DFORK_SIZE(dip, mp, whichfork);
-		pp = XFS_BMDR_PTR_ADDR(rblock, 1, xfs_bmdr_maxrecs(fsize, 0));
+		pp = XFS_BMDR_PTR_ADDR(rblock, 1, libxfs_bmdr_maxrecs(fsize, 0));
 		kp = XFS_BMDR_KEY_ADDR(rblock, 1);
 		bno = select_child(curoffset, kp, pp,
 					be16_to_cpu(rblock->bb_numrecs));
@@ -101,7 +101,7 @@ bmap(
 			if (be16_to_cpu(block->bb_level) == 0)
 				break;
 			pp = XFS_BMBT_PTR_ADDR(mp, block, 1,
-				xfs_bmbt_maxrecs(mp, mp->m_sb.sb_blocksize, 0));
+				libxfs_bmbt_maxrecs(mp, mp->m_sb.sb_blocksize, 0));
 			kp = XFS_BMBT_KEY_ADDR(mp, block, 1);
 			bno = select_child(curoffset, kp, pp,
 					be16_to_cpu(block->bb_numrecs));
diff --git a/db/bmroot.c b/db/bmroot.c
index 0950e19..7697e61 100644
--- a/db/bmroot.c
+++ b/db/bmroot.c
@@ -140,7 +140,7 @@ bmroota_ptr_offset(
 	ASSERT(XFS_DFORK_Q(dip) && (char *)block == XFS_DFORK_APTR(dip));
 	ASSERT(be16_to_cpu(block->bb_level) > 0);
 	pp = XFS_BMDR_PTR_ADDR(block, idx,
-		xfs_bmdr_maxrecs(XFS_DFORK_ASIZE(dip, mp), 0));
+		libxfs_bmdr_maxrecs(XFS_DFORK_ASIZE(dip, mp), 0));
 	return bitize((int)((char *)pp - (char *)block));
 }
 
@@ -235,7 +235,7 @@ bmrootd_ptr_offset(
 	block = (xfs_bmdr_block_t *)((char *)obj + byteize(startoff));
 	ASSERT(be16_to_cpu(block->bb_level) > 0);
 	pp = XFS_BMDR_PTR_ADDR(block, idx,
-		xfs_bmdr_maxrecs(XFS_DFORK_DSIZE(dip, mp), 0));
+		libxfs_bmdr_maxrecs(XFS_DFORK_DSIZE(dip, mp), 0));
 	return bitize((int)((char *)pp - (char *)block));
 }
 
diff --git a/db/check.c b/db/check.c
index 11c6b56..a6a8372 100644
--- a/db/check.c
+++ b/db/check.c
@@ -2186,7 +2186,7 @@ process_btinode(
 		return;
 	}
 	if (be16_to_cpu(dib->bb_numrecs) >
-			xfs_bmdr_maxrecs(XFS_DFORK_SIZE(dip, mp, whichfork),
+			libxfs_bmdr_maxrecs(XFS_DFORK_SIZE(dip, mp, whichfork),
 			be16_to_cpu(dib->bb_level) == 0)) {
 		if (!sflag || id->ilist)
 			dbprintf(_("numrecs for ino %lld %s fork bmap root too "
@@ -2204,7 +2204,7 @@ process_btinode(
 		*nex += be16_to_cpu(dib->bb_numrecs);
 		return;
 	} else {
-		pp = XFS_BMDR_PTR_ADDR(dib, 1, xfs_bmdr_maxrecs(
+		pp = XFS_BMDR_PTR_ADDR(dib, 1, libxfs_bmdr_maxrecs(
 				XFS_DFORK_SIZE(dip, mp, whichfork), 0));
 		for (i = 0; i < be16_to_cpu(dib->bb_numrecs); i++)
 			scan_lbtree(get_unaligned_be64(&pp[i]),
@@ -2684,7 +2684,7 @@ process_inode(
 		error++;
 		return;
 	}
-	if (!xfs_dinode_good_version(mp, xino.i_d.di_version)) {
+	if (!libxfs_dinode_good_version(mp, xino.i_d.di_version)) {
 		if (isfree || v)
 			dbprintf(_("bad version number %#x for inode %lld\n"),
 				xino.i_d.di_version, ino);
diff --git a/db/frag.c b/db/frag.c
index e11b140..8005e45 100644
--- a/db/frag.c
+++ b/db/frag.c
@@ -260,7 +260,7 @@ process_btinode(
 		return;
 	}
 	pp = XFS_BMDR_PTR_ADDR(dib, 1,
-		xfs_bmdr_maxrecs(XFS_DFORK_SIZE(dip, mp, whichfork), 0));
+		libxfs_bmdr_maxrecs(XFS_DFORK_SIZE(dip, mp, whichfork), 0));
 	for (i = 0; i < be16_to_cpu(dib->bb_numrecs); i++)
 		scan_lbtree(get_unaligned_be64(&pp[i]),
 			 be16_to_cpu(dib->bb_level), scanfunc_bmap, extmapp,
diff --git a/db/fsmap.c b/db/fsmap.c
index 4b245b9..67fed20 100644
--- a/db/fsmap.c
+++ b/db/fsmap.c
@@ -85,13 +85,13 @@ fsmap(
 		if (agno == end_ag)
 			high.rm_startblock = XFS_FSB_TO_AGBNO(mp, end_fsb);
 
-		error = xfs_alloc_read_agf(mp, NULL, agno, 0, &agbp);
+		error = -libxfs_alloc_read_agf(mp, NULL, agno, 0, &agbp);
 		if (error) {
 			dbprintf(_("Error %d while reading AGF.\n"), error);
 			return;
 		}
 
-		bt_cur = xfs_rmapbt_init_cursor(mp, NULL, agbp, agno);
+		bt_cur = libxfs_rmapbt_init_cursor(mp, NULL, agbp, agno);
 		if (!bt_cur) {
 			libxfs_putbuf(agbp);
 			dbprintf(_("Not enough memory.\n"));
@@ -102,14 +102,14 @@ fsmap(
 		error = -libxfs_rmap_query_range(bt_cur, &low, &high,
 				fsmap_fn, &info);
 		if (error) {
-			xfs_btree_del_cursor(bt_cur, XFS_BTREE_ERROR);
+			libxfs_btree_del_cursor(bt_cur, XFS_BTREE_ERROR);
 			libxfs_putbuf(agbp);
 			dbprintf(_("Error %d while querying fsmap btree.\n"),
 				error);
 			return;
 		}
 
-		xfs_btree_del_cursor(bt_cur, XFS_BTREE_NOERROR);
+		libxfs_btree_del_cursor(bt_cur, XFS_BTREE_NOERROR);
 		libxfs_putbuf(agbp);
 
 		if (agno == start_ag)
diff --git a/db/init.c b/db/init.c
index c0472c8..ec1e274 100644
--- a/db/init.c
+++ b/db/init.c
@@ -164,7 +164,7 @@ init(
 	 */
 	if (sbp->sb_rootino != NULLFSINO &&
 	    xfs_sb_version_haslazysbcount(&mp->m_sb)) {
-		int error = xfs_initialize_perag_data(mp, sbp->sb_agcount);
+		int error = -libxfs_initialize_perag_data(mp, sbp->sb_agcount);
 		if (error) {
 			fprintf(stderr,
 	_("%s: cannot init perag data (%d). Continuing anyway.\n"),
diff --git a/db/logformat.c b/db/logformat.c
index 254f33d..70097bc 100644
--- a/db/logformat.c
+++ b/db/logformat.c
@@ -101,7 +101,7 @@ logformat_f(int argc, char **argv)
 
 	dbprintf("Formatting the log to cycle %d, stripe unit %d bytes.\n",
 		 cycle, lsunit);
-	error = libxfs_log_clear(mp->m_logdev_targp, NULL,
+	error = -libxfs_log_clear(mp->m_logdev_targp, NULL,
 				 mp->m_log->l_logBBstart,
 				 mp->m_log->l_logBBsize,
 				 &mp->m_sb.sb_uuid, logversion, lsunit,
diff --git a/db/metadump.c b/db/metadump.c
index 609a5d7..44359e1 100644
--- a/db/metadump.c
+++ b/db/metadump.c
@@ -2016,7 +2016,7 @@ process_btinode(
 					    nrecs, itype);
 	}
 
-	maxrecs = xfs_bmdr_maxrecs(XFS_DFORK_SIZE(dip, mp, whichfork), 0);
+	maxrecs = libxfs_bmdr_maxrecs(XFS_DFORK_SIZE(dip, mp, whichfork), 0);
 	if (nrecs > maxrecs) {
 		if (show_warnings)
 			print_warning("invalid numrecs (%u) in inode %lld %s "
@@ -2132,7 +2132,7 @@ process_inode(
 
 	/* we only care about crc recalculation if we will modify the inode. */
 	if (obfuscate || zero_stale_data) {
-		crc_was_ok = xfs_verify_cksum((char *)dip,
+		crc_was_ok = libxfs_verify_cksum((char *)dip,
 					mp->m_sb.sb_inodesize,
 					offsetof(struct xfs_dinode, di_crc));
 	}
diff --git a/io/open.c b/io/open.c
index 2303527..a5d465a 100644
--- a/io/open.c
+++ b/io/open.c
@@ -878,7 +878,7 @@ inode_f(
 
 	lastgrp--;
 	lastino = igroup[lastgrp].xi_startino +
-		  xfs_highbit64(igroup[lastgrp].xi_allocmask);
+		  libxfs_highbit64(igroup[lastgrp].xi_allocmask);
 
 	if (verbose)
 		printf("%llu:%d\n", lastino,
diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h
index 993ca9f..626c79f 100644
--- a/libxfs/libxfs_api_defs.h
+++ b/libxfs/libxfs_api_defs.h
@@ -122,4 +122,19 @@
 
 #define xfs_verify_cksum		libxfs_verify_cksum
 
+#define xfs_alloc_ag_max_usable		libxfs_alloc_ag_max_usable
+#define xfs_allocbt_maxrecs		libxfs_allocbt_maxrecs
+#define xfs_bmbt_maxrecs		libxfs_bmbt_maxrecs
+#define xfs_bmdr_maxrecs		libxfs_bmdr_maxrecs
+#define xfs_btree_init_block		libxfs_btree_init_block
+#define xfs_dir_ino_validate		libxfs_dir_ino_validate
+#define xfs_initialize_perag_data	libxfs_initialize_perag_data
+#define xfs_inobt_maxrecs		libxfs_inobt_maxrecs
+#define xfs_iread_extents		libxfs_iread_extents
+#define xfs_log_calc_minimum_size	libxfs_log_calc_minimum_size
+#define xfs_perag_get			libxfs_perag_get
+#define xfs_perag_put			libxfs_perag_put
+#define xfs_prealloc_blocks		libxfs_prealloc_blocks
+#define xfs_dinode_good_version		libxfs_dinode_good_version
+
 #endif /* __LIBXFS_API_DEFS_H__ */
diff --git a/mkfs/maxtrres.c b/mkfs/maxtrres.c
index fc24eac..d7978b6 100644
--- a/mkfs/maxtrres.c
+++ b/mkfs/maxtrres.c
@@ -77,7 +77,7 @@ max_trans_res(
 		sbp->sb_features_ro_compat |= XFS_SB_FEAT_RO_COMPAT_RMAPBT;
 
 	libxfs_mount(&mount, sbp, 0,0,0,0);
-	maxfsb = xfs_log_calc_minimum_size(&mount);
+	maxfsb = libxfs_log_calc_minimum_size(&mount);
 	libxfs_umount(&mount);
 
 #if 0
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 8c69f69..580119e 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -2675,7 +2675,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
 
 	/*
 	 * sb_versionnum, finobt and rmapbt flags must be set before we use
-	 * xfs_prealloc_blocks().
+	 * libxfs_prealloc_blocks().
 	 */
 	sb_set_features(&mp->m_sb, &sb_feat, sectorsize, lsectorsize, dsunit);
 
@@ -2687,12 +2687,12 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
 		 */
 		if (!logsize) {
 			logblocks = MIN(logblocks,
-					xfs_alloc_ag_max_usable(mp));
+					libxfs_alloc_ag_max_usable(mp));
 
 			/* revalidate the log size is valid if we changed it */
 			validate_log_size(logblocks, blocklog, min_logblocks);
 		}
-		if (logblocks > agsize - xfs_prealloc_blocks(mp)) {
+		if (logblocks > agsize - libxfs_prealloc_blocks(mp)) {
 			fprintf(stderr,
 	_("internal log size %lld too large, must fit in allocation group\n"),
 				(long long)logblocks);
@@ -2709,7 +2709,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
 		} else
 			logagno = (xfs_agnumber_t)(agcount / 2);
 
-		logstart = XFS_AGB_TO_FSB(mp, logagno, xfs_prealloc_blocks(mp));
+		logstart = XFS_AGB_TO_FSB(mp, logagno, libxfs_prealloc_blocks(mp));
 		/*
 		 * Align the logstart at stripe unit boundary.
 		 */
@@ -2788,7 +2788,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
 	sbp->sb_imax_pct = imaxpct;
 	sbp->sb_icount = 0;
 	sbp->sb_ifree = 0;
-	sbp->sb_fdblocks = dblocks - agcount * xfs_prealloc_blocks(mp) -
+	sbp->sb_fdblocks = dblocks - agcount * libxfs_prealloc_blocks(mp) -
 		(loginternal ? logblocks : 0);
 	sbp->sb_frextents = 0;	/* will do a free later */
 	sbp->sb_uquotino = sbp->sb_gquotino = sbp->sb_pquotino = 0;
@@ -2893,7 +2893,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
 	for (agno = 0; agno < agcount; agno++) {
 		struct xfs_agfl	*agfl;
 		int		bucket;
-		struct xfs_perag *pag = xfs_perag_get(mp, agno);
+		struct xfs_perag *pag = libxfs_perag_get(mp, agno);
 
 		/*
 		 * Superblock.
@@ -2937,7 +2937,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
 		agf->agf_flfirst = 0;
 		agf->agf_fllast = cpu_to_be32(XFS_AGFL_SIZE(mp) - 1);
 		agf->agf_flcount = 0;
-		nbmblocks = (xfs_extlen_t)(agsize - xfs_prealloc_blocks(mp));
+		nbmblocks = (xfs_extlen_t)(agsize - libxfs_prealloc_blocks(mp));
 		agf->agf_freeblks = cpu_to_be32(nbmblocks);
 		agf->agf_longest = cpu_to_be32(nbmblocks);
 		if (xfs_sb_version_hascrc(&mp->m_sb))
@@ -2948,8 +2948,8 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
 			agf->agf_longest = cpu_to_be32(agsize -
 				XFS_FSB_TO_AGBNO(mp, logstart) - logblocks);
 		}
-		if (xfs_alloc_min_freelist(mp, pag) > worst_freelist)
-			worst_freelist = xfs_alloc_min_freelist(mp, pag);
+		if (libxfs_alloc_min_freelist(mp, pag) > worst_freelist)
+			worst_freelist = libxfs_alloc_min_freelist(mp, pag);
 		libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
 
 		/*
@@ -3011,14 +3011,14 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
 		block = XFS_BUF_TO_BLOCK(buf);
 		memset(block, 0, blocksize);
 		if (xfs_sb_version_hascrc(&mp->m_sb))
-			xfs_btree_init_block(mp, buf, XFS_ABTB_CRC_MAGIC, 0, 1,
+			libxfs_btree_init_block(mp, buf, XFS_ABTB_CRC_MAGIC, 0, 1,
 						agno, XFS_BTREE_CRC_BLOCKS);
 		else
-			xfs_btree_init_block(mp, buf, XFS_ABTB_MAGIC, 0, 1,
+			libxfs_btree_init_block(mp, buf, XFS_ABTB_MAGIC, 0, 1,
 						agno, 0);
 
 		arec = XFS_ALLOC_REC_ADDR(mp, block, 1);
-		arec->ar_startblock = cpu_to_be32(xfs_prealloc_blocks(mp));
+		arec->ar_startblock = cpu_to_be32(libxfs_prealloc_blocks(mp));
 		if (loginternal && agno == logagno) {
 			if (lalign) {
 				/*
@@ -3066,14 +3066,14 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
 		block = XFS_BUF_TO_BLOCK(buf);
 		memset(block, 0, blocksize);
 		if (xfs_sb_version_hascrc(&mp->m_sb))
-			xfs_btree_init_block(mp, buf, XFS_ABTC_CRC_MAGIC, 0, 1,
+			libxfs_btree_init_block(mp, buf, XFS_ABTC_CRC_MAGIC, 0, 1,
 						agno, XFS_BTREE_CRC_BLOCKS);
 		else
-			xfs_btree_init_block(mp, buf, XFS_ABTC_MAGIC, 0, 1,
+			libxfs_btree_init_block(mp, buf, XFS_ABTC_MAGIC, 0, 1,
 						agno, 0);
 
 		arec = XFS_ALLOC_REC_ADDR(mp, block, 1);
-		arec->ar_startblock = cpu_to_be32(xfs_prealloc_blocks(mp));
+		arec->ar_startblock = cpu_to_be32(libxfs_prealloc_blocks(mp));
 		if (loginternal && agno == logagno) {
 			if (lalign) {
 				arec->ar_blockcount = cpu_to_be32(
@@ -3111,10 +3111,10 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
 		block = XFS_BUF_TO_BLOCK(buf);
 		memset(block, 0, blocksize);
 		if (xfs_sb_version_hascrc(&mp->m_sb))
-			xfs_btree_init_block(mp, buf, XFS_IBT_CRC_MAGIC, 0, 0,
+			libxfs_btree_init_block(mp, buf, XFS_IBT_CRC_MAGIC, 0, 0,
 						agno, XFS_BTREE_CRC_BLOCKS);
 		else
-			xfs_btree_init_block(mp, buf, XFS_IBT_MAGIC, 0, 0,
+			libxfs_btree_init_block(mp, buf, XFS_IBT_MAGIC, 0, 0,
 						agno, 0);
 		libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
 
@@ -3129,10 +3129,10 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
 			block = XFS_BUF_TO_BLOCK(buf);
 			memset(block, 0, blocksize);
 			if (xfs_sb_version_hascrc(&mp->m_sb))
-				xfs_btree_init_block(mp, buf, XFS_FIBT_CRC_MAGIC, 0, 0,
+				libxfs_btree_init_block(mp, buf, XFS_FIBT_CRC_MAGIC, 0, 0,
 							agno, XFS_BTREE_CRC_BLOCKS);
 			else
-				xfs_btree_init_block(mp, buf, XFS_FIBT_MAGIC, 0, 0,
+				libxfs_btree_init_block(mp, buf, XFS_FIBT_MAGIC, 0, 0,
 							agno, 0);
 			libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
 		}
@@ -3148,7 +3148,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
 			block = XFS_BUF_TO_BLOCK(buf);
 			memset(block, 0, blocksize);
 
-			xfs_btree_init_block(mp, buf, XFS_RMAP_CRC_MAGIC, 0, 0,
+			libxfs_btree_init_block(mp, buf, XFS_RMAP_CRC_MAGIC, 0, 0,
 						agno, XFS_BTREE_CRC_BLOCKS);
 
 			/*
@@ -3203,7 +3203,7 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
 			libxfs_writebuf(buf, LIBXFS_EXIT_ON_FAILURE);
 		}
 
-		xfs_perag_put(pag);
+		libxfs_perag_put(pag);
 	}
 
 	/*
@@ -3241,10 +3241,10 @@ _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"),
 		args.mp = mp;
 		args.agno = agno;
 		args.alignment = 1;
-		args.pag = xfs_perag_get(mp,agno);
+		args.pag = libxfs_perag_get(mp,agno);
 
 		libxfs_alloc_fix_freelist(&args, 0);
-		xfs_perag_put(args.pag);
+		libxfs_perag_put(args.pag);
 		libxfs_trans_commit(tp);
 	}
 
diff --git a/repair/dinode.c b/repair/dinode.c
index 89163b1..db55860 100644
--- a/repair/dinode.c
+++ b/repair/dinode.c
@@ -131,7 +131,7 @@ clear_dinode_core(struct xfs_mount *mp, xfs_dinode_t *dinoc, xfs_ino_t ino_num)
 		dinoc->di_magic = cpu_to_be16(XFS_DINODE_MAGIC);
 	}
 
-	if (!xfs_dinode_good_version(mp, dinoc->di_version)) {
+	if (!libxfs_dinode_good_version(mp, dinoc->di_version)) {
 		__dirty_no_modify_ret(dirty);
 		if (xfs_sb_version_hascrc(&mp->m_sb))
 			dinoc->di_version = 3;
@@ -966,7 +966,7 @@ _("bad numrecs 0 in inode %" PRIu64 " bmap btree root block\n"),
 	init_bm_cursor(&cursor, level + 1);
 
 	pp = XFS_BMDR_PTR_ADDR(dib, 1,
-		xfs_bmdr_maxrecs(XFS_DFORK_SIZE(dip, mp, whichfork), 0));
+		libxfs_bmdr_maxrecs(XFS_DFORK_SIZE(dip, mp, whichfork), 0));
 	pkey = XFS_BMDR_KEY_ADDR(dib, 1);
 	last_key = NULLFILEOFF;
 
@@ -2240,7 +2240,7 @@ process_dinode_int(xfs_mount_t *mp,
 	 * rewritten, and the CRC is updated automagically.
 	 */
 	if (xfs_sb_version_hascrc(&mp->m_sb) &&
-	    !xfs_verify_cksum((char *)dino, mp->m_sb.sb_inodesize,
+	    !libxfs_verify_cksum((char *)dino, mp->m_sb.sb_inodesize,
 				XFS_DINODE_CRC_OFF)) {
 		retval = 1;
 		if (!uncertain)
@@ -2271,7 +2271,7 @@ process_dinode_int(xfs_mount_t *mp,
 		}
 	}
 
-	if (!xfs_dinode_good_version(mp, dino->di_version)) {
+	if (!libxfs_dinode_good_version(mp, dino->di_version)) {
 		retval = 1;
 		if (!uncertain)
 			do_warn(_("bad version number 0x%x on inode %" PRIu64 "%c"),
diff --git a/repair/phase5.c b/repair/phase5.c
index 5a7185c..93b1f75 100644
--- a/repair/phase5.c
+++ b/repair/phase5.c
@@ -360,7 +360,7 @@ finish_cursor(bt_status_t *curs)
  * XXX(hch): any reason we don't just look at mp->m_alloc_mxr?
  */
 #define XR_ALLOC_BLOCK_MAXRECS(mp, level) \
-	(xfs_allocbt_maxrecs((mp), (mp)->m_sb.sb_blocksize, (level) == 0) - 2)
+	(libxfs_allocbt_maxrecs((mp), (mp)->m_sb.sb_blocksize, (level) == 0) - 2)
 
 /*
  * this calculates a freespace cursor for an ag.
@@ -693,10 +693,10 @@ prop_freespace_cursor(xfs_mount_t *mp, xfs_agnumber_t agno,
 		bt_hdr = XFS_BUF_TO_BLOCK(lptr->buf_p);
 		memset(bt_hdr, 0, mp->m_sb.sb_blocksize);
 		if (xfs_sb_version_hascrc(&mp->m_sb))
-			xfs_btree_init_block(mp, lptr->buf_p, crc_magic, level,
+			libxfs_btree_init_block(mp, lptr->buf_p, crc_magic, level,
 						0, agno, XFS_BTREE_CRC_BLOCKS);
 		else
-			xfs_btree_init_block(mp, lptr->buf_p, magic, level,
+			libxfs_btree_init_block(mp, lptr->buf_p, magic, level,
 						0, agno, 0);
 
 		bt_hdr->bb_u.s.bb_leftsib = cpu_to_be32(lptr->prev_agbno);
@@ -779,10 +779,10 @@ build_freespace_tree(xfs_mount_t *mp, xfs_agnumber_t agno,
 		bt_hdr = XFS_BUF_TO_BLOCK(lptr->buf_p);
 		memset(bt_hdr, 0, mp->m_sb.sb_blocksize);
 		if (xfs_sb_version_hascrc(&mp->m_sb))
-			xfs_btree_init_block(mp, lptr->buf_p, crc_magic, i,
+			libxfs_btree_init_block(mp, lptr->buf_p, crc_magic, i,
 						0, agno, XFS_BTREE_CRC_BLOCKS);
 		else
-			xfs_btree_init_block(mp, lptr->buf_p, magic, i,
+			libxfs_btree_init_block(mp, lptr->buf_p, magic, i,
 						0, agno, 0);
 	}
 	/*
@@ -811,10 +811,10 @@ build_freespace_tree(xfs_mount_t *mp, xfs_agnumber_t agno,
 		bt_hdr = XFS_BUF_TO_BLOCK(lptr->buf_p);
 		memset(bt_hdr, 0, mp->m_sb.sb_blocksize);
 		if (xfs_sb_version_hascrc(&mp->m_sb))
-			xfs_btree_init_block(mp, lptr->buf_p, crc_magic, 0,
+			libxfs_btree_init_block(mp, lptr->buf_p, crc_magic, 0,
 						0, agno, XFS_BTREE_CRC_BLOCKS);
 		else
-			xfs_btree_init_block(mp, lptr->buf_p, magic, 0,
+			libxfs_btree_init_block(mp, lptr->buf_p, magic, 0,
 						0, agno, 0);
 
 		bt_hdr->bb_u.s.bb_leftsib = cpu_to_be32(lptr->prev_agbno);
@@ -895,7 +895,7 @@ build_freespace_tree(xfs_mount_t *mp, xfs_agnumber_t agno,
  * XXX(hch): any reason we don't just look at mp->m_inobt_mxr?
  */
 #define XR_INOBT_BLOCK_MAXRECS(mp, level) \
-			xfs_inobt_maxrecs((mp), (mp)->m_sb.sb_blocksize, \
+			libxfs_inobt_maxrecs((mp), (mp)->m_sb.sb_blocksize, \
 						(level) == 0)
 
 /*
@@ -1073,11 +1073,11 @@ prop_ino_cursor(xfs_mount_t *mp, xfs_agnumber_t agno, bt_status_t *btree_curs,
 		bt_hdr = XFS_BUF_TO_BLOCK(lptr->buf_p);
 		memset(bt_hdr, 0, mp->m_sb.sb_blocksize);
 		if (xfs_sb_version_hascrc(&mp->m_sb))
-			xfs_btree_init_block(mp, lptr->buf_p, XFS_IBT_CRC_MAGIC,
+			libxfs_btree_init_block(mp, lptr->buf_p, XFS_IBT_CRC_MAGIC,
 						level, 0, agno,
 						XFS_BTREE_CRC_BLOCKS);
 		else
-			xfs_btree_init_block(mp, lptr->buf_p, XFS_IBT_MAGIC,
+			libxfs_btree_init_block(mp, lptr->buf_p, XFS_IBT_MAGIC,
 						level, 0, agno, 0);
 
 		bt_hdr->bb_u.s.bb_leftsib = cpu_to_be32(lptr->prev_agbno);
@@ -1198,11 +1198,11 @@ build_ino_tree(xfs_mount_t *mp, xfs_agnumber_t agno,
 		bt_hdr = XFS_BUF_TO_BLOCK(lptr->buf_p);
 		memset(bt_hdr, 0, mp->m_sb.sb_blocksize);
 		if (xfs_sb_version_hascrc(&mp->m_sb))
-			xfs_btree_init_block(mp, lptr->buf_p, magic,
+			libxfs_btree_init_block(mp, lptr->buf_p, magic,
 						i, 0, agno,
 						XFS_BTREE_CRC_BLOCKS);
 		else
-			xfs_btree_init_block(mp, lptr->buf_p, magic,
+			libxfs_btree_init_block(mp, lptr->buf_p, magic,
 						i, 0, agno, 0);
 	}
 
@@ -1232,11 +1232,11 @@ build_ino_tree(xfs_mount_t *mp, xfs_agnumber_t agno,
 		bt_hdr = XFS_BUF_TO_BLOCK(lptr->buf_p);
 		memset(bt_hdr, 0, mp->m_sb.sb_blocksize);
 		if (xfs_sb_version_hascrc(&mp->m_sb))
-			xfs_btree_init_block(mp, lptr->buf_p, magic,
+			libxfs_btree_init_block(mp, lptr->buf_p, magic,
 						0, 0, agno,
 						XFS_BTREE_CRC_BLOCKS);
 		else
-			xfs_btree_init_block(mp, lptr->buf_p, magic,
+			libxfs_btree_init_block(mp, lptr->buf_p, magic,
 						0, 0, agno, 0);
 
 		bt_hdr->bb_u.s.bb_leftsib = cpu_to_be32(lptr->prev_agbno);
@@ -1490,7 +1490,7 @@ prop_rmap_cursor(
 		lptr->buf_p->b_ops = &xfs_rmapbt_buf_ops;
 		bt_hdr = XFS_BUF_TO_BLOCK(lptr->buf_p);
 		memset(bt_hdr, 0, mp->m_sb.sb_blocksize);
-		xfs_btree_init_block(mp, lptr->buf_p, XFS_RMAP_CRC_MAGIC,
+		libxfs_btree_init_block(mp, lptr->buf_p, XFS_RMAP_CRC_MAGIC,
 					level, 0, agno,
 					XFS_BTREE_CRC_BLOCKS);
 
@@ -1604,7 +1604,7 @@ build_rmap_tree(
 		lptr->buf_p->b_ops = &xfs_rmapbt_buf_ops;
 		bt_hdr = XFS_BUF_TO_BLOCK(lptr->buf_p);
 		memset(bt_hdr, 0, mp->m_sb.sb_blocksize);
-		xfs_btree_init_block(mp, lptr->buf_p, XFS_RMAP_CRC_MAGIC,
+		libxfs_btree_init_block(mp, lptr->buf_p, XFS_RMAP_CRC_MAGIC,
 					i, 0, agno,
 					XFS_BTREE_CRC_BLOCKS);
 	}
@@ -1629,7 +1629,7 @@ _("Insufficient memory to construct reverse-map cursor."));
 		lptr->buf_p->b_ops = &xfs_rmapbt_buf_ops;
 		bt_hdr = XFS_BUF_TO_BLOCK(lptr->buf_p);
 		memset(bt_hdr, 0, mp->m_sb.sb_blocksize);
-		xfs_btree_init_block(mp, lptr->buf_p, XFS_RMAP_CRC_MAGIC,
+		libxfs_btree_init_block(mp, lptr->buf_p, XFS_RMAP_CRC_MAGIC,
 					0, 0, agno,
 					XFS_BTREE_CRC_BLOCKS);
 
@@ -2162,21 +2162,21 @@ phase5(xfs_mount_t *mp)
 
 #ifdef XR_BLD_FREE_TRACE
 	fprintf(stderr, "inobt level 1, maxrec = %d, minrec = %d\n",
-		xfs_inobt_maxrecs(mp, mp->m_sb.sb_blocksize, 0),
-		xfs_inobt_maxrecs(mp, mp->m_sb.sb_blocksize, 0) / 2);
+		libxfs_inobt_maxrecs(mp, mp->m_sb.sb_blocksize, 0),
+		libxfs_inobt_maxrecs(mp, mp->m_sb.sb_blocksize, 0) / 2);
 	fprintf(stderr, "inobt level 0 (leaf), maxrec = %d, minrec = %d\n",
-		xfs_inobt_maxrecs(mp, mp->m_sb.sb_blocksize, 1),
-		xfs_inobt_maxrecs(mp, mp->m_sb.sb_blocksize, 1) / 2);
+		libxfs_inobt_maxrecs(mp, mp->m_sb.sb_blocksize, 1),
+		libxfs_inobt_maxrecs(mp, mp->m_sb.sb_blocksize, 1) / 2);
 	fprintf(stderr, "xr inobt level 0 (leaf), maxrec = %d\n",
 		XR_INOBT_BLOCK_MAXRECS(mp, 0));
 	fprintf(stderr, "xr inobt level 1 (int), maxrec = %d\n",
 		XR_INOBT_BLOCK_MAXRECS(mp, 1));
 	fprintf(stderr, "bnobt level 1, maxrec = %d, minrec = %d\n",
-		xfs_allocbt_maxrecs(mp, mp->m_sb.sb_blocksize, 0),
-		xfs_allocbt_maxrecs(mp, mp->m_sb.sb_blocksize, 0) / 2);
+		libxfs_allocbt_maxrecs(mp, mp->m_sb.sb_blocksize, 0),
+		libxfs_allocbt_maxrecs(mp, mp->m_sb.sb_blocksize, 0) / 2);
 	fprintf(stderr, "bnobt level 0 (leaf), maxrec = %d, minrec = %d\n",
-		xfs_allocbt_maxrecs(mp, mp->m_sb.sb_blocksize, 1),
-		xfs_allocbt_maxrecs(mp, mp->m_sb.sb_blocksize, 1) / 2);
+		libxfs_allocbt_maxrecs(mp, mp->m_sb.sb_blocksize, 1),
+		libxfs_allocbt_maxrecs(mp, mp->m_sb.sb_blocksize, 1) / 2);
 #endif
 	/*
 	 * make sure the root and realtime inodes show up allocated
diff --git a/repair/phase6.c b/repair/phase6.c
index 2500def..973a5f8 100644
--- a/repair/phase6.c
+++ b/repair/phase6.c
@@ -451,7 +451,7 @@ bmap_next_offset(
 	}
 	ifp = XFS_IFORK_PTR(ip, whichfork);
 	if (!(ifp->if_flags & XFS_IFEXTENTS) &&
-	    (error = xfs_iread_extents(tp, ip, whichfork)))
+	    (error = -libxfs_iread_extents(tp, ip, whichfork)))
 		return error;
 	bno = *bnop + 1;
 	libxfs_bmap_search_extents(ip, bno, whichfork, &eof, &lastx,
@@ -1286,7 +1286,7 @@ longform_dir2_rebuild(
 	 */
 	pip.i_ino = get_inode_parent(irec, ino_offset);
 	if (pip.i_ino == NULLFSINO ||
-	    xfs_dir_ino_validate(mp, pip.i_ino))
+	    libxfs_dir_ino_validate(mp, pip.i_ino))
 		pip.i_ino = mp->m_sb.sb_rootino;
 
 	libxfs_defer_init(&dfops, &firstblock);
@@ -1311,7 +1311,7 @@ longform_dir2_rebuild(
 
 	ASSERT(done);
 
-	error = libxfs_dir_init(tp, ip, &pip);
+	error = -libxfs_dir_init(tp, ip, &pip);
 	if (error) {
 		do_warn(_("xfs_dir_init failed -- error - %d\n"), error);
 		goto out_bmap_cancel;
diff --git a/repair/prefetch.c b/repair/prefetch.c
index b4f20d9..b76a784 100644
--- a/repair/prefetch.c
+++ b/repair/prefetch.c
@@ -369,7 +369,7 @@ pf_read_btinode(
 		return;
 
 	dsize = XFS_DFORK_DSIZE(dino, mp);
-	pp = XFS_BMDR_PTR_ADDR(dib, 1, xfs_bmdr_maxrecs(dsize, 0));
+	pp = XFS_BMDR_PTR_ADDR(dib, 1, libxfs_bmdr_maxrecs(dsize, 0));
 
 	for (i = 0; i < numrecs; i++) {
 		dbno = get_unaligned_be64(&pp[i]);
@@ -431,7 +431,7 @@ pf_read_inode_dirs(
 		if (be16_to_cpu(dino->di_magic) != XFS_DINODE_MAGIC)
 			continue;
 
-		if (!xfs_dinode_good_version(mp, dino->di_version))
+		if (!libxfs_dinode_good_version(mp, dino->di_version))
 			continue;
 
 		if (be64_to_cpu(dino->di_size) <= XFS_DFORK_DSIZE(dino, mp))
diff --git a/repair/rmap.c b/repair/rmap.c
index b3d4c25..43b821d 100644
--- a/repair/rmap.c
+++ b/repair/rmap.c
@@ -61,8 +61,8 @@ rmap_compare(
 	__u64			ob;
 
 	pa = a; pb = b;
-	oa = xfs_rmap_irec_offset_pack(pa);
-	ob = xfs_rmap_irec_offset_pack(pb);
+	oa = libxfs_rmap_irec_offset_pack(pa);
+	ob = libxfs_rmap_irec_offset_pack(pb);
 
 	if (pa->rm_startblock < pb->rm_startblock)
 		return -1;
@@ -498,7 +498,7 @@ store_ag_btree_rmap_data(
 		goto err;
 
 	/* Add the AGFL blocks to the rmap list */
-	error = libxfs_trans_read_buf(
+	error = -libxfs_trans_read_buf(
 			mp, NULL, mp->m_ddev_targp,
 			XFS_AG_DADDR(mp, agno, XFS_AGFL_DADDR(mp)),
 			XFS_FSS_TO_BB(mp, 1), 0, &agflbp, &xfs_agfl_buf_ops);
@@ -536,13 +536,13 @@ store_ag_btree_rmap_data(
 		if (error)
 			goto err_slab;
 
-		error = libxfs_alloc_read_agf(mp, tp, agno, 0, &agbp);
+		error = -libxfs_alloc_read_agf(mp, tp, agno, 0, &agbp);
 		if (error)
 			goto err_trans;
 
 		ASSERT(XFS_RMAP_NON_INODE_OWNER(rm_rec->rm_owner));
 		libxfs_rmap_ag_owner(&oinfo, rm_rec->rm_owner);
-		error = libxfs_rmap_alloc(tp, agbp, agno, rm_rec->rm_startblock,
+		error = -libxfs_rmap_alloc(tp, agbp, agno, rm_rec->rm_startblock,
 				rm_rec->rm_blockcount, &oinfo);
 		if (error)
 			goto err_trans;
@@ -716,9 +716,9 @@ check_rmaps(
 		goto err;
 
 	/* Leave the per-ag data "uninitialized" since we rewrite it later */
-	pag = xfs_perag_get(mp, agno);
+	pag = libxfs_perag_get(mp, agno);
 	pag->pagf_init = 0;
-	xfs_perag_put(pag);
+	libxfs_perag_put(pag);
 
 	bt_cur = libxfs_rmapbt_init_cursor(mp, NULL, agbp, agno);
 	if (!bt_cur) {
@@ -804,10 +804,10 @@ rmap_diffkeys(
 
 	tmp = *kp1;
 	tmp.rm_flags &= ~XFS_RMAP_REC_FLAGS;
-	oa = xfs_rmap_irec_offset_pack(&tmp);
+	oa = libxfs_rmap_irec_offset_pack(&tmp);
 	tmp = *kp2;
 	tmp.rm_flags &= ~XFS_RMAP_REC_FLAGS;
-	ob = xfs_rmap_irec_offset_pack(&tmp);
+	ob = libxfs_rmap_irec_offset_pack(&tmp);
 
 	d = (__int64_t)kp1->rm_startblock - kp2->rm_startblock;
 	if (d)
@@ -867,7 +867,7 @@ fix_freelist(
 	args.mp = mp;
 	args.agno = agno;
 	args.alignment = 1;
-	args.pag = xfs_perag_get(mp, agno);
+	args.pag = libxfs_perag_get(mp, agno);
 	error = -libxfs_trans_alloc(mp, &tres,
 			libxfs_alloc_min_freelist(mp, args.pag), 0, 0, &tp);
 	if (error)
@@ -899,8 +899,8 @@ fix_freelist(
 	flags = XFS_ALLOC_FLAG_NOSHRINK;
 	if (skip_rmapbt)
 		flags |= XFS_ALLOC_FLAG_NORMAP;
-	error = libxfs_alloc_fix_freelist(&args, flags);
-	xfs_perag_put(args.pag);
+	error = -libxfs_alloc_fix_freelist(&args, flags);
+	libxfs_perag_put(args.pag);
 	if (error) {
 		do_error(_("failed to fix AGFL on AG %d, error %d\n"),
 				agno, error);
diff --git a/repair/sb.c b/repair/sb.c
index a8170ba..ac13a66 100644
--- a/repair/sb.c
+++ b/repair/sb.c
@@ -384,7 +384,7 @@ verify_sb(char *sb_buf, xfs_sb_t *sb, int is_primary_sb)
 
 	/* sector size in range - CRC check time */
 	if (xfs_sb_version_hascrc(sb) &&
-	    !xfs_verify_cksum(sb_buf, sb->sb_sectsize, XFS_SB_CRC_OFF))
+	    !libxfs_verify_cksum(sb_buf, sb->sb_sectsize, XFS_SB_CRC_OFF))
 		return XR_BAD_CRC;
 
 	/* check to ensure blocksize and blocklog are legal */
diff --git a/tools/find-api-violations.sh b/tools/find-api-violations.sh
new file mode 100755
index 0000000..7937749
--- /dev/null
+++ b/tools/find-api-violations.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+# Find libxfs API violations -- calls to functions defined in libxfs/*.c that
+# don't use the libxfs wrappers; or failing to negate the integer return
+# values.
+
+# NOTE: This script doesn't look for API violations in function parameters.
+
+tool_dirs="copy db estimate fs fsck fsr growfs io mdrestore mkfs quota repair rtcp"
+
+# Calls to xfs_* functions in libxfs/*.c without the libxfs_ prefix
+find_possible_api_calls() {
+	grep -rn '[[:space:],-(]xfs_[a-z_]*(' $tool_dirs | sed -e 's/^.*\(xfs_[a-z_]*\)(.*$/\1/g' | sort | uniq
+}
+
+check_if_api_calls() {
+	while read f; do grep "^$f(" libxfs/*.c; done | sed -e 's/^.*:xfs_/xfs_/g' -e 's/.$//g'
+}
+
+find_libxfs_violations() {
+	grep -r -n -f <(find_possible_api_calls | check_if_api_calls | sed -e 's/^/[[:space:],-(]/g' -e 's/$/(/g' ) $tool_dirs
+}
+
+# libxfs calls without negated error codes
+find_errcode_violations() {
+	grep -r -n 'err.* = libxfs' $tool_dirs
+}
+
+# Find xfs_* calls that are in the libxfs definition list
+find_possible_libxfs_api_calls() {
+	grep '#define[[:space:]]*xfs' libxfs/libxfs_api_defs.h | awk '{print $2}'
+}
+
+find_libxfs_api_violations() {
+	grep -r -n -f <(find_possible_libxfs_api_calls | sed -e 's/^/[[:space:],-(]/g' -e 's/$/(/g') $tool_dirs
+}
+
+(find_libxfs_violations ; find_errcode_violations ; find_libxfs_api_violations) | sort -g -t ':' -k 2 | sort -g -t ':' -k 1 | uniq

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 7/7] xfs_repair: fix naming problems in repair/rmap.c
  2016-08-24  2:24 [PATCH 0/7] xfsprogs: reverse mapping fixes Darrick J. Wong
                   ` (5 preceding siblings ...)
  2016-08-24  2:25 ` [PATCH 6/7] misc: fix libxfs api violations Darrick J. Wong
@ 2016-08-24  2:25 ` Darrick J. Wong
  2016-08-25 21:03 ` [PATCH 0/7] xfsprogs: reverse mapping fixes Darrick J. Wong
  7 siblings, 0 replies; 16+ messages in thread
From: Darrick J. Wong @ 2016-08-24  2:25 UTC (permalink / raw)
  To: david, darrick.wong; +Cc: linux-xfs, xfs

The utility functions in repair/rmap.c should all have a prefix
of 'rmap_' so that they are easily identifiable.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 repair/dinode.c     |    2 +
 repair/phase4.c     |   12 ++++----
 repair/phase5.c     |    6 ++--
 repair/rmap.c       |   76 ++++++++++++++++++++++++++-------------------------
 repair/rmap.h       |   26 +++++++++--------
 repair/scan.c       |    4 +--
 repair/xfs_repair.c |    4 +--
 7 files changed, 65 insertions(+), 65 deletions(-)


diff --git a/repair/dinode.c b/repair/dinode.c
index db55860..512a668 100644
--- a/repair/dinode.c
+++ b/repair/dinode.c
@@ -782,7 +782,7 @@ _("illegal state %d in block map %" PRIu64 "\n"),
 			}
 		}
 		if (collect_rmaps) { /* && !check_dups */
-			error = add_rmap(mp, ino, whichfork, &irec);
+			error = rmap_add_rec(mp, ino, whichfork, &irec);
 			if (error)
 				do_error(
 _("couldn't add reverse mapping\n")
diff --git a/repair/phase4.c b/repair/phase4.c
index 3be3786..9da1bb1 100644
--- a/repair/phase4.c
+++ b/repair/phase4.c
@@ -159,7 +159,7 @@ process_ags(
 
 	do_inode_prefetch(mp, ag_stride, process_ag_func, true, false);
 	for (i = 0; i < mp->m_sb.sb_agcount; i++) {
-		error = finish_collecting_fork_rmaps(mp, i);
+		error = rmap_finish_collecting_fork_recs(mp, i);
 		if (error)
 			do_error(
 _("unable to finish adding attr/data fork reverse-mapping data for AG %u.\n"),
@@ -175,17 +175,17 @@ check_rmap_btrees(
 {
 	int		error;
 
-	error = add_fixed_ag_rmap_data(wq->mp, agno);
+	error = rmap_add_fixed_ag_rec(wq->mp, agno);
 	if (error)
 		do_error(
 _("unable to add AG %u metadata reverse-mapping data.\n"), agno);
 
-	error = fold_raw_rmaps(wq->mp, agno);
+	error = rmap_fold_raw_recs(wq->mp, agno);
 	if (error)
 		do_error(
 _("unable to merge AG %u metadata reverse-mapping data.\n"), agno);
 
-	error = check_rmaps(wq->mp, agno);
+	error = rmaps_verify_btree(wq->mp, agno);
 	if (error)
 		do_error(
 _("%s while checking reverse-mappings"),
@@ -199,7 +199,7 @@ process_rmap_data(
 	struct work_queue	wq;
 	xfs_agnumber_t		i;
 
-	if (!needs_rmap_work(mp))
+	if (!rmap_needs_work(mp))
 		return;
 
 	create_work_queue(&wq, mp, libxfs_nproc());
@@ -223,7 +223,7 @@ phase4(xfs_mount_t *mp)
 	int			ag_hdr_block;
 	int			bstate;
 
-	if (needs_rmap_work(mp))
+	if (rmap_needs_work(mp))
 		collect_rmaps = true;
 	ag_hdr_block = howmany(ag_hdr_len, mp->m_sb.sb_blocksize);
 
diff --git a/repair/phase5.c b/repair/phase5.c
index 93b1f75..4c7655c 100644
--- a/repair/phase5.c
+++ b/repair/phase5.c
@@ -251,7 +251,7 @@ setup_cursor(xfs_mount_t *mp, xfs_agnumber_t agno, bt_status_t *curs)
 			blocks_allocated++;
 		}
 
-		error = add_ag_rmap(mp, agno, ext_ptr->ex_startblock, u,
+		error = rmap_add_ag_rec(mp, agno, ext_ptr->ex_startblock, u,
 				curs->owner);
 		if (error)
 			do_error(_("could not set up btree rmaps: %s\n"),
@@ -1615,7 +1615,7 @@ build_rmap_tree(
 	 * pointers for the parent.  that can recurse up to the root
 	 * if required.  set the sibling pointers for leaf level here.
 	 */
-	error = init_rmap_cursor(agno, &rmap_cur);
+	error = rmap_init_cursor(agno, &rmap_cur);
 	if (error)
 		do_error(
 _("Insufficient memory to construct reverse-map cursor."));
@@ -2137,7 +2137,7 @@ phase5_func(
 		/*
 		 * Put the per-AG btree rmap data into the rmapbt
 		 */
-		error = store_ag_btree_rmap_data(mp, agno);
+		error = rmap_store_ag_btree_rec(mp, agno);
 		if (error)
 			do_error(
 _("unable to add AG %u reverse-mapping data to btree.\n"), agno);
diff --git a/repair/rmap.c b/repair/rmap.c
index 43b821d..a493388 100644
--- a/repair/rmap.c
+++ b/repair/rmap.c
@@ -85,7 +85,7 @@ rmap_compare(
  * mapping trees.
  */
 bool
-needs_rmap_work(
+rmap_needs_work(
 	struct xfs_mount	*mp)
 {
 	return xfs_sb_version_hasrmapbt(&mp->m_sb);
@@ -95,13 +95,13 @@ needs_rmap_work(
  * Initialize per-AG reverse map data.
  */
 void
-init_rmaps(
+rmaps_init(
 	struct xfs_mount	*mp)
 {
 	xfs_agnumber_t		i;
 	int			error;
 
-	if (!needs_rmap_work(mp))
+	if (!rmap_needs_work(mp))
 		return;
 
 	ag_rmaps = calloc(mp->m_sb.sb_agcount, sizeof(struct xfs_ag_rmap));
@@ -127,12 +127,12 @@ _("Insufficient memory while allocating raw metadata reverse mapping slabs."));
  * Free the per-AG reverse-mapping data.
  */
 void
-free_rmaps(
+rmaps_free(
 	struct xfs_mount	*mp)
 {
 	xfs_agnumber_t		i;
 
-	if (!needs_rmap_work(mp))
+	if (!rmap_needs_work(mp))
 		return;
 
 	for (i = 0; i < mp->m_sb.sb_agcount; i++) {
@@ -147,7 +147,7 @@ free_rmaps(
  * Decide if two reverse-mapping records can be merged.
  */
 bool
-mergeable_rmaps(
+rmaps_are_mergeable(
 	struct xfs_rmap_irec	*r1,
 	struct xfs_rmap_irec	*r2)
 {
@@ -173,7 +173,7 @@ mergeable_rmaps(
  * fork for later btree reconstruction.
  */
 int
-add_rmap(
+rmap_add_rec(
 	struct xfs_mount	*mp,
 	xfs_ino_t		ino,
 	int			whichfork,
@@ -185,7 +185,7 @@ add_rmap(
 	struct xfs_rmap_irec	*last_rmap;
 	int			error = 0;
 
-	if (!needs_rmap_work(mp))
+	if (!rmap_needs_work(mp))
 		return 0;
 
 	agno = XFS_FSB_TO_AGNO(mp, irec->br_startblock);
@@ -208,7 +208,7 @@ add_rmap(
 	last_rmap = &ag_rmaps[agno].ar_last_rmap;
 	if (last_rmap->rm_owner == XFS_RMAP_OWN_UNKNOWN)
 		*last_rmap = rmap;
-	else if (mergeable_rmaps(last_rmap, &rmap))
+	else if (rmaps_are_mergeable(last_rmap, &rmap))
 		last_rmap->rm_blockcount += rmap.rm_blockcount;
 	else {
 		error = slab_add(ag_rmaps[agno].ar_rmaps, last_rmap);
@@ -222,11 +222,11 @@ add_rmap(
 
 /* Finish collecting inode data/attr fork rmaps. */
 int
-finish_collecting_fork_rmaps(
+rmap_finish_collecting_fork_recs(
 	struct xfs_mount	*mp,
 	xfs_agnumber_t		agno)
 {
-	if (!needs_rmap_work(mp) ||
+	if (!rmap_needs_work(mp) ||
 	    ag_rmaps[agno].ar_last_rmap.rm_owner == XFS_RMAP_OWN_UNKNOWN)
 		return 0;
 	return slab_add(ag_rmaps[agno].ar_rmaps, &ag_rmaps[agno].ar_last_rmap);
@@ -234,7 +234,7 @@ finish_collecting_fork_rmaps(
 
 /* add a raw rmap; these will be merged later */
 static int
-__add_raw_rmap(
+__rmap_add_raw_rec(
 	struct xfs_mount	*mp,
 	xfs_agnumber_t		agno,
 	xfs_agblock_t		agbno,
@@ -262,7 +262,7 @@ __add_raw_rmap(
  * Add a reverse mapping for an inode fork's block mapping btree block.
  */
 int
-add_bmbt_rmap(
+rmap_add_bmbt_rec(
 	struct xfs_mount	*mp,
 	xfs_ino_t		ino,
 	int			whichfork,
@@ -271,7 +271,7 @@ add_bmbt_rmap(
 	xfs_agnumber_t		agno;
 	xfs_agblock_t		agbno;
 
-	if (!needs_rmap_work(mp))
+	if (!rmap_needs_work(mp))
 		return 0;
 
 	agno = XFS_FSB_TO_AGNO(mp, fsbno);
@@ -280,7 +280,7 @@ add_bmbt_rmap(
 	ASSERT(agno < mp->m_sb.sb_agcount);
 	ASSERT(agbno + 1 <= mp->m_sb.sb_agblocks);
 
-	return __add_raw_rmap(mp, agno, agbno, 1, ino,
+	return __rmap_add_raw_rec(mp, agno, agbno, 1, ino,
 			whichfork == XFS_ATTR_FORK, true);
 }
 
@@ -288,28 +288,28 @@ add_bmbt_rmap(
  * Add a reverse mapping for a per-AG fixed metadata extent.
  */
 int
-add_ag_rmap(
+rmap_add_ag_rec(
 	struct xfs_mount	*mp,
 	xfs_agnumber_t		agno,
 	xfs_agblock_t		agbno,
 	xfs_extlen_t		len,
 	uint64_t		owner)
 {
-	if (!needs_rmap_work(mp))
+	if (!rmap_needs_work(mp))
 		return 0;
 
 	ASSERT(agno != NULLAGNUMBER);
 	ASSERT(agno < mp->m_sb.sb_agcount);
 	ASSERT(agbno + len <= mp->m_sb.sb_agblocks);
 
-	return __add_raw_rmap(mp, agno, agbno, len, owner, false, false);
+	return __rmap_add_raw_rec(mp, agno, agbno, len, owner, false, false);
 }
 
 /*
  * Merge adjacent raw rmaps and add them to the main rmap list.
  */
 int
-fold_raw_rmaps(
+rmap_fold_raw_recs(
 	struct xfs_mount	*mp,
 	xfs_agnumber_t		agno)
 {
@@ -330,7 +330,7 @@ fold_raw_rmaps(
 	prev = pop_slab_cursor(cur);
 	rec = pop_slab_cursor(cur);
 	while (prev && rec) {
-		if (mergeable_rmaps(prev, rec)) {
+		if (rmaps_are_mergeable(prev, rec)) {
 			prev->rm_blockcount += rec->rm_blockcount;
 			rec = pop_slab_cursor(cur);
 			continue;
@@ -395,7 +395,7 @@ popcnt(
  * sb/agi/agf/agfl headers, inode chunks, and the log.
  */
 int
-add_fixed_ag_rmap_data(
+rmap_add_fixed_ag_rec(
 	struct xfs_mount	*mp,
 	xfs_agnumber_t		agno)
 {
@@ -407,11 +407,11 @@ add_fixed_ag_rmap_data(
 	int			startidx;
 	int			nr;
 
-	if (!needs_rmap_work(mp))
+	if (!rmap_needs_work(mp))
 		return 0;
 
 	/* sb/agi/agf/agfl headers */
-	error = add_ag_rmap(mp, agno, 0, XFS_BNO_BLOCK(mp),
+	error = rmap_add_ag_rec(mp, agno, 0, XFS_BNO_BLOCK(mp),
 			XFS_RMAP_OWN_FS);
 	if (error)
 		goto out;
@@ -432,7 +432,7 @@ add_fixed_ag_rmap_data(
 		agino = ino_rec->ino_startnum + startidx;
 		agbno = XFS_AGINO_TO_AGBNO(mp, agino);
 		if (XFS_AGINO_TO_OFFSET(mp, agino) == 0) {
-			error = add_ag_rmap(mp, agno, agbno, nr,
+			error = rmap_add_ag_rec(mp, agno, agbno, nr,
 					XFS_RMAP_OWN_INODES);
 			if (error)
 				goto out;
@@ -443,7 +443,7 @@ add_fixed_ag_rmap_data(
 	fsbno = mp->m_sb.sb_logstart;
 	if (fsbno && XFS_FSB_TO_AGNO(mp, fsbno) == agno) {
 		agbno = XFS_FSB_TO_AGBNO(mp, mp->m_sb.sb_logstart);
-		error = add_ag_rmap(mp, agno, agbno, mp->m_sb.sb_logblocks,
+		error = rmap_add_ag_rec(mp, agno, agbno, mp->m_sb.sb_logblocks,
 				XFS_RMAP_OWN_LOG);
 		if (error)
 			goto out;
@@ -473,7 +473,7 @@ out:
  * the rmapbt, after which it is fully regenerated.
  */
 int
-store_ag_btree_rmap_data(
+rmap_store_ag_btree_rec(
 	struct xfs_mount	*mp,
 	xfs_agnumber_t		agno)
 {
@@ -509,7 +509,7 @@ store_ag_btree_rmap_data(
 	agfl_bno += ag_rmaps[agno].ar_flcount;
 	b = agfl_bno;
 	while (*b != NULLAGBLOCK && b - agfl_bno <= XFS_AGFL_SIZE(mp)) {
-		error = add_ag_rmap(mp, agno, be32_to_cpu(*b), 1,
+		error = rmap_add_ag_rec(mp, agno, be32_to_cpu(*b), 1,
 				XFS_RMAP_OWN_AG);
 		if (error)
 			goto err;
@@ -519,7 +519,7 @@ store_ag_btree_rmap_data(
 	agflbp = NULL;
 
 	/* Merge all the raw rmaps into the main list */
-	error = fold_raw_rmaps(mp, agno);
+	error = rmap_fold_raw_recs(mp, agno);
 	if (error)
 		goto err;
 
@@ -572,7 +572,7 @@ err:
 
 #ifdef RMAP_DEBUG
 static void
-dump_rmap(
+rmap_dump(
 	const char		*msg,
 	xfs_agnumber_t		agno,
 	struct xfs_rmap_irec	*rmap)
@@ -587,7 +587,7 @@ dump_rmap(
 		(unsigned int)rmap->rm_flags);
 }
 #else
-# define dump_rmap(m, a, r)
+# define rmap_dump(m, a, r)
 #endif
 
 /*
@@ -605,7 +605,7 @@ rmap_record_count(
  * Return a slab cursor that will return rmap objects in order.
  */
 int
-init_rmap_cursor(
+rmap_init_cursor(
 	xfs_agnumber_t		agno,
 	struct xfs_slab_cursor	**cur)
 {
@@ -623,7 +623,7 @@ rmap_avoid_check(void)
 
 /* Look for an rmap in the rmapbt that matches a given rmap. */
 static int
-lookup_rmap(
+rmap_lookup(
 	struct xfs_btree_cur	*bt_cur,
 	struct xfs_rmap_irec	*rm_rec,
 	struct xfs_rmap_irec	*tmp,
@@ -647,7 +647,7 @@ lookup_rmap(
 #define NEXTP(x)	((x)->rm_startblock + (x)->rm_blockcount)
 #define NEXTL(x)	((x)->rm_offset + (x)->rm_blockcount)
 static bool
-is_good_rmap(
+rmap_is_good(
 	struct xfs_rmap_irec	*observed,
 	struct xfs_rmap_irec	*btree)
 {
@@ -685,7 +685,7 @@ is_good_rmap(
  * Compare the observed reverse mappings against what's in the ag btree.
  */
 int
-check_rmaps(
+rmaps_verify_btree(
 	struct xfs_mount	*mp,
 	xfs_agnumber_t		agno)
 {
@@ -707,7 +707,7 @@ check_rmaps(
 	}
 
 	/* Create cursors to refcount structures */
-	error = init_rmap_cursor(agno, &rm_cur);
+	error = rmap_init_cursor(agno, &rm_cur);
 	if (error)
 		return error;
 
@@ -728,7 +728,7 @@ check_rmaps(
 
 	rm_rec = pop_slab_cursor(rm_cur);
 	while (rm_rec) {
-		error = lookup_rmap(bt_cur, rm_rec, &tmp, &have);
+		error = rmap_lookup(bt_cur, rm_rec, &tmp, &have);
 		if (error)
 			goto err;
 		if (!have) {
@@ -749,7 +749,7 @@ _("Missing reverse-mapping record for (%u/%u) %slen %u owner %"PRId64" \
 		}
 
 		/* Compare each refcount observation against the btree's */
-		if (!is_good_rmap(rm_rec, &tmp)) {
+		if (!rmap_is_good(rm_rec, &tmp)) {
 			do_warn(
 _("Incorrect reverse-mapping: saw (%u/%u) %slen %u owner %"PRId64" %s%soff \
 %"PRIu64"; should be (%u/%u) %slen %u owner %"PRId64" %s%soff %"PRIu64"\n"),
@@ -918,7 +918,7 @@ rmap_store_agflcount(
 	xfs_agnumber_t		agno,
 	int			count)
 {
-	if (!needs_rmap_work(mp))
+	if (!rmap_needs_work(mp))
 		return;
 
 	ag_rmaps[agno].ar_flcount = count;
diff --git a/repair/rmap.h b/repair/rmap.h
index 69215e8..7106dfc 100644
--- a/repair/rmap.h
+++ b/repair/rmap.h
@@ -22,27 +22,27 @@
 
 extern bool collect_rmaps;
 
-extern bool needs_rmap_work(struct xfs_mount *);
+extern bool rmap_needs_work(struct xfs_mount *);
 
-extern void init_rmaps(struct xfs_mount *);
-extern void free_rmaps(struct xfs_mount *);
+extern void rmaps_init(struct xfs_mount *);
+extern void rmaps_free(struct xfs_mount *);
 
-extern int add_rmap(struct xfs_mount *, xfs_ino_t, int, struct xfs_bmbt_irec *);
-extern int finish_collecting_fork_rmaps(struct xfs_mount *mp,
+extern int rmap_add_rec(struct xfs_mount *, xfs_ino_t, int, struct xfs_bmbt_irec *);
+extern int rmap_finish_collecting_fork_recs(struct xfs_mount *mp,
 		xfs_agnumber_t agno);
-extern int add_ag_rmap(struct xfs_mount *, xfs_agnumber_t agno,
+extern int rmap_add_ag_rec(struct xfs_mount *, xfs_agnumber_t agno,
 		xfs_agblock_t agbno, xfs_extlen_t len, uint64_t owner);
-extern int add_bmbt_rmap(struct xfs_mount *, xfs_ino_t, int, xfs_fsblock_t);
-extern int fold_raw_rmaps(struct xfs_mount *mp, xfs_agnumber_t agno);
-extern bool mergeable_rmaps(struct xfs_rmap_irec *r1, struct xfs_rmap_irec *r2);
+extern int rmap_add_bmbt_rec(struct xfs_mount *, xfs_ino_t, int, xfs_fsblock_t);
+extern int rmap_fold_raw_recs(struct xfs_mount *mp, xfs_agnumber_t agno);
+extern bool rmaps_are_mergeable(struct xfs_rmap_irec *r1, struct xfs_rmap_irec *r2);
 
-extern int add_fixed_ag_rmap_data(struct xfs_mount *, xfs_agnumber_t);
-extern int store_ag_btree_rmap_data(struct xfs_mount *, xfs_agnumber_t);
+extern int rmap_add_fixed_ag_rec(struct xfs_mount *, xfs_agnumber_t);
+extern int rmap_store_ag_btree_rec(struct xfs_mount *, xfs_agnumber_t);
 
 extern size_t rmap_record_count(struct xfs_mount *, xfs_agnumber_t);
-extern int init_rmap_cursor(xfs_agnumber_t, struct xfs_slab_cursor **);
+extern int rmap_init_cursor(xfs_agnumber_t, struct xfs_slab_cursor **);
 extern void rmap_avoid_check(void);
-extern int check_rmaps(struct xfs_mount *, xfs_agnumber_t);
+extern int rmaps_verify_btree(struct xfs_mount *, xfs_agnumber_t);
 
 extern __int64_t rmap_diffkeys(struct xfs_rmap_irec *kp1,
 		struct xfs_rmap_irec *kp2);
diff --git a/repair/scan.c b/repair/scan.c
index 253e3de..8fc4592 100644
--- a/repair/scan.c
+++ b/repair/scan.c
@@ -383,7 +383,7 @@ _("bad state %d, inode %" PRIu64 " bmap block 0x%" PRIx64 "\n"),
 
 	/* Record BMBT blocks in the reverse-mapping data. */
 	if (check_dups && collect_rmaps) {
-		error = add_bmbt_rmap(mp, ino, whichfork, bno);
+		error = rmap_add_bmbt_rec(mp, ino, whichfork, bno);
 		if (error)
 			do_error(
 _("couldn't add inode %"PRIu64" bmbt block %"PRIu64" reverse-mapping data."),
@@ -1040,7 +1040,7 @@ advance:
 			}
 
 			/* Is this mergeable with the previous record? */
-			if (mergeable_rmaps(&rmap_priv->last_rec, &key)) {
+			if (rmaps_are_mergeable(&rmap_priv->last_rec, &key)) {
 				do_warn(
 	_("record %d in block (%u/%u) of %s tree should be merged with previous record\n"),
 					i, agno, bno, name);
diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c
index 3040c46..dc38ece 100644
--- a/repair/xfs_repair.c
+++ b/repair/xfs_repair.c
@@ -900,7 +900,7 @@ main(int argc, char **argv)
 	init_bmaps(mp);
 	incore_ino_init(mp);
 	incore_ext_init(mp);
-	init_rmaps(mp);
+	rmaps_init(mp);
 
 	/* initialize random globals now that we know the fs geometry */
 	inodes_per_block = mp->m_sb.sb_inopblock;
@@ -934,7 +934,7 @@ main(int argc, char **argv)
 	/*
 	 * Done with the block usage maps, toss them...
 	 */
-	free_rmaps(mp);
+	rmaps_free(mp);
 	free_bmaps(mp);
 
 	if (!bad_ino_btree)  {

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH 1/7] xfs: don't perform lookups on zero-height btrees
  2016-08-24  2:24 ` [PATCH 1/7] xfs: don't perform lookups on zero-height btrees Darrick J. Wong
@ 2016-08-25  9:11   ` Christoph Hellwig
  0 siblings, 0 replies; 16+ messages in thread
From: Christoph Hellwig @ 2016-08-25  9:11 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, xfs

Looks good,

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

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH 2/7] xfs: fix some key handling problems in _btree_simple_query_range
  2016-08-24  2:24 ` [PATCH 2/7] xfs: fix some key handling problems in _btree_simple_query_range Darrick J. Wong
@ 2016-08-25  9:11   ` Christoph Hellwig
  0 siblings, 0 replies; 16+ messages in thread
From: Christoph Hellwig @ 2016-08-25  9:11 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, xfs

Looks good,

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

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH 3/7] xfs: simple btree query range should look right if LE lookup fails
  2016-08-24  2:24 ` [PATCH 3/7] xfs: simple btree query range should look right if LE lookup fails Darrick J. Wong
@ 2016-08-25  9:11   ` Christoph Hellwig
  0 siblings, 0 replies; 16+ messages in thread
From: Christoph Hellwig @ 2016-08-25  9:11 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, xfs

Looks good,

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

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH 4/7] libxcmd: fix mount option parsing to find rt/log devices
  2016-08-24  2:24 ` [PATCH 4/7] libxcmd: fix mount option parsing to find rt/log devices Darrick J. Wong
@ 2016-08-25  9:12   ` Christoph Hellwig
  0 siblings, 0 replies; 16+ messages in thread
From: Christoph Hellwig @ 2016-08-25  9:12 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, xfs

On Tue, Aug 23, 2016 at 07:24:50PM -0700, Darrick J. Wong wrote:
> It turns out that glibc's hasmntopt implementation returns NULL
> if the opt parameter ends with an equals ('=').  Therefore, we
> cannot directly search for the option 'rtdev='; we must instead
> have hasmntopt look for 'rtdev' and look for the trailing equals
> sign ourselves.  This fixes xfs_info's reporting of external
> log and realtime device paths, and xfs_scrub will need it for
> data block scrubbing of realtime extents.

Looks good,

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

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH 5/7] misc: fix Coverity errors
  2016-08-24  2:24 ` [PATCH 5/7] misc: fix Coverity errors Darrick J. Wong
@ 2016-08-25  9:14   ` Christoph Hellwig
  2016-08-25 16:30     ` Darrick J. Wong
  2016-08-25 21:02   ` [PATCH v2 " Darrick J. Wong
  1 sibling, 1 reply; 16+ messages in thread
From: Christoph Hellwig @ 2016-08-25  9:14 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, xfs

On Tue, Aug 23, 2016 at 07:24:56PM -0700, Darrick J. Wong wrote:
> Fix various code sloppinesses pointed out by Coverity.
> 
> Coverity-id: 1371628 - 1371638

> @@ -75,6 +75,7 @@ fsmap(
>  	high.rm_owner = ULLONG_MAX;
>  	high.rm_offset = ULLONG_MAX;
>  	high.rm_flags = XFS_RMAP_ATTR_FORK | XFS_RMAP_BMBT_BLOCK | XFS_RMAP_UNWRITTEN;
> +	high.rm_blockcount = low.rm_blockcount = 0;

Do the low initialization near the remaining low fields?

or better do a struct initialization ala

	struct xfs_rmap_irec low = { 0, };
	struct xfs_rmap_irec high = { 0, };

that ensures the who;le structure is zero-filled for uninitialized
fields.

> diff --git a/repair/phase5.c b/repair/phase5.c
> index e583879..5a7185c 100644
> --- a/repair/phase5.c
> +++ b/repair/phase5.c
> @@ -1464,7 +1464,7 @@ prop_rmap_cursor(
>  		 * and set the rightsib pointer of current block
>  		 */
>  #ifdef XR_BLD_INO_TRACE
> -		fprintf(stderr, " ino prop agbno %d ", lptr->prev_agbno);
> +		fprintf(stderr, " rmap prop agbno %d ", lptr->prev_agbno);
>  #endif

Did Coveryity really point this out? :)

> @@ -1548,6 +1548,7 @@ prop_rmap_highkey(
>  		bt_key->rm_offset = cpu_to_be64(
>  				libxfs_rmap_irec_offset_pack(&high_key));
>  
> +		key.rm_blockcount = 0;

should probably be a struct initializer again

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH 5/7] misc: fix Coverity errors
  2016-08-25  9:14   ` Christoph Hellwig
@ 2016-08-25 16:30     ` Darrick J. Wong
  0 siblings, 0 replies; 16+ messages in thread
From: Darrick J. Wong @ 2016-08-25 16:30 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-xfs, xfs

On Thu, Aug 25, 2016 at 02:14:52AM -0700, Christoph Hellwig wrote:
> On Tue, Aug 23, 2016 at 07:24:56PM -0700, Darrick J. Wong wrote:
> > Fix various code sloppinesses pointed out by Coverity.
> > 
> > Coverity-id: 1371628 - 1371638
> 
> > @@ -75,6 +75,7 @@ fsmap(
> >  	high.rm_owner = ULLONG_MAX;
> >  	high.rm_offset = ULLONG_MAX;
> >  	high.rm_flags = XFS_RMAP_ATTR_FORK | XFS_RMAP_BMBT_BLOCK | XFS_RMAP_UNWRITTEN;
> > +	high.rm_blockcount = low.rm_blockcount = 0;
> 
> Do the low initialization near the remaining low fields?
> 
> or better do a struct initialization ala
> 
> 	struct xfs_rmap_irec low = { 0, };
> 	struct xfs_rmap_irec high = { 0, };
> 
> that ensures the who;le structure is zero-filled for uninitialized
> fields.

Ok.

> > diff --git a/repair/phase5.c b/repair/phase5.c
> > index e583879..5a7185c 100644
> > --- a/repair/phase5.c
> > +++ b/repair/phase5.c
> > @@ -1464,7 +1464,7 @@ prop_rmap_cursor(
> >  		 * and set the rightsib pointer of current block
> >  		 */
> >  #ifdef XR_BLD_INO_TRACE
> > -		fprintf(stderr, " ino prop agbno %d ", lptr->prev_agbno);
> > +		fprintf(stderr, " rmap prop agbno %d ", lptr->prev_agbno);
> >  #endif
> 
> Did Coveryity really point this out? :)

Heh, nope.  I'll add it in the changelog.

> > @@ -1548,6 +1548,7 @@ prop_rmap_highkey(
> >  		bt_key->rm_offset = cpu_to_be64(
> >  				libxfs_rmap_irec_offset_pack(&high_key));
> >  
> > +		key.rm_blockcount = 0;
> 
> should probably be a struct initializer again

<nod>

--D

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH v2 5/7] misc: fix Coverity errors
  2016-08-24  2:24 ` [PATCH 5/7] misc: fix Coverity errors Darrick J. Wong
  2016-08-25  9:14   ` Christoph Hellwig
@ 2016-08-25 21:02   ` Darrick J. Wong
  1 sibling, 0 replies; 16+ messages in thread
From: Darrick J. Wong @ 2016-08-25 21:02 UTC (permalink / raw)
  To: david; +Cc: linux-xfs, xfs

Fix various code sloppinesses pointed out by Coverity,
and fix an incorrect comment/debug message.

Coverity-id: 1371628 - 1371638
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 db/fsmap.c      |    7 ++-----
 repair/phase5.c |   17 +++++++++--------
 repair/rmap.c   |    4 ++--
 repair/scan.c   |    2 +-
 4 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/db/fsmap.c b/db/fsmap.c
index b2ba55d..61ccce0 100644
--- a/db/fsmap.c
+++ b/db/fsmap.c
@@ -57,8 +57,8 @@ fsmap(
 	xfs_agnumber_t		end_ag;
 	xfs_agnumber_t		agno;
 	xfs_daddr_t		eofs;
-	struct xfs_rmap_irec	low;
-	struct xfs_rmap_irec	high;
+	struct xfs_rmap_irec	low = {0};
+	struct xfs_rmap_irec	high = {0};
 	struct xfs_btree_cur	*bt_cur;
 	struct xfs_buf		*agbp;
 	int			error;
@@ -68,9 +68,6 @@ fsmap(
 		end_fsb = XFS_DADDR_TO_FSB(mp, eofs - 1);
 
 	low.rm_startblock = XFS_FSB_TO_AGBNO(mp, start_fsb);
-	low.rm_owner = 0;
-	low.rm_offset = 0;
-	low.rm_flags = 0;
 	high.rm_startblock = -1U;
 	high.rm_owner = ULLONG_MAX;
 	high.rm_offset = ULLONG_MAX;
diff --git a/repair/phase5.c b/repair/phase5.c
index e583879..27141cc 100644
--- a/repair/phase5.c
+++ b/repair/phase5.c
@@ -1464,7 +1464,7 @@ prop_rmap_cursor(
 		 * and set the rightsib pointer of current block
 		 */
 #ifdef XR_BLD_INO_TRACE
-		fprintf(stderr, " ino prop agbno %d ", lptr->prev_agbno);
+		fprintf(stderr, " rmap prop agbno %d ", lptr->prev_agbno);
 #endif
 		if (lptr->prev_agbno != NULLAGBLOCK)  {
 			ASSERT(lptr->prev_buf_p != NULL);
@@ -1502,7 +1502,7 @@ prop_rmap_cursor(
 		prop_rmap_cursor(mp, agno, btree_curs, rm_rec, level);
 	}
 	/*
-	 * add inode info to current block
+	 * add rmap info to current block
 	 */
 	be16_add_cpu(&bt_hdr->bb_numrecs, 1);
 
@@ -1529,13 +1529,12 @@ prop_rmap_highkey(
 	struct xfs_btree_block	*bt_hdr;
 	struct xfs_rmap_key	*bt_key;
 	struct bt_stat_level	*lptr;
-	struct xfs_rmap_irec	key;
+	struct xfs_rmap_irec	key = {0};
 	struct xfs_rmap_irec	high_key;
 	int			level;
 	int			i;
 	int			numrecs;
 
-	key.rm_flags = 0;
 	high_key = *rm_highkey;
 	for (level = 1; level < btree_curs->num_levels; level++) {
 		lptr = &btree_curs->level[level];
@@ -1575,8 +1574,8 @@ build_rmap_tree(
 	struct xfs_rmap_irec	*rm_rec;
 	struct xfs_slab_cursor	*rmap_cur;
 	struct xfs_rmap_rec	*bt_rec;
-	struct xfs_rmap_irec	highest_key;
-	struct xfs_rmap_irec	hi_key;
+	struct xfs_rmap_irec	highest_key = {0};
+	struct xfs_rmap_irec	hi_key = {0};
 	struct bt_stat_level	*lptr;
 	int			level = btree_curs->num_levels;
 	int			error;
@@ -1621,7 +1620,7 @@ _("Insufficient memory to construct reverse-map cursor."));
 	rm_rec = pop_slab_cursor(rmap_cur);
 	lptr = &btree_curs->level[0];
 
-	for (i = 0; i < lptr->num_blocks; i++)  {
+	for (i = 0; i < lptr->num_blocks && rm_rec != NULL; i++)  {
 		/*
 		 * block initialization, lay in block header
 		 */
@@ -1639,8 +1638,10 @@ _("Insufficient memory to construct reverse-map cursor."));
 		if (lptr->modulo > 0)
 			lptr->modulo--;
 
-		if (lptr->num_recs_pb > 0)
+		if (lptr->num_recs_pb > 0) {
+			ASSERT(rm_rec != NULL);
 			prop_rmap_cursor(mp, agno, btree_curs, rm_rec, 0);
+		}
 
 		bt_rec = (struct xfs_rmap_rec *)
 			  ((char *)bt_hdr + XFS_RMAP_BLOCK_LEN);
diff --git a/repair/rmap.c b/repair/rmap.c
index f22f4f0..cdd5c3a 100644
--- a/repair/rmap.c
+++ b/repair/rmap.c
@@ -316,7 +316,7 @@ fold_raw_rmaps(
 	struct xfs_slab_cursor	*cur = NULL;
 	struct xfs_rmap_irec	*prev, *rec;
 	size_t			old_sz;
-	int			error;
+	int			error = 0;
 
 	old_sz = slab_count(ag_rmaps[agno].ar_rmaps);
 	if (slab_count(ag_rmaps[agno].ar_raw_rmaps) == 0)
@@ -329,7 +329,7 @@ fold_raw_rmaps(
 
 	prev = pop_slab_cursor(cur);
 	rec = pop_slab_cursor(cur);
-	while (rec) {
+	while (prev && rec) {
 		if (mergeable_rmaps(prev, rec)) {
 			prev->rm_blockcount += rec->rm_blockcount;
 			rec = pop_slab_cursor(cur);
diff --git a/repair/scan.c b/repair/scan.c
index 9a46dd0..0ef1123 100644
--- a/repair/scan.c
+++ b/repair/scan.c
@@ -898,7 +898,7 @@ scan_rmapbt(
 	int			state;
 	xfs_agblock_t		lastblock = 0;
 	struct xfs_rmap_key	*kp;
-	struct xfs_rmap_irec	key;
+	struct xfs_rmap_irec	key = {0};
 
 	if (magic != XFS_RMAP_CRC_MAGIC) {
 		name = "(unknown)";

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH 0/7] xfsprogs: reverse mapping fixes
  2016-08-24  2:24 [PATCH 0/7] xfsprogs: reverse mapping fixes Darrick J. Wong
                   ` (6 preceding siblings ...)
  2016-08-24  2:25 ` [PATCH 7/7] xfs_repair: fix naming problems in repair/rmap.c Darrick J. Wong
@ 2016-08-25 21:03 ` Darrick J. Wong
  7 siblings, 0 replies; 16+ messages in thread
From: Darrick J. Wong @ 2016-08-25 21:03 UTC (permalink / raw)
  To: david; +Cc: linux-xfs, xfs

On Tue, Aug 23, 2016 at 07:24:24PM -0700, Darrick J. Wong wrote:
> Hi all,
> 
> This is a roll-up of a few fixes[1] for reverse-mapping in xfsprogs 4.8.
> 
> The patches have been xfstested with the 'auto' group on x64
> and (afaict) don't cause any regressions.
> 
> This is an extraordinary way to eat your data.  Enjoy! 
> Comments and questions are, as always, welcome.

Just FYI I rolled the updated Coverity fix patch into a new branch:
https://github.com/djwong/xfsprogs/tree/for-dave-for-4.8-7

--D

> 
> --D
> 
> [1] https://github.com/djwong/xfsprogs/tree/for-dave-for-4.8-6
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

end of thread, other threads:[~2016-08-25 21:03 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-24  2:24 [PATCH 0/7] xfsprogs: reverse mapping fixes Darrick J. Wong
2016-08-24  2:24 ` [PATCH 1/7] xfs: don't perform lookups on zero-height btrees Darrick J. Wong
2016-08-25  9:11   ` Christoph Hellwig
2016-08-24  2:24 ` [PATCH 2/7] xfs: fix some key handling problems in _btree_simple_query_range Darrick J. Wong
2016-08-25  9:11   ` Christoph Hellwig
2016-08-24  2:24 ` [PATCH 3/7] xfs: simple btree query range should look right if LE lookup fails Darrick J. Wong
2016-08-25  9:11   ` Christoph Hellwig
2016-08-24  2:24 ` [PATCH 4/7] libxcmd: fix mount option parsing to find rt/log devices Darrick J. Wong
2016-08-25  9:12   ` Christoph Hellwig
2016-08-24  2:24 ` [PATCH 5/7] misc: fix Coverity errors Darrick J. Wong
2016-08-25  9:14   ` Christoph Hellwig
2016-08-25 16:30     ` Darrick J. Wong
2016-08-25 21:02   ` [PATCH v2 " Darrick J. Wong
2016-08-24  2:25 ` [PATCH 6/7] misc: fix libxfs api violations Darrick J. Wong
2016-08-24  2:25 ` [PATCH 7/7] xfs_repair: fix naming problems in repair/rmap.c Darrick J. Wong
2016-08-25 21:03 ` [PATCH 0/7] xfsprogs: reverse mapping fixes Darrick J. Wong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.