Unionfs: Properly handle stale inodes passed to unionfs_permission
authorErez Zadok <ezk@cs.sunysb.edu>
Fri, 23 Mar 2007 00:17:48 +0000 (20:17 -0400)
committerErez Zadok <ezk@cs.sunysb.edu>
Fri, 12 Aug 2011 02:34:01 +0000 (22:34 -0400)
Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
Signed-off-by: Josef 'Jeff' Sipek <jsipek@cs.sunysb.edu>
fs/unionfs/inode.c

index edd226f5d2989d6779828abb722c4e54cd45fc07..5c452b6d87d59f9be54c681d04ab1dc0e73bc1c8 100644 (file)
@@ -843,8 +843,21 @@ static int unionfs_permission(struct inode *inode, int mask,
        const int is_file = !S_ISDIR(inode->i_mode);
        const int write_mask = (mask & MAY_WRITE) && !(mask & MAY_READ);
 
+       unionfs_read_lock(inode->i_sb);
+
        bstart = ibstart(inode);
        bend = ibend(inode);
+       if (bstart < 0 || bend < 0) {
+               /*
+                * With branch-management, we can get a stale inode here.
+                * If so, we return ESTALE back to link_path_walk, which
+                * would discard the dcache entry and re-lookup the
+                * dentry+inode.  This should be equivalent to issuing
+                * __unionfs_d_revalidate_chain on nd.dentry here.
+                */
+               err = -ESTALE;  /* force revalidate */
+               goto out;
+       }
 
        for (bindex = bstart; bindex <= bend; bindex++) {
                hidden_inode = unionfs_lower_inode_idx(inode, bindex);
@@ -881,6 +894,7 @@ static int unionfs_permission(struct inode *inode, int mask,
        }
 
 out:
+       unionfs_read_unlock(inode->i_sb);
        return err;
 }