diff options
Diffstat (limited to 'fs/inode.c')
-rw-r--r-- | fs/inode.c | 177 |
1 files changed, 59 insertions, 118 deletions
diff --git a/fs/inode.c b/fs/inode.c index 722860b323a9..2575244640a8 100644 --- a/fs/inode.c +++ b/fs/inode.c | |||
@@ -294,32 +294,34 @@ void __iget(struct inode *inode) | |||
294 | inodes_stat.nr_unused--; | 294 | inodes_stat.nr_unused--; |
295 | } | 295 | } |
296 | 296 | ||
297 | /** | 297 | 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 | { | 298 | { |
307 | might_sleep(); | 299 | might_sleep(); |
308 | invalidate_inode_buffers(inode); | ||
309 | |||
310 | BUG_ON(inode->i_data.nrpages); | 300 | BUG_ON(inode->i_data.nrpages); |
301 | BUG_ON(!list_empty(&inode->i_data.private_list)); | ||
311 | BUG_ON(!(inode->i_state & I_FREEING)); | 302 | BUG_ON(!(inode->i_state & I_FREEING)); |
312 | BUG_ON(inode->i_state & I_CLEAR); | 303 | BUG_ON(inode->i_state & I_CLEAR); |
313 | inode_sync_wait(inode); | 304 | inode_sync_wait(inode); |
314 | if (inode->i_sb->s_op->clear_inode) | 305 | inode->i_state = I_FREEING | I_CLEAR; |
315 | inode->i_sb->s_op->clear_inode(inode); | 306 | } |
307 | EXPORT_SYMBOL(end_writeback); | ||
308 | |||
309 | static void evict(struct inode *inode) | ||
310 | { | ||
311 | const struct super_operations *op = inode->i_sb->s_op; | ||
312 | |||
313 | if (op->evict_inode) { | ||
314 | op->evict_inode(inode); | ||
315 | } else { | ||
316 | if (inode->i_data.nrpages) | ||
317 | truncate_inode_pages(&inode->i_data, 0); | ||
318 | end_writeback(inode); | ||
319 | } | ||
316 | if (S_ISBLK(inode->i_mode) && inode->i_bdev) | 320 | if (S_ISBLK(inode->i_mode) && inode->i_bdev) |
317 | bd_forget(inode); | 321 | bd_forget(inode); |
318 | if (S_ISCHR(inode->i_mode) && inode->i_cdev) | 322 | if (S_ISCHR(inode->i_mode) && inode->i_cdev) |
319 | cd_forget(inode); | 323 | cd_forget(inode); |
320 | inode->i_state = I_CLEAR; | ||
321 | } | 324 | } |
322 | EXPORT_SYMBOL(clear_inode); | ||
323 | 325 | ||
324 | /* | 326 | /* |
325 | * dispose_list - dispose of the contents of a local list | 327 | * dispose_list - dispose of the contents of a local list |
@@ -338,9 +340,7 @@ static void dispose_list(struct list_head *head) | |||
338 | inode = list_first_entry(head, struct inode, i_list); | 340 | inode = list_first_entry(head, struct inode, i_list); |
339 | list_del(&inode->i_list); | 341 | list_del(&inode->i_list); |
340 | 342 | ||
341 | if (inode->i_data.nrpages) | 343 | evict(inode); |
342 | truncate_inode_pages(&inode->i_data, 0); | ||
343 | clear_inode(inode); | ||
344 | 344 | ||
345 | spin_lock(&inode_lock); | 345 | spin_lock(&inode_lock); |
346 | hlist_del_init(&inode->i_hash); | 346 | hlist_del_init(&inode->i_hash); |
@@ -553,7 +553,7 @@ repeat: | |||
553 | continue; | 553 | continue; |
554 | if (!test(inode, data)) | 554 | if (!test(inode, data)) |
555 | continue; | 555 | continue; |
556 | if (inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) { | 556 | if (inode->i_state & (I_FREEING|I_WILL_FREE)) { |
557 | __wait_on_freeing_inode(inode); | 557 | __wait_on_freeing_inode(inode); |
558 | goto repeat; | 558 | goto repeat; |
559 | } | 559 | } |
@@ -578,7 +578,7 @@ repeat: | |||
578 | continue; | 578 | continue; |
579 | if (inode->i_sb != sb) | 579 | if (inode->i_sb != sb) |
580 | continue; | 580 | continue; |
581 | if (inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) { | 581 | if (inode->i_state & (I_FREEING|I_WILL_FREE)) { |
582 | __wait_on_freeing_inode(inode); | 582 | __wait_on_freeing_inode(inode); |
583 | goto repeat; | 583 | goto repeat; |
584 | } | 584 | } |
@@ -840,7 +840,7 @@ EXPORT_SYMBOL(iunique); | |||
840 | struct inode *igrab(struct inode *inode) | 840 | struct inode *igrab(struct inode *inode) |
841 | { | 841 | { |
842 | spin_lock(&inode_lock); | 842 | spin_lock(&inode_lock); |
843 | if (!(inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE))) | 843 | if (!(inode->i_state & (I_FREEING|I_WILL_FREE))) |
844 | __iget(inode); | 844 | __iget(inode); |
845 | else | 845 | else |
846 | /* | 846 | /* |
@@ -1089,7 +1089,7 @@ int insert_inode_locked(struct inode *inode) | |||
1089 | continue; | 1089 | continue; |
1090 | if (old->i_sb != sb) | 1090 | if (old->i_sb != sb) |
1091 | continue; | 1091 | continue; |
1092 | if (old->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) | 1092 | if (old->i_state & (I_FREEING|I_WILL_FREE)) |
1093 | continue; | 1093 | continue; |
1094 | break; | 1094 | break; |
1095 | } | 1095 | } |
@@ -1128,7 +1128,7 @@ int insert_inode_locked4(struct inode *inode, unsigned long hashval, | |||
1128 | continue; | 1128 | continue; |
1129 | if (!test(old, data)) | 1129 | if (!test(old, data)) |
1130 | continue; | 1130 | continue; |
1131 | if (old->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) | 1131 | if (old->i_state & (I_FREEING|I_WILL_FREE)) |
1132 | continue; | 1132 | continue; |
1133 | break; | 1133 | break; |
1134 | } | 1134 | } |
@@ -1180,69 +1180,51 @@ void remove_inode_hash(struct inode *inode) | |||
1180 | } | 1180 | } |
1181 | EXPORT_SYMBOL(remove_inode_hash); | 1181 | EXPORT_SYMBOL(remove_inode_hash); |
1182 | 1182 | ||
1183 | int generic_delete_inode(struct inode *inode) | ||
1184 | { | ||
1185 | return 1; | ||
1186 | } | ||
1187 | EXPORT_SYMBOL(generic_delete_inode); | ||
1188 | |||
1183 | /* | 1189 | /* |
1184 | * Tell the filesystem that this inode is no longer of any interest and should | 1190 | * Normal UNIX filesystem behaviour: delete the |
1185 | * be completely destroyed. | 1191 | * inode when the usage count drops to zero, and |
1186 | * | 1192 | * 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 | */ | 1193 | */ |
1195 | void generic_delete_inode(struct inode *inode) | 1194 | int generic_drop_inode(struct inode *inode) |
1196 | { | 1195 | { |
1197 | const struct super_operations *op = inode->i_sb->s_op; | 1196 | 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 | } | 1197 | } |
1224 | EXPORT_SYMBOL(generic_delete_inode); | 1198 | EXPORT_SYMBOL_GPL(generic_drop_inode); |
1225 | 1199 | ||
1226 | /** | 1200 | /* |
1227 | * generic_detach_inode - remove inode from inode lists | 1201 | * Called when we're dropping the last reference |
1228 | * @inode: inode to remove | 1202 | * 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 | * | 1203 | * |
1233 | * Returns 1 if inode should be completely destroyed. | 1204 | * Call the FS "drop_inode()" function, defaulting to |
1205 | * the legacy UNIX filesystem behaviour. If it tells | ||
1206 | * us to evict inode, do so. Otherwise, retain inode | ||
1207 | * in cache if fs is alive, sync and evict if fs is | ||
1208 | * shutting down. | ||
1234 | */ | 1209 | */ |
1235 | int generic_detach_inode(struct inode *inode) | 1210 | static void iput_final(struct inode *inode) |
1236 | { | 1211 | { |
1237 | struct super_block *sb = inode->i_sb; | 1212 | struct super_block *sb = inode->i_sb; |
1213 | const struct super_operations *op = inode->i_sb->s_op; | ||
1214 | int drop; | ||
1238 | 1215 | ||
1239 | if (!hlist_unhashed(&inode->i_hash)) { | 1216 | if (op && op->drop_inode) |
1217 | drop = op->drop_inode(inode); | ||
1218 | else | ||
1219 | drop = generic_drop_inode(inode); | ||
1220 | |||
1221 | if (!drop) { | ||
1240 | if (!(inode->i_state & (I_DIRTY|I_SYNC))) | 1222 | if (!(inode->i_state & (I_DIRTY|I_SYNC))) |
1241 | list_move(&inode->i_list, &inode_unused); | 1223 | list_move(&inode->i_list, &inode_unused); |
1242 | inodes_stat.nr_unused++; | 1224 | inodes_stat.nr_unused++; |
1243 | if (sb->s_flags & MS_ACTIVE) { | 1225 | if (sb->s_flags & MS_ACTIVE) { |
1244 | spin_unlock(&inode_lock); | 1226 | spin_unlock(&inode_lock); |
1245 | return 0; | 1227 | return; |
1246 | } | 1228 | } |
1247 | WARN_ON(inode->i_state & I_NEW); | 1229 | WARN_ON(inode->i_state & I_NEW); |
1248 | inode->i_state |= I_WILL_FREE; | 1230 | inode->i_state |= I_WILL_FREE; |
@@ -1260,56 +1242,15 @@ int generic_detach_inode(struct inode *inode) | |||
1260 | inode->i_state |= I_FREEING; | 1242 | inode->i_state |= I_FREEING; |
1261 | inodes_stat.nr_inodes--; | 1243 | inodes_stat.nr_inodes--; |
1262 | spin_unlock(&inode_lock); | 1244 | spin_unlock(&inode_lock); |
1263 | return 1; | 1245 | evict(inode); |
1264 | } | 1246 | spin_lock(&inode_lock); |
1265 | EXPORT_SYMBOL_GPL(generic_detach_inode); | 1247 | hlist_del_init(&inode->i_hash); |
1266 | 1248 | 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); | 1249 | wake_up_inode(inode); |
1250 | BUG_ON(inode->i_state != (I_FREEING | I_CLEAR)); | ||
1275 | destroy_inode(inode); | 1251 | destroy_inode(inode); |
1276 | } | 1252 | } |
1277 | 1253 | ||
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 | /** | 1254 | /** |
1314 | * iput - put an inode | 1255 | * iput - put an inode |
1315 | * @inode: inode to put | 1256 | * @inode: inode to put |
@@ -1322,7 +1263,7 @@ static inline void iput_final(struct inode *inode) | |||
1322 | void iput(struct inode *inode) | 1263 | void iput(struct inode *inode) |
1323 | { | 1264 | { |
1324 | if (inode) { | 1265 | if (inode) { |
1325 | BUG_ON(inode->i_state == I_CLEAR); | 1266 | BUG_ON(inode->i_state & I_CLEAR); |
1326 | 1267 | ||
1327 | if (atomic_dec_and_lock(&inode->i_count, &inode_lock)) | 1268 | if (atomic_dec_and_lock(&inode->i_count, &inode_lock)) |
1328 | iput_final(inode); | 1269 | iput_final(inode); |