GIT: unionfs2-2.6.9.y: Unionfs: lock our dentry in file operations
Erez_Zadok
ezk at fsl.cs.sunysb.edu
Tue Mar 25 21:41:28 EDT 2008
commit 6b822deae47f0adc527af5bfad55897b236d3dde
Author: Erez Zadok <ezk at cs.sunysb.edu>
Date: Sun Mar 23 02:53:56 2008 -0400
Unionfs: lock our dentry in file operations
Signed-off-by: Erez Zadok <ezk at cs.sunysb.edu>
diff --git a/fs/unionfs/commonfops.c b/fs/unionfs/commonfops.c
index 854deff..a6ead9b 100644
--- a/fs/unionfs/commonfops.c
+++ b/fs/unionfs/commonfops.c
@@ -301,7 +301,7 @@ out:
* @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;
@@ -311,6 +311,7 @@ int unionfs_file_revalidate_locked(struct file *file, bool willwrite)
int err = 0;
dentry = file->f_dentry;
+ verify_locked(dentry);
sb = dentry->d_sb;
/*
@@ -418,17 +419,6 @@ out_nofree:
return err;
}
-int unionfs_file_revalidate(struct file *file, bool willwrite)
-{
- int err;
-
- unionfs_lock_dentry(file->f_dentry, UNIONFS_DMUTEX_CHILD);
- err = unionfs_file_revalidate_locked(file, willwrite);
- unionfs_unlock_dentry(file->f_dentry);
-
- return err;
-}
-
/* unionfs_open helper function: open a directory */
static int __open_dir(struct inode *inode, struct file *file)
{
@@ -632,6 +622,8 @@ int unionfs_file_release(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
@@ -650,7 +642,6 @@ int unionfs_file_release(struct inode *inode, struct file *file)
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);
@@ -665,7 +656,6 @@ int unionfs_file_release(struct inode *inode, struct file *file)
unionfs_set_lower_dentry_idx(dentry, bindex, NULL);
}
}
- unionfs_unlock_dentry(dentry);
kfree(fileinfo->lower_files);
kfree(fileinfo->saved_branch_ids);
@@ -683,6 +673,7 @@ int unionfs_file_release(struct inode *inode, struct file *file)
kfree(fileinfo);
out:
+ unionfs_unlock_dentry(dentry);
unionfs_read_unlock(sb);
return err;
}
@@ -726,7 +717,6 @@ static int unionfs_ioctl_queryfile(struct file *file, unsigned int cmd,
struct vfsmount *mnt;
dentry = file->f_dentry;
- unionfs_lock_dentry(dentry, UNIONFS_DMUTEX_CHILD);
orig_bstart = dbstart(dentry);
orig_bend = dbend(dentry);
err = unionfs_partial_lookup(dentry);
@@ -768,7 +758,6 @@ static int unionfs_ioctl_queryfile(struct file *file, unsigned int cmd,
err = -EFAULT;
out:
- unionfs_unlock_dentry(dentry);
return err < 0 ? err : bend;
}
@@ -776,8 +765,10 @@ int unionfs_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
{
long err;
+ struct dentry *dentry = file->f_dentry;
- unionfs_read_lock(file->f_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))
@@ -805,7 +796,8 @@ int unionfs_ioctl(struct inode *inode, struct file *file,
out:
unionfs_check_file(file);
- unionfs_read_unlock(file->f_dentry->d_sb);
+ unionfs_unlock_dentry(dentry);
+ unionfs_read_unlock(dentry->d_sb);
return err;
}
@@ -819,7 +811,7 @@ int unionfs_flush(struct file *file)
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);
@@ -841,7 +833,7 @@ int unionfs_flush(struct file *file)
out:
if (!err)
unionfs_check_file(file);
- unionfs_unlock_dentry(file->f_dentry);
+ unionfs_unlock_dentry(dentry);
unionfs_read_unlock(dentry->d_sb);
return err;
}
diff --git a/fs/unionfs/dirfops.c b/fs/unionfs/dirfops.c
index f423254..9046883 100644
--- a/fs/unionfs/dirfops.c
+++ b/fs/unionfs/dirfops.c
@@ -97,19 +97,21 @@ static int unionfs_readdir(struct file *file, void *dirent, filldir_t filldir)
{
int err = 0;
struct file *lower_file = NULL;
+ struct dentry *dentry = file->f_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_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_dentry->d_inode;
+ inode = dentry->d_inode;
uds = UNIONFS_F(file)->rdstate;
if (!uds) {
@@ -188,7 +190,8 @@ static int unionfs_readdir(struct file *file, void *dirent, filldir_t filldir)
}
out:
- unionfs_read_unlock(file->f_dentry->d_sb);
+ unionfs_unlock_dentry(dentry);
+ unionfs_read_unlock(dentry->d_sb);
return err;
}
@@ -205,9 +208,11 @@ out:
static loff_t unionfs_dir_llseek(struct file *file, loff_t offset, int origin)
{
struct unionfs_dir_state *rdstate;
+ struct dentry *dentry = file->f_dentry;
loff_t err;
- unionfs_read_lock(file->f_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))
@@ -249,7 +254,7 @@ static loff_t unionfs_dir_llseek(struct file *file, loff_t offset, int origin)
err = -EINVAL;
} else {
struct inode *inode;
- inode = file->f_dentry->d_inode;
+ inode = dentry->d_inode;
rdstate = find_rdstate(inode, offset);
if (rdstate) {
UNIONFS_F(file)->rdstate = rdstate;
@@ -268,7 +273,8 @@ static loff_t unionfs_dir_llseek(struct file *file, loff_t offset, int origin)
}
out:
- unionfs_read_unlock(file->f_dentry->d_sb);
+ unionfs_unlock_dentry(dentry);
+ unionfs_read_unlock(dentry->d_sb);
return err;
}
diff --git a/fs/unionfs/file.c b/fs/unionfs/file.c
index 3f55f19..df3756e 100644
--- a/fs/unionfs/file.c
+++ b/fs/unionfs/file.c
@@ -29,8 +29,10 @@ static int unionfs_mmap(struct file *file, struct vm_area_struct *vma)
int err = 0;
bool willwrite;
struct file *lower_file;
+ struct dentry *dentry = file->f_dentry;
- unionfs_read_lock(file->f_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);
@@ -64,10 +66,11 @@ static int unionfs_mmap(struct file *file, struct vm_area_struct *vma)
out:
if (!err) {
/* copyup could cause parent dir times to change */
- unionfs_copy_attr_times(file->f_dentry->d_parent->d_inode);
+ unionfs_copy_attr_times(dentry->d_parent->d_inode);
unionfs_check_file(file);
}
- unionfs_read_unlock(file->f_dentry->d_sb);
+ unionfs_unlock_dentry(dentry);
+ unionfs_read_unlock(dentry->d_sb);
return err;
}
@@ -79,7 +82,8 @@ int unionfs_fsync(struct file *file, struct dentry *dentry, int datasync)
struct inode *lower_inode, *inode;
int err = -EINVAL;
- unionfs_read_lock(file->f_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;
@@ -114,8 +118,10 @@ int unionfs_fsync(struct file *file, struct dentry *dentry, int datasync)
unionfs_copy_attr_times(inode);
out:
- unionfs_check_file(file);
- unionfs_read_unlock(file->f_dentry->d_sb);
+ if (!err)
+ unionfs_check_file(file);
+ unionfs_unlock_dentry(dentry);
+ unionfs_read_unlock(dentry->d_sb);
return err;
}
@@ -123,11 +129,12 @@ int unionfs_fasync(int fd, struct file *file, int flag)
{
int bindex, bstart, bend;
struct file *lower_file;
- struct dentry *dentry;
+ struct dentry *dentry = file->f_dentry;
struct inode *lower_inode, *inode;
int err = 0;
- unionfs_read_lock(file->f_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;
@@ -138,7 +145,6 @@ int unionfs_fasync(int fd, struct file *file, int flag)
if (bstart < 0 || bend < 0)
goto out;
- dentry = file->f_dentry;
inode = dentry->d_inode;
if (unlikely(!inode)) {
printk(KERN_ERR
@@ -160,8 +166,10 @@ int unionfs_fasync(int fd, struct file *file, int flag)
unionfs_copy_attr_times(inode);
out:
- unionfs_check_file(file);
- unionfs_read_unlock(file->f_dentry->d_sb);
+ if (!err)
+ unionfs_check_file(file);
+ unionfs_unlock_dentry(dentry);
+ unionfs_read_unlock(dentry->d_sb);
return err;
}
diff --git a/fs/unionfs/union.h b/fs/unionfs/union.h
index 18ae951..d588277 100644
--- a/fs/unionfs/union.h
+++ b/fs/unionfs/union.h
@@ -357,7 +357,6 @@ extern int unionfs_setlk(struct file *file, int cmd, struct file_lock *fl);
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);
More information about the unionfs-cvs
mailing list