public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Brian Foster <bfoster@redhat.com>
To: xfs@oss.sgi.com
Subject: [PATCH v2 15/17] xfs: use actual inode count for sparse records in bulkstat/inumbers
Date: Mon,  3 Nov 2014 11:12:24 -0500	[thread overview]
Message-ID: <1415031146-9107-16-git-send-email-bfoster@redhat.com> (raw)
In-Reply-To: <1415031146-9107-1-git-send-email-bfoster@redhat.com>

The bulkstat and inumbers mechanisms make the assumption that inode
records consist of a full 64 inode chunk in several places. E.g., this
is used to track how many inodes have been processed overall as well as
to determine when all in-use inodes of a record have been processed. The
record processing, in particular, increments the record freecount for
each in-use inode until it hits the expected max of 64.

This is invalid for sparse inode records. While all inodes might be
marked free in the free mask regardless of whether they are allocated on
disk, ir_freecount is based on the total number of physically allocated
inodes and thus may be less than 64 inodes on a completely free inode
chunk.

Create the xfs_inobt_count() helper to calculate the total number of
physically allocated inodes based on the holemask. Use the helper in
xfs_bulkstat() and xfs_inumbers() instead of the fixed
XFS_INODE_PER_CHUNK value to ensure correct accounting in the event of
sparse inode records.

Signed-off-by: Brian Foster <bfoster@redhat.com>
---
 fs/xfs/libxfs/xfs_ialloc.c | 29 +++++++++++++++++++++++++++++
 fs/xfs/libxfs/xfs_ialloc.h |  5 +++++
 fs/xfs/xfs_itable.c        | 16 +++++++++++-----
 3 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c
index 1fbd0a8..5e92422 100644
--- a/fs/xfs/libxfs/xfs_ialloc.c
+++ b/fs/xfs/libxfs/xfs_ialloc.c
@@ -1002,6 +1002,35 @@ xfs_inobt_first_free_inode(
 }
 
 /*
+ * Calculate the real count of inodes in a chunk.
+ */
+int
+xfs_inobt_count(
+	struct xfs_mount		*mp,
+	struct xfs_inobt_rec_incore	*rec)
+{
+	int	inocount;
+	DECLARE_BITMAP(allocbmap, XFS_INODES_PER_CHUNK);
+
+	if (xfs_sb_version_hassparseinodes(&mp->m_sb)) {
+		/*
+		 * allocated inode bit count should match ir_count
+		 *
+		 * TODO: it might be preferable to tie this validation to an
+		 * fs operation rather than a simple utility function call
+		 */
+		xfs_inobt_ialloc_bitmap(allocbmap, rec);
+		inocount = bitmap_weight(allocbmap, XFS_INODES_PER_CHUNK);
+		WARN_ON(inocount != rec->ir_count);
+	}
+
+	if (!xfs_inobt_issparse(rec->ir_holemask))
+		return XFS_INODES_PER_CHUNK;
+
+	return rec->ir_count;
+}
+
+/*
  * Allocate an inode using the inobt-only algorithm.
  */
 STATIC int
diff --git a/fs/xfs/libxfs/xfs_ialloc.h b/fs/xfs/libxfs/xfs_ialloc.h
index 5aa8d6f..527d889 100644
--- a/fs/xfs/libxfs/xfs_ialloc.h
+++ b/fs/xfs/libxfs/xfs_ialloc.h
@@ -166,4 +166,9 @@ int xfs_ialloc_inode_init(struct xfs_mount *mp, struct xfs_trans *tp,
 			  xfs_agnumber_t agno, xfs_agblock_t agbno,
 			  xfs_agblock_t length, unsigned int gen);
 
+/*
+ * Calculate the real count of inodes in a chunk.
+ */
+int xfs_inobt_count(struct xfs_mount *mp, struct xfs_inobt_rec_incore *rec);
+
 #endif	/* __XFS_IALLOC_H__ */
diff --git a/fs/xfs/xfs_itable.c b/fs/xfs/xfs_itable.c
index 7765ff7..b44a9f0 100644
--- a/fs/xfs/xfs_itable.c
+++ b/fs/xfs/xfs_itable.c
@@ -254,7 +254,8 @@ xfs_bulkstat_grab_ichunk(
 		}
 
 		irec->ir_free |= xfs_inobt_maskn(0, idx);
-		*icount = XFS_INODES_PER_CHUNK - irec->ir_freecount;
+		*icount = xfs_inobt_count(cur->bc_mp, irec) -
+			  irec->ir_freecount;
 	}
 
 	return 0;
@@ -285,7 +286,7 @@ xfs_bulkstat_ag_ichunk(
 
 	for (agino = irbp->ir_startino, chunkidx = clustidx = 0;
 	     XFS_BULKSTAT_UBLEFT(ubleft) &&
-	     irbp->ir_freecount < XFS_INODES_PER_CHUNK;
+	     irbp->ir_freecount < xfs_inobt_count(mp, irbp);
 	     chunkidx++, clustidx++, agino++) {
 		int		fmterror;	/* bulkstat formatter result */
 		int		ubused;
@@ -430,6 +431,8 @@ xfs_bulkstat(
 				goto del_cursor;
 			if (icount) {
 				irbp->ir_startino = r.ir_startino;
+				irbp->ir_holemask = r.ir_holemask;
+				irbp->ir_count = r.ir_count;
 				irbp->ir_freecount = r.ir_freecount;
 				irbp->ir_free = r.ir_free;
 				irbp++;
@@ -461,13 +464,16 @@ xfs_bulkstat(
 			 * If this chunk has any allocated inodes, save it.
 			 * Also start read-ahead now for this chunk.
 			 */
-			if (r.ir_freecount < XFS_INODES_PER_CHUNK) {
+			if (r.ir_freecount < xfs_inobt_count(mp, &r)) {
 				xfs_bulkstat_ichunk_ra(mp, agno, &r);
 				irbp->ir_startino = r.ir_startino;
+				irbp->ir_holemask = r.ir_holemask;
+				irbp->ir_count = r.ir_count;
 				irbp->ir_freecount = r.ir_freecount;
 				irbp->ir_free = r.ir_free;
 				irbp++;
-				icount += XFS_INODES_PER_CHUNK - r.ir_freecount;
+				icount += xfs_inobt_count(mp, &r) -
+					  r.ir_freecount;
 			}
 			/*
 			 * Set agino to after this chunk and bump the cursor.
@@ -620,7 +626,7 @@ xfs_inumbers(
 		buffer[bufidx].xi_startino =
 			XFS_AGINO_TO_INO(mp, agno, r.ir_startino);
 		buffer[bufidx].xi_alloccount =
-			XFS_INODES_PER_CHUNK - r.ir_freecount;
+			xfs_inobt_count(mp, &r) - r.ir_freecount;
 		buffer[bufidx].xi_allocmask = ~r.ir_free;
 		if (++bufidx == bcount) {
 			long	written;
-- 
1.8.3.1

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

  parent reply	other threads:[~2014-11-03 16:12 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-03 16:12 [PATCH v2 00/17] xfs: sparse inode chunks Brian Foster
2014-11-03 16:12 ` [PATCH v2 01/17] xfs: add sparse inode chunk alignment superblock field Brian Foster
2014-11-03 16:12 ` [PATCH v2 02/17] xfs: use sparse chunk alignment for min. inode allocation requirement Brian Foster
2014-11-03 16:12 ` [PATCH v2 03/17] xfs: define sparse inode chunks v5 sb feature bit and helper function Brian Foster
2014-11-03 16:12 ` [PATCH v2 04/17] xfs: introduce inode record hole mask for sparse inode chunks Brian Foster
2014-11-03 16:12 ` [PATCH v2 05/17] xfs: create macros/helpers for dealing with " Brian Foster
2014-11-03 22:12   ` Fanael Linithien
2014-11-03 22:34     ` Brian Foster
2014-11-03 23:56       ` Fanael Linithien
2014-11-04  1:33         ` Dave Chinner
2014-11-04 12:15           ` Brian Foster
2014-11-04 12:14         ` Brian Foster
2014-11-03 16:12 ` [PATCH v2 06/17] xfs: pass inode count through ordered icreate log item Brian Foster
2014-11-03 16:12 ` [PATCH v2 07/17] xfs: handle sparse inode chunks in icreate log recovery Brian Foster
2014-11-03 16:12 ` [PATCH v2 08/17] xfs: create helper to manage record overlap for sparse inode chunks Brian Foster
2014-11-03 16:12 ` [PATCH v2 09/17] xfs: allocate sparse inode chunks on full chunk allocation failure Brian Foster
2014-11-03 16:12 ` [PATCH v2 10/17] xfs: helpers to convert holemask to/from generic bitmap Brian Foster
2014-11-03 16:12 ` [PATCH v2 11/17] xfs: filter out sparse regions from individual inode allocation Brian Foster
2014-11-03 16:12 ` [PATCH v2 12/17] xfs: update free inode record logic to support sparse inode records Brian Foster
2014-11-03 16:12 ` [PATCH v2 13/17] xfs: only free allocated regions of inode chunks Brian Foster
2014-11-03 16:12 ` [PATCH v2 14/17] xfs: skip unallocated regions of inode chunks in xfs_ifree_cluster() Brian Foster
2014-11-03 16:12 ` Brian Foster [this message]
2014-11-03 16:12 ` [PATCH v2 16/17] xfs: add fs geometry bit for sparse inode chunks Brian Foster
2014-11-03 16:12 ` [PATCH v2 17/17] xfs: enable sparse inode chunks for v5 superblocks Brian Foster

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=1415031146-9107-16-git-send-email-bfoster@redhat.com \
    --to=bfoster@redhat.com \
    --cc=xfs@oss.sgi.com \
    /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