xfs: factor out a xfs_bmap_is_real_extent helper
authorChristoph Hellwig <hch@lst.de>
Tue, 28 Mar 2017 21:53:35 +0000 (14:53 -0700)
committerDarrick J. Wong <darrick.wong@oracle.com>
Mon, 3 Apr 2017 22:18:16 +0000 (15:18 -0700)
This checks for all the non-normal extent types, including handling both
encodings of delayed allocations.

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>
fs/xfs/libxfs/xfs_bmap.h
fs/xfs/xfs_aops.c
fs/xfs/xfs_bmap_util.c
fs/xfs/xfs_reflink.c

index cdef87db5262bdc2f43b17f5a1e76fb45a107233..a6e612cabe15892ad8555ce6e9c89b7a2ae82204 100644 (file)
@@ -171,6 +171,18 @@ static inline int xfs_bmapi_whichfork(int bmapi_flags)
        { BMAP_COWFORK,         "COW" }
 
 
+/*
+ * Return true if the extent is a real, allocated extent, or false if it is  a
+ * delayed allocation, and unwritten extent or a hole.
+ */
+static inline bool xfs_bmap_is_real_extent(struct xfs_bmbt_irec *irec)
+{
+       return irec->br_state != XFS_EXT_UNWRITTEN &&
+               irec->br_startblock != HOLESTARTBLOCK &&
+               irec->br_startblock != DELAYSTARTBLOCK &&
+               !isnullstartblock(irec->br_startblock);
+}
+
 /*
  * This macro is used to determine how many extents will be shifted
  * in one write transaction. We could require two splits,
index 61494295d92fe1acb7d343bc3a4e1594f09027ab..8567b385fff4db033e9a5b521a46586f530cd7c9 100644 (file)
@@ -1276,9 +1276,7 @@ xfs_get_blocks(
         * For unwritten extents do not report a disk address in the buffered
         * read case (treat as if we're reading into a hole).
         */
-       if (imap.br_startblock != HOLESTARTBLOCK &&
-           imap.br_startblock != DELAYSTARTBLOCK &&
-           !ISUNWRITTEN(&imap))
+       if (xfs_bmap_is_real_extent(&imap))
                xfs_map_buffer(inode, bh_result, &imap, offset);
 
        /*
index 828532ce0adca80ddfa174540aae6aa06663302b..4d1920e594b05b7bad8aeebff3e8ef6f07676767 100644 (file)
@@ -448,10 +448,9 @@ xfs_getbmap_adjust_shared(
        next_map->br_blockcount = 0;
 
        /* Only written data blocks can be shared. */
-       if (!xfs_is_reflink_inode(ip) || whichfork != XFS_DATA_FORK ||
-           map->br_startblock == DELAYSTARTBLOCK ||
-           map->br_startblock == HOLESTARTBLOCK ||
-           ISUNWRITTEN(map))
+       if (!xfs_is_reflink_inode(ip) ||
+           whichfork != XFS_DATA_FORK ||
+           !xfs_bmap_is_real_extent(map))
                return 0;
 
        agno = XFS_FSB_TO_AGNO(mp, map->br_startblock);
index 4a84c5ea266d8f8fcec61aa55776fec339d27aaf..c0f3754caca2661170fb890d3848528b31199bd0 100644 (file)
@@ -206,11 +206,7 @@ xfs_reflink_trim_around_shared(
        int                     error = 0;
 
        /* Holes, unwritten, and delalloc extents cannot be shared */
-       if (!xfs_is_reflink_inode(ip) ||
-           ISUNWRITTEN(irec) ||
-           irec->br_startblock == HOLESTARTBLOCK ||
-           irec->br_startblock == DELAYSTARTBLOCK ||
-           isnullstartblock(irec->br_startblock)) {
+       if (!xfs_is_reflink_inode(ip) || !xfs_bmap_is_real_extent(irec)) {
                *shared = false;
                return 0;
        }
@@ -1045,12 +1041,12 @@ xfs_reflink_remap_extent(
        xfs_off_t               new_isize)
 {
        struct xfs_mount        *mp = ip->i_mount;
+       bool                    real_extent = xfs_bmap_is_real_extent(irec);
        struct xfs_trans        *tp;
        xfs_fsblock_t           firstfsb;
        unsigned int            resblks;
        struct xfs_defer_ops    dfops;
        struct xfs_bmbt_irec    uirec;
-       bool                    real_extent;
        xfs_filblks_t           rlen;
        xfs_filblks_t           unmap_len;
        xfs_off_t               newlen;
@@ -1059,11 +1055,6 @@ xfs_reflink_remap_extent(
        unmap_len = irec->br_startoff + irec->br_blockcount - destoff;
        trace_xfs_reflink_punch_range(ip, destoff, unmap_len);
 
-       /* Only remap normal extents. */
-       real_extent =  (irec->br_startblock != HOLESTARTBLOCK &&
-                       irec->br_startblock != DELAYSTARTBLOCK &&
-                       !ISUNWRITTEN(irec));
-
        /* No reflinking if we're low on space */
        if (real_extent) {
                error = xfs_reflink_ag_has_free_space(mp,
@@ -1359,9 +1350,7 @@ xfs_reflink_dirty_extents(
                        goto out;
                if (nmaps == 0)
                        break;
-               if (map[0].br_startblock == HOLESTARTBLOCK ||
-                   map[0].br_startblock == DELAYSTARTBLOCK ||
-                   ISUNWRITTEN(&map[0]))
+               if (!xfs_bmap_is_real_extent(&map[0]))
                        goto next;
 
                map[1] = map[0];
@@ -1435,9 +1424,7 @@ xfs_reflink_clear_inode_flag(
                        return error;
                if (nmaps == 0)
                        break;
-               if (map.br_startblock == HOLESTARTBLOCK ||
-                   map.br_startblock == DELAYSTARTBLOCK ||
-                   ISUNWRITTEN(&map))
+               if (!xfs_bmap_is_real_extent(&map))
                        goto next;
 
                agno = XFS_FSB_TO_AGNO(mp, map.br_startblock);