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, 34 insertions, 79 deletions
diff --git a/fs/inode.c b/fs/inode.c
index 82ca3562a688..0e077619cbf6 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1183,58 +1183,51 @@ void remove_inode_hash(struct inode *inode)
1183} 1183}
1184EXPORT_SYMBOL(remove_inode_hash); 1184EXPORT_SYMBOL(remove_inode_hash);
1185 1185
1186int generic_delete_inode(struct inode *inode)
1187{
1188 return 1;
1189}
1190EXPORT_SYMBOL(generic_delete_inode);
1191
1186/* 1192/*
1187 * Tell the filesystem that this inode is no longer of any interest and should 1193 * Normal UNIX filesystem behaviour: delete the
1188 * be completely destroyed. 1194 * inode when the usage count drops to zero, and
1189 * 1195 * i_nlink is zero.
1190 * We leave the inode in the inode hash table until *after* the filesystem's
1191 * ->delete_inode completes. This ensures that an iget (such as nfsd might
1192 * instigate) will always find up-to-date information either in the hash or on
1193 * disk.
1194 *
1195 * I_FREEING is set so that no-one will take a new reference to the inode while
1196 * it is being deleted.
1197 */ 1196 */
1198void generic_delete_inode(struct inode *inode) 1197int generic_drop_inode(struct inode *inode)
1199{ 1198{
1200 list_del_init(&inode->i_list); 1199 return !inode->i_nlink || hlist_unhashed(&inode->i_hash);
1201 list_del_init(&inode->i_sb_list);
1202 WARN_ON(inode->i_state & I_NEW);
1203 inode->i_state |= I_FREEING;
1204 inodes_stat.nr_inodes--;
1205 spin_unlock(&inode_lock);
1206
1207 evict(inode);
1208
1209 spin_lock(&inode_lock);
1210 hlist_del_init(&inode->i_hash);
1211 spin_unlock(&inode_lock);
1212 wake_up_inode(inode);
1213 BUG_ON(inode->i_state != (I_FREEING | I_CLEAR));
1214 destroy_inode(inode);
1215} 1200}
1216EXPORT_SYMBOL(generic_delete_inode); 1201EXPORT_SYMBOL_GPL(generic_drop_inode);
1217 1202
1218/** 1203/*
1219 * generic_detach_inode - remove inode from inode lists 1204 * Called when we're dropping the last reference
1220 * @inode: inode to remove 1205 * to an inode.
1221 *
1222 * Remove inode from inode lists, write it if it's dirty. This is just an
1223 * internal VFS helper exported for hugetlbfs. Do not use!
1224 * 1206 *
1225 * Returns 1 if inode should be completely destroyed. 1207 * Call the FS "drop_inode()" function, defaulting to
1208 * the legacy UNIX filesystem behaviour. If it tells
1209 * us to evict inode, do so. Otherwise, retain inode
1210 * in cache if fs is alive, sync and evict if fs is
1211 * shutting down.
1226 */ 1212 */
1227static int generic_detach_inode(struct inode *inode) 1213static void iput_final(struct inode *inode)
1228{ 1214{
1229 struct super_block *sb = inode->i_sb; 1215 struct super_block *sb = inode->i_sb;
1216 const struct super_operations *op = inode->i_sb->s_op;
1217 int drop;
1218
1219 if (op && op->drop_inode)
1220 drop = op->drop_inode(inode);
1221 else
1222 drop = generic_drop_inode(inode);
1230 1223
1231 if (!hlist_unhashed(&inode->i_hash)) { 1224 if (!drop) {
1232 if (!(inode->i_state & (I_DIRTY|I_SYNC))) 1225 if (!(inode->i_state & (I_DIRTY|I_SYNC)))
1233 list_move(&inode->i_list, &inode_unused); 1226 list_move(&inode->i_list, &inode_unused);
1234 inodes_stat.nr_unused++; 1227 inodes_stat.nr_unused++;
1235 if (sb->s_flags & MS_ACTIVE) { 1228 if (sb->s_flags & MS_ACTIVE) {
1236 spin_unlock(&inode_lock); 1229 spin_unlock(&inode_lock);
1237 return 0; 1230 return;
1238 } 1231 }
1239 WARN_ON(inode->i_state & I_NEW); 1232 WARN_ON(inode->i_state & I_NEW);
1240 inode->i_state |= I_WILL_FREE; 1233 inode->i_state |= I_WILL_FREE;
@@ -1252,53 +1245,15 @@ static int generic_detach_inode(struct inode *inode)
1252 inode->i_state |= I_FREEING; 1245 inode->i_state |= I_FREEING;
1253 inodes_stat.nr_inodes--; 1246 inodes_stat.nr_inodes--;
1254 spin_unlock(&inode_lock); 1247 spin_unlock(&inode_lock);
1255 return 1;
1256}
1257
1258static void generic_forget_inode(struct inode *inode)
1259{
1260 if (!generic_detach_inode(inode))
1261 return;
1262 evict(inode); 1248 evict(inode);
1249 spin_lock(&inode_lock);
1250 hlist_del_init(&inode->i_hash);
1251 spin_unlock(&inode_lock);
1263 wake_up_inode(inode); 1252 wake_up_inode(inode);
1253 BUG_ON(inode->i_state != (I_FREEING | I_CLEAR));
1264 destroy_inode(inode); 1254 destroy_inode(inode);
1265} 1255}
1266 1256
1267/*
1268 * Normal UNIX filesystem behaviour: delete the
1269 * inode when the usage count drops to zero, and
1270 * i_nlink is zero.
1271 */
1272void generic_drop_inode(struct inode *inode)
1273{
1274 if (!inode->i_nlink)
1275 generic_delete_inode(inode);
1276 else
1277 generic_forget_inode(inode);
1278}
1279EXPORT_SYMBOL_GPL(generic_drop_inode);
1280
1281/*
1282 * Called when we're dropping the last reference
1283 * to an inode.
1284 *
1285 * Call the FS "drop()" function, defaulting to
1286 * the legacy UNIX filesystem behaviour..
1287 *
1288 * NOTE! NOTE! NOTE! We're called with the inode lock
1289 * held, and the drop function is supposed to release
1290 * the lock!
1291 */
1292static inline void iput_final(struct inode *inode)
1293{
1294 const struct super_operations *op = inode->i_sb->s_op;
1295 void (*drop)(struct inode *) = generic_drop_inode;
1296
1297 if (op && op->drop_inode)
1298 drop = op->drop_inode;
1299 drop(inode);
1300}
1301
1302/** 1257/**
1303 * iput - put an inode 1258 * iput - put an inode
1304 * @inode: inode to put 1259 * @inode: inode to put