Unionfs: ensure consistent lower inodes types
authorErez Zadok <ezk@cs.sunysb.edu>
Sat, 16 Feb 2008 02:38:30 +0000 (21:38 -0500)
committerErez Zadok <ezk@cs.sunysb.edu>
Sat, 16 Feb 2008 02:38:30 +0000 (21:38 -0500)
When looking up a lower object in multiple branches, especially for
directories, ignore any existing entries whose type is different than the
type of the first found object (otherwise we'll be trying to, say, call
readdir on a non-dir inode).

Signed-off-by: Himanshu Kanda <hkanda@fsl.cs.sunysb.edu>
Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
fs/unionfs/lookup.c

index 377f9d053f324904731d10644c5df8c70c5c5842..228187b2ba4e8ee2dc456a7cefbe2d8f9325a767 100644 (file)
@@ -261,6 +261,19 @@ struct dentry *unionfs_lookup_backend(struct dentry *dentry,
                        continue;
                }
 
+               /*
+                * If we already found at least one positive dentry
+                * (dentry_count is non-zero), then we skip all remaining
+                * positive dentries if their type is a non-dir.  This is
+                * because only directories are allowed to stack on multiple
+                * branches, but we have to skip non-dirs (to avoid, say,
+                * calling readdir on a regular file).
+                */
+               if (!S_ISDIR(lower_dentry->d_inode->i_mode) && dentry_count) {
+                       dput(lower_dentry);
+                       continue;
+               }
+
                /* number of positive dentries */
                dentry_count++;