From: Chengguang Xu <cgxu519@mykernel.net>
To: linux-unionfs@vger.kernel.org, linux-mm@kvack.org
Cc: miklos@szeredi.hu, akpm@linux-foundation.org, amir73il@gmail.com,
riteshh@linux.ibm.com, Chengguang Xu <cgxu519@mykernel.net>
Subject: [RFC PATCH 2/3] ovl: introduce struct ovl_file_entry
Date: Sat, 29 Aug 2020 17:51:00 +0800 [thread overview]
Message-ID: <20200829095101.25350-3-cgxu519@mykernel.net> (raw)
In-Reply-To: <20200829095101.25350-1-cgxu519@mykernel.net>
Introduce new struct ovl_file_entry to store real file
and real vm_ops handler.
Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
fs/overlayfs/file.c | 64 ++++++++++++++++++++++++++++++++++++++-------
1 file changed, 54 insertions(+), 10 deletions(-)
diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
index 0d940e29d62b..14ab5344a918 100644
--- a/fs/overlayfs/file.c
+++ b/fs/overlayfs/file.c
@@ -21,6 +21,39 @@ struct ovl_aio_req {
struct fd fd;
};
+struct ovl_file_entry {
+ struct file *realfile;
+ void *vm_ops;
+};
+
+struct file *ovl_get_realfile(struct file *file)
+{
+ struct ovl_file_entry *ofe = file->private_data;
+
+ return ofe->realfile;
+}
+
+void ovl_set_realfile(struct file *file, struct file *realfile)
+{
+ struct ovl_file_entry *ofe = file->private_data;
+
+ ofe->realfile = realfile;
+}
+
+void *ovl_get_real_vmops(struct file *file)
+{
+ struct ovl_file_entry *ofe = file->private_data;
+
+ return ofe->vm_ops;
+}
+
+void ovl_set_real_vmops(struct file *file, void *vm_ops)
+{
+ struct ovl_file_entry *ofe = file->private_data;
+
+ ofe->vm_ops = vm_ops;
+}
+
static struct kmem_cache *ovl_aio_request_cachep;
static char ovl_whatisit(struct inode *inode, struct inode *realinode)
@@ -105,14 +138,14 @@ static int ovl_change_flags(struct file *file, unsigned int flags)
return 0;
}
-static int ovl_real_fdget_meta(const struct file *file, struct fd *real,
+static int ovl_real_fdget_meta(struct file *file, struct fd *real,
bool allow_meta)
{
struct inode *inode = file_inode(file);
struct inode *realinode;
real->flags = 0;
- real->file = file->private_data;
+ real->file = ovl_get_realfile(file);
if (allow_meta)
realinode = ovl_inode_real(inode);
@@ -134,7 +167,7 @@ static int ovl_real_fdget_meta(const struct file *file, struct fd *real,
return 0;
}
-static int ovl_real_fdget(const struct file *file, struct fd *real)
+static int ovl_real_fdget(struct file *file, struct fd *real)
{
return ovl_real_fdget_meta(file, real, false);
}
@@ -144,25 +177,36 @@ static int ovl_open(struct inode *inode, struct file *file)
struct file *realfile;
int err;
+ file->private_data = kzalloc(sizeof(struct ovl_file_entry), GFP_KERNEL);
+ if (!file->private_data)
+ return -ENOMEM;
+
err = ovl_maybe_copy_up(file_dentry(file), file->f_flags);
if (err)
- return err;
+ goto out;
/* No longer need these flags, so don't pass them on to underlying fs */
file->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
realfile = ovl_open_realfile(file, ovl_inode_realdata(inode));
- if (IS_ERR(realfile))
- return PTR_ERR(realfile);
-
- file->private_data = realfile;
+ if (IS_ERR(realfile)) {
+ err = PTR_ERR(realfile);
+ goto out;
+ }
+ ovl_set_realfile(file, realfile);
return 0;
+out:
+ kfree(file->private_data);
+ file->private_data = NULL;
+ return err;
}
static int ovl_release(struct inode *inode, struct file *file)
{
- fput(file->private_data);
+ fput(ovl_get_realfile(file));
+ kfree(file->private_data);
+ file->private_data = NULL;
return 0;
}
@@ -451,7 +495,7 @@ static int ovl_fsync(struct file *file, loff_t start, loff_t end, int datasync)
static int ovl_mmap(struct file *file, struct vm_area_struct *vma)
{
- struct file *realfile = file->private_data;
+ struct file *realfile = ovl_get_realfile(file);
const struct cred *old_cred;
int ret;
--
2.20.1
next prev parent reply other threads:[~2020-08-29 9:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-29 9:50 [RFC PATCH 0/3] ovl: stacked mmap for shared map Chengguang Xu
2020-08-29 9:50 ` [RFC PATCH 1/3] mm: mmap: export necessary functions for overlayfs' mmap Chengguang Xu
2020-08-29 9:51 ` Chengguang Xu [this message]
2020-08-29 9:51 ` [RFC PATCH 3/3] ovl: implement stacked mmap for shared map Chengguang Xu
2020-08-30 11:33 ` Amir Goldstein
2020-08-31 13:47 ` cgxu
2020-08-31 15:51 ` Amir Goldstein
2020-09-01 7:44 ` Miklos Szeredi
2020-09-01 13:20 ` cgxu
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=20200829095101.25350-3-cgxu519@mykernel.net \
--to=cgxu519@mykernel.net \
--cc=akpm@linux-foundation.org \
--cc=amir73il@gmail.com \
--cc=linux-mm@kvack.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=riteshh@linux.ibm.com \
/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