]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: spilt xfs_dialloc() into 2 functions
authorDave Chinner <dchinner@redhat.com>
Thu, 7 Jan 2021 20:59:17 +0000 (15:59 -0500)
committerEric Sandeen <sandeen@sandeen.net>
Thu, 7 Jan 2021 20:59:17 +0000 (15:59 -0500)
Source kernel commit: 8d822dc38ad781b1bfa5c03227da80dbd87e9959

This patch explicitly separates free inode chunk allocation and
inode allocation into two individual high level operations.

Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/util.c
libxfs/xfs_ialloc.c
libxfs/xfs_ialloc.h

index 5f42de6d1d16f384bad343c6ce8217c657d9e725..2ee9337ad9be61c660233596a517ffefc5366592 100644 (file)
@@ -521,6 +521,7 @@ libxfs_dir_ialloc(
        struct fsxattr          *fsx,
        struct xfs_inode        **ipp)
 {
+       struct xfs_buf          *agibp;
        xfs_ino_t               parent_ino = dp ? dp->i_ino : 0;
        xfs_ino_t               ino;
        int                     error;
@@ -529,13 +530,19 @@ libxfs_dir_ialloc(
         * Call the space management code to pick the on-disk inode to be
         * allocated.
         */
-       error = xfs_dialloc(tpp, parent_ino, mode, &ino);
+       error = xfs_dialloc_select_ag(tpp, parent_ino, mode, &agibp);
        if (error)
                return error;
 
-       if (ino == NULLFSINO)
+       if (!agibp)
                return -ENOSPC;
 
+       /* Allocate an inode from the selected AG */
+       error = xfs_dialloc_ag(*tpp, agibp, parent_ino, &ino);
+       if (error)
+               return error;
+       ASSERT(ino != NULLFSINO);
+
        return libxfs_init_new_inode(*tpp, dp, ino, mode, nlink, rdev, cr,
                                fsx, ipp);
 }
index c6b5cc67072b217a9b39ff1a9a7f3f3c1d3135e9..3b5956fb5412fcd2b1910868e2e3ff5f59ccb164 100644 (file)
@@ -1565,7 +1565,7 @@ xfs_dialloc_ag_update_inobt(
  * The caller selected an AG for us, and made sure that free inodes are
  * available.
  */
-STATIC int
+int
 xfs_dialloc_ag(
        struct xfs_trans        *tp,
        struct xfs_buf          *agbp,
@@ -1713,21 +1713,22 @@ xfs_dialloc_roll(
 }
 
 /*
- * Allocate an inode on disk.
+ * Select and prepare an AG for inode allocation.
  *
- * Mode is used to tell whether the new inode will need space, and whether it
- * is a directory.
+ * Mode is used to tell whether the new inode is a directory and hence where to
+ * locate it.
  *
- * Once we successfully pick an inode its number is returned and the on-disk
- * data structures are updated.  The inode itself is not read in, since doing so
- * would break ordering constraints with xfs_reclaim.
+ * This function will ensure that the selected AG has free inodes available to
+ * allocate from. The selected AGI will be returned locked to the caller, and it
+ * will allocate more free inodes if required. If no free inodes are found or
+ * can be allocated, no AGI will be returned.
  */
 int
-xfs_dialloc(
+xfs_dialloc_select_ag(
        struct xfs_trans        **tpp,
        xfs_ino_t               parent,
        umode_t                 mode,
-       xfs_ino_t               *inop)
+       struct xfs_buf          **IO_agbp)
 {
        struct xfs_mount        *mp = (*tpp)->t_mountp;
        struct xfs_buf          *agbp;
@@ -1740,15 +1741,15 @@ xfs_dialloc(
        struct xfs_ino_geometry *igeo = M_IGEO(mp);
        bool                    okalloc = true;
 
+       *IO_agbp = NULL;
+
        /*
         * We do not have an agbp, so select an initial allocation
         * group for inode allocation.
         */
        start_agno = xfs_ialloc_ag_select(*tpp, parent, mode);
-       if (start_agno == NULLAGNUMBER) {
-               *inop = NULLFSINO;
+       if (start_agno == NULLAGNUMBER)
                return 0;
-       }
 
        /*
         * If we have already hit the ceiling of inode blocks then clear
@@ -1781,7 +1782,7 @@ xfs_dialloc(
                if (!pag->pagi_init) {
                        error = xfs_ialloc_pagi_init(mp, *tpp, agno);
                        if (error)
-                               goto out_error;
+                               break;
                }
 
                /*
@@ -1796,11 +1797,11 @@ xfs_dialloc(
                 */
                error = xfs_ialloc_read_agi(mp, *tpp, agno, &agbp);
                if (error)
-                       goto out_error;
+                       break;
 
                if (pag->pagi_freecount) {
                        xfs_perag_put(pag);
-                       goto out_alloc;
+                       goto found_ag;
                }
 
                if (!okalloc)
@@ -1811,12 +1812,9 @@ xfs_dialloc(
                if (error) {
                        xfs_trans_brelse(*tpp, agbp);
 
-                       if (error != -ENOSPC)
-                               goto out_error;
-
-                       xfs_perag_put(pag);
-                       *inop = NULLFSINO;
-                       return 0;
+                       if (error == -ENOSPC)
+                               error = 0;
+                       break;
                }
 
                if (ialloced) {
@@ -1833,9 +1831,7 @@ xfs_dialloc(
                                xfs_buf_relse(agbp);
                                return error;
                        }
-
-                       *inop = NULLFSINO;
-                       goto out_alloc;
+                       goto found_ag;
                }
 
 nextag_relse_buffer:
@@ -1844,17 +1840,15 @@ nextag:
                xfs_perag_put(pag);
                if (++agno == mp->m_sb.sb_agcount)
                        agno = 0;
-               if (agno == start_agno) {
-                       *inop = NULLFSINO;
+               if (agno == start_agno)
                        return noroom ? -ENOSPC : 0;
-               }
        }
 
-out_alloc:
-       return xfs_dialloc_ag(*tpp, agbp, parent, inop);
-out_error:
        xfs_perag_put(pag);
        return error;
+found_ag:
+       *IO_agbp = agbp;
+       return 0;
 }
 
 /*
index 13810ffe4af9eabd4e006f27f8ce7ab5ae47bc36..3511086a7ae107e905fa244c4882fffd51299245 100644 (file)
@@ -37,16 +37,26 @@ xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o)
  * Mode is used to tell whether the new inode will need space, and whether
  * it is a directory.
  *
- * Once we successfully pick an inode its number is returned and the
- * on-disk data structures are updated.  The inode itself is not read
- * in, since doing so would break ordering constraints with xfs_reclaim.
+ * There are two phases to inode allocation: selecting an AG and ensuring
+ * that it contains free inodes, followed by allocating one of the free
+ * inodes. xfs_dialloc_select_ag() does the former and returns a locked AGI
+ * to the caller, ensuring that followup call to xfs_dialloc_ag() will
+ * have free inodes to allocate from. xfs_dialloc_ag() will return the inode
+ * number of the free inode we allocated.
  */
 int                                    /* error */
-xfs_dialloc(
+xfs_dialloc_select_ag(
        struct xfs_trans **tpp,         /* double pointer of transaction */
        xfs_ino_t       parent,         /* parent inode (directory) */
        umode_t         mode,           /* mode bits for new inode */
-       xfs_ino_t       *inop);         /* inode number allocated */
+       struct xfs_buf  **IO_agbp);
+
+int
+xfs_dialloc_ag(
+       struct xfs_trans        *tp,
+       struct xfs_buf          *agbp,
+       xfs_ino_t               parent,
+       xfs_ino_t               *inop);
 
 /*
  * Free disk inode.  Carefully avoids touching the incore inode, all