xfs
[Top] [All Lists]

[PATCH 1/3] xfs: create helper to delete multiple inobt records

To: xfs@xxxxxxxxxxx
Subject: [PATCH 1/3] xfs: create helper to delete multiple inobt records
From: Brian Foster <bfoster@xxxxxxxxxx>
Date: Thu, 28 May 2015 16:16:54 -0400
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <1432844216-5820-1-git-send-email-bfoster@xxxxxxxxxx>
References: <1432844216-5820-1-git-send-email-bfoster@xxxxxxxxxx>
In most cases an inode chunk is tracked by a single inode record. With
large block size support up to 64k, however, XFS supports conditions
where a single block might be large enough to allocate an inode chunk
that requires multiple inobt records. For example, an inode record is
fixed at 64 inodes. With a 64k block size, a 512b inode size results in
128-inode chunks and thus requires 2 inobt records per-chunk.

This is handled appropriately at inode allocation time via insertion of
multiple inobt records to span the chunk. We currently have no mechanism
to delete multiple records nor broader chunk context for a particular
record at inode deletion time. Therefore, inode chunks on such
filesystems are never freed and result in non-recoverable space
consumption for the lifetime of the filesystem.

Create the xfs_inobt_delete() helper to remove several inobt records at
a time. Call the helper from the appropriate locations instead of
xfs_btree_delete(). Note that we still do not have the requisite chunk
context at inode deletion time to delete multiple records and therefore
can still only delete records that map to full chunks.

This patch does not alter current behavior but provides a mechanism to
be used by future work that provides the appropriate chunk context.

Signed-off-by: Brian Foster <bfoster@xxxxxxxxxx>
---
 fs/xfs/libxfs/xfs_ialloc.c | 56 +++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 53 insertions(+), 3 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c
index c6d684e..745d965 100644
--- a/fs/xfs/libxfs/xfs_ialloc.c
+++ b/fs/xfs/libxfs/xfs_ialloc.c
@@ -199,6 +199,53 @@ xfs_inobt_insert(
 }
 
 /*
+ * Delete a series of records from the inode btree. Handle multiple records as
+ * an inode chunk might consist of more than one record for large block sizes.
+ */
+static int
+xfs_inobt_delete(
+       struct xfs_mount                *mp,
+       struct xfs_btree_cur            *cur,
+       xfs_agnumber_t                  agno,
+       xfs_agino_t                     agino,
+       int                             ilen)
+{
+       struct xfs_inobt_rec_incore     rec;
+       int                             error;
+       int                             i;
+
+       ASSERT(ilen % XFS_INODES_PER_CHUNK == 0);
+
+       while (ilen > 0) {
+               error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_EQ, &i);
+               if (error)
+                       goto out_error;
+               XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error);
+
+               /* make sure the record is what we expect */
+               error = xfs_inobt_get_rec(cur, &rec, &i);
+               if (error)
+                       goto out_error;
+               XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error);
+               XFS_WANT_CORRUPTED_GOTO(mp, rec.ir_startino == agino,
+                                       out_error);
+
+               error = xfs_btree_delete(cur, &i);
+               if (error)
+                       goto out_error;
+               XFS_WANT_CORRUPTED_GOTO(mp, i == 1, out_error);
+
+               agino += XFS_INODES_PER_CHUNK;
+               ilen -= XFS_INODES_PER_CHUNK;
+       }
+
+       return 0;
+
+out_error:
+       return error;
+}
+
+/*
  * Verify that the number of free inodes in the AGI is correct.
  */
 #ifdef DEBUG
@@ -1965,8 +2012,10 @@ xfs_difree_inobt(
                xfs_trans_mod_sb(tp, XFS_TRANS_SB_ICOUNT, -ilen);
                xfs_trans_mod_sb(tp, XFS_TRANS_SB_IFREE, -(ilen - 1));
 
-               if ((error = xfs_btree_delete(cur, &i))) {
-                       xfs_warn(mp, "%s: xfs_btree_delete returned error %d.",
+               error = xfs_inobt_delete(mp, cur, agno, rec.ir_startino,
+                                        XFS_INODES_PER_CHUNK);
+               if (error) {
+                       xfs_warn(mp, "%s: xfs_inobt_delete returned error %d.",
                                __func__, error);
                        goto error0;
                }
@@ -2083,7 +2132,8 @@ xfs_difree_finobt(
        if (rec.ir_free == XFS_INOBT_ALL_FREE &&
            mp->m_sb.sb_inopblock <= XFS_INODES_PER_CHUNK &&
            !(mp->m_flags & XFS_MOUNT_IKEEP)) {
-               error = xfs_btree_delete(cur, &i);
+               error = xfs_inobt_delete(mp, cur, agno, rec.ir_startino,
+                                        XFS_INODES_PER_CHUNK);
                if (error)
                        goto error;
                ASSERT(i == 1);
-- 
1.9.3

<Prev in Thread] Current Thread [Next in Thread>