mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-12 05:48:40 +00:00
fs/proc: calculate /proc/* and /proc/*/task/* nlink at init time
Runtime nlink calculation works but meh. I don't know how to do it at compile time, but I know how to do it at init time. Shift "2+" part into init time as a bonus. Link: http://lkml.kernel.org/r/20161122195549.GB29812@avx2 Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Reviewed-by: Vegard Nossum <vegard.nossum@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
bac5f5d56b
commit
1270dd8d99
3 changed files with 15 additions and 6 deletions
|
@ -104,6 +104,9 @@
|
||||||
* in /proc for a task before it execs a suid executable.
|
* in /proc for a task before it execs a suid executable.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static u8 nlink_tid;
|
||||||
|
static u8 nlink_tgid;
|
||||||
|
|
||||||
struct pid_entry {
|
struct pid_entry {
|
||||||
const char *name;
|
const char *name;
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
|
@ -139,13 +142,13 @@ struct pid_entry {
|
||||||
* Count the number of hardlinks for the pid_entry table, excluding the .
|
* Count the number of hardlinks for the pid_entry table, excluding the .
|
||||||
* and .. links.
|
* and .. links.
|
||||||
*/
|
*/
|
||||||
static unsigned int pid_entry_count_dirs(const struct pid_entry *entries,
|
static unsigned int __init pid_entry_nlink(const struct pid_entry *entries,
|
||||||
unsigned int n)
|
unsigned int n)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
|
|
||||||
count = 0;
|
count = 2;
|
||||||
for (i = 0; i < n; ++i) {
|
for (i = 0; i < n; ++i) {
|
||||||
if (S_ISDIR(entries[i].mode))
|
if (S_ISDIR(entries[i].mode))
|
||||||
++count;
|
++count;
|
||||||
|
@ -3068,8 +3071,7 @@ static int proc_pid_instantiate(struct inode *dir,
|
||||||
inode->i_fop = &proc_tgid_base_operations;
|
inode->i_fop = &proc_tgid_base_operations;
|
||||||
inode->i_flags|=S_IMMUTABLE;
|
inode->i_flags|=S_IMMUTABLE;
|
||||||
|
|
||||||
set_nlink(inode, 2 + pid_entry_count_dirs(tgid_base_stuff,
|
set_nlink(inode, nlink_tgid);
|
||||||
ARRAY_SIZE(tgid_base_stuff)));
|
|
||||||
|
|
||||||
d_set_d_op(dentry, &pid_dentry_operations);
|
d_set_d_op(dentry, &pid_dentry_operations);
|
||||||
|
|
||||||
|
@ -3361,8 +3363,7 @@ static int proc_task_instantiate(struct inode *dir,
|
||||||
inode->i_fop = &proc_tid_base_operations;
|
inode->i_fop = &proc_tid_base_operations;
|
||||||
inode->i_flags|=S_IMMUTABLE;
|
inode->i_flags|=S_IMMUTABLE;
|
||||||
|
|
||||||
set_nlink(inode, 2 + pid_entry_count_dirs(tid_base_stuff,
|
set_nlink(inode, nlink_tid);
|
||||||
ARRAY_SIZE(tid_base_stuff)));
|
|
||||||
|
|
||||||
d_set_d_op(dentry, &pid_dentry_operations);
|
d_set_d_op(dentry, &pid_dentry_operations);
|
||||||
|
|
||||||
|
@ -3552,3 +3553,9 @@ static const struct file_operations proc_task_operations = {
|
||||||
.iterate_shared = proc_task_readdir,
|
.iterate_shared = proc_task_readdir,
|
||||||
.llseek = generic_file_llseek,
|
.llseek = generic_file_llseek,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void __init set_proc_pid_nlink(void)
|
||||||
|
{
|
||||||
|
nlink_tid = pid_entry_nlink(tid_base_stuff, ARRAY_SIZE(tid_base_stuff));
|
||||||
|
nlink_tgid = pid_entry_nlink(tgid_base_stuff, ARRAY_SIZE(tgid_base_stuff));
|
||||||
|
}
|
||||||
|
|
|
@ -211,6 +211,7 @@ extern const struct inode_operations proc_link_inode_operations;
|
||||||
extern const struct inode_operations proc_pid_link_inode_operations;
|
extern const struct inode_operations proc_pid_link_inode_operations;
|
||||||
|
|
||||||
extern void proc_init_inodecache(void);
|
extern void proc_init_inodecache(void);
|
||||||
|
void set_proc_pid_nlink(void);
|
||||||
extern struct inode *proc_get_inode(struct super_block *, struct proc_dir_entry *);
|
extern struct inode *proc_get_inode(struct super_block *, struct proc_dir_entry *);
|
||||||
extern int proc_fill_super(struct super_block *, void *data, int flags);
|
extern int proc_fill_super(struct super_block *, void *data, int flags);
|
||||||
extern void proc_entry_rundown(struct proc_dir_entry *);
|
extern void proc_entry_rundown(struct proc_dir_entry *);
|
||||||
|
|
|
@ -122,6 +122,7 @@ void __init proc_root_init(void)
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
proc_init_inodecache();
|
proc_init_inodecache();
|
||||||
|
set_proc_pid_nlink();
|
||||||
err = register_filesystem(&proc_fs_type);
|
err = register_filesystem(&proc_fs_type);
|
||||||
if (err)
|
if (err)
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue