Skip to content

Commit 168e153

Browse files
committed
Merge branch 'work.icache' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull vfs inode freeing updates from Al Viro: "Introduction of separate method for RCU-delayed part of ->destroy_inode() (if any). Pretty much as posted, except that destroy_inode() stashes ->free_inode into the victim (anon-unioned with ->i_fops) before scheduling i_callback() and the last two patches (sockfs conversion and folding struct socket_wq into struct socket) are excluded - that pair should go through netdev once davem reopens his tree" * 'work.icache' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (58 commits) orangefs: make use of ->free_inode() shmem: make use of ->free_inode() hugetlb: make use of ->free_inode() overlayfs: make use of ->free_inode() jfs: switch to ->free_inode() fuse: switch to ->free_inode() ext4: make use of ->free_inode() ecryptfs: make use of ->free_inode() ceph: use ->free_inode() btrfs: use ->free_inode() afs: switch to use of ->free_inode() dax: make use of ->free_inode() ntfs: switch to ->free_inode() securityfs: switch to ->free_inode() apparmor: switch to ->free_inode() rpcpipe: switch to ->free_inode() bpf: switch to ->free_inode() mqueue: switch to ->free_inode() ufs: switch to ->free_inode() coda: switch to ->free_inode() ...
2 parents 8ff468c + f276ae0 commit 168e153

74 files changed

Lines changed: 230 additions & 493 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/filesystems/Locking‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ set: exclusive
118118
--------------------------- super_operations ---------------------------
119119
prototypes:
120120
struct inode *(*alloc_inode)(struct super_block *sb);
121+
void (*free_inode)(struct inode *);
121122
void (*destroy_inode)(struct inode *);
122123
void (*dirty_inode) (struct inode *, int flags);
123124
int (*write_inode) (struct inode *, struct writeback_control *wbc);
@@ -139,6 +140,7 @@ locking rules:
139140
All may block [not true, see below]
140141
s_umount
141142
alloc_inode:
143+
free_inode: called from RCU callback
142144
destroy_inode:
143145
dirty_inode:
144146
write_inode:

‎Documentation/filesystems/porting‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,3 +638,28 @@ in your dentry operations instead.
638638
inode to d_splice_alias() will also do the right thing (equivalent of
639639
d_add(dentry, NULL); return NULL;), so that kind of special cases
640640
also doesn't need a separate treatment.
641+
--
642+
[strongly recommended]
643+
take the RCU-delayed parts of ->destroy_inode() into a new method -
644+
->free_inode(). If ->destroy_inode() becomes empty - all the better,
645+
just get rid of it. Synchronous work (e.g. the stuff that can't
646+
be done from an RCU callback, or any WARN_ON() where we want the
647+
stack trace) *might* be movable to ->evict_inode(); however,
648+
that goes only for the things that are not needed to balance something
649+
done by ->alloc_inode(). IOW, if it's cleaning up the stuff that
650+
might have accumulated over the life of in-core inode, ->evict_inode()
651+
might be a fit.
652+
653+
Rules for inode destruction:
654+
* if ->destroy_inode() is non-NULL, it gets called
655+
* if ->free_inode() is non-NULL, it gets scheduled by call_rcu()
656+
* combination of NULL ->destroy_inode and NULL ->free_inode is
657+
treated as NULL/free_inode_nonrcu, to preserve the compatibility.
658+
659+
Note that the callback (be it via ->free_inode() or explicit call_rcu()
660+
in ->destroy_inode()) is *NOT* ordered wrt superblock destruction;
661+
as the matter of fact, the superblock and all associated structures
662+
might be already gone. The filesystem driver is guaranteed to be still
663+
there, but that's it. Freeing memory in the callback is fine; doing
664+
more than that is possible, but requires a lot of care and is best
665+
avoided.

‎arch/powerpc/platforms/cell/spufs/inode.c‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,11 @@ spufs_alloc_inode(struct super_block *sb)
7171
return &ei->vfs_inode;
7272
}
7373

74-
static void spufs_i_callback(struct rcu_head *head)
74+
static void spufs_free_inode(struct inode *inode)
7575
{
76-
struct inode *inode = container_of(head, struct inode, i_rcu);
7776
kmem_cache_free(spufs_inode_cache, SPUFS_I(inode));
7877
}
7978

80-
static void spufs_destroy_inode(struct inode *inode)
81-
{
82-
call_rcu(&inode->i_rcu, spufs_i_callback);
83-
}
84-
8579
static void
8680
spufs_init_once(void *p)
8781
{
@@ -739,7 +733,7 @@ spufs_fill_super(struct super_block *sb, void *data, int silent)
739733
struct spufs_sb_info *info;
740734
static const struct super_operations s_ops = {
741735
.alloc_inode = spufs_alloc_inode,
742-
.destroy_inode = spufs_destroy_inode,
736+
.free_inode = spufs_free_inode,
743737
.statfs = simple_statfs,
744738
.evict_inode = spufs_evict_inode,
745739
.show_options = spufs_show_options,

‎drivers/dax/super.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,9 @@ static struct dax_device *to_dax_dev(struct inode *inode)
412412
return container_of(inode, struct dax_device, inode);
413413
}
414414

415-
static void dax_i_callback(struct rcu_head *head)
415+
static void dax_free_inode(struct inode *inode)
416416
{
417-
struct inode *inode = container_of(head, struct inode, i_rcu);
418417
struct dax_device *dax_dev = to_dax_dev(inode);
419-
420418
kfree(dax_dev->host);
421419
dax_dev->host = NULL;
422420
if (inode->i_rdev)
@@ -427,16 +425,15 @@ static void dax_i_callback(struct rcu_head *head)
427425
static void dax_destroy_inode(struct inode *inode)
428426
{
429427
struct dax_device *dax_dev = to_dax_dev(inode);
430-
431428
WARN_ONCE(test_bit(DAXDEV_ALIVE, &dax_dev->flags),
432429
"kill_dax() must be called before final iput()\n");
433-
call_rcu(&inode->i_rcu, dax_i_callback);
434430
}
435431

436432
static const struct super_operations dax_sops = {
437433
.statfs = simple_statfs,
438434
.alloc_inode = dax_alloc_inode,
439435
.destroy_inode = dax_destroy_inode,
436+
.free_inode = dax_free_inode,
440437
.drop_inode = generic_delete_inode,
441438
};
442439

‎drivers/staging/erofs/super.c‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ static struct inode *alloc_inode(struct super_block *sb)
5757
return &vi->vfs_inode;
5858
}
5959

60-
static void i_callback(struct rcu_head *head)
60+
static void free_inode(struct inode *inode)
6161
{
62-
struct inode *inode = container_of(head, struct inode, i_rcu);
6362
struct erofs_vnode *vi = EROFS_V(inode);
6463

6564
/* be careful RCU symlink path (see ext4_inode_info->i_data)! */
@@ -71,11 +70,6 @@ static void i_callback(struct rcu_head *head)
7170
kmem_cache_free(erofs_inode_cachep, vi);
7271
}
7372

74-
static void destroy_inode(struct inode *inode)
75-
{
76-
call_rcu(&inode->i_rcu, i_callback);
77-
}
78-
7973
static int superblock_read(struct super_block *sb)
8074
{
8175
struct erofs_sb_info *sbi;
@@ -668,7 +662,7 @@ static int erofs_remount(struct super_block *sb, int *flags, char *data)
668662
const struct super_operations erofs_sops = {
669663
.put_super = erofs_put_super,
670664
.alloc_inode = alloc_inode,
671-
.destroy_inode = destroy_inode,
665+
.free_inode = free_inode,
672666
.statfs = erofs_statfs,
673667
.show_options = erofs_show_options,
674668
.remount_fs = erofs_remount,

‎fs/9p/v9fs_vfs.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ extern const struct file_operations v9fs_mmap_file_operations_dotl;
5858
extern struct kmem_cache *v9fs_inode_cache;
5959

6060
struct inode *v9fs_alloc_inode(struct super_block *sb);
61-
void v9fs_destroy_inode(struct inode *inode);
61+
void v9fs_free_inode(struct inode *inode);
6262
struct inode *v9fs_get_inode(struct super_block *sb, umode_t mode, dev_t);
6363
int v9fs_init_inode(struct v9fs_session_info *v9ses,
6464
struct inode *inode, umode_t mode, dev_t);

‎fs/9p/vfs_inode.c‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,21 +253,15 @@ struct inode *v9fs_alloc_inode(struct super_block *sb)
253253
}
254254

255255
/**
256-
* v9fs_destroy_inode - destroy an inode
256+
* v9fs_free_inode - destroy an inode
257257
*
258258
*/
259259

260-
static void v9fs_i_callback(struct rcu_head *head)
260+
void v9fs_free_inode(struct inode *inode)
261261
{
262-
struct inode *inode = container_of(head, struct inode, i_rcu);
263262
kmem_cache_free(v9fs_inode_cache, V9FS_I(inode));
264263
}
265264

266-
void v9fs_destroy_inode(struct inode *inode)
267-
{
268-
call_rcu(&inode->i_rcu, v9fs_i_callback);
269-
}
270-
271265
int v9fs_init_inode(struct v9fs_session_info *v9ses,
272266
struct inode *inode, umode_t mode, dev_t rdev)
273267
{

‎fs/9p/vfs_super.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ static int v9fs_write_inode_dotl(struct inode *inode,
344344

345345
static const struct super_operations v9fs_super_ops = {
346346
.alloc_inode = v9fs_alloc_inode,
347-
.destroy_inode = v9fs_destroy_inode,
347+
.free_inode = v9fs_free_inode,
348348
.statfs = simple_statfs,
349349
.evict_inode = v9fs_evict_inode,
350350
.show_options = v9fs_show_options,
@@ -354,7 +354,7 @@ static const struct super_operations v9fs_super_ops = {
354354

355355
static const struct super_operations v9fs_super_ops_dotl = {
356356
.alloc_inode = v9fs_alloc_inode,
357-
.destroy_inode = v9fs_destroy_inode,
357+
.free_inode = v9fs_free_inode,
358358
.statfs = v9fs_statfs,
359359
.drop_inode = v9fs_drop_inode,
360360
.evict_inode = v9fs_evict_inode,

‎fs/adfs/super.c‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,11 @@ static struct inode *adfs_alloc_inode(struct super_block *sb)
248248
return &ei->vfs_inode;
249249
}
250250

251-
static void adfs_i_callback(struct rcu_head *head)
251+
static void adfs_free_inode(struct inode *inode)
252252
{
253-
struct inode *inode = container_of(head, struct inode, i_rcu);
254253
kmem_cache_free(adfs_inode_cachep, ADFS_I(inode));
255254
}
256255

257-
static void adfs_destroy_inode(struct inode *inode)
258-
{
259-
call_rcu(&inode->i_rcu, adfs_i_callback);
260-
}
261-
262256
static void init_once(void *foo)
263257
{
264258
struct adfs_inode_info *ei = (struct adfs_inode_info *) foo;
@@ -290,7 +284,7 @@ static void destroy_inodecache(void)
290284

291285
static const struct super_operations adfs_sops = {
292286
.alloc_inode = adfs_alloc_inode,
293-
.destroy_inode = adfs_destroy_inode,
287+
.free_inode = adfs_free_inode,
294288
.drop_inode = generic_delete_inode,
295289
.write_inode = adfs_write_inode,
296290
.put_super = adfs_put_super,

‎fs/affs/super.c‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,11 @@ static struct inode *affs_alloc_inode(struct super_block *sb)
111111
return &i->vfs_inode;
112112
}
113113

114-
static void affs_i_callback(struct rcu_head *head)
114+
static void affs_free_inode(struct inode *inode)
115115
{
116-
struct inode *inode = container_of(head, struct inode, i_rcu);
117116
kmem_cache_free(affs_inode_cachep, AFFS_I(inode));
118117
}
119118

120-
static void affs_destroy_inode(struct inode *inode)
121-
{
122-
call_rcu(&inode->i_rcu, affs_i_callback);
123-
}
124-
125119
static void init_once(void *foo)
126120
{
127121
struct affs_inode_info *ei = (struct affs_inode_info *) foo;
@@ -155,7 +149,7 @@ static void destroy_inodecache(void)
155149

156150
static const struct super_operations affs_sops = {
157151
.alloc_inode = affs_alloc_inode,
158-
.destroy_inode = affs_destroy_inode,
152+
.free_inode = affs_free_inode,
159153
.write_inode = affs_write_inode,
160154
.evict_inode = affs_evict_inode,
161155
.put_super = affs_put_super,

0 commit comments

Comments
 (0)