diff options
Diffstat (limited to 'fs/inode.c')
-rw-r--r-- | fs/inode.c | 215 |
1 files changed, 83 insertions, 132 deletions
diff --git a/fs/inode.c b/fs/inode.c index 407bf392e20a..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); |
@@ -286,42 +281,42 @@ static void init_once(void *foo) | |||
286 | */ | 281 | */ |
287 | void __iget(struct inode *inode) | 282 | void __iget(struct inode *inode) |
288 | { | 283 | { |
289 | if (atomic_read(&inode->i_count)) { | 284 | if (atomic_inc_return(&inode->i_count) != 1) |
290 | atomic_inc(&inode->i_count); | ||
291 | return; | 285 | return; |
292 | } | 286 | |
293 | atomic_inc(&inode->i_count); | ||
294 | if (!(inode->i_state & (I_DIRTY|I_SYNC))) | 287 | if (!(inode->i_state & (I_DIRTY|I_SYNC))) |
295 | list_move(&inode->i_list, &inode_in_use); | 288 | list_move(&inode->i_list, &inode_in_use); |
296 | inodes_stat.nr_unused--; | 289 | inodes_stat.nr_unused--; |
297 | } | 290 | } |
298 | 291 | ||
299 | /** | 292 | void end_writeback(struct inode *inode) |
300 | * clear_inode - clear an inode | ||
301 | * @inode: inode to clear | ||
302 | * | ||
303 | * This is called by the filesystem to tell us | ||
304 | * that the inode is no longer useful. We just | ||
305 | * terminate it with extreme prejudice. | ||
306 | */ | ||
307 | void clear_inode(struct inode *inode) | ||
308 | { | 293 | { |
309 | might_sleep(); | 294 | might_sleep(); |
310 | invalidate_inode_buffers(inode); | ||
311 | |||
312 | BUG_ON(inode->i_data.nrpages); | 295 | BUG_ON(inode->i_data.nrpages); |
296 | BUG_ON(!list_empty(&inode->i_data.private_list)); | ||
313 | BUG_ON(!(inode->i_state & I_FREEING)); | 297 | BUG_ON(!(inode->i_state & I_FREEING)); |
314 | BUG_ON(inode->i_state & I_CLEAR); | 298 | BUG_ON(inode->i_state & I_CLEAR); |
315 | inode_sync_wait(inode); | 299 | inode_sync_wait(inode); |
316 | if (inode->i_sb->s_op->clear_inode) | 300 | inode->i_state = I_FREEING | I_CLEAR; |
317 | 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 | } | ||
318 | if (S_ISBLK(inode->i_mode) && inode->i_bdev) | 315 | if (S_ISBLK(inode->i_mode) && inode->i_bdev) |
319 | bd_forget(inode); | 316 | bd_forget(inode); |
320 | if (S_ISCHR(inode->i_mode) && inode->i_cdev) | 317 | if (S_ISCHR(inode->i_mode) && inode->i_cdev) |
321 | cd_forget(inode); | 318 | cd_forget(inode); |
322 | inode->i_state = I_CLEAR; | ||
323 | } | 319 | } |
324 | EXPORT_SYMBOL(clear_inode); | ||
325 | 320 | ||
326 | /* | 321 | /* |
327 | * dispose_list - dispose of the contents of a local list | 322 | * dispose_list - dispose of the contents of a local list |
@@ -340,9 +335,7 @@ static void dispose_list(struct list_head *head) | |||
340 | inode = list_first_entry(head, struct inode, i_list); | 335 | inode = list_first_entry(head, struct inode, i_list); |
341 | list_del(&inode->i_list); | 336 | list_del(&inode->i_list); |
342 | 337 | ||
343 | if (inode->i_data.nrpages) | 338 | evict(inode); |
344 | truncate_inode_pages(&inode->i_data, 0); | ||
345 | clear_inode(inode); | ||
346 | 339 | ||
347 | spin_lock(&inode_lock); | 340 | spin_lock(&inode_lock); |
348 | hlist_del_init(&inode->i_hash); | 341 | hlist_del_init(&inode->i_hash); |
@@ -415,7 +408,6 @@ int invalidate_inodes(struct super_block *sb) | |||
415 | 408 | ||
416 | down_write(&iprune_sem); | 409 | down_write(&iprune_sem); |
417 | spin_lock(&inode_lock); | 410 | spin_lock(&inode_lock); |
418 | inotify_unmount_inodes(&sb->s_inodes); | ||
419 | fsnotify_unmount_inodes(&sb->s_inodes); | 411 | fsnotify_unmount_inodes(&sb->s_inodes); |
420 | busy = invalidate_list(&sb->s_inodes, &throw_away); | 412 | busy = invalidate_list(&sb->s_inodes, &throw_away); |
421 | spin_unlock(&inode_lock); | 413 | spin_unlock(&inode_lock); |
@@ -514,7 +506,7 @@ static void prune_icache(int nr_to_scan) | |||
514 | * This function is passed the number of inodes to scan, and it returns the | 506 | * This function is passed the number of inodes to scan, and it returns the |
515 | * total number of remaining possibly-reclaimable inodes. | 507 | * total number of remaining possibly-reclaimable inodes. |
516 | */ | 508 | */ |
517 | static int shrink_icache_memory(int nr, gfp_t gfp_mask) | 509 | static int shrink_icache_memory(struct shrinker *shrink, int nr, gfp_t gfp_mask) |
518 | { | 510 | { |
519 | if (nr) { | 511 | if (nr) { |
520 | /* | 512 | /* |
@@ -555,7 +547,7 @@ repeat: | |||
555 | continue; | 547 | continue; |
556 | if (!test(inode, data)) | 548 | if (!test(inode, data)) |
557 | continue; | 549 | continue; |
558 | if (inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) { | 550 | if (inode->i_state & (I_FREEING|I_WILL_FREE)) { |
559 | __wait_on_freeing_inode(inode); | 551 | __wait_on_freeing_inode(inode); |
560 | goto repeat; | 552 | goto repeat; |
561 | } | 553 | } |
@@ -580,7 +572,7 @@ repeat: | |||
580 | continue; | 572 | continue; |
581 | if (inode->i_sb != sb) | 573 | if (inode->i_sb != sb) |
582 | continue; | 574 | continue; |
583 | if (inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) { | 575 | if (inode->i_state & (I_FREEING|I_WILL_FREE)) { |
584 | __wait_on_freeing_inode(inode); | 576 | __wait_on_freeing_inode(inode); |
585 | goto repeat; | 577 | goto repeat; |
586 | } | 578 | } |
@@ -842,7 +834,7 @@ EXPORT_SYMBOL(iunique); | |||
842 | struct inode *igrab(struct inode *inode) | 834 | struct inode *igrab(struct inode *inode) |
843 | { | 835 | { |
844 | spin_lock(&inode_lock); | 836 | spin_lock(&inode_lock); |
845 | if (!(inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE))) | 837 | if (!(inode->i_state & (I_FREEING|I_WILL_FREE))) |
846 | __iget(inode); | 838 | __iget(inode); |
847 | else | 839 | else |
848 | /* | 840 | /* |
@@ -1091,7 +1083,7 @@ int insert_inode_locked(struct inode *inode) | |||
1091 | continue; | 1083 | continue; |
1092 | if (old->i_sb != sb) | 1084 | if (old->i_sb != sb) |
1093 | continue; | 1085 | continue; |
1094 | if (old->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) | 1086 | if (old->i_state & (I_FREEING|I_WILL_FREE)) |
1095 | continue; | 1087 | continue; |
1096 | break; | 1088 | break; |
1097 | } | 1089 | } |
@@ -1130,7 +1122,7 @@ int insert_inode_locked4(struct inode *inode, unsigned long hashval, | |||
1130 | continue; | 1122 | continue; |
1131 | if (!test(old, data)) | 1123 | if (!test(old, data)) |
1132 | continue; | 1124 | continue; |
1133 | if (old->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) | 1125 | if (old->i_state & (I_FREEING|I_WILL_FREE)) |
1134 | continue; | 1126 | continue; |
1135 | break; | 1127 | break; |
1136 | } | 1128 | } |
@@ -1182,71 +1174,51 @@ void remove_inode_hash(struct inode *inode) | |||
1182 | } | 1174 | } |
1183 | EXPORT_SYMBOL(remove_inode_hash); | 1175 | EXPORT_SYMBOL(remove_inode_hash); |
1184 | 1176 | ||
1177 | int generic_delete_inode(struct inode *inode) | ||
1178 | { | ||
1179 | return 1; | ||
1180 | } | ||
1181 | EXPORT_SYMBOL(generic_delete_inode); | ||
1182 | |||
1185 | /* | 1183 | /* |
1186 | * Tell the filesystem that this inode is no longer of any interest and should | 1184 | * Normal UNIX filesystem behaviour: delete the |
1187 | * be completely destroyed. | 1185 | * inode when the usage count drops to zero, and |
1188 | * | 1186 | * i_nlink is zero. |
1189 | * We leave the inode in the inode hash table until *after* the filesystem's | ||
1190 | * ->delete_inode completes. This ensures that an iget (such as nfsd might | ||
1191 | * instigate) will always find up-to-date information either in the hash or on | ||
1192 | * disk. | ||
1193 | * | ||
1194 | * I_FREEING is set so that no-one will take a new reference to the inode while | ||
1195 | * it is being deleted. | ||
1196 | */ | 1187 | */ |
1197 | void generic_delete_inode(struct inode *inode) | 1188 | int generic_drop_inode(struct inode *inode) |
1198 | { | 1189 | { |
1199 | const struct super_operations *op = inode->i_sb->s_op; | 1190 | return !inode->i_nlink || hlist_unhashed(&inode->i_hash); |
1200 | |||
1201 | list_del_init(&inode->i_list); | ||
1202 | list_del_init(&inode->i_sb_list); | ||
1203 | WARN_ON(inode->i_state & I_NEW); | ||
1204 | inode->i_state |= I_FREEING; | ||
1205 | inodes_stat.nr_inodes--; | ||
1206 | spin_unlock(&inode_lock); | ||
1207 | |||
1208 | security_inode_delete(inode); | ||
1209 | |||
1210 | if (op->delete_inode) { | ||
1211 | void (*delete)(struct inode *) = op->delete_inode; | ||
1212 | /* Filesystems implementing their own | ||
1213 | * s_op->delete_inode are required to call | ||
1214 | * truncate_inode_pages and clear_inode() | ||
1215 | * internally */ | ||
1216 | delete(inode); | ||
1217 | } else { | ||
1218 | truncate_inode_pages(&inode->i_data, 0); | ||
1219 | clear_inode(inode); | ||
1220 | } | ||
1221 | spin_lock(&inode_lock); | ||
1222 | hlist_del_init(&inode->i_hash); | ||
1223 | spin_unlock(&inode_lock); | ||
1224 | wake_up_inode(inode); | ||
1225 | BUG_ON(inode->i_state != I_CLEAR); | ||
1226 | destroy_inode(inode); | ||
1227 | } | 1191 | } |
1228 | EXPORT_SYMBOL(generic_delete_inode); | 1192 | EXPORT_SYMBOL_GPL(generic_drop_inode); |
1229 | 1193 | ||
1230 | /** | 1194 | /* |
1231 | * generic_detach_inode - remove inode from inode lists | 1195 | * Called when we're dropping the last reference |
1232 | * @inode: inode to remove | 1196 | * to an inode. |
1233 | * | ||
1234 | * Remove inode from inode lists, write it if it's dirty. This is just an | ||
1235 | * internal VFS helper exported for hugetlbfs. Do not use! | ||
1236 | * | 1197 | * |
1237 | * 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. | ||
1238 | */ | 1203 | */ |
1239 | int generic_detach_inode(struct inode *inode) | 1204 | static void iput_final(struct inode *inode) |
1240 | { | 1205 | { |
1241 | 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; | ||
1242 | 1209 | ||
1243 | 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) { | ||
1244 | if (!(inode->i_state & (I_DIRTY|I_SYNC))) | 1216 | if (!(inode->i_state & (I_DIRTY|I_SYNC))) |
1245 | list_move(&inode->i_list, &inode_unused); | 1217 | list_move(&inode->i_list, &inode_unused); |
1246 | inodes_stat.nr_unused++; | 1218 | inodes_stat.nr_unused++; |
1247 | if (sb->s_flags & MS_ACTIVE) { | 1219 | if (sb->s_flags & MS_ACTIVE) { |
1248 | spin_unlock(&inode_lock); | 1220 | spin_unlock(&inode_lock); |
1249 | return 0; | 1221 | return; |
1250 | } | 1222 | } |
1251 | WARN_ON(inode->i_state & I_NEW); | 1223 | WARN_ON(inode->i_state & I_NEW); |
1252 | inode->i_state |= I_WILL_FREE; | 1224 | inode->i_state |= I_WILL_FREE; |
@@ -1264,56 +1236,15 @@ int generic_detach_inode(struct inode *inode) | |||
1264 | inode->i_state |= I_FREEING; | 1236 | inode->i_state |= I_FREEING; |
1265 | inodes_stat.nr_inodes--; | 1237 | inodes_stat.nr_inodes--; |
1266 | spin_unlock(&inode_lock); | 1238 | spin_unlock(&inode_lock); |
1267 | return 1; | 1239 | evict(inode); |
1268 | } | 1240 | spin_lock(&inode_lock); |
1269 | EXPORT_SYMBOL_GPL(generic_detach_inode); | 1241 | hlist_del_init(&inode->i_hash); |
1270 | 1242 | spin_unlock(&inode_lock); | |
1271 | static void generic_forget_inode(struct inode *inode) | ||
1272 | { | ||
1273 | if (!generic_detach_inode(inode)) | ||
1274 | return; | ||
1275 | if (inode->i_data.nrpages) | ||
1276 | truncate_inode_pages(&inode->i_data, 0); | ||
1277 | clear_inode(inode); | ||
1278 | wake_up_inode(inode); | 1243 | wake_up_inode(inode); |
1244 | BUG_ON(inode->i_state != (I_FREEING | I_CLEAR)); | ||
1279 | destroy_inode(inode); | 1245 | destroy_inode(inode); |
1280 | } | 1246 | } |
1281 | 1247 | ||
1282 | /* | ||
1283 | * Normal UNIX filesystem behaviour: delete the | ||
1284 | * inode when the usage count drops to zero, and | ||
1285 | * i_nlink is zero. | ||
1286 | */ | ||
1287 | void generic_drop_inode(struct inode *inode) | ||
1288 | { | ||
1289 | if (!inode->i_nlink) | ||
1290 | generic_delete_inode(inode); | ||
1291 | else | ||
1292 | generic_forget_inode(inode); | ||
1293 | } | ||
1294 | EXPORT_SYMBOL_GPL(generic_drop_inode); | ||
1295 | |||
1296 | /* | ||
1297 | * Called when we're dropping the last reference | ||
1298 | * to an inode. | ||
1299 | * | ||
1300 | * Call the FS "drop()" function, defaulting to | ||
1301 | * the legacy UNIX filesystem behaviour.. | ||
1302 | * | ||
1303 | * NOTE! NOTE! NOTE! We're called with the inode lock | ||
1304 | * held, and the drop function is supposed to release | ||
1305 | * the lock! | ||
1306 | */ | ||
1307 | static inline void iput_final(struct inode *inode) | ||
1308 | { | ||
1309 | const struct super_operations *op = inode->i_sb->s_op; | ||
1310 | void (*drop)(struct inode *) = generic_drop_inode; | ||
1311 | |||
1312 | if (op && op->drop_inode) | ||
1313 | drop = op->drop_inode; | ||
1314 | drop(inode); | ||
1315 | } | ||
1316 | |||
1317 | /** | 1248 | /** |
1318 | * iput - put an inode | 1249 | * iput - put an inode |
1319 | * @inode: inode to put | 1250 | * @inode: inode to put |
@@ -1326,7 +1257,7 @@ static inline void iput_final(struct inode *inode) | |||
1326 | void iput(struct inode *inode) | 1257 | void iput(struct inode *inode) |
1327 | { | 1258 | { |
1328 | if (inode) { | 1259 | if (inode) { |
1329 | BUG_ON(inode->i_state == I_CLEAR); | 1260 | BUG_ON(inode->i_state & I_CLEAR); |
1330 | 1261 | ||
1331 | if (atomic_dec_and_lock(&inode->i_count, &inode_lock)) | 1262 | if (atomic_dec_and_lock(&inode->i_count, &inode_lock)) |
1332 | iput_final(inode); | 1263 | iput_final(inode); |
@@ -1610,3 +1541,23 @@ void init_special_inode(struct inode *inode, umode_t mode, dev_t rdev) | |||
1610 | inode->i_ino); | 1541 | inode->i_ino); |
1611 | } | 1542 | } |
1612 | EXPORT_SYMBOL(init_special_inode); | 1543 | EXPORT_SYMBOL(init_special_inode); |
1544 | |||
1545 | /** | ||
1546 | * Init uid,gid,mode for new inode according to posix standards | ||
1547 | * @inode: New inode | ||
1548 | * @dir: Directory inode | ||
1549 | * @mode: mode of the new inode | ||
1550 | */ | ||
1551 | void inode_init_owner(struct inode *inode, const struct inode *dir, | ||
1552 | mode_t mode) | ||
1553 | { | ||
1554 | inode->i_uid = current_fsuid(); | ||
1555 | if (dir && dir->i_mode & S_ISGID) { | ||
1556 | inode->i_gid = dir->i_gid; | ||
1557 | if (S_ISDIR(mode)) | ||
1558 | mode |= S_ISGID; | ||
1559 | } else | ||
1560 | inode->i_gid = current_fsgid(); | ||
1561 | inode->i_mode = mode; | ||
1562 | } | ||
1563 | EXPORT_SYMBOL(inode_init_owner); | ||