Wrapfs: implement vm_ops->page_mkwrite
authorErez Zadok <ezk@cs.sunysb.edu>
Thu, 15 May 2014 03:45:28 +0000 (23:45 -0400)
committerErez Zadok <ezk@cs.sunysb.edu>
Tue, 27 Dec 2016 19:05:18 +0000 (14:05 -0500)
Some file systems (e.g., ext4) require it.  Reported by Ted Ts'o.

Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
fs/wrapfs/mmap.c

index a1fefada516fa75cc62a5b3866b1343b18ccb36d..dc0bd27935c8514e7e2d6b83338215d41debfac4 100644 (file)
@@ -39,6 +39,39 @@ static int wrapfs_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
        return err;
 }
 
+static int wrapfs_page_mkwrite(struct vm_area_struct *vma,
+                              struct vm_fault *vmf)
+{
+       int err = 0;
+       struct file *file, *lower_file;
+       const struct vm_operations_struct *lower_vm_ops;
+       struct vm_area_struct lower_vma;
+
+       memcpy(&lower_vma, vma, sizeof(struct vm_area_struct));
+       file = lower_vma.vm_file;
+       lower_vm_ops = WRAPFS_F(file)->lower_vm_ops;
+       BUG_ON(!lower_vm_ops);
+       if (!lower_vm_ops->page_mkwrite)
+               goto out;
+
+       lower_file = wrapfs_lower_file(file);
+       /*
+        * XXX: vm_ops->page_mkwrite may be called in parallel.
+        * Because we have to resort to temporarily changing the
+        * vma->vm_file to point to the lower file, a concurrent
+        * invocation of wrapfs_page_mkwrite could see a different
+        * value.  In this workaround, we keep a different copy of the
+        * vma structure in our stack, so we never expose a different
+        * value of the vma->vm_file called to us, even temporarily.
+        * A better fix would be to change the calling semantics of
+        * ->page_mkwrite to take an explicit file pointer.
+        */
+       lower_vma.vm_file = lower_file;
+       err = lower_vm_ops->page_mkwrite(&lower_vma, vmf);
+out:
+       return err;
+}
+
 /*
  * XXX: the default address_space_ops for wrapfs is empty.  We cannot set
  * our inode->i_mapping->a_ops to NULL because too many code paths expect
@@ -50,4 +83,5 @@ const struct address_space_operations wrapfs_aops = {
 
 const struct vm_operations_struct wrapfs_vm_ops = {
        .fault          = wrapfs_fault,
+       .page_mkwrite   = wrapfs_page_mkwrite,
 };