Unionfs: handle whiteouts more efficiently in filldir
authorErez Zadok <ezk@cs.sunysb.edu>
Wed, 21 Nov 2007 03:29:20 +0000 (22:29 -0500)
committerErez Zadok <ezk@cs.sunysb.edu>
Tue, 11 Nov 2014 01:03:48 +0000 (20:03 -0500)
If we cache a dirent for file "foo", and then it gets deleted, then we look
for a ".wh.foo" whiteout entry in the same dirent cache.  But our dirent
cache strips the ".wh." prefix, thus looking for an entry named "foo" whose
filldir_node->whiteout should be 1 instead of 0.  In that case, don't
display  an incorrect printk  message that the file system may be corrupt,
but set that filldir_node->whiteout to 1.

CC: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
fs/unionfs/dirfops.c
fs/unionfs/dirhelper.c
fs/unionfs/rdstate.c
fs/unionfs/union.h

index 5276cb363ae9de57ddb0dd8a6967ce49d5038828..88df635e536aeb3066a290524fe04d02005837de 100644 (file)
@@ -53,10 +53,17 @@ static int unionfs_filldir(void *dirent, const char *name, int namelen,
                is_wh_entry = 1;
        }
 
-       found = find_filldir_node(buf->rdstate, name, namelen);
-
-       if (found)
+       found = find_filldir_node(buf->rdstate, name, namelen, is_wh_entry);
+
+       if (found) {
+               /*
+                * If we had non-whiteout entry in dir cache, then mark it
+                * as a whiteout and but leave it in the dir cache.
+                */
+               if (is_wh_entry && !found->whiteout)
+                       found->whiteout = is_wh_entry;
                goto out;
+       }
 
        /* if 'name' isn't a whiteout, filldir it. */
        if (!is_wh_entry) {
index 7a28444ab36351ff2181881dcf7a58b54957eb57..2e52fc3a1622315a54795ff99c632581856ebe51 100644 (file)
@@ -158,7 +158,7 @@ static int readdir_util_callback(void *dirent, const char *name, int namelen,
                whiteout = 1;
        }
 
-       found = find_filldir_node(buf->rdstate, name, namelen);
+       found = find_filldir_node(buf->rdstate, name, namelen, whiteout);
        /* If it was found in the table there was a previous whiteout. */
        if (found)
                goto out;
index bdf335d36560db99eec2236a4413adc1f5dcd0de..7ba1e1a3ebfbc178bbbce4c475cfa817f4a0eca3 100644 (file)
@@ -188,7 +188,8 @@ void free_rdstate(struct unionfs_dir_state *state)
 }
 
 struct filldir_node *find_filldir_node(struct unionfs_dir_state *rdstate,
-                                      const char *name, int namelen)
+                                      const char *name, int namelen,
+                                      int is_whiteout)
 {
        int index;
        unsigned int hash;
@@ -215,10 +216,12 @@ struct filldir_node *find_filldir_node(struct unionfs_dir_state *rdstate,
                        found = 1;
 
                        /*
-                        * if the duplicate is in this branch, then the file
-                        * system is corrupted.
+                        * if a duplicate is found in this branch, and is
+                        * not due to the caller looking for an entry to
+                        * whiteout, then the file system may be corrupted.
                         */
-                       if (unlikely(cursor->bindex == rdstate->bindex))
+                       if (unlikely(!is_whiteout &&
+                                    cursor->bindex == rdstate->bindex))
                                printk(KERN_ERR "unionfs: filldir: possible "
                                       "I/O error: a file is duplicated "
                                       "in the same branch %d: %s\n",
index ae277d1f769dd518267a8dd5d5227226d1844a1f..d158671677fae8ffe9f64e67c04529388f4300e5 100644 (file)
@@ -230,7 +230,8 @@ extern int add_filldir_node(struct unionfs_dir_state *rdstate,
                            const char *name, int namelen, int bindex,
                            int whiteout);
 extern struct filldir_node *find_filldir_node(struct unionfs_dir_state *rdstate,
-                                             const char *name, int namelen);
+                                             const char *name, int namelen,
+                                             int is_whiteout);
 
 extern struct dentry **alloc_new_dentries(int objs);
 extern struct unionfs_data *alloc_new_data(int objs);