aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorBrian Foster <bfoster@redhat.com>2017-01-09 10:38:34 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-01-12 05:39:39 -0500
commit2f092422e1ce1f155c6a9da147a78759f0e04f40 (patch)
tree0617c09def071ffe22a44c7cc0f8ff085146f9ab /fs
parenta11f90ca5f306a1c38db4f24db8bff97ffb87bd2 (diff)
xfs: don't skip cow forks w/ delalloc blocks in cowblocks scan
commit 399372349a7f9b2d7e56e4fa4467c69822d07024 upstream. The cowblocks background scanner currently clears the cowblocks tag for inodes without any real allocations in the cow fork. This excludes inodes with only delalloc blocks in the cow fork. While we might never expect to clear delalloc blocks from the cow fork in the background scanner, it is not necessarily correct to clear the cowblocks tag from such inodes. For example, if the background scanner happens to process an inode between a buffered write and writeback, the scanner catches the inode in a state after delalloc blocks have been allocated to the cow fork but before the delalloc blocks have been converted to real blocks by writeback. The background scanner then incorrectly clears the cowblocks tag, even if part of the aforementioned delalloc reservation will not be remapped to the data fork (i.e., extra blocks due to the cowextsize hint). This means that any such additional blocks in the cow fork might never be reclaimed by the background scanner and could persist until the inode itself is reclaimed. To address this problem, only skip and clear inodes without any cow fork allocations whatsoever from the background scanner. While we generally do not want to cancel delalloc reservations from the background scanner, the pagecache dirty check following the cowblocks check should prevent that situation. If we do end up with delalloc cow fork blocks without a dirty address space mapping, this is probably an indication that something has gone wrong and the blocks should be reclaimed, as they may never be converted to a real allocation. Signed-off-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Dave Chinner <david@fromorbit.com> Cc: Christoph Hellwig <hch@lst.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/xfs/xfs_icache.c7
-rw-r--r--fs/xfs/xfs_reflink.c34
-rw-r--r--fs/xfs/xfs_reflink.h2
3 files changed, 6 insertions, 37 deletions
diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c
index f295049db681..1b4861f5d3d8 100644
--- a/fs/xfs/xfs_icache.c
+++ b/fs/xfs/xfs_icache.c
@@ -1580,10 +1580,15 @@ xfs_inode_free_cowblocks(
1580 struct xfs_eofblocks *eofb = args; 1580 struct xfs_eofblocks *eofb = args;
1581 bool need_iolock = true; 1581 bool need_iolock = true;
1582 int match; 1582 int match;
1583 struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_COW_FORK);
1583 1584
1584 ASSERT(!eofb || (eofb && eofb->eof_scan_owner != 0)); 1585 ASSERT(!eofb || (eofb && eofb->eof_scan_owner != 0));
1585 1586
1586 if (!xfs_reflink_has_real_cow_blocks(ip)) { 1587 /*
1588 * Just clear the tag if we have an empty cow fork or none at all. It's
1589 * possible the inode was fully unshared since it was originally tagged.
1590 */
1591 if (!xfs_is_reflink_inode(ip) || !ifp->if_bytes) {
1587 trace_xfs_inode_free_cowblocks_invalid(ip); 1592 trace_xfs_inode_free_cowblocks_invalid(ip);
1588 xfs_inode_clear_cowblocks_tag(ip); 1593 xfs_inode_clear_cowblocks_tag(ip);
1589 return 0; 1594 return 0;
diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
index a279b4e7f5fe..c06904893202 100644
--- a/fs/xfs/xfs_reflink.c
+++ b/fs/xfs/xfs_reflink.c
@@ -1697,37 +1697,3 @@ out:
1697 trace_xfs_reflink_unshare_error(ip, error, _RET_IP_); 1697 trace_xfs_reflink_unshare_error(ip, error, _RET_IP_);
1698 return error; 1698 return error;
1699} 1699}
1700
1701/*
1702 * Does this inode have any real CoW reservations?
1703 */
1704bool
1705xfs_reflink_has_real_cow_blocks(
1706 struct xfs_inode *ip)
1707{
1708 struct xfs_bmbt_irec irec;
1709 struct xfs_ifork *ifp;
1710 struct xfs_bmbt_rec_host *gotp;
1711 xfs_extnum_t idx;
1712
1713 if (!xfs_is_reflink_inode(ip))
1714 return false;
1715
1716 /* Go find the old extent in the CoW fork. */
1717 ifp = XFS_IFORK_PTR(ip, XFS_COW_FORK);
1718 gotp = xfs_iext_bno_to_ext(ifp, 0, &idx);
1719 while (gotp) {
1720 xfs_bmbt_get_all(gotp, &irec);
1721
1722 if (!isnullstartblock(irec.br_startblock))
1723 return true;
1724
1725 /* Roll on... */
1726 idx++;
1727 if (idx >= ifp->if_bytes / sizeof(xfs_bmbt_rec_t))
1728 break;
1729 gotp = xfs_iext_get_ext(ifp, idx);
1730 }
1731
1732 return false;
1733}
diff --git a/fs/xfs/xfs_reflink.h b/fs/xfs/xfs_reflink.h
index fad11607c9ad..97ea9b487884 100644
--- a/fs/xfs/xfs_reflink.h
+++ b/fs/xfs/xfs_reflink.h
@@ -50,6 +50,4 @@ extern int xfs_reflink_clear_inode_flag(struct xfs_inode *ip,
50extern int xfs_reflink_unshare(struct xfs_inode *ip, xfs_off_t offset, 50extern int xfs_reflink_unshare(struct xfs_inode *ip, xfs_off_t offset,
51 xfs_off_t len); 51 xfs_off_t len);
52 52
53extern bool xfs_reflink_has_real_cow_blocks(struct xfs_inode *ip);
54
55#endif /* __XFS_REFLINK_H */ 53#endif /* __XFS_REFLINK_H */