Skip to contentSkip to conversation

xfs: introduce a new helper xfs_inobt_lookup_grab_ichunk()

RFC PATCH In review Jeff Liu 2 participants 3 messages Nov 12, 2013 – Nov 17, 2013 XFS filesystem

lore
Share & tools
lore

Jeff Liu

author
#0 lore raw

RFC PATCH 2/4 xfs: introduce a new helper xfs_inobt_lookup_grab_ichunk()

From: Jie Liu <[email protected]>

introduce a new helper xfs_inobt_lookup_grab_ichunk(). This function can be used to lookup the inode chunk that the given inode lives in, and then get the record if we found that chunk. If the inode was not the last in the chunk and there are some left allocated, update the data for the pointed-to record.

Refactor xfs_bulkstat() to make use of the founction.

---
 fs/xfs/xfs_ialloc.c |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/xfs/xfs_ialloc.h |    9 +++++++++
 fs/xfs/xfs_itable.c |   45 +++++++++--------------------------------
 3 files changed, 73 insertions(+), 36 deletions(-)
fs/xfs/xfs_ialloc.c +55 -0
index 86436e7..e34e16f 100644
@@ -111,6 +111,61 @@ xfs_inobt_get_rec(
 }
 
 /*
+ * Lookup the inode chunk that the given inode lives in and then get
+ * the record if we found the chunk.  If the inode was not the last
+ * in the chunk and there are some left allocated, update the data
+ * for the pointed-to record.
+ */
+int
+xfs_inobt_lookup_grab_ichunk(
+	struct xfs_btree_cur		*cur,	/* btree cursor */
+	xfs_agino_t			agino,	/* starting inode of chunk */
+	struct xfs_inobt_rec_incore	*irec,	/* btree record */
+	int				*stat)	/* success/failure */
+{
+	int				idx;	/* Index into inode chunk */
+	int				error;
+
+	/* Lookup the inode chunk that this inode lives in */
+	error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, stat);
+	if (error || !*stat)
+		return error;
+
+	/* Get the record, should always work */
+	error = xfs_inobt_get_rec(cur, irec, stat);
+	ASSERT(!error && *stat);
+	if (error || !*stat)
+		return error;
+
+	*stat = 0;
+	if (irec->ir_startino + XFS_INODES_PER_CHUNK <= agino)
+		return error;
+
+	idx = agino - irec->ir_startino + 1;
+	/*
+	 * We got a right chunk and there are some left inodes allocated at it.
+	 */
+	if (idx < XFS_INODES_PER_CHUNK &&
+	    (xfs_inobt_maskn(idx, XFS_INODES_PER_CHUNK - idx) & ~irec->ir_free)) {
+		int	i;
+
+		/*
+		 * Grab the chunk record.  Mark all the uninteresting inodes free
+		 * (because they're before our start point).
+		 */
+		for (i = 0; i < idx; i++) {
+			if (XFS_INOBT_MASK(i) & ~irec->ir_free)
+				irec->ir_freecount++;
+		}
+
+		irec->ir_free |= xfs_inobt_maskn(0, idx);
+		*stat = 1;
+	}
+
+	return error;
+}
+
+/*
  * Loop over all clusters in a chunk for a given incore inode
  * allocation btree record.  Do a readahead if there are any
  * allocated inodes in that cluster.
fs/xfs/xfs_ialloc.h +9 -0
index 65b2bef..4b032d6 100644
@@ -166,4 +166,13 @@ int xfs_ialloc_inode_init(struct xfs_mount *mp, struct xfs_trans *tp,
 void xfs_inobt_reada_chunk(struct xfs_mount *mp, xfs_agnumber_t agno,
 			   struct xfs_inobt_rec_incore *irec);
 
+/*
+ * Lookup the inode chunk that the given inode lives in and then get
+ * the record if we found the chunk.  If the inode was not the last
+ * in the chunk and there are some left allocated, update the data
+ * for the pointed-to record.
+ */
+int xfs_inobt_lookup_grab_ichunk(struct xfs_btree_cur *cur, xfs_agino_t agino,
+				 struct xfs_inobt_rec_incore *irec, int *stat);
+
 #endif	/* __XFS_IALLOC_H__ */
fs/xfs/xfs_itable.c +9 -36

59 lines not on this page · raw message

Signature · 6 lines
1.7.9.5

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#1 lore raw
Quoted 1 line

Refactor xfs_bulkstat() to make use of the founction.

                                         ... function.
Quoted 8 lines
fs/xfs/xfs_ialloc.c +8 -0
+int
+xfs_inobt_lookup_grab_ichunk(
+	struct xfs_btree_cur		*cur,	/* btree cursor */
+	xfs_agino_t			agino,	/* starting inode of chunk */
+	struct xfs_inobt_rec_incore	*irec,	/* btree record */
+	int				*stat)	/* success/failure */
+{
+	int				idx;	/* Index into inode chunk */

fs/xfs/xfs_ialloc.c xfs_inobt_get_rec( · line 136

Quoted 10 lines
fs/xfs/xfs_ialloc.c +10 -0
+	int				error;
+
+	/* Lookup the inode chunk that this inode lives in */
+	error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, stat);
+	if (error || !*stat)
+		return error;
+
+	/* Get the record, should always work */
+	error = xfs_inobt_get_rec(cur, irec, stat);
+	ASSERT(!error && *stat);

If it wails it's a corruption error, so this shouldn't be an assert, but rather an XFS_WANT_CORRUPTED_GOTO/RETURN

fs/xfs/xfs_ialloc.c xfs_inobt_get_rec( · line 140

Quoted 4 lines
fs/xfs/xfs_ialloc.c +4 -0
+	if (error || !*stat)
+		return error;
+
+	*stat = 0;

Btw, I don't think we need to pass around the status pointer here, the caller doesn't care about the internal lookup status, just if we succeeded or failed.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (irec->ir_startino + XFS_INODES_PER_CHUNK <= agino)
+		return error;

error will usually be zero here, shouldn't we return a real error?

Quoted 10 lines
fs/xfs/xfs_ialloc.c +10 -0
+	idx = agino - irec->ir_startino + 1;
+	/*
+	 * We got a right chunk and there are some left inodes allocated at it.
+	 */
+	if (idx < XFS_INODES_PER_CHUNK &&
+	    (xfs_inobt_maskn(idx, XFS_INODES_PER_CHUNK - idx) & ~irec->ir_free)) {
+		int	i;
+
+		/*
+		 * Grab the chunk record.  Mark all the uninteresting inodes free

fs/xfs/xfs_ialloc.c xfs_inobt_get_rec( · line 163

Quoted 10 lines
fs/xfs/xfs_ialloc.c +10 -0
+		 * (because they're before our start point).
+		 */
+		for (i = 0; i < idx; i++) {
+			if (XFS_INOBT_MASK(i) & ~irec->ir_free)
+				irec->ir_freecount++;
+		}
+
+		irec->ir_free |= xfs_inobt_maskn(0, idx);
+		*stat = 1;
+	}

At this point the function is so bulkstate specific that it should stay in xfs_itable.c and have a name more like xfs_bulkstate_grab_ichunk.

I still like factoring it out though, thanks for the work!

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

author
#2 lore raw
Quoted 17 lines · Christoph Hellwig
Quoted 1 line

Refactor xfs_bulkstat() to make use of the founction.

                                         ... function.
Quoted 13 lines
fs/xfs/xfs_ialloc.c +13 -0
+int
+xfs_inobt_lookup_grab_ichunk(
+	struct xfs_btree_cur		*cur,	/* btree cursor */
+	xfs_agino_t			agino,	/* starting inode of chunk */
+	struct xfs_inobt_rec_incore	*irec,	/* btree record */
+	int				*stat)	/* success/failure */
+{
+	int				idx;	/* Index into inode chunk */
+	int				error;
+
+	/* Lookup the inode chunk that this inode lives in */
+	error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, stat);
+	if (error || !*stat)
Quoted 8 lines

fs/xfs/xfs_ialloc.c xfs_inobt_get_rec( · line 136

Quoted 5 lines
fs/xfs/xfs_ialloc.c +5 -0
+		return error;
+
+	/* Get the record, should always work */
+	error = xfs_inobt_get_rec(cur, irec, stat);
+	ASSERT(!error && *stat);

If it wails it's a corruption error, so this shouldn't be an assert, but rather an XFS_WANT_CORRUPTED_GOTO/RETURN

Indeed.

Quoted 9 lines

fs/xfs/xfs_ialloc.c xfs_inobt_get_rec( · line 140

Quoted 5 lines
fs/xfs/xfs_ialloc.c +4 -0
+	if (error || !*stat)
+		return error;
+
+	*stat = 0;

Btw, I don't think we need to pass around the status pointer here, the caller doesn't care about the internal lookup status, just if we succeeded or failed.

Yes, I'll fix it in next version.

Quoted 5 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+	if (irec->ir_startino + XFS_INODES_PER_CHUNK <= agino)
+		return error;

error will usually be zero here, shouldn't we return a real error?

In xfs_imap_lookup(), it return EINVAL if the given inode is not inside the returned record, looks we should follow up the same rule here.

Quoted 17 lines
Quoted 17 lines
fs/xfs/xfs_ialloc.c +16 -0
+	idx = agino - irec->ir_startino + 1;
+	/*
+	 * We got a right chunk and there are some left inodes allocated at it.
+	 */
+	if (idx < XFS_INODES_PER_CHUNK &&
+	    (xfs_inobt_maskn(idx, XFS_INODES_PER_CHUNK - idx) & ~irec->ir_free)) {
+		int	i;
+
+		/*
+		 * Grab the chunk record.  Mark all the uninteresting inodes free
+		 * (because they're before our start point).
+		 */
+		for (i = 0; i < idx; i++) {
+			if (XFS_INOBT_MASK(i) & ~irec->ir_free)
+				irec->ir_freecount++;
+		}
Quoted 8 lines

fs/xfs/xfs_ialloc.c xfs_inobt_get_rec( · line 163

Quoted 4 lines
fs/xfs/xfs_ialloc.c +4 -0
+
+		irec->ir_free |= xfs_inobt_maskn(0, idx);
+		*stat = 1;
+	}

At this point the function is so bulkstate specific that it should stay in xfs_itable.c and have a name more like xfs_bulkstate_grab_ichunk.

Nice point. :)

Thanks,
-Jeff

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs