Browse Source

xfs: check inode reflink flag before calling reflink functions

There are a couple of places where we don't check the inode's
reflink flag before calling into the reflink code.  Fix those,
and add some asserts so we don't make this mistake again.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reported-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
Darrick J. Wong 8 years ago
parent
commit
63646fc58d
2 changed files with 9 additions and 7 deletions
  1. 2 2
      fs/xfs/xfs_reflink.c
  2. 7 5
      fs/xfs/xfs_super.c

+ 2 - 2
fs/xfs/xfs_reflink.c

@@ -624,6 +624,7 @@ xfs_reflink_cancel_cow_range(
 	int			error;
 	int			error;
 
 
 	trace_xfs_reflink_cancel_cow_range(ip, offset, count);
 	trace_xfs_reflink_cancel_cow_range(ip, offset, count);
+	ASSERT(xfs_is_reflink_inode(ip));
 
 
 	offset_fsb = XFS_B_TO_FSBT(ip->i_mount, offset);
 	offset_fsb = XFS_B_TO_FSBT(ip->i_mount, offset);
 	if (count == NULLFILEOFF)
 	if (count == NULLFILEOFF)
@@ -1510,8 +1511,7 @@ xfs_reflink_clear_inode_flag(
 	int			nmaps;
 	int			nmaps;
 	int			error = 0;
 	int			error = 0;
 
 
-	if (!(ip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK))
-		return 0;
+	ASSERT(xfs_is_reflink_inode(ip));
 
 
 	fbno = 0;
 	fbno = 0;
 	end = XFS_B_TO_FSB(mp, i_size_read(VFS_I(ip)));
 	end = XFS_B_TO_FSB(mp, i_size_read(VFS_I(ip)));

+ 7 - 5
fs/xfs/xfs_super.c

@@ -947,11 +947,13 @@ xfs_fs_destroy_inode(
 	XFS_STATS_INC(ip->i_mount, vn_rele);
 	XFS_STATS_INC(ip->i_mount, vn_rele);
 	XFS_STATS_INC(ip->i_mount, vn_remove);
 	XFS_STATS_INC(ip->i_mount, vn_remove);
 
 
-	error = xfs_reflink_cancel_cow_range(ip, 0, NULLFILEOFF);
-	if (error && !XFS_FORCED_SHUTDOWN(ip->i_mount))
-		xfs_warn(ip->i_mount, "Error %d while evicting CoW blocks "
-				"for inode %llu.",
-				error, ip->i_ino);
+	if (xfs_is_reflink_inode(ip)) {
+		error = xfs_reflink_cancel_cow_range(ip, 0, NULLFILEOFF);
+		if (error && !XFS_FORCED_SHUTDOWN(ip->i_mount))
+			xfs_warn(ip->i_mount,
+"Error %d while evicting CoW blocks for inode %llu.",
+					error, ip->i_ino);
+	}
 
 
 	xfs_inactive(ip);
 	xfs_inactive(ip);