aboutsummaryrefslogtreecommitdiffstats
path: root/fs/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/inode.c')
-rw-r--r--fs/inode.c107
1 files changed, 71 insertions, 36 deletions
diff --git a/fs/inode.c b/fs/inode.c
index 1f9a3a2b89bc..f80a79ff156b 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -21,6 +21,7 @@
21#include <linux/pagemap.h> 21#include <linux/pagemap.h>
22#include <linux/cdev.h> 22#include <linux/cdev.h>
23#include <linux/bootmem.h> 23#include <linux/bootmem.h>
24#include <linux/inotify.h>
24 25
25/* 26/*
26 * This is needed for the following functions: 27 * This is needed for the following functions:
@@ -202,6 +203,10 @@ void inode_init_once(struct inode *inode)
202 INIT_LIST_HEAD(&inode->i_data.i_mmap_nonlinear); 203 INIT_LIST_HEAD(&inode->i_data.i_mmap_nonlinear);
203 spin_lock_init(&inode->i_lock); 204 spin_lock_init(&inode->i_lock);
204 i_size_ordered_init(inode); 205 i_size_ordered_init(inode);
206#ifdef CONFIG_INOTIFY
207 INIT_LIST_HEAD(&inode->inotify_watches);
208 sema_init(&inode->inotify_sem, 1);
209#endif
205} 210}
206 211
207EXPORT_SYMBOL(inode_init_once); 212EXPORT_SYMBOL(inode_init_once);
@@ -282,6 +287,13 @@ static void dispose_list(struct list_head *head)
282 if (inode->i_data.nrpages) 287 if (inode->i_data.nrpages)
283 truncate_inode_pages(&inode->i_data, 0); 288 truncate_inode_pages(&inode->i_data, 0);
284 clear_inode(inode); 289 clear_inode(inode);
290
291 spin_lock(&inode_lock);
292 hlist_del_init(&inode->i_hash);
293 list_del_init(&inode->i_sb_list);
294 spin_unlock(&inode_lock);
295
296 wake_up_inode(inode);
285 destroy_inode(inode); 297 destroy_inode(inode);
286 nr_disposed++; 298 nr_disposed++;
287 } 299 }
@@ -317,8 +329,6 @@ static int invalidate_list(struct list_head *head, struct list_head *dispose)
317 inode = list_entry(tmp, struct inode, i_sb_list); 329 inode = list_entry(tmp, struct inode, i_sb_list);
318 invalidate_inode_buffers(inode); 330 invalidate_inode_buffers(inode);
319 if (!atomic_read(&inode->i_count)) { 331 if (!atomic_read(&inode->i_count)) {
320 hlist_del_init(&inode->i_hash);
321 list_del(&inode->i_sb_list);
322 list_move(&inode->i_list, dispose); 332 list_move(&inode->i_list, dispose);
323 inode->i_state |= I_FREEING; 333 inode->i_state |= I_FREEING;
324 count++; 334 count++;
@@ -346,6 +356,7 @@ int invalidate_inodes(struct super_block * sb)
346 356
347 down(&iprune_sem); 357 down(&iprune_sem);
348 spin_lock(&inode_lock); 358 spin_lock(&inode_lock);
359 inotify_unmount_inodes(&sb->s_inodes);
349 busy = invalidate_list(&sb->s_inodes, &throw_away); 360 busy = invalidate_list(&sb->s_inodes, &throw_away);
350 spin_unlock(&inode_lock); 361 spin_unlock(&inode_lock);
351 362
@@ -439,8 +450,6 @@ static void prune_icache(int nr_to_scan)
439 if (!can_unuse(inode)) 450 if (!can_unuse(inode))
440 continue; 451 continue;
441 } 452 }
442 hlist_del_init(&inode->i_hash);
443 list_del_init(&inode->i_sb_list);
444 list_move(&inode->i_list, &freeable); 453 list_move(&inode->i_list, &freeable);
445 inode->i_state |= I_FREEING; 454 inode->i_state |= I_FREEING;
446 nr_pruned++; 455 nr_pruned++;
@@ -748,6 +757,7 @@ EXPORT_SYMBOL(igrab);
748 * @head: the head of the list to search 757 * @head: the head of the list to search
749 * @test: callback used for comparisons between inodes 758 * @test: callback used for comparisons between inodes
750 * @data: opaque data pointer to pass to @test 759 * @data: opaque data pointer to pass to @test
760 * @wait: if true wait for the inode to be unlocked, if false do not
751 * 761 *
752 * ifind() searches for the inode specified by @data in the inode 762 * ifind() searches for the inode specified by @data in the inode
753 * cache. This is a generalized version of ifind_fast() for file systems where 763 * cache. This is a generalized version of ifind_fast() for file systems where
@@ -762,7 +772,7 @@ EXPORT_SYMBOL(igrab);
762 */ 772 */
763static inline struct inode *ifind(struct super_block *sb, 773static inline struct inode *ifind(struct super_block *sb,
764 struct hlist_head *head, int (*test)(struct inode *, void *), 774 struct hlist_head *head, int (*test)(struct inode *, void *),
765 void *data) 775 void *data, const int wait)
766{ 776{
767 struct inode *inode; 777 struct inode *inode;
768 778
@@ -771,7 +781,8 @@ static inline struct inode *ifind(struct super_block *sb,
771 if (inode) { 781 if (inode) {
772 __iget(inode); 782 __iget(inode);
773 spin_unlock(&inode_lock); 783 spin_unlock(&inode_lock);
774 wait_on_inode(inode); 784 if (likely(wait))
785 wait_on_inode(inode);
775 return inode; 786 return inode;
776 } 787 }
777 spin_unlock(&inode_lock); 788 spin_unlock(&inode_lock);
@@ -811,7 +822,7 @@ static inline struct inode *ifind_fast(struct super_block *sb,
811} 822}
812 823
813/** 824/**
814 * ilookup5 - search for an inode in the inode cache 825 * ilookup5_nowait - search for an inode in the inode cache
815 * @sb: super block of file system to search 826 * @sb: super block of file system to search
816 * @hashval: hash value (usually inode number) to search for 827 * @hashval: hash value (usually inode number) to search for
817 * @test: callback used for comparisons between inodes 828 * @test: callback used for comparisons between inodes
@@ -823,7 +834,38 @@ static inline struct inode *ifind_fast(struct super_block *sb,
823 * identification of an inode. 834 * identification of an inode.
824 * 835 *
825 * If the inode is in the cache, the inode is returned with an incremented 836 * If the inode is in the cache, the inode is returned with an incremented
826 * reference count. 837 * reference count. Note, the inode lock is not waited upon so you have to be
838 * very careful what you do with the returned inode. You probably should be
839 * using ilookup5() instead.
840 *
841 * Otherwise NULL is returned.
842 *
843 * Note, @test is called with the inode_lock held, so can't sleep.
844 */
845struct inode *ilookup5_nowait(struct super_block *sb, unsigned long hashval,
846 int (*test)(struct inode *, void *), void *data)
847{
848 struct hlist_head *head = inode_hashtable + hash(sb, hashval);
849
850 return ifind(sb, head, test, data, 0);
851}
852
853EXPORT_SYMBOL(ilookup5_nowait);
854
855/**
856 * ilookup5 - search for an inode in the inode cache
857 * @sb: super block of file system to search
858 * @hashval: hash value (usually inode number) to search for
859 * @test: callback used for comparisons between inodes
860 * @data: opaque data pointer to pass to @test
861 *
862 * ilookup5() uses ifind() to search for the inode specified by @hashval and
863 * @data in the inode cache. This is a generalized version of ilookup() for
864 * file systems where the inode number is not sufficient for unique
865 * identification of an inode.
866 *
867 * If the inode is in the cache, the inode lock is waited upon and the inode is
868 * returned with an incremented reference count.
827 * 869 *
828 * Otherwise NULL is returned. 870 * Otherwise NULL is returned.
829 * 871 *
@@ -834,7 +876,7 @@ struct inode *ilookup5(struct super_block *sb, unsigned long hashval,
834{ 876{
835 struct hlist_head *head = inode_hashtable + hash(sb, hashval); 877 struct hlist_head *head = inode_hashtable + hash(sb, hashval);
836 878
837 return ifind(sb, head, test, data); 879 return ifind(sb, head, test, data, 1);
838} 880}
839 881
840EXPORT_SYMBOL(ilookup5); 882EXPORT_SYMBOL(ilookup5);
@@ -891,7 +933,7 @@ struct inode *iget5_locked(struct super_block *sb, unsigned long hashval,
891 struct hlist_head *head = inode_hashtable + hash(sb, hashval); 933 struct hlist_head *head = inode_hashtable + hash(sb, hashval);
892 struct inode *inode; 934 struct inode *inode;
893 935
894 inode = ifind(sb, head, test, data); 936 inode = ifind(sb, head, test, data, 1);
895 if (inode) 937 if (inode)
896 return inode; 938 return inode;
897 /* 939 /*
@@ -992,19 +1034,21 @@ void generic_delete_inode(struct inode *inode)
992 inodes_stat.nr_inodes--; 1034 inodes_stat.nr_inodes--;
993 spin_unlock(&inode_lock); 1035 spin_unlock(&inode_lock);
994 1036
995 if (inode->i_data.nrpages)
996 truncate_inode_pages(&inode->i_data, 0);
997
998 security_inode_delete(inode); 1037 security_inode_delete(inode);
999 1038
1000 if (op->delete_inode) { 1039 if (op->delete_inode) {
1001 void (*delete)(struct inode *) = op->delete_inode; 1040 void (*delete)(struct inode *) = op->delete_inode;
1002 if (!is_bad_inode(inode)) 1041 if (!is_bad_inode(inode))
1003 DQUOT_INIT(inode); 1042 DQUOT_INIT(inode);
1004 /* s_op->delete_inode internally recalls clear_inode() */ 1043 /* Filesystems implementing their own
1044 * s_op->delete_inode are required to call
1045 * truncate_inode_pages and clear_inode()
1046 * internally */
1005 delete(inode); 1047 delete(inode);
1006 } else 1048 } else {
1049 truncate_inode_pages(&inode->i_data, 0);
1007 clear_inode(inode); 1050 clear_inode(inode);
1051 }
1008 spin_lock(&inode_lock); 1052 spin_lock(&inode_lock);
1009 hlist_del_init(&inode->i_hash); 1053 hlist_del_init(&inode->i_hash);
1010 spin_unlock(&inode_lock); 1054 spin_unlock(&inode_lock);
@@ -1052,7 +1096,7 @@ static void generic_forget_inode(struct inode *inode)
1052 * inode when the usage count drops to zero, and 1096 * inode when the usage count drops to zero, and
1053 * i_nlink is zero. 1097 * i_nlink is zero.
1054 */ 1098 */
1055static void generic_drop_inode(struct inode *inode) 1099void generic_drop_inode(struct inode *inode)
1056{ 1100{
1057 if (!inode->i_nlink) 1101 if (!inode->i_nlink)
1058 generic_delete_inode(inode); 1102 generic_delete_inode(inode);
@@ -1060,6 +1104,8 @@ static void generic_drop_inode(struct inode *inode)
1060 generic_forget_inode(inode); 1104 generic_forget_inode(inode);
1061} 1105}
1062 1106
1107EXPORT_SYMBOL_GPL(generic_drop_inode);
1108
1063/* 1109/*
1064 * Called when we're dropping the last reference 1110 * Called when we're dropping the last reference
1065 * to an inode. 1111 * to an inode.
@@ -1151,9 +1197,6 @@ void update_atime(struct inode *inode)
1151 if (!timespec_equal(&inode->i_atime, &now)) { 1197 if (!timespec_equal(&inode->i_atime, &now)) {
1152 inode->i_atime = now; 1198 inode->i_atime = now;
1153 mark_inode_dirty_sync(inode); 1199 mark_inode_dirty_sync(inode);
1154 } else {
1155 if (!timespec_equal(&inode->i_atime, &now))
1156 inode->i_atime = now;
1157 } 1200 }
1158} 1201}
1159 1202
@@ -1242,29 +1285,21 @@ int inode_wait(void *word)
1242} 1285}
1243 1286
1244/* 1287/*
1245 * If we try to find an inode in the inode hash while it is being deleted, we 1288 * If we try to find an inode in the inode hash while it is being
1246 * have to wait until the filesystem completes its deletion before reporting 1289 * deleted, we have to wait until the filesystem completes its
1247 * that it isn't found. This is because iget will immediately call 1290 * deletion before reporting that it isn't found. This function waits
1248 * ->read_inode, and we want to be sure that evidence of the deletion is found 1291 * until the deletion _might_ have completed. Callers are responsible
1249 * by ->read_inode. 1292 * to recheck inode state.
1293 *
1294 * It doesn't matter if I_LOCK is not set initially, a call to
1295 * wake_up_inode() after removing from the hash list will DTRT.
1296 *
1250 * This is called with inode_lock held. 1297 * This is called with inode_lock held.
1251 */ 1298 */
1252static void __wait_on_freeing_inode(struct inode *inode) 1299static void __wait_on_freeing_inode(struct inode *inode)
1253{ 1300{
1254 wait_queue_head_t *wq; 1301 wait_queue_head_t *wq;
1255 DEFINE_WAIT_BIT(wait, &inode->i_state, __I_LOCK); 1302 DEFINE_WAIT_BIT(wait, &inode->i_state, __I_LOCK);
1256
1257 /*
1258 * I_FREEING and I_CLEAR are cleared in process context under
1259 * inode_lock, so we have to give the tasks who would clear them
1260 * a chance to run and acquire inode_lock.
1261 */
1262 if (!(inode->i_state & I_LOCK)) {
1263 spin_unlock(&inode_lock);
1264 yield();
1265 spin_lock(&inode_lock);
1266 return;
1267 }
1268 wq = bit_waitqueue(&inode->i_state, __I_LOCK); 1303 wq = bit_waitqueue(&inode->i_state, __I_LOCK);
1269 prepare_to_wait(wq, &wait.wait, TASK_UNINTERRUPTIBLE); 1304 prepare_to_wait(wq, &wait.wait, TASK_UNINTERRUPTIBLE);
1270 spin_unlock(&inode_lock); 1305 spin_unlock(&inode_lock);