Unionfs: move debugging checks inside locks
authorErez Zadok <ezk@cs.sunysb.edu>
Fri, 16 Nov 2007 18:45:04 +0000 (13:45 -0500)
committerRachita Kothiyal <rachita@dewey.fsl.cs.sunysb.edu>
Thu, 1 May 2008 23:03:19 +0000 (19:03 -0400)
This is to ensure that the objects we want to check aren't being destroyed
or changed by another thread.

Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
fs/unionfs/commonfops.c
fs/unionfs/dentry.c
fs/unionfs/file.c
fs/unionfs/inode.c
fs/unionfs/mmap.c
fs/unionfs/super.c
fs/unionfs/xattr.c

index 8d2cfdc12078faade2a6b56cdf667edf403159a1..b8fcdca1276c31aff3a8fe8fafefbabd4994447c 100644 (file)
@@ -667,6 +667,7 @@ int unionfs_open(struct inode *inode, struct file *file)
                }
        }
 
+       /* XXX: should this unlock be moved to the function bottom? */
        unionfs_unlock_dentry(dentry);
 
 out:
@@ -676,12 +677,12 @@ out:
                kfree(UNIONFS_F(file));
        }
 out_nofree:
-       unionfs_read_unlock(inode->i_sb);
        unionfs_check_inode(inode);
        if (!err) {
                unionfs_check_file(file);
                unionfs_check_dentry(file->f_path.dentry->d_parent);
        }
+       unionfs_read_unlock(inode->i_sb);
        return err;
 }
 
@@ -863,8 +864,8 @@ long unionfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        }
 
 out:
-       unionfs_read_unlock(file->f_path.dentry->d_sb);
        unionfs_check_file(file);
+       unionfs_read_unlock(file->f_path.dentry->d_sb);
        return err;
 }
 
@@ -902,7 +903,7 @@ int unionfs_flush(struct file *file, fl_owner_t id)
        unionfs_copy_attr_times(dentry->d_parent->d_inode);
 
 out:
-       unionfs_read_unlock(dentry->d_sb);
        unionfs_check_file(file);
+       unionfs_read_unlock(dentry->d_sb);
        return err;
 }
index 7e8c338aec3cb43838a0017654df61824bf5a312..cf96310ac54d2165c730837fe505bd86ed9eeac8 100644 (file)
@@ -449,11 +449,11 @@ static int unionfs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
 
        unionfs_lock_dentry(dentry);
        err = __unionfs_d_revalidate_chain(dentry, nd, false);
-       unionfs_unlock_dentry(dentry);
        if (likely(err > 0)) { /* true==1: dentry is valid */
                unionfs_check_dentry(dentry);
                unionfs_check_nd(nd);
        }
+       unionfs_unlock_dentry(dentry);
 
        unionfs_read_unlock(dentry->d_sb);
 
index 809e0f14adbc19cc5bca25492e4ff7056ea44801..cfbfb8e9cbbbc31e4be7efc4d18598e0614f30d3 100644 (file)
@@ -32,8 +32,8 @@ static ssize_t unionfs_read(struct file *file, char __user *buf,
        err = do_sync_read(file, buf, count, ppos);
 
 out:
-       unionfs_read_unlock(file->f_path.dentry->d_sb);
        unionfs_check_file(file);
+       unionfs_read_unlock(file->f_path.dentry->d_sb);
        return err;
 }
 
@@ -55,8 +55,8 @@ static ssize_t unionfs_aio_read(struct kiocb *iocb, const struct iovec *iov,
                err = wait_on_sync_kiocb(iocb);
 
 out:
-       unionfs_read_unlock(file->f_path.dentry->d_sb);
        unionfs_check_file(file);
+       unionfs_read_unlock(file->f_path.dentry->d_sb);
        return err;
 }
 
@@ -127,13 +127,13 @@ static int unionfs_mmap(struct file *file, struct vm_area_struct *vma)
        }
 
 out:
-       unionfs_read_unlock(file->f_path.dentry->d_sb);
        if (!err) {
                /* copyup could cause parent dir times to change */
                unionfs_copy_attr_times(file->f_path.dentry->d_parent->d_inode);
                unionfs_check_file(file);
                unionfs_check_dentry(file->f_path.dentry->d_parent);
        }
+       unionfs_read_unlock(file->f_path.dentry->d_sb);
        return err;
 }
 
@@ -180,8 +180,8 @@ int unionfs_fsync(struct file *file, struct dentry *dentry, int datasync)
        unionfs_copy_attr_times(inode);
 
 out:
-       unionfs_read_unlock(file->f_path.dentry->d_sb);
        unionfs_check_file(file);
+       unionfs_read_unlock(file->f_path.dentry->d_sb);
        return err;
 }
 
@@ -226,8 +226,8 @@ int unionfs_fasync(int fd, struct file *file, int flag)
        unionfs_copy_attr_times(inode);
 
 out:
-       unionfs_read_unlock(file->f_path.dentry->d_sb);
        unionfs_check_file(file);
+       unionfs_read_unlock(file->f_path.dentry->d_sb);
        return err;
 }
 
index e522b565f5866ca021a2fc8d6c7d8523d1ada379..ce293b84b12d7ec1d71325198b8f617640d56fec 100644 (file)
@@ -127,8 +127,6 @@ static int unionfs_create(struct inode *parent, struct dentry *dentry,
 out:
        if (!err)
                unionfs_postcopyup_setmnt(dentry);
-       unionfs_unlock_dentry(dentry);
-       unionfs_read_unlock(dentry->d_sb);
 
        unionfs_check_inode(parent);
        if (!err) {
@@ -136,6 +134,8 @@ out:
                unionfs_check_nd(nd);
        }
        unionfs_check_dentry(dentry);
+       unionfs_unlock_dentry(dentry);
+       unionfs_read_unlock(dentry->d_sb);
        return err;
 }
 
@@ -175,13 +175,14 @@ static struct dentry *unionfs_lookup(struct inode *parent,
                        dentry = ret;
                /* parent times may have changed */
                unionfs_copy_attr_times(dentry->d_parent->d_inode);
-               unionfs_unlock_dentry(dentry);
        }
 
        unionfs_check_inode(parent);
        unionfs_check_dentry(dentry);
        unionfs_check_dentry(dentry->d_parent);
        unionfs_check_nd(nd);
+       if (!IS_ERR(ret))
+               unionfs_unlock_dentry(dentry);
        unionfs_read_unlock(dentry->d_sb);
 
        return ret;
@@ -324,12 +325,12 @@ out:
        if (!err)
                unionfs_postcopyup_setmnt(new_dentry);
 
-       unionfs_unlock_dentry(new_dentry);
-       unionfs_unlock_dentry(old_dentry);
-
        unionfs_check_inode(dir);
        unionfs_check_dentry(new_dentry);
        unionfs_check_dentry(old_dentry);
+
+       unionfs_unlock_dentry(new_dentry);
+       unionfs_unlock_dentry(old_dentry);
        unionfs_read_unlock(old_dentry->d_sb);
 
        return err;
@@ -423,10 +424,10 @@ static int unionfs_symlink(struct inode *dir, struct dentry *dentry,
 out:
        if (!err)
                unionfs_postcopyup_setmnt(dentry);
-       unionfs_unlock_dentry(dentry);
 
        unionfs_check_inode(dir);
        unionfs_check_dentry(dentry);
+       unionfs_unlock_dentry(dentry);
        unionfs_read_unlock(dentry->d_sb);
 
        return err;
@@ -532,9 +533,9 @@ out:
 
        if (!err)
                unionfs_copy_attr_times(dentry->d_inode);
-       unionfs_unlock_dentry(dentry);
        unionfs_check_inode(parent);
        unionfs_check_dentry(dentry);
+       unionfs_unlock_dentry(dentry);
        unionfs_read_unlock(dentry->d_sb);
 
        return err;
@@ -622,10 +623,10 @@ out:
 
        if (!err)
                unionfs_postcopyup_setmnt(dentry);
-       unionfs_unlock_dentry(dentry);
 
        unionfs_check_inode(dir);
        unionfs_check_dentry(dentry);
+       unionfs_unlock_dentry(dentry);
        unionfs_read_unlock(dentry->d_sb);
 
        return err;
@@ -660,8 +661,8 @@ static int unionfs_readlink(struct dentry *dentry, char __user *buf,
                                        lower_dentry->d_inode);
 
 out:
-       unionfs_unlock_dentry(dentry);
        unionfs_check_dentry(dentry);
+       unionfs_unlock_dentry(dentry);
        unionfs_read_unlock(dentry->d_sb);
 
        return err;
@@ -724,11 +725,11 @@ static void unionfs_put_link(struct dentry *dentry, struct nameidata *nd,
        if (unlikely(!__unionfs_d_revalidate_chain(dentry, nd, false)))
                printk(KERN_ERR
                       "unionfs: put_link failed to revalidate dentry\n");
-       unionfs_unlock_dentry(dentry);
 
        unionfs_check_dentry(dentry);
        unionfs_check_nd(nd);
        kfree(nd_get_link(nd));
+       unionfs_unlock_dentry(dentry);
        unionfs_read_unlock(dentry->d_sb);
 }
 
@@ -908,9 +909,9 @@ static int unionfs_setattr(struct dentry *dentry, struct iattr *ia)
        /* if setattr succeeded, then parent dir may have changed */
        unionfs_copy_attr_times(dentry->d_parent->d_inode);
 out:
-       unionfs_unlock_dentry(dentry);
        unionfs_check_dentry(dentry);
        unionfs_check_dentry(dentry->d_parent);
+       unionfs_unlock_dentry(dentry);
        unionfs_read_unlock(dentry->d_sb);
 
        return err;
index ef8822ff7f85220de5668d40eeea50d6657eb577..4918f777d54a61a95818b274580734ebe34d598b 100644 (file)
@@ -296,8 +296,8 @@ out:
        if (err < 0)
                ClearPageUptodate(page);
 
-       unionfs_read_unlock(file->f_path.dentry->d_sb);
        unionfs_check_file(file);
+       unionfs_read_unlock(file->f_path.dentry->d_sb);
        return err;             /* assume all is ok */
 }
 
index cdb54393859374e50c02a9aba0224fe285ab3c6a..afc972bb243f30f73e1d939791bba122fa33db9e 100644 (file)
@@ -146,8 +146,8 @@ static int unionfs_statfs(struct dentry *dentry, struct kstatfs *buf)
        memset(&buf->f_spare, 0, sizeof(buf->f_spare));
 
 out:
-       unionfs_unlock_dentry(dentry);
        unionfs_check_dentry(dentry);
+       unionfs_unlock_dentry(dentry);
        unionfs_read_unlock(sb);
        return err;
 }
@@ -829,8 +829,8 @@ out_free:
        kfree(new_data);
        kfree(new_lower_inodes);
 out_error:
-       unionfs_write_unlock(sb);
        unionfs_check_dentry(sb->s_root);
+       unionfs_write_unlock(sb);
        return err;
 }
 
index 602cedfc4b21c53ebb19e8cad19a4844045d126d..00c6d0dc0e833471335057fef52bce42972c5a6b 100644 (file)
@@ -58,8 +58,8 @@ ssize_t unionfs_getxattr(struct dentry *dentry, const char *name, void *value,
        err = vfs_getxattr(lower_dentry, (char *) name, value, size);
 
 out:
-       unionfs_unlock_dentry(dentry);
        unionfs_check_dentry(dentry);
+       unionfs_unlock_dentry(dentry);
        unionfs_read_unlock(dentry->d_sb);
        return err;
 }
@@ -88,8 +88,8 @@ int unionfs_setxattr(struct dentry *dentry, const char *name,
                           size, flags);
 
 out:
-       unionfs_unlock_dentry(dentry);
        unionfs_check_dentry(dentry);
+       unionfs_unlock_dentry(dentry);
        unionfs_read_unlock(dentry->d_sb);
        return err;
 }
@@ -116,8 +116,8 @@ int unionfs_removexattr(struct dentry *dentry, const char *name)
        err = vfs_removexattr(lower_dentry, (char *) name);
 
 out:
-       unionfs_unlock_dentry(dentry);
        unionfs_check_dentry(dentry);
+       unionfs_unlock_dentry(dentry);
        unionfs_read_unlock(dentry->d_sb);
        return err;
 }
@@ -146,8 +146,8 @@ ssize_t unionfs_listxattr(struct dentry *dentry, char *list, size_t size)
        err = vfs_listxattr(lower_dentry, encoded_list, size);
 
 out:
-       unionfs_unlock_dentry(dentry);
        unionfs_check_dentry(dentry);
+       unionfs_unlock_dentry(dentry);
        unionfs_read_unlock(dentry->d_sb);
        return err;
 }