linux-unionfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chengguang Xu <cgxu519@mykernel.net>
To: miklos@szeredi.hu
Cc: linux-unionfs@vger.kernel.org, root <root@localhost.localdomain>
Subject: [PATCH] ovl: stacked file operation for mmap
Date: Fri, 16 Oct 2020 23:48:52 +0800	[thread overview]
Message-ID: <20201016154852.2958-1-cgxu519@mykernel.net> (raw)

From: root <root@localhost.localdomain>

Currently only mmap does not behave as stacked file operation,
although in practice there is less change to open a file in
RDONLY mode and take long time to do mmap but the fix looks
reasonable.

Signed-off-by: root <root@localhost.localdomain>
---
 fs/overlayfs/file.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
index 3582c3ae819c..f98b1c0c975b 100644
--- a/fs/overlayfs/file.c
+++ b/fs/overlayfs/file.c
@@ -461,6 +461,7 @@ static int ovl_mmap(struct file *file, struct vm_area_struct *vma)
 {
 	struct file *realfile = file->private_data;
 	const struct cred *old_cred;
+	struct fd real;
 	int ret;
 
 	if (!realfile->f_op->mmap)
@@ -469,7 +470,11 @@ static int ovl_mmap(struct file *file, struct vm_area_struct *vma)
 	if (WARN_ON(file != vma->vm_file))
 		return -EIO;
 
-	vma->vm_file = get_file(realfile);
+	ret = ovl_real_fdget(file, &real);
+	if (ret)
+		return ret;
+
+	vma->vm_file = get_file(real.file);
 
 	old_cred = ovl_override_creds(file_inode(file)->i_sb);
 	ret = call_mmap(vma->vm_file, vma);
@@ -477,13 +482,14 @@ static int ovl_mmap(struct file *file, struct vm_area_struct *vma)
 
 	if (ret) {
 		/* Drop reference count from new vm_file value */
-		fput(realfile);
+		fput(real.file);
 	} else {
 		/* Drop reference count from previous vm_file value */
 		fput(file);
 	}
 
 	ovl_file_accessed(file);
+	fdput(real);
 
 	return ret;
 }
-- 
2.26.2



                 reply	other threads:[~2020-10-16 15:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20201016154852.2958-1-cgxu519@mykernel.net \
    --to=cgxu519@mykernel.net \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=root@localhost.localdomain \
    /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).