From: Christoph Hellwig <hch@infradead.org>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: hch@infradead.org, bfoster@redhat.com, linux-xfs@vger.kernel.org,
viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 3/7] xfs: only grab shared inode locks for source file during reflink
Date: Fri, 26 Jan 2018 23:33:16 -0800 [thread overview]
Message-ID: <20180127073316.GC11515@infradead.org> (raw)
In-Reply-To: <151701542824.3070.12415207450562775643.stgit@magnolia>
Looks fine, although the fs.h addition would usually warrant a Cc to
Al and fsdevel. (thus included as a full quote)
Reviewed-by: Christoph Hellwig <hch@lst.de>
On Fri, Jan 26, 2018 at 05:10:28PM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
>
> Reflink and dedupe operations remap blocks from a source file into a
> destination file. The destination file needs exclusive locks on all
> levels because we're updating its block map, but the source file isn't
> undergoing any block map changes so we can use a shared lock.
>
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
> fs/xfs/xfs_reflink.c | 25 +++++++++++++++----------
> include/linux/fs.h | 5 +++++
> 2 files changed, 20 insertions(+), 10 deletions(-)
>
>
> diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
> index bcc58c2..85a119e 100644
> --- a/fs/xfs/xfs_reflink.c
> +++ b/fs/xfs/xfs_reflink.c
> @@ -1202,13 +1202,16 @@ xfs_reflink_remap_blocks(
>
> /* drange = (destoff, destoff + len); srange = (srcoff, srcoff + len) */
> while (len) {
> + uint lock_mode;
> +
> trace_xfs_reflink_remap_blocks_loop(src, srcoff, len,
> dest, destoff);
> +
> /* Read extent from the source file */
> nimaps = 1;
> - xfs_ilock(src, XFS_ILOCK_EXCL);
> + lock_mode = xfs_ilock_data_map_shared(src);
> error = xfs_bmapi_read(src, srcoff, len, &imap, &nimaps, 0);
> - xfs_iunlock(src, XFS_ILOCK_EXCL);
> + xfs_iunlock(src, lock_mode);
> if (error)
> goto err;
> ASSERT(nimaps == 1);
> @@ -1260,7 +1263,7 @@ xfs_iolock_two_inodes_and_break_layout(
>
> retry:
> if (src < dest) {
> - inode_lock(src);
> + inode_lock_shared(src);
> inode_lock_nested(dest, I_MUTEX_NONDIR2);
> } else {
> /* src >= dest */
> @@ -1271,7 +1274,7 @@ xfs_iolock_two_inodes_and_break_layout(
> if (error == -EWOULDBLOCK) {
> inode_unlock(dest);
> if (src < dest)
> - inode_unlock(src);
> + inode_unlock_shared(src);
> error = break_layout(dest, true);
> if (error)
> return error;
> @@ -1280,11 +1283,11 @@ xfs_iolock_two_inodes_and_break_layout(
> if (error) {
> inode_unlock(dest);
> if (src < dest)
> - inode_unlock(src);
> + inode_unlock_shared(src);
> return error;
> }
> if (src > dest)
> - inode_lock_nested(src, I_MUTEX_NONDIR2);
> + inode_lock_shared_nested(src, I_MUTEX_NONDIR2);
> return 0;
> }
>
> @@ -1324,7 +1327,7 @@ xfs_reflink_remap_range(
> if (same_inode)
> xfs_ilock(src, XFS_MMAPLOCK_EXCL);
> else
> - xfs_lock_two_inodes(src, XFS_MMAPLOCK_EXCL, dest,
> + xfs_lock_two_inodes(src, XFS_MMAPLOCK_SHARED, dest,
> XFS_MMAPLOCK_EXCL);
>
> /* Check file eligibility and prepare for block sharing. */
> @@ -1393,10 +1396,12 @@ xfs_reflink_remap_range(
> is_dedupe);
>
> out_unlock:
> - xfs_iunlock(src, XFS_MMAPLOCK_EXCL);
> + xfs_iunlock(dest, XFS_MMAPLOCK_EXCL);
> + if (!same_inode)
> + xfs_iunlock(src, XFS_MMAPLOCK_SHARED);
> + inode_unlock(inode_out);
> if (!same_inode)
> - xfs_iunlock(dest, XFS_MMAPLOCK_EXCL);
> - unlock_two_nondirectories(inode_in, inode_out);
> + inode_unlock_shared(inode_in);
> if (ret)
> trace_xfs_reflink_remap_range_error(dest, ret, _RET_IP_);
> return ret;
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 7f8d96d..5cbeab8 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -748,6 +748,11 @@ static inline void inode_lock_nested(struct inode *inode, unsigned subclass)
> down_write_nested(&inode->i_rwsem, subclass);
> }
>
> +static inline void inode_lock_shared_nested(struct inode *inode, unsigned subclass)
> +{
> + down_read_nested(&inode->i_rwsem, subclass);
> +}
> +
> void lock_two_nondirectories(struct inode *, struct inode*);
> void unlock_two_nondirectories(struct inode *, struct inode*);
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
---end quoted text---
next prev parent reply other threads:[~2018-01-27 7:33 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-27 1:10 [PATCH v3 0/7] xfs: reflink/scrub/quota fixes Darrick J. Wong
2018-01-27 1:10 ` [PATCH 1/7] xfs: reflink should break pnfs leases before sharing blocks Darrick J. Wong
2018-01-27 7:31 ` Christoph Hellwig
2018-01-27 1:10 ` [PATCH 2/7] xfs: allow xfs_lock_two_inodes to take different EXCL/SHARED modes Darrick J. Wong
2018-01-27 7:32 ` Christoph Hellwig
2018-01-27 1:10 ` [PATCH 3/7] xfs: only grab shared inode locks for source file during reflink Darrick J. Wong
2018-01-27 7:33 ` Christoph Hellwig [this message]
2018-01-27 1:10 ` [PATCH 4/7] xfs: treat CoW fork operations as delalloc for quota accounting Darrick J. Wong
2018-01-27 7:33 ` Christoph Hellwig
2018-01-29 12:26 ` Brian Foster
2018-01-29 23:00 ` Darrick J. Wong
2018-01-30 11:48 ` Brian Foster
2018-01-27 1:10 ` [PATCH 5/7] iomap: warn on zero-length mappings Darrick J. Wong
2018-01-27 7:34 ` Christoph Hellwig
2018-01-27 18:04 ` Darrick J. Wong
2018-01-27 18:08 ` [PATCH v2 " Darrick J. Wong
2018-01-27 1:10 ` [PATCH 6/7] xfs: check reflink allocation mappings Darrick J. Wong
2018-01-27 7:35 ` Christoph Hellwig
2018-01-27 1:10 ` [PATCH 7/7] xfs: don't screw up direct writes when freesp is fragmented 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=20180127073316.GC11515@infradead.org \
--to=hch@infradead.org \
--cc=bfoster@redhat.com \
--cc=darrick.wong@oracle.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.