diff options
Diffstat (limited to 'fs/inode.c')
-rw-r--r-- | fs/inode.c | 185 |
1 files changed, 60 insertions, 125 deletions
diff --git a/fs/inode.c b/fs/inode.c index 722860b323a9..86464332e590 100644 --- a/fs/inode.c +++ b/fs/inode.c | |||
@@ -20,7 +20,6 @@ | |||
20 | #include <linux/pagemap.h> | 20 | #include <linux/pagemap.h> |
21 | #include <linux/cdev.h> | 21 | #include <linux/cdev.h> |
22 | #include <linux/bootmem.h> | 22 | #include <linux/bootmem.h> |
23 | #include <linux/inotify.h> | ||
24 | #include <linux/fsnotify.h> | 23 | #include <linux/fsnotify.h> |
25 | #include <linux/mount.h> | 24 | #include <linux/mount.h> |
26 | #include <linux/async.h> | 25 | #include <linux/async.h> |
@@ -264,12 +263,8 @@ void inode_init_once(struct inode *inode) | |||
264 | INIT_RAW_PRIO_TREE_ROOT(&inode->i_data.i_mmap); | 263 | INIT_RAW_PRIO_TREE_ROOT(&inode->i_data.i_mmap); |
265 | INIT_LIST_HEAD(&inode->i_data.i_mmap_nonlinear); | 264 | INIT_LIST_HEAD(&inode->i_data.i_mmap_nonlinear); |
266 | i_size_ordered_init(inode); | 265 | i_size_ordered_init(inode); |
267 | #ifdef CONFIG_INOTIFY | ||
268 | INIT_LIST_HEAD(&inode->inotify_watches); | ||
269 | mutex_init(&inode->inotify_mutex); | ||
270 | #endif | ||
271 | #ifdef CONFIG_FSNOTIFY | 266 | #ifdef CONFIG_FSNOTIFY |
272 | INIT_HLIST_HEAD(&inode->i_fsnotify_mark_entries); | 267 | INIT_HLIST_HEAD(&inode->i_fsnotify_marks); |
273 | #endif | 268 | #endif |
274 | } | 269 | } |
275 | EXPORT_SYMBOL(inode_init_once); | 270 | EXPORT_SYMBOL(inode_init_once); |
@@ -294,32 +289,34 @@ void __iget(struct inode *inode) | |||
294 | inodes_stat.nr_unused--; | 289 | inodes_stat.nr_unused--; |
295 | } | 290 | } |
296 | 291 | ||
297 | /** | 292 | void end_writeback(struct inode *inode) |
298 | * clear_inode - clear an inode | ||
299 | * @inode: inode to clear | ||
300 | * | ||
301 | * This is called by the filesystem to tell us | ||
302 | * that the inode is no longer useful. We just | ||
303 | * terminate it with extreme prejudice. | ||
304 | */ | ||
305 | void clear_inode(struct inode *inode) | ||
306 | { | 293 | { |
307 | might_sleep(); | 294 | might_sleep(); |
308 | invalidate_inode_buffers(inode); | ||
309 | |||
310 | BUG_ON(inode->i_data.nrpages); | 295 | BUG_ON(inode->i_data.nrpages); |
296 | BUG_ON(!list_empty(&inode->i_data.private_list)); | ||
311 | BUG_ON(!(inode->i_state & I_FREEING)); | 297 | BUG_ON(!(inode->i_state & I_FREEING)); |
312 | BUG_ON(inode->i_state & I_CLEAR); | 298 | BUG_ON(inode->i_state & I_CLEAR); |
313 | inode_sync_wait(inode); | 299 | inode_sync_wait(inode); |
314 | if (inode->i_sb->s_op->clear_inode) | 300 | inode->i_state = I_FREEING | I_CLEAR; |
315 | inode->i_sb->s_op->clear_inode(inode); | 301 | } |
302 | EXPORT_SYMBOL(end_writeback); | ||
303 | |||
304 | static void evict(struct inode *inode) | ||
305 | { | ||
306 | const struct super_operations *op = inode->i_sb->s_op; | ||
307 | |||
308 | if (op->evict_inode) { | ||
309 | op->evict_inode(inode); | ||
310 | } else { | ||
311 | if (inode->i_data.nrpages) | ||
312 | truncate_inode_pages(&inode->i_data, 0); | ||
313 | end_writeback(inode); | ||
314 | } | ||
316 | if (S_ISBLK(inode->i_mode) && inode->i_bdev) | 315 | if (S_ISBLK(inode->i_mode) && inode->i_bdev) |
317 | bd_forget(inode); | 316 | bd_forget(inode); |
318 | if (S_ISCHR(inode->i_mode) && inode->i_cdev) | 317 | if (S_ISCHR(inode->i_mode) && inode->i_cdev) |
319 | cd_forget(inode); | 318 | cd_forget(inode); |
320 | inode->i_state = I_CLEAR; | ||
321 | } | 319 | } |
322 | EXPORT_SYMBOL(clear_inode); | ||
323 | 320 | ||
324 | /* | 321 | /* |
325 | * dispose_list - dispose of the contents of a local list | 322 | * dispose_list - dispose of the contents of a local list |
@@ -338,9 +335,7 @@ static void dispose_list(struct list_head *head) | |||
338 | inode = list_first_entry(head, struct inode, i_list); | 335 | inode = list_first_entry(head, struct inode, i_list); |
339 | list_del(&inode->i_list); | 336 | list_del(&inode->i_list); |
340 | 337 | ||
341 | if (inode->i_data.nrpages) | 338 | evict(inode); |
342 | truncate_inode_pages(&inode->i_data, 0); | ||
343 | clear_inode(inode); | ||
344 | 339 | ||
345 | spin_lock(&inode_lock); | 340 | spin_lock(&inode_lock); |
346 | hlist_del_init(&inode->i_hash); | 341 | hlist_del_init(&inode->i_hash); |
@@ -413,7 +408,6 @@ int invalidate_inodes(struct super_block *sb) | |||
413 | 408 | ||
414 | down_write(&iprune_sem); | 409 | down_write(&iprune_sem); |
415 | spin_lock(&inode_lock); | 410 | spin_lock(&inode_lock); |
416 | inotify_unmount_inodes(&sb->s_inodes); | ||
417 | fsnotify_unmount_inodes(&sb->s_inodes); | 411 | fsnotify_unmount_inodes(&sb->s_inodes); |
418 | busy = invalidate_list(&sb->s_inodes, &throw_away); | 412 | busy = invalidate_list(&sb->s_inodes, &throw_away); |
419 | spin_unlock(&inode_lock); | 413 | spin_unlock(&inode_lock); |
@@ -553,7 +547,7 @@ repeat: | |||
553 | continue; | 547 | continue; |
554 | if (!test(inode, data)) | 548 | if (!test(inode, data)) |
555 | continue; | 549 | continue; |
556 | if (inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) { | 550 | if (inode->i_state & (I_FREEING|I_WILL_FREE)) { |
557 | __wait_on_freeing_inode(inode); | 551 | __wait_on_freeing_inode(inode); |
558 | goto repeat; | 552 | goto repeat; |
559 | } | 553 | } |
@@ -578,7 +572,7 @@ repeat: | |||
578 | continue; | 572 | continue; |
579 | if (inode->i_sb != sb) | 573 | if (inode->i_sb != sb) |
580 | continue; | 574 | continue; |
581 | if (inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) { | 575 | if (inode->i_state & (I_FREEING|I_WILL_FREE)) { |
582 | __wait_on_freeing_inode(inode); | 576 | __wait_on_freeing_inode(inode); |
583 | goto repeat; | 577 | goto repeat; |
584 | } | 578 | } |
@@ -840,7 +834,7 @@ EXPORT_SYMBOL(iunique); | |||
840 | struct inode *igrab(struct inode *inode) | 834 | struct inode *igrab(struct inode *inode) |
841 | { | 835 | { |
842 | spin_lock(&inode_lock); | 836 | spin_lock(&inode_lock); |
843 | if (!(inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE))) | 837 | if (!(inode->i_state & (I_FREEING|I_WILL_FREE))) |
844 | __iget(inode); | 838 | __iget(inode); |
845 | else | 839 | else |
846 | /* | 840 | /* |
@@ -1089,7 +1083,7 @@ int insert_inode_locked(struct inode *inode) | |||
1089 | continue; | 1083 | continue; |
1090 | if (old->i_sb != sb) | 1084 | if (old->i_sb != sb) |
1091 | continue; | 1085 | continue; |
1092 | if (old->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) | 1086 | if (old->i_state & (I_FREEING|I_WILL_FREE)) |
1093 | continue; | 1087 | continue; |
1094 | break; | 1088 | break; |
1095 | } | 1089 | } |
@@ -1128,7 +1122,7 @@ int insert_inode_locked4(struct inode *inode, unsigned long hashval, | |||
1128 | continue; | 1122 | continue; |
1129 | if (!test(old, data)) | 1123 | if (!test(old, data)) |
1130 | continue; | 1124 | continue; |
1131 | if (old->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) | 1125 | if (old->i_state & (I_FREEING|I_WILL_FREE)) |
1132 | continue; | 1126 | continue; |
1133 | break; | 1127 | break; |
1134 | } | 1128 | } |
@@ -1180,69 +1174,51 @@ void remove_inode_hash(struct inode *inode) | |||
1180 | } | 1174 | } |
1181 | EXPORT_SYMBOL(remove_inode_hash); | 1175 | EXPORT_SYMBOL(remove_inode_hash); |
1182 | 1176 | ||
1177 | int generic_delete_inode(struct inode *inode) | ||
1178 | { | ||
1179 | return 1; | ||
1180 | } | ||
1181 | EXPORT_SYMBOL(generic_delete_inode); | ||
1182 | |||
1183 | /* | 1183 | /* |
1184 | * Tell the filesystem that this inode is no longer of any interest and should | 1184 | * Normal UNIX filesystem behaviour: delete the |
1185 | * be completely destroyed. | 1185 | * inode when the usage count drops to zero, and |
1186 | * | 1186 | * i_nlink is zero. |
1187 | * We leave the inode in the inode hash table until *after* the filesystem's | ||
1188 | * ->delete_inode completes. This ensures that an iget (such as nfsd might | ||
1189 | * instigate) will always find up-to-date information either in the hash or on | ||
1190 | * disk. | ||
1191 | * | ||
1192 | * I_FREEING is set so that no-one will take a new reference to the inode while | ||
1193 | * it is being deleted. | ||
1194 | */ | 1187 | */ |
1195 | void generic_delete_inode(struct inode *inode) | 1188 | int generic_drop_inode(struct inode *inode) |
1196 | { | 1189 | { |
1197 | const struct super_operations *op = inode->i_sb->s_op; | 1190 | return !inode->i_nlink || hlist_unhashed(&inode->i_hash); |
1198 | |||
1199 | list_del_init(&inode->i_list); | ||
1200 | list_del_init(&inode->i_sb_list); | ||
1201 | WARN_ON(inode->i_state & I_NEW); | ||
1202 | inode->i_state |= I_FREEING; | ||
1203 | inodes_stat.nr_inodes--; | ||
1204 | spin_unlock(&inode_lock); | ||
1205 | |||
1206 | if (op->delete_inode) { | ||
1207 | void (*delete)(struct inode *) = op->delete_inode; | ||
1208 | /* Filesystems implementing their own | ||
1209 | * s_op->delete_inode are required to call | ||
1210 | * truncate_inode_pages and clear_inode() | ||
1211 | * internally */ | ||
1212 | delete(inode); | ||
1213 | } else { | ||
1214 | truncate_inode_pages(&inode->i_data, 0); | ||
1215 | clear_inode(inode); | ||
1216 | } | ||
1217 | spin_lock(&inode_lock); | ||
1218 | hlist_del_init(&inode->i_hash); | ||
1219 | spin_unlock(&inode_lock); | ||
1220 | wake_up_inode(inode); | ||
1221 | BUG_ON(inode->i_state != I_CLEAR); | ||
1222 | destroy_inode(inode); | ||
1223 | } | 1191 | } |
1224 | EXPORT_SYMBOL(generic_delete_inode); | 1192 | EXPORT_SYMBOL_GPL(generic_drop_inode); |
1225 | 1193 | ||
1226 | /** | 1194 | /* |
1227 | * generic_detach_inode - remove inode from inode lists | 1195 | * Called when we're dropping the last reference |
1228 | * @inode: inode to remove | 1196 | * to an inode. |
1229 | * | ||
1230 | * Remove inode from inode lists, write it if it's dirty. This is just an | ||
1231 | * internal VFS helper exported for hugetlbfs. Do not use! | ||
1232 | * | 1197 | * |
1233 | * Returns 1 if inode should be completely destroyed. | 1198 | * Call the FS "drop_inode()" function, defaulting to |
1199 | * the legacy UNIX filesystem behaviour. If it tells | ||
1200 | * us to evict inode, do so. Otherwise, retain inode | ||
1201 | * in cache if fs is alive, sync and evict if fs is | ||
1202 | * shutting down. | ||
1234 | */ | 1203 | */ |
1235 | int generic_detach_inode(struct inode *inode) | 1204 | static void iput_final(struct inode *inode) |
1236 | { | 1205 | { |
1237 | struct super_block *sb = inode->i_sb; | 1206 | struct super_block *sb = inode->i_sb; |
1207 | const struct super_operations *op = inode->i_sb->s_op; | ||
1208 | int drop; | ||
1238 | 1209 | ||
1239 | if (!hlist_unhashed(&inode->i_hash)) { | 1210 | if (op && op->drop_inode) |
1211 | drop = op->drop_inode(inode); | ||
1212 | else | ||
1213 | drop = generic_drop_inode(inode); | ||
1214 | |||
1215 | if (!drop) { | ||
1240 | if (!(inode->i_state & (I_DIRTY|I_SYNC))) | 1216 | if (!(inode->i_state & (I_DIRTY|I_SYNC))) |
1241 | list_move(&inode->i_list, &inode_unused); | 1217 | list_move(&inode->i_list, &inode_unused); |
1242 | inodes_stat.nr_unused++; | 1218 | inodes_stat.nr_unused++; |
1243 | if (sb->s_flags & MS_ACTIVE) { | 1219 | if (sb->s_flags & MS_ACTIVE) { |
1244 | spin_unlock(&inode_lock); | 1220 | spin_unlock(&inode_lock); |
1245 | return 0; | 1221 | return; |
1246 | } | 1222 | } |
1247 | WARN_ON(inode->i_state & I_NEW); | 1223 | WARN_ON(inode->i_state & I_NEW); |
1248 | inode->i_state |= I_WILL_FREE; | 1224 | inode->i_state |= I_WILL_FREE; |
@@ -1260,56 +1236,15 @@ int generic_detach_inode(struct inode *inode) | |||
1260 | inode->i_state |= I_FREEING; | 1236 | inode->i_state |= I_FREEING; |
1261 | inodes_stat.nr_inodes--; | 1237 | inodes_stat.nr_inodes--; |
1262 | spin_unlock(&inode_lock); | 1238 | spin_unlock(&inode_lock); |
1263 | return 1; | 1239 | evict(inode); |
1264 | } | 1240 | spin_lock(&inode_lock); |
1265 | EXPORT_SYMBOL_GPL(generic_detach_inode); | 1241 | hlist_del_init(&inode->i_hash); |
1266 | 1242 | spin_unlock(&inode_lock); | |
1267 | static void generic_forget_inode(struct inode *inode) | ||
1268 | { | ||
1269 | if (!generic_detach_inode(inode)) | ||
1270 | return; | ||
1271 | if (inode->i_data.nrpages) | ||
1272 | truncate_inode_pages(&inode->i_data, 0); | ||
1273 | clear_inode(inode); | ||
1274 | wake_up_inode(inode); | 1243 | wake_up_inode(inode); |
1244 | BUG_ON(inode->i_state != (I_FREEING | I_CLEAR)); | ||
1275 | destroy_inode(inode); | 1245 | destroy_inode(inode); |
1276 | } | 1246 | } |
1277 | 1247 | ||
1278 | /* | ||
1279 | * Normal UNIX filesystem behaviour: delete the | ||
1280 | * inode when the usage count drops to zero, and | ||
1281 | * i_nlink is zero. | ||
1282 | */ | ||
1283 | void generic_drop_inode(struct inode *inode) | ||
1284 | { | ||
1285 | if (!inode->i_nlink) | ||
1286 | generic_delete_inode(inode); | ||
1287 | else | ||
1288 | generic_forget_inode(inode); | ||
1289 | } | ||
1290 | EXPORT_SYMBOL_GPL(generic_drop_inode); | ||
1291 | |||
1292 | /* | ||
1293 | * Called when we're dropping the last reference | ||
1294 | * to an inode. | ||
1295 | * | ||
1296 | * Call the FS "drop()" function, defaulting to | ||
1297 | * the legacy UNIX filesystem behaviour.. | ||
1298 | * | ||
1299 | * NOTE! NOTE! NOTE! We're called with the inode lock | ||
1300 | * held, and the drop function is supposed to release | ||
1301 | * the lock! | ||
1302 | */ | ||
1303 | static inline void iput_final(struct inode *inode) | ||
1304 | { | ||
1305 | const struct super_operations *op = inode->i_sb->s_op; | ||
1306 | void (*drop)(struct inode *) = generic_drop_inode; | ||
1307 | |||
1308 | if (op && op->drop_inode) | ||
1309 | drop = op->drop_inode; | ||
1310 | drop(inode); | ||
1311 | } | ||
1312 | |||
1313 | /** | 1248 | /** |
1314 | * iput - put an inode | 1249 | * iput - put an inode |
1315 | * @inode: inode to put | 1250 | * @inode: inode to put |
@@ -1322,7 +1257,7 @@ static inline void iput_final(struct inode *inode) | |||
1322 | void iput(struct inode *inode) | 1257 | void iput(struct inode *inode) |
1323 | { | 1258 | { |
1324 | if (inode) { | 1259 | if (inode) { |
1325 | BUG_ON(inode->i_state == I_CLEAR); | 1260 | BUG_ON(inode->i_state & I_CLEAR); |
1326 | 1261 | ||
1327 | if (atomic_dec_and_lock(&inode->i_count, &inode_lock)) | 1262 | if (atomic_dec_and_lock(&inode->i_count, &inode_lock)) |
1328 | iput_final(inode); | 1263 | iput_final(inode); |