Unionfs: move debugging checks inside locks
authorErez Zadok <ezk@cs.sunysb.edu>
Tue, 27 Nov 2007 00:53:55 +0000 (19:53 -0500)
committerErez Zadok <ezk@cs.sunysb.edu>
Tue, 27 Nov 2007 00:53:55 +0000 (19:53 -0500)
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 3a60fa63082d451734621bc4bf6ea42265850941..6eec818a6ac3dc8a1ee6c4aee90b366361c813da 100644 (file)
@@ -573,6 +573,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:
@@ -582,12 +583,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_dentry->d_parent);
        }
+       unionfs_read_unlock(inode->i_sb);
        return err;
 }
 
@@ -784,8 +785,8 @@ int unionfs_ioctl(struct inode *inode, struct file *file,
        }
 
 out:
-       unionfs_read_unlock(file->f_dentry->d_sb);
        unionfs_check_file(file);
+       unionfs_read_unlock(file->f_dentry->d_sb);
        return err;
 }
 
@@ -823,7 +824,7 @@ int unionfs_flush(struct file *file)
        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 889d5a081e351383e482d11f2f34c8e6d33183b6..47a05e58710424072e8622a9745c191b94644187 100644 (file)
@@ -426,9 +426,9 @@ 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_unlock_dentry(dentry);
 
        unionfs_read_unlock(dentry->d_sb);
 
index 32749a3a2657c547f95940ad99e7ca081d199a93..3b9c9c33f1d23d1ed842ae94048859d31126bd09 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_dentry->d_sb);
        unionfs_check_file(file);
+       unionfs_read_unlock(file->f_dentry->d_sb);
        return err;
 }
 
@@ -55,8 +55,8 @@ static ssize_t unionfs_aio_read(struct kiocb *iocb, char __user *iov,
                err = wait_on_sync_kiocb(iocb);
 
 out:
-       unionfs_read_unlock(file->f_dentry->d_sb);
        unionfs_check_file(file);
+       unionfs_read_unlock(file->f_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_dentry->d_sb);
        if (!err) {
                /* copyup could cause parent dir times to change */
                unionfs_copy_attr_times(file->f_dentry->d_parent->d_inode);
                unionfs_check_file(file);
                unionfs_check_dentry(file->f_dentry->d_parent);
        }
+       unionfs_read_unlock(file->f_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_dentry->d_sb);
        unionfs_check_file(file);
+       unionfs_read_unlock(file->f_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_dentry->d_sb);
        unionfs_check_file(file);
+       unionfs_read_unlock(file->f_dentry->d_sb);
        return err;
 }
 
index 35a71c3d135b66985d31ccd4e82db72789a14d6b..959769fa27de41d4de98f05be633856d0b10b7c0 100644 (file)
@@ -152,13 +152,13 @@ out:
 
        if (!err)
                unionfs_postcopyup_setmnt(dentry);
-       unionfs_unlock_dentry(dentry);
-       unionfs_read_unlock(dentry->d_sb);
 
        unionfs_check_inode(parent);
        if (!err)
                unionfs_check_dentry(dentry->d_parent);
        unionfs_check_dentry(dentry);
+       unionfs_unlock_dentry(dentry);
+       unionfs_read_unlock(dentry->d_sb);
        return err;
 }
 
@@ -198,12 +198,13 @@ 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);
+       if (!IS_ERR(ret))
+               unionfs_unlock_dentry(dentry);
        unionfs_read_unlock(dentry->d_sb);
 
        return ret;
@@ -347,12 +348,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;
@@ -513,10 +514,10 @@ out:
        kfree(name);
        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;
@@ -666,9 +667,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;
@@ -796,10 +797,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;
@@ -834,8 +835,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;
@@ -895,10 +896,10 @@ 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);
        kfree(nd_get_link(nd));
+       unionfs_unlock_dentry(dentry);
        unionfs_read_unlock(dentry->d_sb);
 }
 
@@ -1070,9 +1071,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 d5aba72b05632873325ae99f8aa64c135a0d27c1..95c3fcb6156e0dbaa3d07ad085603aeee941739f 100644 (file)
@@ -324,8 +324,8 @@ out:
        if (err < 0)
                ClearPageUptodate(page);
 
-       unionfs_read_unlock(file->f_dentry->d_sb);
        unionfs_check_file(file);
+       unionfs_read_unlock(file->f_dentry->d_sb);
        return err;             /* assume all is ok */
 }
 
index b325b9aaa381d588cddea90a244a452f97646d31..7827e34a3bc6a1745bd8f49d6970149b101c10e2 100644 (file)
@@ -151,8 +151,8 @@ static int unionfs_statfs(struct super_block *sb, 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;
 }
@@ -796,8 +796,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 cd5978b44863d718d82220cf9220789e5da9dfec..6386fb74e8f18f2915f304fa27b3871325ef8bd6 100644 (file)
@@ -60,8 +60,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;
 }
@@ -90,8 +90,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;
 }
@@ -118,8 +118,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;
 }
@@ -148,8 +148,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;
 }