* @willwrite: true if caller may cause changes to the file; false otherwise.
* Caller must lock/unlock dentry's branch configuration.
*/
-int unionfs_file_revalidate_locked(struct file *file, bool willwrite)
+int unionfs_file_revalidate(struct file *file, bool willwrite)
{
struct super_block *sb;
struct dentry *dentry;
int err = 0;
dentry = file->f_path.dentry;
+ verify_locked(dentry);
sb = dentry->d_sb;
/*
return err;
}
-int unionfs_file_revalidate(struct file *file, bool willwrite)
-{
- int err;
-
- unionfs_lock_dentry(file->f_path.dentry, UNIONFS_DMUTEX_CHILD);
- err = unionfs_file_revalidate_locked(file, willwrite);
- unionfs_unlock_dentry(file->f_path.dentry);
-
- return err;
-}
-
/* unionfs_open helper function: open a directory */
static int __open_dir(struct inode *inode, struct file *file)
{
int fgen, err = 0;
unionfs_read_lock(sb, UNIONFS_SMUTEX_PARENT);
+ unionfs_lock_dentry(dentry, UNIONFS_DMUTEX_CHILD);
+
/*
* Yes, we have to revalidate this file even if it's being released.
* This is important for open-but-unlinked files, as well as mmap
bstart = fbstart(file);
bend = fbend(file);
- unionfs_lock_dentry(dentry, UNIONFS_DMUTEX_CHILD);
for (bindex = bstart; bindex <= bend; bindex++) {
lower_file = unionfs_lower_file_idx(file, bindex);
unionfs_set_lower_dentry_idx(dentry, bindex, NULL);
}
}
- unionfs_unlock_dentry(dentry);
kfree(fileinfo->lower_files);
kfree(fileinfo->saved_branch_ids);
kfree(fileinfo);
out:
+ unionfs_unlock_dentry(dentry);
unionfs_read_unlock(sb);
return err;
}
struct vfsmount *mnt;
dentry = file->f_path.dentry;
- unionfs_lock_dentry(dentry, UNIONFS_DMUTEX_CHILD);
orig_bstart = dbstart(dentry);
orig_bend = dbend(dentry);
err = unionfs_partial_lookup(dentry);
err = -EFAULT;
out:
- unionfs_unlock_dentry(dentry);
return err < 0 ? err : bend;
}
long unionfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
long err;
+ struct dentry *dentry = file->f_path.dentry;
- unionfs_read_lock(file->f_path.dentry->d_sb, UNIONFS_SMUTEX_PARENT);
+ unionfs_read_lock(dentry->d_sb, UNIONFS_SMUTEX_PARENT);
+ unionfs_lock_dentry(dentry, UNIONFS_DMUTEX_CHILD);
err = unionfs_file_revalidate(file, true);
if (unlikely(err))
out:
unionfs_check_file(file);
- unionfs_read_unlock(file->f_path.dentry->d_sb);
+ unionfs_unlock_dentry(dentry);
+ unionfs_read_unlock(dentry->d_sb);
return err;
}
unionfs_read_lock(dentry->d_sb, UNIONFS_SMUTEX_PARENT);
unionfs_lock_dentry(dentry, UNIONFS_DMUTEX_CHILD);
- err = unionfs_file_revalidate_locked(file, true);
+ err = unionfs_file_revalidate(file, true);
if (unlikely(err))
goto out;
unionfs_check_file(file);
out:
if (!err)
unionfs_check_file(file);
- unionfs_unlock_dentry(file->f_path.dentry);
+ unionfs_unlock_dentry(dentry);
unionfs_read_unlock(dentry->d_sb);
return err;
}
{
int err = 0;
struct file *lower_file = NULL;
+ struct dentry *dentry = file->f_path.dentry;
struct inode *inode = NULL;
struct unionfs_getdents_callback buf;
struct unionfs_dir_state *uds;
int bend;
loff_t offset;
- unionfs_read_lock(file->f_path.dentry->d_sb, UNIONFS_SMUTEX_PARENT);
+ unionfs_read_lock(dentry->d_sb, UNIONFS_SMUTEX_PARENT);
+ unionfs_lock_dentry(dentry, UNIONFS_DMUTEX_CHILD);
err = unionfs_file_revalidate(file, false);
if (unlikely(err))
goto out;
- inode = file->f_path.dentry->d_inode;
+ inode = dentry->d_inode;
uds = UNIONFS_F(file)->rdstate;
if (!uds) {
}
out:
- unionfs_read_unlock(file->f_path.dentry->d_sb);
+ unionfs_unlock_dentry(dentry);
+ unionfs_read_unlock(dentry->d_sb);
return err;
}
static loff_t unionfs_dir_llseek(struct file *file, loff_t offset, int origin)
{
struct unionfs_dir_state *rdstate;
+ struct dentry *dentry = file->f_path.dentry;
loff_t err;
- unionfs_read_lock(file->f_path.dentry->d_sb, UNIONFS_SMUTEX_PARENT);
+ unionfs_read_lock(dentry->d_sb, UNIONFS_SMUTEX_PARENT);
+ unionfs_lock_dentry(dentry, UNIONFS_DMUTEX_CHILD);
err = unionfs_file_revalidate(file, false);
if (unlikely(err))
err = -EINVAL;
} else {
struct inode *inode;
- inode = file->f_path.dentry->d_inode;
+ inode = dentry->d_inode;
rdstate = find_rdstate(inode, offset);
if (rdstate) {
UNIONFS_F(file)->rdstate = rdstate;
}
out:
- unionfs_read_unlock(file->f_path.dentry->d_sb);
+ unionfs_unlock_dentry(dentry);
+ unionfs_read_unlock(dentry->d_sb);
return err;
}
unionfs_read_lock(dentry->d_sb, UNIONFS_SMUTEX_PARENT);
unionfs_lock_dentry(dentry, UNIONFS_DMUTEX_CHILD);
- err = unionfs_file_revalidate_locked(file, false);
+ err = unionfs_file_revalidate(file, false);
if (unlikely(err))
goto out;
unionfs_read_lock(dentry->d_sb, UNIONFS_SMUTEX_PARENT);
unionfs_lock_dentry(dentry, UNIONFS_DMUTEX_CHILD);
- err = unionfs_file_revalidate_locked(file, true);
+ err = unionfs_file_revalidate(file, true);
if (unlikely(err))
goto out;
int err = 0;
bool willwrite;
struct file *lower_file;
+ struct dentry *dentry = file->f_path.dentry;
struct vm_operations_struct *saved_vm_ops = NULL;
- unionfs_read_lock(file->f_path.dentry->d_sb, UNIONFS_SMUTEX_PARENT);
+ unionfs_read_lock(dentry->d_sb, UNIONFS_SMUTEX_PARENT);
+ unionfs_lock_dentry(dentry, UNIONFS_DMUTEX_CHILD);
/* This might be deferred to mmap's writepage */
willwrite = ((vma->vm_flags | VM_SHARED | VM_WRITE) == vma->vm_flags);
out:
if (!err) {
/* copyup could cause parent dir times to change */
- unionfs_copy_attr_times(file->f_path.dentry->d_parent->d_inode);
+ unionfs_copy_attr_times(dentry->d_parent->d_inode);
unionfs_check_file(file);
}
- unionfs_read_unlock(file->f_path.dentry->d_sb);
+ unionfs_unlock_dentry(dentry);
+ unionfs_read_unlock(dentry->d_sb);
return err;
}
struct inode *lower_inode, *inode;
int err = -EINVAL;
- unionfs_read_lock(file->f_path.dentry->d_sb, UNIONFS_SMUTEX_PARENT);
+ unionfs_read_lock(dentry->d_sb, UNIONFS_SMUTEX_PARENT);
+ unionfs_lock_dentry(dentry, UNIONFS_DMUTEX_CHILD);
err = unionfs_file_revalidate(file, true);
if (unlikely(err))
goto out;
unionfs_copy_attr_times(inode);
out:
- unionfs_check_file(file);
- unionfs_read_unlock(file->f_path.dentry->d_sb);
+ if (!err)
+ unionfs_check_file(file);
+ unionfs_unlock_dentry(dentry);
+ unionfs_read_unlock(dentry->d_sb);
return err;
}
{
int bindex, bstart, bend;
struct file *lower_file;
- struct dentry *dentry;
+ struct dentry *dentry = file->f_path.dentry;
struct inode *lower_inode, *inode;
int err = 0;
- unionfs_read_lock(file->f_path.dentry->d_sb, UNIONFS_SMUTEX_PARENT);
+ unionfs_read_lock(dentry->d_sb, UNIONFS_SMUTEX_PARENT);
+ unionfs_lock_dentry(dentry, UNIONFS_DMUTEX_CHILD);
err = unionfs_file_revalidate(file, true);
if (unlikely(err))
goto out;
if (bstart < 0 || bend < 0)
goto out;
- dentry = file->f_path.dentry;
inode = dentry->d_inode;
if (unlikely(!inode)) {
printk(KERN_ERR
unionfs_copy_attr_times(inode);
out:
- unionfs_check_file(file);
- unionfs_read_unlock(file->f_path.dentry->d_sb);
+ if (!err)
+ unionfs_check_file(file);
+ unionfs_unlock_dentry(dentry);
+ unionfs_read_unlock(dentry->d_sb);
return err;
}
{
ssize_t err;
struct file *lower_file;
+ struct dentry *dentry = file->f_path.dentry;
- unionfs_read_lock(file->f_path.dentry->d_sb, UNIONFS_SMUTEX_PARENT);
+ unionfs_read_lock(dentry->d_sb, UNIONFS_SMUTEX_PARENT);
+ unionfs_lock_dentry(dentry, UNIONFS_DMUTEX_CHILD);
err = unionfs_file_revalidate(file, false);
if (unlikely(err))
goto out;
err = vfs_splice_to(lower_file, ppos, pipe, len, flags);
/* update our inode atime upon a successful lower splice-read */
if (err >= 0) {
- fsstack_copy_attr_atime(file->f_path.dentry->d_inode,
+ fsstack_copy_attr_atime(dentry->d_inode,
lower_file->f_path.dentry->d_inode);
unionfs_check_file(file);
}
out:
- unionfs_check_file(file);
- unionfs_read_unlock(file->f_path.dentry->d_sb);
+ unionfs_unlock_dentry(dentry);
+ unionfs_read_unlock(dentry->d_sb);
return err;
}
{
ssize_t err = 0;
struct file *lower_file;
+ struct dentry *dentry = file->f_path.dentry;
- unionfs_read_lock(file->f_path.dentry->d_sb, UNIONFS_SMUTEX_PARENT);
+ unionfs_read_lock(dentry->d_sb, UNIONFS_SMUTEX_PARENT);
+ unionfs_lock_dentry(dentry, UNIONFS_DMUTEX_CHILD);
err = unionfs_file_revalidate(file, true);
if (unlikely(err))
goto out;
err = vfs_splice_from(pipe, lower_file, ppos, len, flags);
/* update our inode times+sizes upon a successful lower write */
if (err >= 0) {
- fsstack_copy_inode_size(file->f_path.dentry->d_inode,
+ fsstack_copy_inode_size(dentry->d_inode,
lower_file->f_path.dentry->d_inode);
- fsstack_copy_attr_times(file->f_path.dentry->d_inode,
+ fsstack_copy_attr_times(dentry->d_inode,
lower_file->f_path.dentry->d_inode);
unionfs_check_file(file);
}
out:
- unionfs_read_unlock(file->f_path.dentry->d_sb);
+ unionfs_unlock_dentry(dentry);
+ unionfs_read_unlock(dentry->d_sb);
return err;
}
extern int unionfs_getlk(struct file *file, struct file_lock *fl);
/* Common file operations. */
-extern int unionfs_file_revalidate_locked(struct file *file, bool willwrite);
extern int unionfs_file_revalidate(struct file *file, bool willwrite);
extern int unionfs_open(struct inode *inode, struct file *file);
extern int unionfs_file_release(struct inode *inode, struct file *file);