Linux Overlay Filesystem development
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Christian Brauner <brauner@kernel.org>
Cc: Miklos Szeredi <miklos@szeredi.hu>,
	Daan De Meyer <daan.j.demeyer@gmail.com>,
	linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [RFC][PATCH 5/5] ovl: add support for copy file range to another fs
Date: Thu, 23 Jul 2026 13:48:48 +0200	[thread overview]
Message-ID: <20260723114848.1212429-6-amir73il@gmail.com> (raw)
In-Reply-To: <20260723114848.1212429-1-amir73il@gmail.com>

It is technically possible for overlayfs to copy_file_range() to
the base fs of the real layer.

Implementation of copy to other fs is a bit more subtle, because
we must not take the other fs locks in overlayfs code.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 fs/overlayfs/file.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
index 169a48de565e9..cc52ccc35961f 100644
--- a/fs/overlayfs/file.c
+++ b/fs/overlayfs/file.c
@@ -535,10 +535,23 @@ static loff_t ovl_copyfile(struct file *file_in, loff_t pos_in,
 
 	/*
 	 * Overlayfs may be able to copy to a non overlayfs dst which is on the
-	 * same sb or same fs type as real file_in fs, but not implemented yet.
+	 * same sb or same fs type as real file_in fs, but we must avoid taking
+	 * the locks on the foreign fs.
 	 */
-	if (WARN_ON_ONCE(!is_ovl_fs(inode_out->i_sb)))
-		return -EXDEV;
+	if (unlikely(!is_ovl_fs(inode_out->i_sb))) {
+		if (WARN_ON_ONCE(op != OVL_COPY) ||
+		    WARN_ON_ONCE(!is_ovl_fs(file_inode(file_in)->i_sb)))
+			return -EXDEV;
+
+		realfile_in = ovl_real_file(file_in);
+		if (IS_ERR(realfile_in))
+			return PTR_ERR(realfile_in);
+
+		with_ovl_creds(file_inode(file_in)->i_sb)
+			return vfs_copy_file_range(realfile_in, pos_in,
+						   file_out, pos_out, len,
+						   flags);
+	}
 
 	inode_lock(inode_out);
 	if (op != OVL_DEDUPE) {
-- 
2.54.0


  parent reply	other threads:[~2026-07-23 11:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-23 11:48 [RFC][PATCH 0/5] Proposal for Cross-fs copy_file_range() Amir Goldstein
2026-07-23 11:48 ` [RFC][PATCH 1/5] fs: clarify cross-sb copy_file_range() code Amir Goldstein
2026-07-23 11:48 ` [RFC][PATCH 2/5] fs: add support for copy file range from another fs Amir Goldstein
2026-07-23 11:48 ` [RFC][PATCH 3/5] fs: add support for copy file range to " Amir Goldstein
2026-07-23 11:48 ` [RFC][PATCH 4/5] ovl: add support for copy file range from " Amir Goldstein
2026-07-23 11:48 ` Amir Goldstein [this message]
2026-07-23 13:05 ` [RFC][PATCH 0/5] Proposal for Cross-fs copy_file_range() Daan De Meyer
2026-07-23 13:36   ` Amir Goldstein
2026-07-23 13:54     ` Daan De Meyer
2026-07-23 14:17       ` Amir Goldstein
2026-07-23 23:29 ` Gao Xiang

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=20260723114848.1212429-6-amir73il@gmail.com \
    --to=amir73il@gmail.com \
    --cc=brauner@kernel.org \
    --cc=daan.j.demeyer@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    /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