aboutsummaryrefslogtreecommitdiffstats
path: root/fs/inode.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-08-13 23:25:58 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-08-13 23:25:58 -0400
commit0ea97a2d61df729ccce75b00a2fa37d39a508ab6 (patch)
tree953c13d8309938b93af2c257de8f7b84004ae748 /fs/inode.c
parenta66b4cd1e7163adb327838a3c81faaf6a9330d5a (diff)
parentc7b15a8657da7f8d11269c7cc3d8beef10d26b43 (diff)
Merge branch 'work.mkdir' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull vfs icache updates from Al Viro: - NFS mkdir/open_by_handle race fix - analogous solution for FUSE, replacing the one currently in mainline - new primitive to be used when discarding halfway set up inodes on failed object creation; gives sane warranties re icache lookups not returning such doomed by still not freed inodes. A bunch of filesystems switched to that animal. - Miklos' fix for last cycle regression in iget5_locked(); -stable will need a slightly different variant, unfortunately. - misc bits and pieces around things icache-related (in adfs and jfs). * 'work.mkdir' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: jfs: don't bother with make_bad_inode() in ialloc() adfs: don't put inodes into icache new helper: inode_fake_hash() vfs: don't evict uninitialized inode jfs: switch to discard_new_inode() ext2: make sure that partially set up inodes won't be returned by ext2_iget() udf: switch to discard_new_inode() ufs: switch to discard_new_inode() btrfs: switch to discard_new_inode() new primitive: discard_new_inode() kill d_instantiate_no_diralias() nfs_instantiate(): prevent multiple aliases for directory inode
Diffstat (limited to 'fs/inode.c')
-rw-r--r--fs/inode.c53
1 files changed, 47 insertions, 6 deletions
diff --git a/fs/inode.c b/fs/inode.c
index 8c86c809ca17..a06de4454232 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -804,6 +804,10 @@ repeat:
804 __wait_on_freeing_inode(inode); 804 __wait_on_freeing_inode(inode);
805 goto repeat; 805 goto repeat;
806 } 806 }
807 if (unlikely(inode->i_state & I_CREATING)) {
808 spin_unlock(&inode->i_lock);
809 return ERR_PTR(-ESTALE);
810 }
807 __iget(inode); 811 __iget(inode);
808 spin_unlock(&inode->i_lock); 812 spin_unlock(&inode->i_lock);
809 return inode; 813 return inode;
@@ -831,6 +835,10 @@ repeat:
831 __wait_on_freeing_inode(inode); 835 __wait_on_freeing_inode(inode);
832 goto repeat; 836 goto repeat;
833 } 837 }
838 if (unlikely(inode->i_state & I_CREATING)) {
839 spin_unlock(&inode->i_lock);
840 return ERR_PTR(-ESTALE);
841 }
834 __iget(inode); 842 __iget(inode);
835 spin_unlock(&inode->i_lock); 843 spin_unlock(&inode->i_lock);
836 return inode; 844 return inode;
@@ -961,13 +969,26 @@ void unlock_new_inode(struct inode *inode)
961 lockdep_annotate_inode_mutex_key(inode); 969 lockdep_annotate_inode_mutex_key(inode);
962 spin_lock(&inode->i_lock); 970 spin_lock(&inode->i_lock);
963 WARN_ON(!(inode->i_state & I_NEW)); 971 WARN_ON(!(inode->i_state & I_NEW));
964 inode->i_state &= ~I_NEW; 972 inode->i_state &= ~I_NEW & ~I_CREATING;
965 smp_mb(); 973 smp_mb();
966 wake_up_bit(&inode->i_state, __I_NEW); 974 wake_up_bit(&inode->i_state, __I_NEW);
967 spin_unlock(&inode->i_lock); 975 spin_unlock(&inode->i_lock);
968} 976}
969EXPORT_SYMBOL(unlock_new_inode); 977EXPORT_SYMBOL(unlock_new_inode);
970 978
979void discard_new_inode(struct inode *inode)
980{
981 lockdep_annotate_inode_mutex_key(inode);
982 spin_lock(&inode->i_lock);
983 WARN_ON(!(inode->i_state & I_NEW));
984 inode->i_state &= ~I_NEW;
985 smp_mb();
986 wake_up_bit(&inode->i_state, __I_NEW);
987 spin_unlock(&inode->i_lock);
988 iput(inode);
989}
990EXPORT_SYMBOL(discard_new_inode);
991
971/** 992/**
972 * lock_two_nondirectories - take two i_mutexes on non-directory objects 993 * lock_two_nondirectories - take two i_mutexes on non-directory objects
973 * 994 *
@@ -1029,6 +1050,7 @@ struct inode *inode_insert5(struct inode *inode, unsigned long hashval,
1029{ 1050{
1030 struct hlist_head *head = inode_hashtable + hash(inode->i_sb, hashval); 1051 struct hlist_head *head = inode_hashtable + hash(inode->i_sb, hashval);
1031 struct inode *old; 1052 struct inode *old;
1053 bool creating = inode->i_state & I_CREATING;
1032 1054
1033again: 1055again:
1034 spin_lock(&inode_hash_lock); 1056 spin_lock(&inode_hash_lock);
@@ -1039,6 +1061,8 @@ again:
1039 * Use the old inode instead of the preallocated one. 1061 * Use the old inode instead of the preallocated one.
1040 */ 1062 */
1041 spin_unlock(&inode_hash_lock); 1063 spin_unlock(&inode_hash_lock);
1064 if (IS_ERR(old))
1065 return NULL;
1042 wait_on_inode(old); 1066 wait_on_inode(old);
1043 if (unlikely(inode_unhashed(old))) { 1067 if (unlikely(inode_unhashed(old))) {
1044 iput(old); 1068 iput(old);
@@ -1060,6 +1084,8 @@ again:
1060 inode->i_state |= I_NEW; 1084 inode->i_state |= I_NEW;
1061 hlist_add_head(&inode->i_hash, head); 1085 hlist_add_head(&inode->i_hash, head);
1062 spin_unlock(&inode->i_lock); 1086 spin_unlock(&inode->i_lock);
1087 if (!creating)
1088 inode_sb_list_add(inode);
1063unlock: 1089unlock:
1064 spin_unlock(&inode_hash_lock); 1090 spin_unlock(&inode_hash_lock);
1065 1091
@@ -1094,12 +1120,13 @@ struct inode *iget5_locked(struct super_block *sb, unsigned long hashval,
1094 struct inode *inode = ilookup5(sb, hashval, test, data); 1120 struct inode *inode = ilookup5(sb, hashval, test, data);
1095 1121
1096 if (!inode) { 1122 if (!inode) {
1097 struct inode *new = new_inode(sb); 1123 struct inode *new = alloc_inode(sb);
1098 1124
1099 if (new) { 1125 if (new) {
1126 new->i_state = 0;
1100 inode = inode_insert5(new, hashval, test, set, data); 1127 inode = inode_insert5(new, hashval, test, set, data);
1101 if (unlikely(inode != new)) 1128 if (unlikely(inode != new))
1102 iput(new); 1129 destroy_inode(new);
1103 } 1130 }
1104 } 1131 }
1105 return inode; 1132 return inode;
@@ -1128,6 +1155,8 @@ again:
1128 inode = find_inode_fast(sb, head, ino); 1155 inode = find_inode_fast(sb, head, ino);
1129 spin_unlock(&inode_hash_lock); 1156 spin_unlock(&inode_hash_lock);
1130 if (inode) { 1157 if (inode) {
1158 if (IS_ERR(inode))
1159 return NULL;
1131 wait_on_inode(inode); 1160 wait_on_inode(inode);
1132 if (unlikely(inode_unhashed(inode))) { 1161 if (unlikely(inode_unhashed(inode))) {
1133 iput(inode); 1162 iput(inode);
@@ -1165,6 +1194,8 @@ again:
1165 */ 1194 */
1166 spin_unlock(&inode_hash_lock); 1195 spin_unlock(&inode_hash_lock);
1167 destroy_inode(inode); 1196 destroy_inode(inode);
1197 if (IS_ERR(old))
1198 return NULL;
1168 inode = old; 1199 inode = old;
1169 wait_on_inode(inode); 1200 wait_on_inode(inode);
1170 if (unlikely(inode_unhashed(inode))) { 1201 if (unlikely(inode_unhashed(inode))) {
@@ -1282,7 +1313,7 @@ struct inode *ilookup5_nowait(struct super_block *sb, unsigned long hashval,
1282 inode = find_inode(sb, head, test, data); 1313 inode = find_inode(sb, head, test, data);
1283 spin_unlock(&inode_hash_lock); 1314 spin_unlock(&inode_hash_lock);
1284 1315
1285 return inode; 1316 return IS_ERR(inode) ? NULL : inode;
1286} 1317}
1287EXPORT_SYMBOL(ilookup5_nowait); 1318EXPORT_SYMBOL(ilookup5_nowait);
1288 1319
@@ -1338,6 +1369,8 @@ again:
1338 spin_unlock(&inode_hash_lock); 1369 spin_unlock(&inode_hash_lock);
1339 1370
1340 if (inode) { 1371 if (inode) {
1372 if (IS_ERR(inode))
1373 return NULL;
1341 wait_on_inode(inode); 1374 wait_on_inode(inode);
1342 if (unlikely(inode_unhashed(inode))) { 1375 if (unlikely(inode_unhashed(inode))) {
1343 iput(inode); 1376 iput(inode);
@@ -1421,12 +1454,17 @@ int insert_inode_locked(struct inode *inode)
1421 } 1454 }
1422 if (likely(!old)) { 1455 if (likely(!old)) {
1423 spin_lock(&inode->i_lock); 1456 spin_lock(&inode->i_lock);
1424 inode->i_state |= I_NEW; 1457 inode->i_state |= I_NEW | I_CREATING;
1425 hlist_add_head(&inode->i_hash, head); 1458 hlist_add_head(&inode->i_hash, head);
1426 spin_unlock(&inode->i_lock); 1459 spin_unlock(&inode->i_lock);
1427 spin_unlock(&inode_hash_lock); 1460 spin_unlock(&inode_hash_lock);
1428 return 0; 1461 return 0;
1429 } 1462 }
1463 if (unlikely(old->i_state & I_CREATING)) {
1464 spin_unlock(&old->i_lock);
1465 spin_unlock(&inode_hash_lock);
1466 return -EBUSY;
1467 }
1430 __iget(old); 1468 __iget(old);
1431 spin_unlock(&old->i_lock); 1469 spin_unlock(&old->i_lock);
1432 spin_unlock(&inode_hash_lock); 1470 spin_unlock(&inode_hash_lock);
@@ -1443,7 +1481,10 @@ EXPORT_SYMBOL(insert_inode_locked);
1443int insert_inode_locked4(struct inode *inode, unsigned long hashval, 1481int insert_inode_locked4(struct inode *inode, unsigned long hashval,
1444 int (*test)(struct inode *, void *), void *data) 1482 int (*test)(struct inode *, void *), void *data)
1445{ 1483{
1446 struct inode *old = inode_insert5(inode, hashval, test, NULL, data); 1484 struct inode *old;
1485
1486 inode->i_state |= I_CREATING;
1487 old = inode_insert5(inode, hashval, test, NULL, data);
1447 1488
1448 if (old != inode) { 1489 if (old != inode) {
1449 iput(old); 1490 iput(old);