Skip to content

Commit 172ed39

Browse files
Christoph Hellwigdjwong
authored andcommitted
xfs: don't allocate COW blocks for zeroing holes or unwritten extents
The iomap zeroing interface is smart enough to skip zeroing holes or unwritten extents. Don't subvert this logic for reflink files. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
1 parent 5b4c845 commit 172ed39

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

fs/xfs/xfs_iomap.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,13 @@ static inline bool imap_needs_alloc(struct inode *inode,
955955
(IS_DAX(inode) && imap->br_state == XFS_EXT_UNWRITTEN);
956956
}
957957

958+
static inline bool needs_cow_for_zeroing(struct xfs_bmbt_irec *imap, int nimaps)
959+
{
960+
return nimaps &&
961+
imap->br_startblock != HOLESTARTBLOCK &&
962+
imap->br_state != XFS_EXT_UNWRITTEN;
963+
}
964+
958965
static inline bool need_excl_ilock(struct xfs_inode *ip, unsigned flags)
959966
{
960967
/*
@@ -1024,7 +1031,9 @@ xfs_file_iomap_begin(
10241031
goto out_unlock;
10251032
}
10261033

1027-
if ((flags & (IOMAP_WRITE | IOMAP_ZERO)) && xfs_is_reflink_inode(ip)) {
1034+
if (xfs_is_reflink_inode(ip) &&
1035+
((flags & IOMAP_WRITE) ||
1036+
((flags & IOMAP_ZERO) && needs_cow_for_zeroing(&imap, nimaps)))) {
10281037
if (flags & IOMAP_DIRECT) {
10291038
/*
10301039
* A reflinked inode will result in CoW alloc.

0 commit comments

Comments
 (0)