Unionfs: unionfs_create rewrite
authorJosef 'Jeff' Sipek <jsipek@cs.sunysb.edu>
Sun, 18 Nov 2007 03:27:29 +0000 (22:27 -0500)
committerRachita Kothiyal <rachita@dewey.fsl.cs.sunysb.edu>
Thu, 1 May 2008 23:03:04 +0000 (19:03 -0400)
The code was hard to follow and violated some invariants (e.g., never modify
a read only branch, and always create on branch 0).

Signed-off-by: Josef 'Jeff' Sipek <jsipek@cs.sunysb.edu>
fs/unionfs/inode.c

index 262e955672ac16bfb5c09f2e33a20e3a1e0bcaa7..bfac4331f337ace6420186e7ac3ac42108842496 100644 (file)
@@ -44,7 +44,20 @@ static int unionfs_create(struct inode *parent, struct dentry *dentry,
         */
        BUG_ON(!valid && dentry->d_inode);
 
-       /* We start out in the leftmost branch. */
+       /*
+        * We shouldn't create things in a read-only branch; this check is a
+        * bit redundant as we don't allow branch 0 to be read-only at the
+        * moment
+        */
+       err = is_robranch_super(dentry->d_sb, 0);
+       if (err) {
+               err = -EROFS;
+               goto out;
+       }
+
+       /*
+        * We _always_ create on branch 0
+        */
        bstart = 0;
 
        lower_dentry = unionfs_lower_dentry_idx(dentry, bstart);
@@ -77,10 +90,8 @@ static int unionfs_create(struct inode *parent, struct dentry *dentry,
                err = PTR_ERR(lower_parent_dentry);
                goto out;
        }
-       /* We shouldn't create things in a read-only branch. */
-       if (!(err = is_robranch_super(dentry->d_sb, bstart)))
-               err = vfs_create(lower_parent_dentry->d_inode,
-                                lower_dentry, mode, nd);
+       err = vfs_create(lower_parent_dentry->d_inode,
+                        lower_dentry, mode, nd);
 
        if (err || !lower_dentry->d_inode)
                unlock_dir(lower_parent_dentry);