]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
xfs: consolidate preallocation in xfs_file_fallocate
authorChristoph Hellwig <hch@lst.de>
Fri, 25 Oct 2019 05:26:27 +0000 (22:26 -0700)
committerDarrick J. Wong <darrick.wong@oracle.com>
Mon, 28 Oct 2019 23:08:17 +0000 (16:08 -0700)
Remove xfs_zero_file_space and reorganize xfs_file_fallocate so that a
single call to xfs_alloc_file_space covers all modes that preallocate
blocks.

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/xfs_bmap_util.c
fs/xfs/xfs_bmap_util.h
fs/xfs/xfs_file.c

index ba53201dcaf65649b4af5feb7751e98556a3d2c7..fb31d7d6701eb8f1670259ea52310574ba71a9e9 100644 (file)
@@ -1133,43 +1133,6 @@ xfs_free_file_space(
        return error;
 }
 
-/*
- * Preallocate and zero a range of a file. This mechanism has the allocation
- * semantics of fallocate and in addition converts data in the range to zeroes.
- */
-int
-xfs_zero_file_space(
-       struct xfs_inode        *ip,
-       xfs_off_t               offset,
-       xfs_off_t               len)
-{
-       struct xfs_mount        *mp = ip->i_mount;
-       uint                    blksize;
-       int                     error;
-
-       trace_xfs_zero_file_space(ip);
-
-       blksize = 1 << mp->m_sb.sb_blocklog;
-
-       /*
-        * Punch a hole and prealloc the range. We use hole punch rather than
-        * unwritten extent conversion for two reasons:
-        *
-        * 1.) Hole punch handles partial block zeroing for us.
-        *
-        * 2.) If prealloc returns ENOSPC, the file range is still zero-valued
-        * by virtue of the hole punch.
-        */
-       error = xfs_free_file_space(ip, offset, len);
-       if (error || xfs_is_always_cow_inode(ip))
-               return error;
-
-       return xfs_alloc_file_space(ip, round_down(offset, blksize),
-                                    round_up(offset + len, blksize) -
-                                    round_down(offset, blksize),
-                                    XFS_BMAPI_PREALLOC);
-}
-
 static int
 xfs_prepare_shift(
        struct xfs_inode        *ip,
index 7a78229cf1a79807c7794e5f468eff6e4bf8ff7f..3e0fa0d363d1f299681f4a87c311556750a48d78 100644 (file)
@@ -59,8 +59,6 @@ int   xfs_alloc_file_space(struct xfs_inode *ip, xfs_off_t offset,
                             xfs_off_t len, int alloc_type);
 int    xfs_free_file_space(struct xfs_inode *ip, xfs_off_t offset,
                            xfs_off_t len);
-int    xfs_zero_file_space(struct xfs_inode *ip, xfs_off_t offset,
-                           xfs_off_t len);
 int    xfs_collapse_file_space(struct xfs_inode *, xfs_off_t offset,
                                xfs_off_t len);
 int    xfs_insert_file_space(struct xfs_inode *, xfs_off_t offset,
index 156238d5af19a73626ed29e78bf879dce4db7082..525b29b991165ea4ab9526c5e58fbce016efaecd 100644 (file)
@@ -880,16 +880,30 @@ xfs_file_fallocate(
                }
 
                if (mode & FALLOC_FL_ZERO_RANGE) {
-                       error = xfs_zero_file_space(ip, offset, len);
+                       /*
+                        * Punch a hole and prealloc the range.  We use a hole
+                        * punch rather than unwritten extent conversion for two
+                        * reasons:
+                        *
+                        *   1.) Hole punch handles partial block zeroing for us.
+                        *   2.) If prealloc returns ENOSPC, the file range is
+                        *       still zero-valued by virtue of the hole punch.
+                        */
+                       unsigned int blksize = i_blocksize(inode);
+
+                       trace_xfs_zero_file_space(ip);
+
+                       error = xfs_free_file_space(ip, offset, len);
+                       if (error)
+                               goto out_unlock;
+
+                       len = round_up(offset + len, blksize) -
+                             round_down(offset, blksize);
+                       offset = round_down(offset, blksize);
                } else if (mode & FALLOC_FL_UNSHARE_RANGE) {
                        error = xfs_reflink_unshare(ip, offset, len);
                        if (error)
                                goto out_unlock;
-
-                       if (!xfs_is_always_cow_inode(ip)) {
-                               error = xfs_alloc_file_space(ip, offset, len,
-                                               XFS_BMAPI_PREALLOC);
-                       }
                } else {
                        /*
                         * If always_cow mode we can't use preallocations and
@@ -899,12 +913,14 @@ xfs_file_fallocate(
                                error = -EOPNOTSUPP;
                                goto out_unlock;
                        }
+               }
 
+               if (!xfs_is_always_cow_inode(ip)) {
                        error = xfs_alloc_file_space(ip, offset, len,
                                                     XFS_BMAPI_PREALLOC);
+                       if (error)
+                               goto out_unlock;
                }
-               if (error)
-                       goto out_unlock;
        }
 
        if (file->f_flags & O_DSYNC)