]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: make COW fork unwritten extent conversions more robust
authorChristoph Hellwig <hch@lst.de>
Mon, 6 May 2019 22:00:29 +0000 (18:00 -0400)
committerEric Sandeen <sandeen@redhat.com>
Mon, 6 May 2019 22:00:29 +0000 (18:00 -0400)
Source kernel commit: 26b91c728b2d15952432371dc2b6ba1dda1fb61f

If we have racing buffered and direct I/O COW fork extents under
writeback can have been moved to the data fork by the time we call
xfs_reflink_convert_cow from xfs_submit_ioend.  This would be mostly
harmless as the block numbers don't change by this move, except for
the fact that xfs_bmapi_write will crash or trigger asserts when
not finding existing extents, even despite trying to paper over this
with the XFS_BMAPI_CONVERT_ONLY flag.

Instead of special casing non-transaction conversions in the already
way too complicated xfs_bmapi_write just add a new helper for the much
simpler non-transactional COW fork case, which simplify ignores not
found extents.

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 60769f3ac71a827c9f79e4ffa6bf9de354d185ff..3ef11e8979e35f71b39c66a3cc542c8706f54f52 100644 (file)
@@ -2022,7 +2022,7 @@ done:
 /*
  * Convert an unwritten allocation to a real allocation or vice versa.
  */
-STATIC int                             /* error */
+int                                    /* error */
 xfs_bmap_add_extent_unwritten_real(
        struct xfs_trans        *tp,
        xfs_inode_t             *ip,    /* incore inode pointer */
@@ -4267,9 +4267,7 @@ xfs_bmapi_write(
 
        ASSERT(*nmap >= 1);
        ASSERT(*nmap <= XFS_BMAP_MAX_NMAP);
-       ASSERT(tp != NULL ||
-              (flags & (XFS_BMAPI_CONVERT | XFS_BMAPI_COWFORK)) ==
-                       (XFS_BMAPI_CONVERT | XFS_BMAPI_COWFORK));
+       ASSERT(tp != NULL);
        ASSERT(len > 0);
        ASSERT(XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_LOCAL);
        ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
@@ -4343,8 +4341,7 @@ xfs_bmapi_write(
                 * First, deal with the hole before the allocated space
                 * that we found, if any.
                 */
-               if ((need_alloc || wasdelay) &&
-                   !(flags & XFS_BMAPI_CONVERT_ONLY)) {
+               if (need_alloc || wasdelay) {
                        bma.eof = eof;
                        bma.conv = !!(flags & XFS_BMAPI_CONVERT);
                        bma.wasdel = wasdelay;
index 78b190b6e9080ea5464634c3a8e02a18589e30b0..8f597f9abdbe952e8e92fb4fc12f568fa9886cba 100644 (file)
@@ -95,9 +95,6 @@ struct xfs_extent_free_item
 /* Map something in the CoW fork. */
 #define XFS_BMAPI_COWFORK      0x200
 
-/* Only convert unwritten extents, don't allocate new blocks */
-#define XFS_BMAPI_CONVERT_ONLY 0x800
-
 /* Skip online discard of freed extents */
 #define XFS_BMAPI_NODISCARD    0x1000
 
@@ -114,7 +111,6 @@ struct xfs_extent_free_item
        { XFS_BMAPI_ZERO,       "ZERO" }, \
        { XFS_BMAPI_REMAP,      "REMAP" }, \
        { XFS_BMAPI_COWFORK,    "COWFORK" }, \
-       { XFS_BMAPI_CONVERT_ONLY, "CONVERT_ONLY" }, \
        { XFS_BMAPI_NODISCARD,  "NODISCARD" }, \
        { XFS_BMAPI_NORMAP,     "NORMAP" }
 
@@ -226,6 +222,10 @@ int        xfs_bmapi_reserve_delalloc(struct xfs_inode *ip, int whichfork,
 int    xfs_bmapi_convert_delalloc(struct xfs_inode *ip, int whichfork,
                xfs_fileoff_t offset_fsb, struct xfs_bmbt_irec *imap,
                unsigned int *seq);
+int    xfs_bmap_add_extent_unwritten_real(struct xfs_trans *tp,
+               struct xfs_inode *ip, int whichfork,
+               struct xfs_iext_cursor *icur, struct xfs_btree_cur **curp,
+               struct xfs_bmbt_irec *new, int *logflagsp);
 
 static inline void
 xfs_bmap_add_free(