From: Christoph Hellwig <hch@lst.de>
To: linux-xfs@vger.kernel.org
Cc: darrick.wong@oracle.com
Subject: [PATCH 3/5] xfs: move inode locking from xfs_reflink_remap_range to xfs_file_share_range
Date: Wed, 19 Oct 2016 14:47:26 +0200 [thread overview]
Message-ID: <1476881248-18669-4-git-send-email-hch@lst.de> (raw)
In-Reply-To: <1476881248-18669-1-git-send-email-hch@lst.de>
We need the iolock protection to stabilizie the IS_SWAPFILE and IS_IMMUTABLE
values, as well as preventing new buffered writers re-dirtying the file data
that we just wrote out.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
---
fs/xfs/xfs_file.c | 62 ++++++++++++++++++++++++++++++++++------------------
fs/xfs/xfs_reflink.c | 15 -------------
2 files changed, 41 insertions(+), 36 deletions(-)
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index 012a960..0960264 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -996,38 +996,54 @@ xfs_file_share_range(
inode_out = file_inode(file_out);
bs = inode_out->i_sb->s_blocksize;
+ /* Lock both files against IO */
+ same_inode = (inode_in == inode_out);
+ if (same_inode) {
+ xfs_ilock(XFS_I(inode_in), XFS_IOLOCK_EXCL);
+ xfs_ilock(XFS_I(inode_in), XFS_MMAPLOCK_EXCL);
+ } else {
+ xfs_lock_two_inodes(XFS_I(inode_in), XFS_I(inode_out),
+ XFS_IOLOCK_EXCL);
+ xfs_lock_two_inodes(XFS_I(inode_in), XFS_I(inode_out),
+ XFS_MMAPLOCK_EXCL);
+ }
+
/* Don't touch certain kinds of inodes */
+ ret = -EPERM;
if (IS_IMMUTABLE(inode_out))
- return -EPERM;
- if (IS_SWAPFILE(inode_in) ||
- IS_SWAPFILE(inode_out))
- return -ETXTBSY;
-
- same_inode = (inode_in == inode_out);
+ goto out_unlock;
+ ret = -ETXTBSY;
+ if (IS_SWAPFILE(inode_in) || IS_SWAPFILE(inode_out))
+ goto out_unlock;
/* Don't reflink dirs, pipes, sockets... */
+ ret = -EISDIR;
if (S_ISDIR(inode_in->i_mode) || S_ISDIR(inode_out->i_mode))
- return -EISDIR;
+ goto out_unlock;
+ ret = -EINVAL;
if (S_ISFIFO(inode_in->i_mode) || S_ISFIFO(inode_out->i_mode))
- return -EINVAL;
+ goto out_unlock;
if (!S_ISREG(inode_in->i_mode) || !S_ISREG(inode_out->i_mode))
- return -EINVAL;
+ goto out_unlock;
/* Don't share DAX file data for now. */
if (IS_DAX(inode_in) || IS_DAX(inode_out))
- return -EINVAL;
+ goto out_unlock;
/* Are we going all the way to the end? */
isize = i_size_read(inode_in);
- if (isize == 0)
- return 0;
+ if (isize == 0) {
+ ret = 0;
+ goto out_unlock;
+ }
+
if (len == 0)
len = isize - pos_in;
/* Ensure offsets don't wrap and the input is inside i_size */
if (pos_in + len < pos_in || pos_out + len < pos_out ||
pos_in + len > isize)
- return -EINVAL;
+ goto out_unlock;
/* Don't allow dedupe past EOF in the dest file */
if (is_dedupe) {
@@ -1035,7 +1051,7 @@ xfs_file_share_range(
disize = i_size_read(inode_out);
if (pos_out >= disize || pos_out + len > disize)
- return -EINVAL;
+ goto out_unlock;
}
/* If we're linking to EOF, continue to the block boundary. */
@@ -1047,28 +1063,32 @@ xfs_file_share_range(
/* Only reflink if we're aligned to block boundaries */
if (!IS_ALIGNED(pos_in, bs) || !IS_ALIGNED(pos_in + blen, bs) ||
!IS_ALIGNED(pos_out, bs) || !IS_ALIGNED(pos_out + blen, bs))
- return -EINVAL;
+ goto out_unlock;
/* Don't allow overlapped reflink within the same file */
if (same_inode && pos_out + blen > pos_in && pos_out < pos_in + blen)
- return -EINVAL;
+ goto out_unlock;
/* Wait for the completion of any pending IOs on srcfile */
ret = xfs_file_wait_for_io(inode_in, pos_in, len);
if (ret)
- goto out;
+ goto out_unlock;
ret = xfs_file_wait_for_io(inode_out, pos_out, len);
if (ret)
- goto out;
+ goto out_unlock;
if (is_dedupe)
flags |= XFS_REFLINK_DEDUPE;
ret = xfs_reflink_remap_range(XFS_I(inode_in), pos_in, XFS_I(inode_out),
pos_out, len, flags);
- if (ret < 0)
- goto out;
-out:
+out_unlock:
+ xfs_iunlock(XFS_I(inode_in), XFS_MMAPLOCK_EXCL);
+ xfs_iunlock(XFS_I(inode_in), XFS_IOLOCK_EXCL);
+ if (!same_inode) {
+ xfs_iunlock(XFS_I(inode_out), XFS_MMAPLOCK_EXCL);
+ xfs_iunlock(XFS_I(inode_out), XFS_IOLOCK_EXCL);
+ }
return ret;
}
diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
index 5965e94..d012746 100644
--- a/fs/xfs/xfs_reflink.c
+++ b/fs/xfs/xfs_reflink.c
@@ -1341,15 +1341,6 @@ xfs_reflink_remap_range(
trace_xfs_reflink_remap_range(src, srcoff, len, dest, destoff);
- /* Lock both files against IO */
- if (src->i_ino == dest->i_ino) {
- xfs_ilock(src, XFS_IOLOCK_EXCL);
- xfs_ilock(src, XFS_MMAPLOCK_EXCL);
- } else {
- xfs_lock_two_inodes(src, dest, XFS_IOLOCK_EXCL);
- xfs_lock_two_inodes(src, dest, XFS_MMAPLOCK_EXCL);
- }
-
/*
* Check that the extents are the same.
*/
@@ -1401,12 +1392,6 @@ xfs_reflink_remap_range(
goto out_error;
out_error:
- xfs_iunlock(src, XFS_MMAPLOCK_EXCL);
- xfs_iunlock(src, XFS_IOLOCK_EXCL);
- if (src->i_ino != dest->i_ino) {
- xfs_iunlock(dest, XFS_MMAPLOCK_EXCL);
- xfs_iunlock(dest, XFS_IOLOCK_EXCL);
- }
if (error)
trace_xfs_reflink_remap_range_error(dest, error, _RET_IP_);
return error;
--
2.1.4
next prev parent reply other threads:[~2016-10-19 14:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-19 12:47 fix locking for the reflink operation V2 Christoph Hellwig
2016-10-19 12:47 ` [PATCH 1/5] xfs: remove the same fs check from xfs_file_share_range Christoph Hellwig
2016-10-19 12:47 ` [PATCH 2/5] xfs: fix the same_inode check in xfs_file_share_range Christoph Hellwig
2016-10-19 12:47 ` Christoph Hellwig [this message]
2016-10-19 12:47 ` [PATCH 4/5] xfs: remove xfs_file_wait_for_io Christoph Hellwig
2016-10-19 15:24 ` Darrick J. Wong
2016-10-19 12:47 ` [PATCH 5/5] xfs: merge xfs_reflink_remap_range and xfs_file_share_range Christoph Hellwig
2016-10-19 15:53 ` Darrick J. Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1476881248-18669-4-git-send-email-hch@lst.de \
--to=hch@lst.de \
--cc=darrick.wong@oracle.com \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).