xfs: introduce xfs_dialloc_roll()
authorDave Chinner <dchinner@redhat.com>
Wed, 9 Dec 2020 18:02:17 +0000 (10:02 -0800)
committerDarrick J. Wong <darrick.wong@oracle.com>
Sat, 12 Dec 2020 18:48:24 +0000 (10:48 -0800)
Introduce a helper to make the on-disk inode allocation rolling
logic clearer in preparation of the following cleanup.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
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>
fs/xfs/libxfs/xfs_ialloc.c
fs/xfs/libxfs/xfs_ialloc.h
fs/xfs/xfs_inode.c

index 45cf7e5..3ae83f6 100644 (file)
@@ -1682,6 +1682,41 @@ error_cur:
        return error;
 }
 
+int
+xfs_dialloc_roll(
+       struct xfs_trans        **tpp,
+       struct xfs_buf          *agibp)
+{
+       struct xfs_trans        *tp = *tpp;
+       struct xfs_dquot_acct   *dqinfo;
+       int                     error;
+
+       /*
+        * Hold to on to the agibp across the commit so no other allocation can
+        * come in and take the free inodes we just allocated for our caller.
+        */
+       xfs_trans_bhold(tp, agibp);
+
+       /*
+        * We want the quota changes to be associated with the next transaction,
+        * NOT this one. So, detach the dqinfo from this and attach it to the
+        * next transaction.
+        */
+       dqinfo = tp->t_dqinfo;
+       tp->t_dqinfo = NULL;
+
+       error = xfs_trans_roll(&tp);
+
+       /* Re-attach the quota info that we detached from prev trx. */
+       tp->t_dqinfo = dqinfo;
+
+       *tpp = tp;
+       if (error)
+               return error;
+       xfs_trans_bjoin(tp, agibp);
+       return 0;
+}
+
 /*
  * Allocate an inode on disk.
  *
index 72b3468..bd6e0db 100644 (file)
@@ -32,6 +32,11 @@ xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o)
        return xfs_buf_offset(b, o << (mp)->m_sb.sb_inodelog);
 }
 
+int
+xfs_dialloc_roll(
+       struct xfs_trans        **tpp,
+       struct xfs_buf          *agibp);
+
 /*
  * Allocate an inode on disk.
  * Mode is used to tell whether the new inode will need space, and whether
index 034fe0a..6329b04 100644 (file)
@@ -958,7 +958,6 @@ xfs_dir_ialloc(
        xfs_inode_t     *ip;
        xfs_buf_t       *ialloc_context = NULL;
        int             code;
-       void            *dqinfo;
 
        tp = *tpp;
        ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
@@ -1002,41 +1001,13 @@ xfs_dir_ialloc(
         * to succeed the second time.
         */
        if (ialloc_context) {
-               /*
-                * Normally, xfs_trans_commit releases all the locks.
-                * We call bhold to hang on to the ialloc_context across
-                * the commit.  Holding this buffer prevents any other
-                * processes from doing any allocations in this
-                * allocation group.
-                */
-               xfs_trans_bhold(tp, ialloc_context);
-
-               /*
-                * We want the quota changes to be associated with the next
-                * transaction, NOT this one. So, detach the dqinfo from this
-                * and attach it to the next transaction.
-                */
-               dqinfo = NULL;
-               if (tp->t_dqinfo) {
-                       dqinfo = (void *)tp->t_dqinfo;
-                       tp->t_dqinfo = NULL;
-               }
-
-               code = xfs_trans_roll(&tp);
-
-               /*
-                * Re-attach the quota info that we detached from prev trx.
-                */
-               if (dqinfo)
-                       tp->t_dqinfo = dqinfo;
-
+               code = xfs_dialloc_roll(&tp, ialloc_context);
                if (code) {
                        xfs_buf_relse(ialloc_context);
                        *tpp = tp;
                        *ipp = NULL;
                        return code;
                }
-               xfs_trans_bjoin(tp, ialloc_context);
 
                /*
                 * Call ialloc again. Since we've locked out all