Skip to content

Commit 26dbc60

Browse files
committed
proc: Generalize proc_sys_prune_dcache into proc_prune_siblings_dcache
This prepares the way for allowing the pid part of proc to use this dcache pruning code as well. Signed-off-by: Eric W. Biederman <[email protected]>
1 parent 0afa5ca commit 26dbc60

File tree

3 files changed

+40
-34
lines changed

3 files changed

+40
-34
lines changed

fs/proc/inode.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,44 @@ void __init proc_init_kmemcache(void)
103103
BUILD_BUG_ON(sizeof(struct proc_dir_entry) >= SIZEOF_PDE);
104104
}
105105

106+
void proc_prune_siblings_dcache(struct hlist_head *inodes, spinlock_t *lock)
107+
{
108+
struct inode *inode;
109+
struct proc_inode *ei;
110+
struct hlist_node *node;
111+
struct super_block *sb;
112+
113+
rcu_read_lock();
114+
for (;;) {
115+
node = hlist_first_rcu(inodes);
116+
if (!node)
117+
break;
118+
ei = hlist_entry(node, struct proc_inode, sibling_inodes);
119+
spin_lock(lock);
120+
hlist_del_init_rcu(&ei->sibling_inodes);
121+
spin_unlock(lock);
122+
123+
inode = &ei->vfs_inode;
124+
sb = inode->i_sb;
125+
if (!atomic_inc_not_zero(&sb->s_active))
126+
continue;
127+
inode = igrab(inode);
128+
rcu_read_unlock();
129+
if (unlikely(!inode)) {
130+
deactivate_super(sb);
131+
rcu_read_lock();
132+
continue;
133+
}
134+
135+
d_prune_aliases(inode);
136+
iput(inode);
137+
deactivate_super(sb);
138+
139+
rcu_read_lock();
140+
}
141+
rcu_read_unlock();
142+
}
143+
106144
static int proc_show_options(struct seq_file *seq, struct dentry *root)
107145
{
108146
struct super_block *sb = root->d_sb;

fs/proc/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ extern const struct inode_operations proc_pid_link_inode_operations;
210210
extern const struct super_operations proc_sops;
211211

212212
void proc_init_kmemcache(void);
213+
void proc_prune_siblings_dcache(struct hlist_head *inodes, spinlock_t *lock);
213214
void set_proc_pid_nlink(void);
214215
extern struct inode *proc_get_inode(struct super_block *, struct proc_dir_entry *);
215216
extern void proc_entry_rundown(struct proc_dir_entry *);

fs/proc/proc_sysctl.c

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -269,40 +269,7 @@ static void unuse_table(struct ctl_table_header *p)
269269

270270
static void proc_sys_prune_dcache(struct ctl_table_header *head)
271271
{
272-
struct inode *inode;
273-
struct proc_inode *ei;
274-
struct hlist_node *node;
275-
struct super_block *sb;
276-
277-
rcu_read_lock();
278-
for (;;) {
279-
node = hlist_first_rcu(&head->inodes);
280-
if (!node)
281-
break;
282-
ei = hlist_entry(node, struct proc_inode, sibling_inodes);
283-
spin_lock(&sysctl_lock);
284-
hlist_del_init_rcu(&ei->sibling_inodes);
285-
spin_unlock(&sysctl_lock);
286-
287-
inode = &ei->vfs_inode;
288-
sb = inode->i_sb;
289-
if (!atomic_inc_not_zero(&sb->s_active))
290-
continue;
291-
inode = igrab(inode);
292-
rcu_read_unlock();
293-
if (unlikely(!inode)) {
294-
deactivate_super(sb);
295-
rcu_read_lock();
296-
continue;
297-
}
298-
299-
d_prune_aliases(inode);
300-
iput(inode);
301-
deactivate_super(sb);
302-
303-
rcu_read_lock();
304-
}
305-
rcu_read_unlock();
272+
proc_prune_siblings_dcache(&head->inodes, &sysctl_lock);
306273
}
307274

308275
/* called under sysctl_lock, will reacquire if has to wait */

0 commit comments

Comments
 (0)