]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: move transaction handling to xfs_bmapi_convert_delalloc
authorChristoph Hellwig <hch@lst.de>
Mon, 6 May 2019 22:00:28 +0000 (18:00 -0400)
committerEric Sandeen <sandeen@redhat.com>
Mon, 6 May 2019 22:00:28 +0000 (18:00 -0400)
Source kernel commit: 491ce61e939f76399e344b0414dc5a4c08c1f0cf

No need to deal with the transaction and the inode locking in the
caller. Note that we also switch to passing whichfork as the second
paramter, matching what most related functions do.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/xfs_bmap.c
libxfs/xfs_bmap.h

index d18c17c0b3ca5ab0c352acc1f8d9ee96e162389d..9c312b6ca6c2e4117facae29ff7f3e789e70d256 100644 (file)
@@ -4437,16 +4437,30 @@ error0:
  */
 int
 xfs_bmapi_convert_delalloc(
-       struct xfs_trans        *tp,
        struct xfs_inode        *ip,
-       xfs_fileoff_t           offset_fsb,
        int                     whichfork,
-       struct xfs_bmbt_irec    *imap)
+       xfs_fileoff_t           offset_fsb,
+       struct xfs_bmbt_irec    *imap,
+       unsigned int            *seq)
 {
        struct xfs_ifork        *ifp = XFS_IFORK_PTR(ip, whichfork);
+       struct xfs_mount        *mp = ip->i_mount;
        struct xfs_bmalloca     bma = { NULL };
+       struct xfs_trans        *tp;
        int                     error;
 
+       /*
+        * Space for the extent and indirect blocks was reserved when the
+        * delalloc extent was created so there's no need to do so here.
+        */
+       error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, 0, 0,
+                               XFS_TRANS_RESERVE, &tp);
+       if (error)
+               return error;
+
+       xfs_ilock(ip, XFS_ILOCK_EXCL);
+       xfs_trans_ijoin(tp, ip, 0);
+
        if (!xfs_iext_lookup_extent(ip, ifp, offset_fsb, &bma.icur, &bma.got) ||
            bma.got.br_startoff > offset_fsb) {
                /*
@@ -4455,7 +4469,8 @@ xfs_bmapi_convert_delalloc(
                 * might have moved the extent to the data fork in the meantime.
                 */
                WARN_ON_ONCE(whichfork != XFS_COW_FORK);
-               return -EAGAIN;
+               error = -EAGAIN;
+               goto out_trans_cancel;
        }
 
        /*
@@ -4464,7 +4479,8 @@ xfs_bmapi_convert_delalloc(
         */
        if (!isnullstartblock(bma.got.br_startblock)) {
                *imap = bma.got;
-               return 0;
+               *seq = READ_ONCE(ifp->if_seq);
+               goto out_trans_cancel;
        }
 
        bma.tp = tp;
@@ -4493,6 +4509,7 @@ xfs_bmapi_convert_delalloc(
 
        ASSERT(!isnullstartblock(bma.got.br_startblock));
        *imap = bma.got;
+       *seq = READ_ONCE(ifp->if_seq);
 
        if (whichfork == XFS_COW_FORK) {
                error = xfs_refcount_alloc_cow_extent(tp, bma.blkno,
@@ -4503,8 +4520,19 @@ xfs_bmapi_convert_delalloc(
 
        error = xfs_bmap_btree_to_extents(tp, ip, bma.cur, &bma.logflags,
                        whichfork);
+       if (error)
+               goto out_finish;
+
+       xfs_bmapi_finish(&bma, whichfork, 0);
+       error = xfs_trans_commit(tp);
+       xfs_iunlock(ip, XFS_ILOCK_EXCL);
+       return error;
+
 out_finish:
        xfs_bmapi_finish(&bma, whichfork, error);
+out_trans_cancel:
+       xfs_trans_cancel(tp);
+       xfs_iunlock(ip, XFS_ILOCK_EXCL);
        return error;
 }
 
index b5eca7a2694982af0dfb592f5ebb0424c12a2c88..78b190b6e9080ea5464634c3a8e02a18589e30b0 100644 (file)
@@ -223,8 +223,9 @@ int xfs_bmapi_reserve_delalloc(struct xfs_inode *ip, int whichfork,
                xfs_fileoff_t off, xfs_filblks_t len, xfs_filblks_t prealloc,
                struct xfs_bmbt_irec *got, struct xfs_iext_cursor *cur,
                int eof);
-int    xfs_bmapi_convert_delalloc(struct xfs_trans *, struct xfs_inode *,
-               xfs_fileoff_t, int, struct xfs_bmbt_irec *);
+int    xfs_bmapi_convert_delalloc(struct xfs_inode *ip, int whichfork,
+               xfs_fileoff_t offset_fsb, struct xfs_bmbt_irec *imap,
+               unsigned int *seq);
 
 static inline void
 xfs_bmap_add_free(