Skip to content

Commit f90f3ca

Browse files
committed
proc: Use d_invalidate in proc_prune_siblings_dcache
The function d_prune_aliases has the problem that it will only prune aliases thare are completely unused. It will not remove aliases for the dcache or even think of removing mounts from the dcache. For that behavior d_invalidate is needed. To use d_invalidate replace d_prune_aliases with d_find_alias followed by d_invalidate and dput. For completeness the directory and the non-directory cases are separated because in theory (although not in currently in practice for proc) directories can only ever have a single dentry while non-directories can have hardlinks and thus multiple dentries. As part of this separation use d_find_any_alias for directories to spare d_find_alias the extra work of doing that. Plus the differences between d_find_any_alias and d_find_alias makes it clear why the directory and non-directory code and not share code. To make it clear these routines now invalidate dentries rename proc_prune_siblings_dache to proc_invalidate_siblings_dcache, and rename proc_sys_prune_dcache proc_sys_invalidate_dcache. V2: Split the directory and non-directory cases. To make this code robust to future changes in proc. Signed-off-by: "Eric W. Biederman" <[email protected]>
1 parent 080f627 commit f90f3ca

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

fs/proc/inode.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ 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)
106+
void proc_invalidate_siblings_dcache(struct hlist_head *inodes, spinlock_t *lock)
107107
{
108108
struct inode *inode;
109109
struct proc_inode *ei;
@@ -137,7 +137,19 @@ void proc_prune_siblings_dcache(struct hlist_head *inodes, spinlock_t *lock)
137137
continue;
138138
}
139139

140-
d_prune_aliases(inode);
140+
if (S_ISDIR(inode->i_mode)) {
141+
struct dentry *dir = d_find_any_alias(inode);
142+
if (dir) {
143+
d_invalidate(dir);
144+
dput(dir);
145+
}
146+
} else {
147+
struct dentry *dentry;
148+
while ((dentry = d_find_alias(inode))) {
149+
d_invalidate(dentry);
150+
dput(dentry);
151+
}
152+
}
141153
iput(inode);
142154

143155
rcu_read_lock();

fs/proc/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +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);
213+
void proc_invalidate_siblings_dcache(struct hlist_head *inodes, spinlock_t *lock);
214214
void set_proc_pid_nlink(void);
215215
extern struct inode *proc_get_inode(struct super_block *, struct proc_dir_entry *);
216216
extern void proc_entry_rundown(struct proc_dir_entry *);

fs/proc/proc_sysctl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@ static void unuse_table(struct ctl_table_header *p)
267267
complete(p->unregistering);
268268
}
269269

270-
static void proc_sys_prune_dcache(struct ctl_table_header *head)
270+
static void proc_sys_invalidate_dcache(struct ctl_table_header *head)
271271
{
272-
proc_prune_siblings_dcache(&head->inodes, &sysctl_lock);
272+
proc_invalidate_siblings_dcache(&head->inodes, &sysctl_lock);
273273
}
274274

275275
/* called under sysctl_lock, will reacquire if has to wait */
@@ -291,10 +291,10 @@ static void start_unregistering(struct ctl_table_header *p)
291291
spin_unlock(&sysctl_lock);
292292
}
293293
/*
294-
* Prune dentries for unregistered sysctls: namespaced sysctls
294+
* Invalidate dentries for unregistered sysctls: namespaced sysctls
295295
* can have duplicate names and contaminate dcache very badly.
296296
*/
297-
proc_sys_prune_dcache(p);
297+
proc_sys_invalidate_dcache(p);
298298
/*
299299
* do not remove from the list until nobody holds it; walking the
300300
* list in do_sysctl() relies on that.

0 commit comments

Comments
 (0)