aboutsummaryrefslogtreecommitdiffstats
path: root/fs/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/inode.c')
-rw-r--r--fs/inode.c177
1 files changed, 59 insertions, 118 deletions
diff --git a/fs/inode.c b/fs/inode.c
index a2da778467bb..86464332e590 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -289,32 +289,34 @@ void __iget(struct inode *inode)
289 inodes_stat.nr_unused--; 289 inodes_stat.nr_unused--;
290} 290}
291 291
292/** 292void end_writeback(struct inode *inode)
293 * clear_inode - clear an inode
294 * @inode: inode to clear
295 *
296 * This is called by the filesystem to tell us
297 * that the inode is no longer useful. We just
298 * terminate it with extreme prejudice.
299 */
300void clear_inode(struct inode *inode)
301{ 293{
302 might_sleep(); 294 might_sleep();
303 invalidate_inode_buffers(inode);
304
305 BUG_ON(inode->i_data.nrpages); 295 BUG_ON(inode->i_data.nrpages);
296 BUG_ON(!list_empty(&inode->i_data.private_list));
306 BUG_ON(!(inode->i_state & I_FREEING)); 297 BUG_ON(!(inode->i_state & I_FREEING));
307 BUG_ON(inode->i_state & I_CLEAR); 298 BUG_ON(inode->i_state & I_CLEAR);
308 inode_sync_wait(inode); 299 inode_sync_wait(inode);
309 if (inode->i_sb->s_op->clear_inode) 300 inode->i_state = I_FREEING | I_CLEAR;
310 inode->i_sb->s_op->clear_inode(inode); 301}
302EXPORT_SYMBOL(end_writeback);
303
304static 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 }
311 if (S_ISBLK(inode->i_mode) && inode->i_bdev) 315 if (S_ISBLK(inode->i_mode) && inode->i_bdev)
312 bd_forget(inode); 316 bd_forget(inode);
313 if (S_ISCHR(inode->i_mode) && inode->i_cdev) 317 if (S_ISCHR(inode->i_mode) && inode->i_cdev)
314 cd_forget(inode); 318 cd_forget(inode);
315 inode->i_state = I_CLEAR;
316} 319}
317EXPORT_SYMBOL(clear_inode);
318 320
319/* 321/*
320 * dispose_list - dispose of the contents of a local list 322 * dispose_list - dispose of the contents of a local list
@@ -333,9 +335,7 @@ static void dispose_list(struct list_head *head)
333 inode = list_first_entry(head, struct inode, i_list); 335 inode = list_first_entry(head, struct inode, i_list);
334 list_del(&inode->i_list); 336 list_del(&inode->i_list);
335 337
336 if (inode->i_data.nrpages) 338 evict(inode);
337 truncate_inode_pages(&inode->i_data, 0);
338 clear_inode(inode);
339 339
340 spin_lock(&inode_lock); 340 spin_lock(&inode_lock);
341 hlist_del_init(&inode->i_hash); 341 hlist_del_init(&inode->i_hash);
@@ -547,7 +547,7 @@ repeat:
547 continue; 547 continue;
548 if (!test(inode, data)) 548 if (!test(inode, data))
549 continue; 549 continue;
550 if (inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) { 550 if (inode->i_state & (I_FREEING|I_WILL_FREE)) {
551 __wait_on_freeing_inode(inode); 551 __wait_on_freeing_inode(inode);
552 goto repeat; 552 goto repeat;
553 } 553 }
@@ -572,7 +572,7 @@ repeat:
572 continue; 572 continue;
573 if (inode->i_sb != sb) 573 if (inode->i_sb != sb)
574 continue; 574 continue;
575 if (inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) { 575 if (inode->i_state & (I_FREEING|I_WILL_FREE)) {
576 __wait_on_freeing_inode(inode); 576 __wait_on_freeing_inode(inode);
577 goto repeat; 577 goto repeat;
578 } 578 }
@@ -834,7 +834,7 @@ EXPORT_SYMBOL(iunique);
834struct inode *igrab(struct inode *inode) 834struct inode *igrab(struct inode *inode)
835{ 835{
836 spin_lock(&inode_lock); 836 spin_lock(&inode_lock);
837 if (!(inode->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE))) 837 if (!(inode->i_state & (I_FREEING|I_WILL_FREE)))
838 __iget(inode); 838 __iget(inode);
839 else 839 else
840 /* 840 /*
@@ -1083,7 +1083,7 @@ int insert_inode_locked(struct inode *inode)
1083 continue; 1083 continue;
1084 if (old->i_sb != sb) 1084 if (old->i_sb != sb)
1085 continue; 1085 continue;
1086 if (old->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) 1086 if (old->i_state & (I_FREEING|I_WILL_FREE))
1087 continue; 1087 continue;
1088 break; 1088 break;
1089 } 1089 }
@@ -1122,7 +1122,7 @@ int insert_inode_locked4(struct inode *inode, unsigned long hashval,
1122 continue; 1122 continue;
1123 if (!test(old, data)) 1123 if (!test(old, data))
1124 continue; 1124 continue;
1125 if (old->i_state & (I_FREEING|I_CLEAR|I_WILL_FREE)) 1125 if (old->i_state & (I_FREEING|I_WILL_FREE))
1126 continue; 1126 continue;
1127 break; 1127 break;
1128 } 1128 }
@@ -1174,69 +1174,51 @@ void remove_inode_hash(struct inode *inode)
1174} 1174}
1175EXPORT_SYMBOL(remove_inode_hash); 1175EXPORT_SYMBOL(remove_inode_hash);
1176 1176
1177int generic_delete_inode(struct inode *inode)
1178{
1179 return 1;
1180}
1181EXPORT_SYMBOL(generic_delete_inode);
1182
1177/* 1183/*
1178 * Tell the filesystem that this inode is no longer of any interest and should 1184 * Normal UNIX filesystem behaviour: delete the
1179 * be completely destroyed. 1185 * inode when the usage count drops to zero, and
1180 * 1186 * i_nlink is zero.
1181 * We leave the inode in the inode hash table until *after* the filesystem's
1182 * ->delete_inode completes. This ensures that an iget (such as nfsd might
1183 * instigate) will always find up-to-date information either in the hash or on
1184 * disk.
1185 *
1186 * I_FREEING is set so that no-one will take a new reference to the inode while
1187 * it is being deleted.
1188 */ 1187 */
1189void generic_delete_inode(struct inode *inode) 1188int generic_drop_inode(struct inode *inode)
1190{ 1189{
1191 const struct super_operations *op = inode->i_sb->s_op; 1190 return !inode->i_nlink || hlist_unhashed(&inode->i_hash);
1192
1193 list_del_init(&inode->i_list);
1194 list_del_init(&inode->i_sb_list);
1195 WARN_ON(inode->i_state & I_NEW);
1196 inode->i_state |= I_FREEING;
1197 inodes_stat.nr_inodes--;
1198 spin_unlock(&inode_lock);
1199
1200 if (op->delete_inode) {
1201 void (*delete)(struct inode *) = op->delete_inode;
1202 /* Filesystems implementing their own
1203 * s_op->delete_inode are required to call
1204 * truncate_inode_pages and clear_inode()
1205 * internally */
1206 delete(inode);
1207 } else {
1208 truncate_inode_pages(&inode->i_data, 0);
1209 clear_inode(inode);
1210 }
1211 spin_lock(&inode_lock);
1212 hlist_del_init(&inode->i_hash);
1213 spin_unlock(&inode_lock);
1214 wake_up_inode(inode);
1215 BUG_ON(inode->i_state != I_CLEAR);
1216 destroy_inode(inode);
1217} 1191}
1218EXPORT_SYMBOL(generic_delete_inode); 1192EXPORT_SYMBOL_GPL(generic_drop_inode);
1219 1193
1220/** 1194/*
1221 * generic_detach_inode - remove inode from inode lists 1195 * Called when we're dropping the last reference
1222 * @inode: inode to remove 1196 * to an inode.
1223 *
1224 * Remove inode from inode lists, write it if it's dirty. This is just an
1225 * internal VFS helper exported for hugetlbfs. Do not use!
1226 * 1197 *
1227 * 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.
1228 */ 1203 */
1229int generic_detach_inode(struct inode *inode) 1204static void iput_final(struct inode *inode)
1230{ 1205{
1231 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;
1232 1209
1233 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) {
1234 if (!(inode->i_state & (I_DIRTY|I_SYNC))) 1216 if (!(inode->i_state & (I_DIRTY|I_SYNC)))
1235 list_move(&inode->i_list, &inode_unused); 1217 list_move(&inode->i_list, &inode_unused);
1236 inodes_stat.nr_unused++; 1218 inodes_stat.nr_unused++;
1237 if (sb->s_flags & MS_ACTIVE) { 1219 if (sb->s_flags & MS_ACTIVE) {
1238 spin_unlock(&inode_lock); 1220 spin_unlock(&inode_lock);
1239 return 0; 1221 return;
1240 } 1222 }
1241 WARN_ON(inode->i_state & I_NEW); 1223 WARN_ON(inode->i_state & I_NEW);
1242 inode->i_state |= I_WILL_FREE; 1224 inode->i_state |= I_WILL_FREE;
@@ -1254,56 +1236,15 @@ int generic_detach_inode(struct inode *inode)
1254 inode->i_state |= I_FREEING; 1236 inode->i_state |= I_FREEING;
1255 inodes_stat.nr_inodes--; 1237 inodes_stat.nr_inodes--;
1256 spin_unlock(&inode_lock); 1238 spin_unlock(&inode_lock);
1257 return 1; 1239 evict(inode);
1258} 1240 spin_lock(&inode_lock);
1259EXPORT_SYMBOL_GPL(generic_detach_inode); 1241 hlist_del_init(&inode->i_hash);
1260 1242 spin_unlock(&inode_lock);
1261static void generic_forget_inode(struct inode *inode)
1262{
1263 if (!generic_detach_inode(inode))
1264 return;
1265 if (inode->i_data.nrpages)
1266 truncate_inode_pages(&inode->i_data, 0);
1267 clear_inode(inode);
1268 wake_up_inode(inode); 1243 wake_up_inode(inode);
1244 BUG_ON(inode->i_state != (I_FREEING | I_CLEAR));
1269 destroy_inode(inode); 1245 destroy_inode(inode);
1270} 1246}
1271 1247
1272/*
1273 * Normal UNIX filesystem behaviour: delete the
1274 * inode when the usage count drops to zero, and
1275 * i_nlink is zero.
1276 */
1277void generic_drop_inode(struct inode *inode)
1278{
1279 if (!inode->i_nlink)
1280 generic_delete_inode(inode);
1281 else
1282 generic_forget_inode(inode);
1283}
1284EXPORT_SYMBOL_GPL(generic_drop_inode);
1285
1286/*
1287 * Called when we're dropping the last reference
1288 * to an inode.
1289 *
1290 * Call the FS "drop()" function, defaulting to
1291 * the legacy UNIX filesystem behaviour..
1292 *
1293 * NOTE! NOTE! NOTE! We're called with the inode lock
1294 * held, and the drop function is supposed to release
1295 * the lock!
1296 */
1297static inline void iput_final(struct inode *inode)
1298{
1299 const struct super_operations *op = inode->i_sb->s_op;
1300 void (*drop)(struct inode *) = generic_drop_inode;
1301
1302 if (op && op->drop_inode)
1303 drop = op->drop_inode;
1304 drop(inode);
1305}
1306
1307/** 1248/**
1308 * iput - put an inode 1249 * iput - put an inode
1309 * @inode: inode to put 1250 * @inode: inode to put
@@ -1316,7 +1257,7 @@ static inline void iput_final(struct inode *inode)
1316void iput(struct inode *inode) 1257void iput(struct inode *inode)
1317{ 1258{
1318 if (inode) { 1259 if (inode) {
1319 BUG_ON(inode->i_state == I_CLEAR); 1260 BUG_ON(inode->i_state & I_CLEAR);
1320 1261
1321 if (atomic_dec_and_lock(&inode->i_count, &inode_lock)) 1262 if (atomic_dec_and_lock(&inode->i_count, &inode_lock))
1322 iput_final(inode); 1263 iput_final(inode);