Commit 45321ac54316eaeeebde0b5f728a1791e500974c

Authored by Al Viro
1 parent 30140837f2

Make ->drop_inode() just return whether inode needs to be dropped

... and let iput_final() do the actual eviction or retention

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Showing 10 changed files with 60 additions and 103 deletions Side-by-side Diff

drivers/staging/pohmelfs/inode.c
... ... @@ -1223,7 +1223,7 @@
1223 1223 }
1224 1224 }
1225 1225  
1226   -static void pohmelfs_drop_inode(struct inode *inode)
  1226 +static int pohmelfs_drop_inode(struct inode *inode)
1227 1227 {
1228 1228 struct pohmelfs_sb *psb = POHMELFS_SB(inode->i_sb);
1229 1229 struct pohmelfs_inode *pi = POHMELFS_I(inode);
... ... @@ -1232,7 +1232,7 @@
1232 1232 list_del_init(&pi->inode_entry);
1233 1233 spin_unlock(&psb->ino_lock);
1234 1234  
1235   - generic_drop_inode(inode);
  1235 + return generic_drop_inode(inode);
1236 1236 }
1237 1237  
1238 1238 static struct pohmelfs_inode *pohmelfs_get_inode_from_list(struct pohmelfs_sb *psb,
... ... @@ -2395,7 +2395,7 @@
2395 2395 void btrfs_dirty_inode(struct inode *inode);
2396 2396 struct inode *btrfs_alloc_inode(struct super_block *sb);
2397 2397 void btrfs_destroy_inode(struct inode *inode);
2398   -void btrfs_drop_inode(struct inode *inode);
  2398 +int btrfs_drop_inode(struct inode *inode);
2399 2399 int btrfs_init_cachep(void);
2400 2400 void btrfs_destroy_cachep(void);
2401 2401 long btrfs_ioctl_trans_end(struct file *file);
... ... @@ -3943,7 +3943,7 @@
3943 3943 if (atomic_read(&inode->i_count) > 1)
3944 3944 d_prune_aliases(inode);
3945 3945 /*
3946   - * btrfs_drop_inode will remove it from
  3946 + * btrfs_drop_inode will have it removed from
3947 3947 * the inode cache when its usage count
3948 3948 * hits zero.
3949 3949 */
3950 3950  
3951 3951  
... ... @@ -6337,13 +6337,14 @@
6337 6337 kmem_cache_free(btrfs_inode_cachep, BTRFS_I(inode));
6338 6338 }
6339 6339  
6340   -void btrfs_drop_inode(struct inode *inode)
  6340 +int btrfs_drop_inode(struct inode *inode)
6341 6341 {
6342 6342 struct btrfs_root *root = BTRFS_I(inode)->root;
6343   - if (inode->i_nlink > 0 && btrfs_root_refs(&root->root_item) == 0)
6344   - generic_delete_inode(inode);
  6343 +
  6344 + if (btrfs_root_refs(&root->root_item) == 0)
  6345 + return 1;
6345 6346 else
6346   - generic_drop_inode(inode);
  6347 + return generic_drop_inode(inode);
6347 6348 }
6348 6349  
6349 6350 static void init_once(void *foo)
... ... @@ -480,14 +480,13 @@
480 480 return 0;
481 481 }
482 482  
483   -void cifs_drop_inode(struct inode *inode)
  483 +static int cifs_drop_inode(struct inode *inode)
484 484 {
485 485 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
486 486  
487   - if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
488   - return generic_drop_inode(inode);
489   -
490   - return generic_delete_inode(inode);
  487 + /* no serverino => unconditional eviction */
  488 + return !(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) ||
  489 + generic_drop_inode(inode);
491 490 }
492 491  
493 492 static const struct super_operations cifs_super_ops = {
... ... @@ -1191,7 +1191,7 @@
1191 1191 * node for later deallocation.
1192 1192 */
1193 1193  
1194   -static void gfs2_drop_inode(struct inode *inode)
  1194 +static int gfs2_drop_inode(struct inode *inode)
1195 1195 {
1196 1196 struct gfs2_inode *ip = GFS2_I(inode);
1197 1197  
... ... @@ -1200,7 +1200,7 @@
1200 1200 if (gl && test_bit(GLF_DEMOTE, &gl->gl_flags))
1201 1201 clear_nlink(inode);
1202 1202 }
1203   - generic_drop_inode(inode);
  1203 + return generic_drop_inode(inode);
1204 1204 }
1205 1205  
1206 1206 static int is_ancestor(const struct dentry *d1, const struct dentry *d2)
... ... @@ -1183,58 +1183,51 @@
1183 1183 }
1184 1184 EXPORT_SYMBOL(remove_inode_hash);
1185 1185  
  1186 +int generic_delete_inode(struct inode *inode)
  1187 +{
  1188 + return 1;
  1189 +}
  1190 +EXPORT_SYMBOL(generic_delete_inode);
  1191 +
1186 1192 /*
1187   - * Tell the filesystem that this inode is no longer of any interest and should
1188   - * be completely destroyed.
1189   - *
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.
  1193 + * Normal UNIX filesystem behaviour: delete the
  1194 + * inode when the usage count drops to zero, and
  1195 + * i_nlink is zero.
1197 1196 */
1198   -void generic_delete_inode(struct inode *inode)
  1197 +int generic_drop_inode(struct inode *inode)
1199 1198 {
1200   - list_del_init(&inode->i_list);
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);
  1199 + return !inode->i_nlink || hlist_unhashed(&inode->i_hash);
1215 1200 }
1216   -EXPORT_SYMBOL(generic_delete_inode);
  1201 +EXPORT_SYMBOL_GPL(generic_drop_inode);
1217 1202  
1218   -/**
1219   - * generic_detach_inode - remove inode from inode lists
1220   - * @inode: inode to remove
  1203 +/*
  1204 + * Called when we're dropping the last reference
  1205 + * to an inode.
1221 1206 *
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   - *
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 */
1227   -static int generic_detach_inode(struct inode *inode)
  1213 +static void iput_final(struct inode *inode)
1228 1214 {
1229 1215 struct super_block *sb = inode->i_sb;
  1216 + const struct super_operations *op = inode->i_sb->s_op;
  1217 + int drop;
1230 1218  
1231   - if (!hlist_unhashed(&inode->i_hash)) {
  1219 + if (op && op->drop_inode)
  1220 + drop = op->drop_inode(inode);
  1221 + else
  1222 + drop = generic_drop_inode(inode);
  1223 +
  1224 + if (!drop) {
1232 1225 if (!(inode->i_state & (I_DIRTY|I_SYNC)))
1233 1226 list_move(&inode->i_list, &inode_unused);
1234 1227 inodes_stat.nr_unused++;
1235 1228 if (sb->s_flags & MS_ACTIVE) {
1236 1229 spin_unlock(&inode_lock);
1237   - return 0;
  1230 + return;
1238 1231 }
1239 1232 WARN_ON(inode->i_state & I_NEW);
1240 1233 inode->i_state |= I_WILL_FREE;
1241 1234  
1242 1235  
1243 1236  
... ... @@ -1252,51 +1245,13 @@
1252 1245 inode->i_state |= I_FREEING;
1253 1246 inodes_stat.nr_inodes--;
1254 1247 spin_unlock(&inode_lock);
1255   - return 1;
1256   -}
1257   -
1258   -static void generic_forget_inode(struct inode *inode)
1259   -{
1260   - if (!generic_detach_inode(inode))
1261   - return;
1262 1248 evict(inode);
  1249 + spin_lock(&inode_lock);
  1250 + hlist_del_init(&inode->i_hash);
  1251 + spin_unlock(&inode_lock);
1263 1252 wake_up_inode(inode);
  1253 + BUG_ON(inode->i_state != (I_FREEING | I_CLEAR));
1264 1254 destroy_inode(inode);
1265   -}
1266   -
1267   -/*
1268   - * Normal UNIX filesystem behaviour: delete the
1269   - * inode when the usage count drops to zero, and
1270   - * i_nlink is zero.
1271   - */
1272   -void 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   -}
1279   -EXPORT_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   - */
1292   -static 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 1255 }
1301 1256  
1302 1257 /**
... ... @@ -287,7 +287,7 @@
287 287 }
288 288  
289 289 /* called with inode_lock held */
290   -static void logfs_drop_inode(struct inode *inode)
  290 +static int logfs_drop_inode(struct inode *inode)
291 291 {
292 292 struct logfs_super *super = logfs_super(inode->i_sb);
293 293 struct logfs_inode *li = logfs_inode(inode);
... ... @@ -295,7 +295,7 @@
295 295 spin_lock(&logfs_inode_lock);
296 296 list_move(&li->li_freeing_list, &super->s_freeing_list);
297 297 spin_unlock(&logfs_inode_lock);
298   - generic_drop_inode(inode);
  298 + return generic_drop_inode(inode);
299 299 }
300 300  
301 301 static void logfs_set_ino_generation(struct super_block *sb,
... ... @@ -1194,9 +1194,10 @@
1194 1194 /* Called under inode_lock, with no more references on the
1195 1195 * struct inode, so it's safe here to check the flags field
1196 1196 * and to manipulate i_nlink without any other locks. */
1197   -void ocfs2_drop_inode(struct inode *inode)
  1197 +int ocfs2_drop_inode(struct inode *inode)
1198 1198 {
1199 1199 struct ocfs2_inode_info *oi = OCFS2_I(inode);
  1200 + int res;
1200 1201  
1201 1202 mlog_entry_void();
1202 1203  
1203 1204  
1204 1205  
... ... @@ -1204,11 +1205,12 @@
1204 1205 (unsigned long long)oi->ip_blkno, inode->i_nlink, oi->ip_flags);
1205 1206  
1206 1207 if (oi->ip_flags & OCFS2_INODE_MAYBE_ORPHANED)
1207   - generic_delete_inode(inode);
  1208 + res = 1;
1208 1209 else
1209   - generic_drop_inode(inode);
  1210 + res = generic_drop_inode(inode);
1210 1211  
1211 1212 mlog_exit_void();
  1213 + return res;
1212 1214 }
1213 1215  
1214 1216 /*
... ... @@ -124,7 +124,7 @@
124 124 }
125 125  
126 126 void ocfs2_evict_inode(struct inode *inode);
127   -void ocfs2_drop_inode(struct inode *inode);
  127 +int ocfs2_drop_inode(struct inode *inode);
128 128  
129 129 /* Flags for ocfs2_iget() */
130 130 #define OCFS2_FI_FLAG_SYSFILE 0x1
... ... @@ -1562,7 +1562,7 @@
1562 1562  
1563 1563 void (*dirty_inode) (struct inode *);
1564 1564 int (*write_inode) (struct inode *, struct writeback_control *wbc);
1565   - void (*drop_inode) (struct inode *);
  1565 + int (*drop_inode) (struct inode *);
1566 1566 void (*evict_inode) (struct inode *);
1567 1567 void (*put_super) (struct super_block *);
1568 1568 void (*write_super) (struct super_block *);
... ... @@ -2164,8 +2164,8 @@
2164 2164 extern struct inode * igrab(struct inode *);
2165 2165 extern ino_t iunique(struct super_block *, ino_t);
2166 2166 extern int inode_needs_sync(struct inode *inode);
2167   -extern void generic_delete_inode(struct inode *inode);
2168   -extern void generic_drop_inode(struct inode *inode);
  2167 +extern int generic_delete_inode(struct inode *inode);
  2168 +extern int generic_drop_inode(struct inode *inode);
2169 2169  
2170 2170 extern struct inode *ilookup5_nowait(struct super_block *sb,
2171 2171 unsigned long hashval, int (*test)(struct inode *, void *),