]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: refactor common transaction/inode/quota allocation idiom
authorDarrick J. Wong <djwong@kernel.org>
Tue, 6 Apr 2021 20:55:40 +0000 (16:55 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Tue, 6 Apr 2021 20:55:40 +0000 (16:55 -0400)
Source kernel commit: 3a1af6c317d0a55524f39079183be107be4c1f39

Create a new helper xfs_trans_alloc_inode that allocates a transaction,
locks and joins an inode to it, and then reserves the appropriate amount
of quota against that transction.  Then replace all the open-coded
idioms with a single call to this helper.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
include/xfs_trans.h
libxfs/libxfs_api_defs.h
libxfs/trans.c
libxfs/xfs_attr.c
libxfs/xfs_bmap.c

index a2f1889982a0399f0e742763ff5ed08156fdf199..281caf306d031a45c7cf85d9d24195c419e93ddd 100644 (file)
@@ -85,6 +85,8 @@ int   xfs_trans_roll(struct xfs_trans **);
 int    libxfs_trans_alloc(struct xfs_mount *mp, struct xfs_trans_res *resp,
                           uint blocks, uint rtextents, uint flags,
                           struct xfs_trans **tpp);
+int    libxfs_trans_alloc_inode(struct xfs_inode *ip, struct xfs_trans_res *resv,
+                       unsigned int dblocks, bool force, struct xfs_trans **tpp);
 int    libxfs_trans_alloc_rollable(struct xfs_mount *mp, uint blocks,
                                    struct xfs_trans **tpp);
 int    libxfs_trans_alloc_empty(struct xfs_mount *mp, struct xfs_trans **tpp);
index e4192e1b1eaa25a41f93216f06d060dd3299f714..d759ff6545c247c555d60785f10e6b061e9c0c81 100644 (file)
 #define xfs_trans_add_item             libxfs_trans_add_item
 #define xfs_trans_alloc_empty          libxfs_trans_alloc_empty
 #define xfs_trans_alloc                        libxfs_trans_alloc
+#define xfs_trans_alloc_inode          libxfs_trans_alloc_inode
 #define xfs_trans_bhold                        libxfs_trans_bhold
 #define xfs_trans_bhold_release                libxfs_trans_bhold_release
 #define xfs_trans_binval               libxfs_trans_binval
index a4a5cbe0734104bc8a1855c3f566157d42d884ec..04f878c521a0ce4a26d6798c28a01201ae5e0bb6 100644 (file)
@@ -996,3 +996,34 @@ libxfs_trans_commit(
 {
        return __xfs_trans_commit(tp, false);
 }
+
+/*
+ * Allocate an transaction, lock and join the inode to it, and reserve quota.
+ *
+ * The caller must ensure that the on-disk dquots attached to this inode have
+ * already been allocated and initialized.  The caller is responsible for
+ * releasing ILOCK_EXCL if a new transaction is returned.
+ */
+int
+libxfs_trans_alloc_inode(
+       struct xfs_inode        *ip,
+       struct xfs_trans_res    *resv,
+       unsigned int            dblocks,
+       bool                    force,
+       struct xfs_trans        **tpp)
+{
+       struct xfs_trans        *tp;
+       struct xfs_mount        *mp = ip->i_mount;
+       int                     error;
+
+       error = libxfs_trans_alloc(mp, resv, dblocks, 0,
+                       force ? XFS_TRANS_RESERVE : 0, &tp);
+       if (error)
+               return error;
+
+       xfs_ilock(ip, XFS_ILOCK_EXCL);
+       xfs_trans_ijoin(tp, ip, 0);
+
+       *tpp = tp;
+       return 0;
+}
index 6e38eae5f943accc880eb3f548ddeeba0df03d25..8cf631b675def13d1aa299bfffdf39084799543a 100644 (file)
@@ -458,14 +458,10 @@ xfs_attr_set(
         * Root fork attributes can use reserved data blocks for this
         * operation if necessary
         */
-       error = xfs_trans_alloc(mp, &tres, total, 0,
-                       rsvd ? XFS_TRANS_RESERVE : 0, &args->trans);
+       error = xfs_trans_alloc_inode(dp, &tres, total, rsvd, &args->trans);
        if (error)
                return error;
 
-       xfs_ilock(dp, XFS_ILOCK_EXCL);
-       xfs_trans_ijoin(args->trans, dp, 0);
-
        if (args->value || xfs_inode_hasattr(dp)) {
                error = xfs_iext_count_may_overflow(dp, XFS_ATTR_FORK,
                                XFS_IEXT_ATTR_MANIP_CNT(rmt_blks));
@@ -474,11 +470,6 @@ xfs_attr_set(
        }
 
        if (args->value) {
-               error = xfs_trans_reserve_quota_nblks(args->trans, dp,
-                               args->total, 0, rsvd);
-               if (error)
-                       goto out_trans_cancel;
-
                error = xfs_has_attr(args);
                if (error == -EEXIST && (args->attr_flags & XATTR_CREATE))
                        goto out_trans_cancel;
index 2079bc2f929501069328f2957638811570cdbfff..445280f44a6e8b176b3ac91a523a700a3c35b5ae 100644 (file)
@@ -1072,19 +1072,13 @@ xfs_bmap_add_attrfork(
 
        blks = XFS_ADDAFORK_SPACE_RES(mp);
 
-       error = xfs_trans_alloc(mp, &M_RES(mp)->tr_addafork, blks, 0,
-                       rsvd ? XFS_TRANS_RESERVE : 0, &tp);
+       error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_addafork, blks,
+                       rsvd, &tp);
        if (error)
                return error;
-
-       xfs_ilock(ip, XFS_ILOCK_EXCL);
-       error = xfs_trans_reserve_quota_nblks(tp, ip, blks, 0, rsvd);
-       if (error)
-               goto trans_cancel;
        if (XFS_IFORK_Q(ip))
                goto trans_cancel;
 
-       xfs_trans_ijoin(tp, ip, 0);
        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
        error = xfs_bmap_set_attrforkoff(ip, size, &version);
        if (error)