Skip to content

Commit 3993723

Browse files
Brian Fosterdchinner
authored andcommitted
xfs: don't skip cow forks w/ delalloc blocks in cowblocks scan
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 <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Dave Chinner <[email protected]>
1 parent b77428b commit 3993723

File tree

3 files changed

+6
-37
lines changed

3 files changed

+6
-37
lines changed

fs/xfs/xfs_icache.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1580,10 +1580,15 @@ xfs_inode_free_cowblocks(
15801580
struct xfs_eofblocks *eofb = args;
15811581
bool need_iolock = true;
15821582
int match;
1583+
struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_COW_FORK);
15831584

15841585
ASSERT(!eofb || (eofb && eofb->eof_scan_owner != 0));
15851586

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) {
15871592
trace_xfs_inode_free_cowblocks_invalid(ip);
15881593
xfs_inode_clear_cowblocks_tag(ip);
15891594
return 0;

fs/xfs/xfs_reflink.c

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,37 +1697,3 @@ xfs_reflink_unshare(
16971697
trace_xfs_reflink_unshare_error(ip, error, _RET_IP_);
16981698
return error;
16991699
}
1700-
1701-
/*
1702-
* Does this inode have any real CoW reservations?
1703-
*/
1704-
bool
1705-
xfs_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-
}

fs/xfs/xfs_reflink.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,4 @@ extern int xfs_reflink_clear_inode_flag(struct xfs_inode *ip,
5050
extern int xfs_reflink_unshare(struct xfs_inode *ip, xfs_off_t offset,
5151
xfs_off_t len);
5252

53-
extern bool xfs_reflink_has_real_cow_blocks(struct xfs_inode *ip);
54-
5553
#endif /* __XFS_REFLINK_H */

0 commit comments

Comments
 (0)