summaryrefslogtreecommitdiff
path: root/fs/overlayfs/file.c
diff options
context:
space:
mode:
authorMiklos Szeredi <mszeredi@redhat.com>2018-07-18 15:44:42 +0200
committerMiklos Szeredi <mszeredi@redhat.com>2018-07-18 15:44:42 +0200
commit2f502839e85ab265f03f25f30d6463154aee5473 (patch)
treec11841651dc11330ab0a39f655945893c55e1d18 /fs/overlayfs/file.c
parentde30dfd629e2e07e2e9d672b2931bcd60f9a34c0 (diff)
ovl: add ovl_mmap()
Implement stacked mmap. Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Diffstat (limited to 'fs/overlayfs/file.c')
-rw-r--r--fs/overlayfs/file.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c
index 8adddee93418..4c8bf77e048f 100644
--- a/fs/overlayfs/file.c
+++ b/fs/overlayfs/file.c
@@ -255,6 +255,37 @@ static int ovl_fsync(struct file *file, loff_t start, loff_t end, int datasync)
return ret;
}
+static int ovl_mmap(struct file *file, struct vm_area_struct *vma)
+{
+ struct file *realfile = file->private_data;
+ const struct cred *old_cred;
+ int ret;
+
+ if (!realfile->f_op->mmap)
+ return -ENODEV;
+
+ if (WARN_ON(file != vma->vm_file))
+ return -EIO;
+
+ vma->vm_file = get_file(realfile);
+
+ old_cred = ovl_override_creds(file_inode(file)->i_sb);
+ ret = call_mmap(vma->vm_file, vma);
+ revert_creds(old_cred);
+
+ if (ret) {
+ /* Drop reference count from new vm_file value */
+ fput(realfile);
+ } else {
+ /* Drop reference count from previous vm_file value */
+ fput(file);
+ }
+
+ ovl_file_accessed(file);
+
+ return ret;
+}
+
const struct file_operations ovl_file_operations = {
.open = ovl_open,
.release = ovl_release,
@@ -262,4 +293,5 @@ const struct file_operations ovl_file_operations = {
.read_iter = ovl_read_iter,
.write_iter = ovl_write_iter,
.fsync = ovl_fsync,
+ .mmap = ovl_mmap,
};