aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2017-03-07 19:45:58 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-04-08 03:30:32 -0400
commit3b83a02af271a290eed708246bf03ef7d41786ee (patch)
treece243441ade18cdca39568366789b468ffd447ee /fs
parenta2402936943364e39ef5833db29387d019182ce7 (diff)
xfs: only reclaim unwritten COW extents periodically
commit 3802a345321a08093ba2ddb1849e736f84e8d450 upstream. We only want to reclaim preallocations from our periodic work item. Currently this is archived by looking for a dirty inode, but that check is rather fragile. Instead add a flag to xfs_reflink_cancel_cow_* so that the caller can ask for just cancelling unwritten extents in the COW fork. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> [darrick: fix typos in commit message] Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/xfs/xfs_aops.c2
-rw-r--r--fs/xfs/xfs_icache.c2
-rw-r--r--fs/xfs/xfs_inode.c2
-rw-r--r--fs/xfs/xfs_reflink.c23
-rw-r--r--fs/xfs/xfs_reflink.h4
-rw-r--r--fs/xfs/xfs_super.c2
6 files changed, 22 insertions, 13 deletions
diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
index f5f51d40a2ec..08a2515460ff 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -298,7 +298,7 @@ xfs_end_io(
298 goto done; 298 goto done;
299 if (ioend->io_bio->bi_error) { 299 if (ioend->io_bio->bi_error) {
300 error = xfs_reflink_cancel_cow_range(ip, 300 error = xfs_reflink_cancel_cow_range(ip,
301 ioend->io_offset, ioend->io_size); 301 ioend->io_offset, ioend->io_size, true);
302 goto done; 302 goto done;
303 } 303 }
304 error = xfs_reflink_end_cow(ip, ioend->io_offset, 304 error = xfs_reflink_end_cow(ip, ioend->io_offset,
diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c
index 78708d001a63..3fb1f3fb8efe 100644
--- a/fs/xfs/xfs_icache.c
+++ b/fs/xfs/xfs_icache.c
@@ -1610,7 +1610,7 @@ xfs_inode_free_cowblocks(
1610 xfs_ilock(ip, XFS_IOLOCK_EXCL); 1610 xfs_ilock(ip, XFS_IOLOCK_EXCL);
1611 xfs_ilock(ip, XFS_MMAPLOCK_EXCL); 1611 xfs_ilock(ip, XFS_MMAPLOCK_EXCL);
1612 1612
1613 ret = xfs_reflink_cancel_cow_range(ip, 0, NULLFILEOFF); 1613 ret = xfs_reflink_cancel_cow_range(ip, 0, NULLFILEOFF, false);
1614 1614
1615 xfs_iunlock(ip, XFS_MMAPLOCK_EXCL); 1615 xfs_iunlock(ip, XFS_MMAPLOCK_EXCL);
1616 xfs_iunlock(ip, XFS_IOLOCK_EXCL); 1616 xfs_iunlock(ip, XFS_IOLOCK_EXCL);
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index f9f44cb56fe8..e50636c9a89c 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -1624,7 +1624,7 @@ xfs_itruncate_extents(
1624 1624
1625 /* Remove all pending CoW reservations. */ 1625 /* Remove all pending CoW reservations. */
1626 error = xfs_reflink_cancel_cow_blocks(ip, &tp, first_unmap_block, 1626 error = xfs_reflink_cancel_cow_blocks(ip, &tp, first_unmap_block,
1627 last_block); 1627 last_block, true);
1628 if (error) 1628 if (error)
1629 goto out; 1629 goto out;
1630 1630
diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
index eff070accf04..2252f163c38f 100644
--- a/fs/xfs/xfs_reflink.c
+++ b/fs/xfs/xfs_reflink.c
@@ -571,14 +571,18 @@ xfs_reflink_trim_irec_to_next_cow(
571} 571}
572 572
573/* 573/*
574 * Cancel all pending CoW reservations for some block range of an inode. 574 * Cancel CoW reservations for some block range of an inode.
575 *
576 * If cancel_real is true this function cancels all COW fork extents for the
577 * inode; if cancel_real is false, real extents are not cleared.
575 */ 578 */
576int 579int
577xfs_reflink_cancel_cow_blocks( 580xfs_reflink_cancel_cow_blocks(
578 struct xfs_inode *ip, 581 struct xfs_inode *ip,
579 struct xfs_trans **tpp, 582 struct xfs_trans **tpp,
580 xfs_fileoff_t offset_fsb, 583 xfs_fileoff_t offset_fsb,
581 xfs_fileoff_t end_fsb) 584 xfs_fileoff_t end_fsb,
585 bool cancel_real)
582{ 586{
583 struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_COW_FORK); 587 struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, XFS_COW_FORK);
584 struct xfs_bmbt_irec got, prev, del; 588 struct xfs_bmbt_irec got, prev, del;
@@ -605,7 +609,7 @@ xfs_reflink_cancel_cow_blocks(
605 &idx, &got, &del); 609 &idx, &got, &del);
606 if (error) 610 if (error)
607 break; 611 break;
608 } else { 612 } else if (del.br_state == XFS_EXT_UNWRITTEN || cancel_real) {
609 xfs_trans_ijoin(*tpp, ip, 0); 613 xfs_trans_ijoin(*tpp, ip, 0);
610 xfs_defer_init(&dfops, &firstfsb); 614 xfs_defer_init(&dfops, &firstfsb);
611 615
@@ -648,13 +652,17 @@ xfs_reflink_cancel_cow_blocks(
648} 652}
649 653
650/* 654/*
651 * Cancel all pending CoW reservations for some byte range of an inode. 655 * Cancel CoW reservations for some byte range of an inode.
656 *
657 * If cancel_real is true this function cancels all COW fork extents for the
658 * inode; if cancel_real is false, real extents are not cleared.
652 */ 659 */
653int 660int
654xfs_reflink_cancel_cow_range( 661xfs_reflink_cancel_cow_range(
655 struct xfs_inode *ip, 662 struct xfs_inode *ip,
656 xfs_off_t offset, 663 xfs_off_t offset,
657 xfs_off_t count) 664 xfs_off_t count,
665 bool cancel_real)
658{ 666{
659 struct xfs_trans *tp; 667 struct xfs_trans *tp;
660 xfs_fileoff_t offset_fsb; 668 xfs_fileoff_t offset_fsb;
@@ -680,7 +688,8 @@ xfs_reflink_cancel_cow_range(
680 xfs_trans_ijoin(tp, ip, 0); 688 xfs_trans_ijoin(tp, ip, 0);
681 689
682 /* Scrape out the old CoW reservations */ 690 /* Scrape out the old CoW reservations */
683 error = xfs_reflink_cancel_cow_blocks(ip, &tp, offset_fsb, end_fsb); 691 error = xfs_reflink_cancel_cow_blocks(ip, &tp, offset_fsb, end_fsb,
692 cancel_real);
684 if (error) 693 if (error)
685 goto out_cancel; 694 goto out_cancel;
686 695
@@ -1686,7 +1695,7 @@ next:
1686 * We didn't find any shared blocks so turn off the reflink flag. 1695 * We didn't find any shared blocks so turn off the reflink flag.
1687 * First, get rid of any leftover CoW mappings. 1696 * First, get rid of any leftover CoW mappings.
1688 */ 1697 */
1689 error = xfs_reflink_cancel_cow_blocks(ip, tpp, 0, NULLFILEOFF); 1698 error = xfs_reflink_cancel_cow_blocks(ip, tpp, 0, NULLFILEOFF, true);
1690 if (error) 1699 if (error)
1691 return error; 1700 return error;
1692 1701
diff --git a/fs/xfs/xfs_reflink.h b/fs/xfs/xfs_reflink.h
index 523e06d88f43..a57966fc7ddd 100644
--- a/fs/xfs/xfs_reflink.h
+++ b/fs/xfs/xfs_reflink.h
@@ -39,9 +39,9 @@ extern int xfs_reflink_trim_irec_to_next_cow(struct xfs_inode *ip,
39 39
40extern int xfs_reflink_cancel_cow_blocks(struct xfs_inode *ip, 40extern int xfs_reflink_cancel_cow_blocks(struct xfs_inode *ip,
41 struct xfs_trans **tpp, xfs_fileoff_t offset_fsb, 41 struct xfs_trans **tpp, xfs_fileoff_t offset_fsb,
42 xfs_fileoff_t end_fsb); 42 xfs_fileoff_t end_fsb, bool cancel_real);
43extern int xfs_reflink_cancel_cow_range(struct xfs_inode *ip, xfs_off_t offset, 43extern int xfs_reflink_cancel_cow_range(struct xfs_inode *ip, xfs_off_t offset,
44 xfs_off_t count); 44 xfs_off_t count, bool cancel_real);
45extern int xfs_reflink_end_cow(struct xfs_inode *ip, xfs_off_t offset, 45extern int xfs_reflink_end_cow(struct xfs_inode *ip, xfs_off_t offset,
46 xfs_off_t count); 46 xfs_off_t count);
47extern int xfs_reflink_recover_cow(struct xfs_mount *mp); 47extern int xfs_reflink_recover_cow(struct xfs_mount *mp);
diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
index ade4691e3f74..dbbd3f1fd2b7 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -948,7 +948,7 @@ xfs_fs_destroy_inode(
948 XFS_STATS_INC(ip->i_mount, vn_remove); 948 XFS_STATS_INC(ip->i_mount, vn_remove);
949 949
950 if (xfs_is_reflink_inode(ip)) { 950 if (xfs_is_reflink_inode(ip)) {
951 error = xfs_reflink_cancel_cow_range(ip, 0, NULLFILEOFF); 951 error = xfs_reflink_cancel_cow_range(ip, 0, NULLFILEOFF, true);
952 if (error && !XFS_FORCED_SHUTDOWN(ip->i_mount)) 952 if (error && !XFS_FORCED_SHUTDOWN(ip->i_mount))
953 xfs_warn(ip->i_mount, 953 xfs_warn(ip->i_mount,
954"Error %d while evicting CoW blocks for inode %llu.", 954"Error %d while evicting CoW blocks for inode %llu.",