aboutsummaryrefslogtreecommitdiffstats
path: root/fs/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/inode.c')
-rw-r--r--fs/inode.c113
1 files changed, 61 insertions, 52 deletions
diff --git a/fs/inode.c b/fs/inode.c
index 6ad14a1cd8c9..bca0c618fdb3 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -99,7 +99,7 @@ static DEFINE_MUTEX(iprune_mutex);
99 */ 99 */
100struct inodes_stat_t inodes_stat; 100struct inodes_stat_t inodes_stat;
101 101
102static struct kmem_cache * inode_cachep __read_mostly; 102static struct kmem_cache *inode_cachep __read_mostly;
103 103
104static void wake_up_inode(struct inode *inode) 104static void wake_up_inode(struct inode *inode)
105{ 105{
@@ -124,7 +124,7 @@ struct inode *inode_init_always(struct super_block *sb, struct inode *inode)
124 static struct inode_operations empty_iops; 124 static struct inode_operations empty_iops;
125 static const struct file_operations empty_fops; 125 static const struct file_operations empty_fops;
126 126
127 struct address_space * const mapping = &inode->i_data; 127 struct address_space *const mapping = &inode->i_data;
128 128
129 inode->i_sb = sb; 129 inode->i_sb = sb;
130 inode->i_blkbits = sb->s_blocksize_bits; 130 inode->i_blkbits = sb->s_blocksize_bits;
@@ -216,9 +216,10 @@ static struct inode *alloc_inode(struct super_block *sb)
216 return NULL; 216 return NULL;
217} 217}
218 218
219void destroy_inode(struct inode *inode) 219void destroy_inode(struct inode *inode)
220{ 220{
221 BUG_ON(inode_has_buffers(inode)); 221 BUG_ON(inode_has_buffers(inode));
222 ima_inode_free(inode);
222 security_inode_free(inode); 223 security_inode_free(inode);
223 if (inode->i_sb->s_op->destroy_inode) 224 if (inode->i_sb->s_op->destroy_inode)
224 inode->i_sb->s_op->destroy_inode(inode); 225 inode->i_sb->s_op->destroy_inode(inode);
@@ -252,12 +253,11 @@ void inode_init_once(struct inode *inode)
252 mutex_init(&inode->inotify_mutex); 253 mutex_init(&inode->inotify_mutex);
253#endif 254#endif
254} 255}
255
256EXPORT_SYMBOL(inode_init_once); 256EXPORT_SYMBOL(inode_init_once);
257 257
258static void init_once(void *foo) 258static void init_once(void *foo)
259{ 259{
260 struct inode * inode = (struct inode *) foo; 260 struct inode *inode = (struct inode *) foo;
261 261
262 inode_init_once(inode); 262 inode_init_once(inode);
263} 263}
@@ -265,7 +265,7 @@ static void init_once(void *foo)
265/* 265/*
266 * inode_lock must be held 266 * inode_lock must be held
267 */ 267 */
268void __iget(struct inode * inode) 268void __iget(struct inode *inode)
269{ 269{
270 if (atomic_read(&inode->i_count)) { 270 if (atomic_read(&inode->i_count)) {
271 atomic_inc(&inode->i_count); 271 atomic_inc(&inode->i_count);
@@ -289,7 +289,7 @@ void clear_inode(struct inode *inode)
289{ 289{
290 might_sleep(); 290 might_sleep();
291 invalidate_inode_buffers(inode); 291 invalidate_inode_buffers(inode);
292 292
293 BUG_ON(inode->i_data.nrpages); 293 BUG_ON(inode->i_data.nrpages);
294 BUG_ON(!(inode->i_state & I_FREEING)); 294 BUG_ON(!(inode->i_state & I_FREEING));
295 BUG_ON(inode->i_state & I_CLEAR); 295 BUG_ON(inode->i_state & I_CLEAR);
@@ -303,7 +303,6 @@ void clear_inode(struct inode *inode)
303 cd_forget(inode); 303 cd_forget(inode);
304 inode->i_state = I_CLEAR; 304 inode->i_state = I_CLEAR;
305} 305}
306
307EXPORT_SYMBOL(clear_inode); 306EXPORT_SYMBOL(clear_inode);
308 307
309/* 308/*
@@ -351,8 +350,8 @@ static int invalidate_list(struct list_head *head, struct list_head *dispose)
351 350
352 next = head->next; 351 next = head->next;
353 for (;;) { 352 for (;;) {
354 struct list_head * tmp = next; 353 struct list_head *tmp = next;
355 struct inode * inode; 354 struct inode *inode;
356 355
357 /* 356 /*
358 * We can reschedule here without worrying about the list's 357 * We can reschedule here without worrying about the list's
@@ -391,7 +390,7 @@ static int invalidate_list(struct list_head *head, struct list_head *dispose)
391 * fails because there are busy inodes then a non zero value is returned. 390 * fails because there are busy inodes then a non zero value is returned.
392 * If the discard is successful all the inodes have been discarded. 391 * If the discard is successful all the inodes have been discarded.
393 */ 392 */
394int invalidate_inodes(struct super_block * sb) 393int invalidate_inodes(struct super_block *sb)
395{ 394{
396 int busy; 395 int busy;
397 LIST_HEAD(throw_away); 396 LIST_HEAD(throw_away);
@@ -407,7 +406,6 @@ int invalidate_inodes(struct super_block * sb)
407 406
408 return busy; 407 return busy;
409} 408}
410
411EXPORT_SYMBOL(invalidate_inodes); 409EXPORT_SYMBOL(invalidate_inodes);
412 410
413static int can_unuse(struct inode *inode) 411static int can_unuse(struct inode *inode)
@@ -504,7 +502,7 @@ static int shrink_icache_memory(int nr, gfp_t gfp_mask)
504 * Nasty deadlock avoidance. We may hold various FS locks, 502 * Nasty deadlock avoidance. We may hold various FS locks,
505 * and we don't want to recurse into the FS that called us 503 * and we don't want to recurse into the FS that called us
506 * in clear_inode() and friends.. 504 * in clear_inode() and friends..
507 */ 505 */
508 if (!(gfp_mask & __GFP_FS)) 506 if (!(gfp_mask & __GFP_FS))
509 return -1; 507 return -1;
510 prune_icache(nr); 508 prune_icache(nr);
@@ -524,10 +522,13 @@ static void __wait_on_freeing_inode(struct inode *inode);
524 * by hand after calling find_inode now! This simplifies iunique and won't 522 * by hand after calling find_inode now! This simplifies iunique and won't
525 * add any additional branch in the common code. 523 * add any additional branch in the common code.
526 */ 524 */
527static struct inode * find_inode(struct super_block * sb, struct hlist_head *head, int (*test)(struct inode *, void *), void *data) 525static struct inode *find_inode(struct super_block *sb,
526 struct hlist_head *head,
527 int (*test)(struct inode *, void *),
528 void *data)
528{ 529{
529 struct hlist_node *node; 530 struct hlist_node *node;
530 struct inode * inode = NULL; 531 struct inode *inode = NULL;
531 532
532repeat: 533repeat:
533 hlist_for_each_entry(inode, node, head, i_hash) { 534 hlist_for_each_entry(inode, node, head, i_hash) {
@@ -548,10 +549,11 @@ repeat:
548 * find_inode_fast is the fast path version of find_inode, see the comment at 549 * find_inode_fast is the fast path version of find_inode, see the comment at
549 * iget_locked for details. 550 * iget_locked for details.
550 */ 551 */
551static struct inode * find_inode_fast(struct super_block * sb, struct hlist_head *head, unsigned long ino) 552static struct inode *find_inode_fast(struct super_block *sb,
553 struct hlist_head *head, unsigned long ino)
552{ 554{
553 struct hlist_node *node; 555 struct hlist_node *node;
554 struct inode * inode = NULL; 556 struct inode *inode = NULL;
555 557
556repeat: 558repeat:
557 hlist_for_each_entry(inode, node, head, i_hash) { 559 hlist_for_each_entry(inode, node, head, i_hash) {
@@ -631,10 +633,10 @@ struct inode *new_inode(struct super_block *sb)
631 * here to attempt to avoid that. 633 * here to attempt to avoid that.
632 */ 634 */
633 static unsigned int last_ino; 635 static unsigned int last_ino;
634 struct inode * inode; 636 struct inode *inode;
635 637
636 spin_lock_prefetch(&inode_lock); 638 spin_lock_prefetch(&inode_lock);
637 639
638 inode = alloc_inode(sb); 640 inode = alloc_inode(sb);
639 if (inode) { 641 if (inode) {
640 spin_lock(&inode_lock); 642 spin_lock(&inode_lock);
@@ -645,7 +647,6 @@ struct inode *new_inode(struct super_block *sb)
645 } 647 }
646 return inode; 648 return inode;
647} 649}
648
649EXPORT_SYMBOL(new_inode); 650EXPORT_SYMBOL(new_inode);
650 651
651void unlock_new_inode(struct inode *inode) 652void unlock_new_inode(struct inode *inode)
@@ -674,7 +675,6 @@ void unlock_new_inode(struct inode *inode)
674 inode->i_state &= ~(I_LOCK|I_NEW); 675 inode->i_state &= ~(I_LOCK|I_NEW);
675 wake_up_inode(inode); 676 wake_up_inode(inode);
676} 677}
677
678EXPORT_SYMBOL(unlock_new_inode); 678EXPORT_SYMBOL(unlock_new_inode);
679 679
680/* 680/*
@@ -683,13 +683,17 @@ EXPORT_SYMBOL(unlock_new_inode);
683 * We no longer cache the sb_flags in i_flags - see fs.h 683 * We no longer cache the sb_flags in i_flags - see fs.h
684 * -- rmk@arm.uk.linux.org 684 * -- rmk@arm.uk.linux.org
685 */ 685 */
686static struct inode * get_new_inode(struct super_block *sb, struct hlist_head *head, int (*test)(struct inode *, void *), int (*set)(struct inode *, void *), void *data) 686static struct inode *get_new_inode(struct super_block *sb,
687 struct hlist_head *head,
688 int (*test)(struct inode *, void *),
689 int (*set)(struct inode *, void *),
690 void *data)
687{ 691{
688 struct inode * inode; 692 struct inode *inode;
689 693
690 inode = alloc_inode(sb); 694 inode = alloc_inode(sb);
691 if (inode) { 695 if (inode) {
692 struct inode * old; 696 struct inode *old;
693 697
694 spin_lock(&inode_lock); 698 spin_lock(&inode_lock);
695 /* We released the lock, so.. */ 699 /* We released the lock, so.. */
@@ -731,13 +735,14 @@ set_failed:
731 * get_new_inode_fast is the fast path version of get_new_inode, see the 735 * get_new_inode_fast is the fast path version of get_new_inode, see the
732 * comment at iget_locked for details. 736 * comment at iget_locked for details.
733 */ 737 */
734static struct inode * get_new_inode_fast(struct super_block *sb, struct hlist_head *head, unsigned long ino) 738static struct inode *get_new_inode_fast(struct super_block *sb,
739 struct hlist_head *head, unsigned long ino)
735{ 740{
736 struct inode * inode; 741 struct inode *inode;
737 742
738 inode = alloc_inode(sb); 743 inode = alloc_inode(sb);
739 if (inode) { 744 if (inode) {
740 struct inode * old; 745 struct inode *old;
741 746
742 spin_lock(&inode_lock); 747 spin_lock(&inode_lock);
743 /* We released the lock, so.. */ 748 /* We released the lock, so.. */
@@ -823,7 +828,6 @@ struct inode *igrab(struct inode *inode)
823 spin_unlock(&inode_lock); 828 spin_unlock(&inode_lock);
824 return inode; 829 return inode;
825} 830}
826
827EXPORT_SYMBOL(igrab); 831EXPORT_SYMBOL(igrab);
828 832
829/** 833/**
@@ -924,7 +928,6 @@ struct inode *ilookup5_nowait(struct super_block *sb, unsigned long hashval,
924 928
925 return ifind(sb, head, test, data, 0); 929 return ifind(sb, head, test, data, 0);
926} 930}
927
928EXPORT_SYMBOL(ilookup5_nowait); 931EXPORT_SYMBOL(ilookup5_nowait);
929 932
930/** 933/**
@@ -953,7 +956,6 @@ struct inode *ilookup5(struct super_block *sb, unsigned long hashval,
953 956
954 return ifind(sb, head, test, data, 1); 957 return ifind(sb, head, test, data, 1);
955} 958}
956
957EXPORT_SYMBOL(ilookup5); 959EXPORT_SYMBOL(ilookup5);
958 960
959/** 961/**
@@ -976,7 +978,6 @@ struct inode *ilookup(struct super_block *sb, unsigned long ino)
976 978
977 return ifind_fast(sb, head, ino); 979 return ifind_fast(sb, head, ino);
978} 980}
979
980EXPORT_SYMBOL(ilookup); 981EXPORT_SYMBOL(ilookup);
981 982
982/** 983/**
@@ -1015,7 +1016,6 @@ struct inode *iget5_locked(struct super_block *sb, unsigned long hashval,
1015 */ 1016 */
1016 return get_new_inode(sb, head, test, set, data); 1017 return get_new_inode(sb, head, test, set, data);
1017} 1018}
1018
1019EXPORT_SYMBOL(iget5_locked); 1019EXPORT_SYMBOL(iget5_locked);
1020 1020
1021/** 1021/**
@@ -1047,7 +1047,6 @@ struct inode *iget_locked(struct super_block *sb, unsigned long ino)
1047 */ 1047 */
1048 return get_new_inode_fast(sb, head, ino); 1048 return get_new_inode_fast(sb, head, ino);
1049} 1049}
1050
1051EXPORT_SYMBOL(iget_locked); 1050EXPORT_SYMBOL(iget_locked);
1052 1051
1053int insert_inode_locked(struct inode *inode) 1052int insert_inode_locked(struct inode *inode)
@@ -1055,13 +1054,22 @@ int insert_inode_locked(struct inode *inode)
1055 struct super_block *sb = inode->i_sb; 1054 struct super_block *sb = inode->i_sb;
1056 ino_t ino = inode->i_ino; 1055 ino_t ino = inode->i_ino;
1057 struct hlist_head *head = inode_hashtable + hash(sb, ino); 1056 struct hlist_head *head = inode_hashtable + hash(sb, ino);
1058 struct inode *old;
1059 1057
1060 inode->i_state |= I_LOCK|I_NEW; 1058 inode->i_state |= I_LOCK|I_NEW;
1061 while (1) { 1059 while (1) {
1060 struct hlist_node *node;
1061 struct inode *old = NULL;
1062 spin_lock(&inode_lock); 1062 spin_lock(&inode_lock);
1063 old = find_inode_fast(sb, head, ino); 1063 hlist_for_each_entry(old, node, head, i_hash) {
1064 if (likely(!old)) { 1064 if (old->i_ino != ino)
1065 continue;
1066 if (old->i_sb != sb)
1067 continue;
1068 if (old->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE))
1069 continue;
1070 break;
1071 }
1072 if (likely(!node)) {
1065 hlist_add_head(&inode->i_hash, head); 1073 hlist_add_head(&inode->i_hash, head);
1066 spin_unlock(&inode_lock); 1074 spin_unlock(&inode_lock);
1067 return 0; 1075 return 0;
@@ -1076,7 +1084,6 @@ int insert_inode_locked(struct inode *inode)
1076 iput(old); 1084 iput(old);
1077 } 1085 }
1078} 1086}
1079
1080EXPORT_SYMBOL(insert_inode_locked); 1087EXPORT_SYMBOL(insert_inode_locked);
1081 1088
1082int insert_inode_locked4(struct inode *inode, unsigned long hashval, 1089int insert_inode_locked4(struct inode *inode, unsigned long hashval,
@@ -1084,14 +1091,24 @@ int insert_inode_locked4(struct inode *inode, unsigned long hashval,
1084{ 1091{
1085 struct super_block *sb = inode->i_sb; 1092 struct super_block *sb = inode->i_sb;
1086 struct hlist_head *head = inode_hashtable + hash(sb, hashval); 1093 struct hlist_head *head = inode_hashtable + hash(sb, hashval);
1087 struct inode *old;
1088 1094
1089 inode->i_state |= I_LOCK|I_NEW; 1095 inode->i_state |= I_LOCK|I_NEW;
1090 1096
1091 while (1) { 1097 while (1) {
1098 struct hlist_node *node;
1099 struct inode *old = NULL;
1100
1092 spin_lock(&inode_lock); 1101 spin_lock(&inode_lock);
1093 old = find_inode(sb, head, test, data); 1102 hlist_for_each_entry(old, node, head, i_hash) {
1094 if (likely(!old)) { 1103 if (old->i_sb != sb)
1104 continue;
1105 if (!test(old, data))
1106 continue;
1107 if (old->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE))
1108 continue;
1109 break;
1110 }
1111 if (likely(!node)) {
1095 hlist_add_head(&inode->i_hash, head); 1112 hlist_add_head(&inode->i_hash, head);
1096 spin_unlock(&inode_lock); 1113 spin_unlock(&inode_lock);
1097 return 0; 1114 return 0;
@@ -1106,7 +1123,6 @@ int insert_inode_locked4(struct inode *inode, unsigned long hashval,
1106 iput(old); 1123 iput(old);
1107 } 1124 }
1108} 1125}
1109
1110EXPORT_SYMBOL(insert_inode_locked4); 1126EXPORT_SYMBOL(insert_inode_locked4);
1111 1127
1112/** 1128/**
@@ -1124,7 +1140,6 @@ void __insert_inode_hash(struct inode *inode, unsigned long hashval)
1124 hlist_add_head(&inode->i_hash, head); 1140 hlist_add_head(&inode->i_hash, head);
1125 spin_unlock(&inode_lock); 1141 spin_unlock(&inode_lock);
1126} 1142}
1127
1128EXPORT_SYMBOL(__insert_inode_hash); 1143EXPORT_SYMBOL(__insert_inode_hash);
1129 1144
1130/** 1145/**
@@ -1139,7 +1154,6 @@ void remove_inode_hash(struct inode *inode)
1139 hlist_del_init(&inode->i_hash); 1154 hlist_del_init(&inode->i_hash);
1140 spin_unlock(&inode_lock); 1155 spin_unlock(&inode_lock);
1141} 1156}
1142
1143EXPORT_SYMBOL(remove_inode_hash); 1157EXPORT_SYMBOL(remove_inode_hash);
1144 1158
1145/* 1159/*
@@ -1187,7 +1201,6 @@ void generic_delete_inode(struct inode *inode)
1187 BUG_ON(inode->i_state != I_CLEAR); 1201 BUG_ON(inode->i_state != I_CLEAR);
1188 destroy_inode(inode); 1202 destroy_inode(inode);
1189} 1203}
1190
1191EXPORT_SYMBOL(generic_delete_inode); 1204EXPORT_SYMBOL(generic_delete_inode);
1192 1205
1193static void generic_forget_inode(struct inode *inode) 1206static void generic_forget_inode(struct inode *inode)
@@ -1237,12 +1250,11 @@ void generic_drop_inode(struct inode *inode)
1237 else 1250 else
1238 generic_forget_inode(inode); 1251 generic_forget_inode(inode);
1239} 1252}
1240
1241EXPORT_SYMBOL_GPL(generic_drop_inode); 1253EXPORT_SYMBOL_GPL(generic_drop_inode);
1242 1254
1243/* 1255/*
1244 * Called when we're dropping the last reference 1256 * Called when we're dropping the last reference
1245 * to an inode. 1257 * to an inode.
1246 * 1258 *
1247 * Call the FS "drop()" function, defaulting to 1259 * Call the FS "drop()" function, defaulting to
1248 * the legacy UNIX filesystem behaviour.. 1260 * the legacy UNIX filesystem behaviour..
@@ -1262,7 +1274,7 @@ static inline void iput_final(struct inode *inode)
1262} 1274}
1263 1275
1264/** 1276/**
1265 * iput - put an inode 1277 * iput - put an inode
1266 * @inode: inode to put 1278 * @inode: inode to put
1267 * 1279 *
1268 * Puts an inode, dropping its usage count. If the inode use count hits 1280 * Puts an inode, dropping its usage count. If the inode use count hits
@@ -1279,7 +1291,6 @@ void iput(struct inode *inode)
1279 iput_final(inode); 1291 iput_final(inode);
1280 } 1292 }
1281} 1293}
1282
1283EXPORT_SYMBOL(iput); 1294EXPORT_SYMBOL(iput);
1284 1295
1285/** 1296/**
@@ -1290,10 +1301,10 @@ EXPORT_SYMBOL(iput);
1290 * Returns the block number on the device holding the inode that 1301 * Returns the block number on the device holding the inode that
1291 * is the disk block number for the block of the file requested. 1302 * is the disk block number for the block of the file requested.
1292 * That is, asked for block 4 of inode 1 the function will return the 1303 * That is, asked for block 4 of inode 1 the function will return the
1293 * disk block relative to the disk start that holds that block of the 1304 * disk block relative to the disk start that holds that block of the
1294 * file. 1305 * file.
1295 */ 1306 */
1296sector_t bmap(struct inode * inode, sector_t block) 1307sector_t bmap(struct inode *inode, sector_t block)
1297{ 1308{
1298 sector_t res = 0; 1309 sector_t res = 0;
1299 if (inode->i_mapping->a_ops->bmap) 1310 if (inode->i_mapping->a_ops->bmap)
@@ -1425,7 +1436,6 @@ void file_update_time(struct file *file)
1425 mark_inode_dirty_sync(inode); 1436 mark_inode_dirty_sync(inode);
1426 mnt_drop_write(file->f_path.mnt); 1437 mnt_drop_write(file->f_path.mnt);
1427} 1438}
1428
1429EXPORT_SYMBOL(file_update_time); 1439EXPORT_SYMBOL(file_update_time);
1430 1440
1431int inode_needs_sync(struct inode *inode) 1441int inode_needs_sync(struct inode *inode)
@@ -1436,7 +1446,6 @@ int inode_needs_sync(struct inode *inode)
1436 return 1; 1446 return 1;
1437 return 0; 1447 return 0;
1438} 1448}
1439
1440EXPORT_SYMBOL(inode_needs_sync); 1449EXPORT_SYMBOL(inode_needs_sync);
1441 1450
1442int inode_wait(void *word) 1451int inode_wait(void *word)