Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull vfs fixes from Al Viro:
"double iput() on failure exit in lustre, racy removal of spliced
dentries from ->s_anon in __d_materialise_dentry() plus a bunch of
assorted RCU pathwalk fixes"

The RCU pathwalk fixes end up fixing a couple of cases where we
incorrectly dropped out of RCU walking, due to incorrect initialization
and testing of the sequence locks in some corner cases. Since dropping
out of RCU walk mode forces the slow locked accesses, those corner cases
slowed down quite dramatically.

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
be careful with nd->inode in path_init() and follow_dotdot_rcu()
don't bugger nd->seq on set_root_rcu() from follow_dotdot_rcu()
fix bogus read_seqretry() checks introduced in b37199e
move the call of __d_drop(anon) into __d_materialise_unique(dentry, anon)
[fix] lustre: d_make_root() does iput() on dentry allocation failure

Changed files
+39 -23
drivers
staging
lustre
lustre
llite
fs
+1 -1
drivers/staging/lustre/lustre/llite/llite_lib.c
··· 568 568 if (sb->s_root == NULL) { 569 569 CERROR("%s: can't make root dentry\n", 570 570 ll_get_fsname(sb, NULL, 0)); 571 - GOTO(out_root, err = -ENOMEM); 571 + GOTO(out_lock_cn_cb, err = -ENOMEM); 572 572 } 573 573 574 574 sbi->ll_sdev_orig = sb->s_dev;
+6 -2
fs/dcache.c
··· 2655 2655 dentry->d_parent = dentry; 2656 2656 list_del_init(&dentry->d_u.d_child); 2657 2657 anon->d_parent = dparent; 2658 + if (likely(!d_unhashed(anon))) { 2659 + hlist_bl_lock(&anon->d_sb->s_anon); 2660 + __hlist_bl_del(&anon->d_hash); 2661 + anon->d_hash.pprev = NULL; 2662 + hlist_bl_unlock(&anon->d_sb->s_anon); 2663 + } 2658 2664 list_move(&anon->d_u.d_child, &dparent->d_subdirs); 2659 2665 2660 2666 write_seqcount_end(&dentry->d_seq); ··· 2719 2713 write_seqlock(&rename_lock); 2720 2714 __d_materialise_dentry(dentry, new); 2721 2715 write_sequnlock(&rename_lock); 2722 - __d_drop(new); 2723 2716 _d_rehash(new); 2724 2717 spin_unlock(&new->d_lock); 2725 2718 spin_unlock(&inode->i_lock); ··· 2782 2777 * could splice into our tree? */ 2783 2778 __d_materialise_dentry(dentry, alias); 2784 2779 write_sequnlock(&rename_lock); 2785 - __d_drop(alias); 2786 2780 goto found; 2787 2781 } else { 2788 2782 /* Nope, but we must(!) avoid directory
+32 -20
fs/namei.c
··· 644 644 645 645 static __always_inline void set_root(struct nameidata *nd) 646 646 { 647 - if (!nd->root.mnt) 648 - get_fs_root(current->fs, &nd->root); 647 + get_fs_root(current->fs, &nd->root); 649 648 } 650 649 651 650 static int link_path_walk(const char *, struct nameidata *); 652 651 653 - static __always_inline void set_root_rcu(struct nameidata *nd) 652 + static __always_inline unsigned set_root_rcu(struct nameidata *nd) 654 653 { 655 - if (!nd->root.mnt) { 656 - struct fs_struct *fs = current->fs; 657 - unsigned seq; 654 + struct fs_struct *fs = current->fs; 655 + unsigned seq, res; 658 656 659 - do { 660 - seq = read_seqcount_begin(&fs->seq); 661 - nd->root = fs->root; 662 - nd->seq = __read_seqcount_begin(&nd->root.dentry->d_seq); 663 - } while (read_seqcount_retry(&fs->seq, seq)); 664 - } 657 + do { 658 + seq = read_seqcount_begin(&fs->seq); 659 + nd->root = fs->root; 660 + res = __read_seqcount_begin(&nd->root.dentry->d_seq); 661 + } while (read_seqcount_retry(&fs->seq, seq)); 662 + return res; 665 663 } 666 664 667 665 static void path_put_conditional(struct path *path, struct nameidata *nd) ··· 859 861 return PTR_ERR(s); 860 862 } 861 863 if (*s == '/') { 862 - set_root(nd); 864 + if (!nd->root.mnt) 865 + set_root(nd); 863 866 path_put(&nd->path); 864 867 nd->path = nd->root; 865 868 path_get(&nd->root); ··· 1137 1138 */ 1138 1139 *inode = path->dentry->d_inode; 1139 1140 } 1140 - return read_seqretry(&mount_lock, nd->m_seq) && 1141 + return !read_seqretry(&mount_lock, nd->m_seq) && 1141 1142 !(path->dentry->d_flags & DCACHE_NEED_AUTOMOUNT); 1142 1143 } 1143 1144 1144 1145 static int follow_dotdot_rcu(struct nameidata *nd) 1145 1146 { 1146 - set_root_rcu(nd); 1147 + struct inode *inode = nd->inode; 1148 + if (!nd->root.mnt) 1149 + set_root_rcu(nd); 1147 1150 1148 1151 while (1) { 1149 1152 if (nd->path.dentry == nd->root.dentry && ··· 1157 1156 struct dentry *parent = old->d_parent; 1158 1157 unsigned seq; 1159 1158 1159 + inode = parent->d_inode; 1160 1160 seq = read_seqcount_begin(&parent->d_seq); 1161 1161 if (read_seqcount_retry(&old->d_seq, nd->seq)) 1162 1162 goto failed; ··· 1167 1165 } 1168 1166 if (!follow_up_rcu(&nd->path)) 1169 1167 break; 1168 + inode = nd->path.dentry->d_inode; 1170 1169 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq); 1171 1170 } 1172 1171 while (d_mountpoint(nd->path.dentry)) { ··· 1177 1174 break; 1178 1175 nd->path.mnt = &mounted->mnt; 1179 1176 nd->path.dentry = mounted->mnt.mnt_root; 1177 + inode = nd->path.dentry->d_inode; 1180 1178 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq); 1181 - if (!read_seqretry(&mount_lock, nd->m_seq)) 1179 + if (read_seqretry(&mount_lock, nd->m_seq)) 1182 1180 goto failed; 1183 1181 } 1184 - nd->inode = nd->path.dentry->d_inode; 1182 + nd->inode = inode; 1185 1183 return 0; 1186 1184 1187 1185 failed: ··· 1261 1257 1262 1258 static void follow_dotdot(struct nameidata *nd) 1263 1259 { 1264 - set_root(nd); 1260 + if (!nd->root.mnt) 1261 + set_root(nd); 1265 1262 1266 1263 while(1) { 1267 1264 struct dentry *old = nd->path.dentry; ··· 1858 1853 if (*name=='/') { 1859 1854 if (flags & LOOKUP_RCU) { 1860 1855 rcu_read_lock(); 1861 - set_root_rcu(nd); 1856 + nd->seq = set_root_rcu(nd); 1862 1857 } else { 1863 1858 set_root(nd); 1864 1859 path_get(&nd->root); ··· 1909 1904 } 1910 1905 1911 1906 nd->inode = nd->path.dentry->d_inode; 1912 - return 0; 1907 + if (!(flags & LOOKUP_RCU)) 1908 + return 0; 1909 + if (likely(!read_seqcount_retry(&nd->path.dentry->d_seq, nd->seq))) 1910 + return 0; 1911 + if (!(nd->flags & LOOKUP_ROOT)) 1912 + nd->root.mnt = NULL; 1913 + rcu_read_unlock(); 1914 + return -ECHILD; 1913 1915 } 1914 1916 1915 1917 static inline int lookup_last(struct nameidata *nd, struct path *path)