static int esdfs_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 = ESDFS_F(file)->lower_vm_ops; BUG_ON(!lower_vm_ops); if (!lower_vm_ops->page_mkwrite) goto out; lower_file = esdfs_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 esdfs_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; }
static int esdfs_setattr(struct dentry *dentry, struct iattr *ia) { int err = 0; struct dentry *lower_dentry; struct inode *inode; struct inode *lower_inode; struct path lower_path; struct iattr lower_ia; const struct cred *creds; /* We don't allow chmod or chown, so skip those */ ia->ia_valid &= ~(ATTR_UID | ATTR_GID | ATTR_MODE); if (!ia->ia_valid) return 0; inode = dentry->d_inode; /* * Check if user has permission to change inode. We don't check if * this user can change the lower inode: that should happen when * calling notify_change on the lower inode. */ err = inode_change_ok(inode, ia); if (err) return err; creds = esdfs_override_creds(ESDFS_SB(dentry->d_inode->i_sb), NULL); if (!creds) return -ENOMEM; esdfs_get_lower_path(dentry, &lower_path); lower_dentry = lower_path.dentry; lower_inode = esdfs_lower_inode(inode); /* prepare our own lower struct iattr (with the lower file) */ memcpy(&lower_ia, ia, sizeof(lower_ia)); if (ia->ia_valid & ATTR_FILE) lower_ia.ia_file = esdfs_lower_file(ia->ia_file); /* * If shrinking, first truncate upper level to cancel writing dirty * pages beyond the new eof; and also if its' maxbytes is more * limiting (fail with -EFBIG before making any change to the lower * level). There is no need to vmtruncate the upper level * afterwards in the other cases: we fsstack_copy_inode_size from * the lower level. */ if (ia->ia_valid & ATTR_SIZE) { err = inode_newsize_ok(inode, ia->ia_size); if (err) goto out; truncate_setsize(inode, ia->ia_size); } /* * mode change is for clearing setuid/setgid bits. Allow lower fs * to interpret this in its own way. */ if (lower_ia.ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) lower_ia.ia_valid &= ~ATTR_MODE; /* notify the (possibly copied-up) lower inode */ /* * Note: we use lower_dentry->d_inode, because lower_inode may be * unlinked (no inode->i_sb and i_ino==0. This happens if someone * tries to open(), unlink(), then ftruncate() a file. */ mutex_lock(&lower_dentry->d_inode->i_mutex); err = notify_change(lower_dentry, &lower_ia); /* note: lower_ia */ mutex_unlock(&lower_dentry->d_inode->i_mutex); if (err) goto out; /* get attributes from the lower inode */ esdfs_copy_attr(inode, lower_inode); /* * Not running fsstack_copy_inode_size(inode, lower_inode), because * VFS should update our inode size, and notify_change on * lower_inode should update its size. */ out: esdfs_put_lower_path(dentry, &lower_path); esdfs_revert_creds(creds, NULL); return err; }