diff options
author | Alexey Dobriyan <adobriyan@gmail.com> | 2016-12-12 19:45:32 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-12-12 21:55:09 -0500 |
commit | 1270dd8d994039b677d0504ba7260873d608bf75 (patch) | |
tree | ced0d62305e9cfa38afb22f6eed06e59e499763d /fs/proc/base.c | |
parent | bac5f5d56bbcb0ef7d3a926dd28b5f1db09117b7 (diff) |
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>
Diffstat (limited to 'fs/proc/base.c')
-rw-r--r-- | fs/proc/base.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c index 04a5fcad4c34..9b99df4893a4 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -104,6 +104,9 @@ | |||
104 | * in /proc for a task before it execs a suid executable. | 104 | * in /proc for a task before it execs a suid executable. |
105 | */ | 105 | */ |
106 | 106 | ||
107 | static u8 nlink_tid; | ||
108 | static u8 nlink_tgid; | ||
109 | |||
107 | struct pid_entry { | 110 | struct pid_entry { |
108 | const char *name; | 111 | const char *name; |
109 | unsigned int len; | 112 | unsigned int len; |
@@ -139,13 +142,13 @@ struct pid_entry { | |||
139 | * Count the number of hardlinks for the pid_entry table, excluding the . | 142 | * Count the number of hardlinks for the pid_entry table, excluding the . |
140 | * and .. links. | 143 | * and .. links. |
141 | */ | 144 | */ |
142 | static unsigned int pid_entry_count_dirs(const struct pid_entry *entries, | 145 | static unsigned int __init pid_entry_nlink(const struct pid_entry *entries, |
143 | unsigned int n) | 146 | unsigned int n) |
144 | { | 147 | { |
145 | unsigned int i; | 148 | unsigned int i; |
146 | unsigned int count; | 149 | unsigned int count; |
147 | 150 | ||
148 | count = 0; | 151 | count = 2; |
149 | for (i = 0; i < n; ++i) { | 152 | for (i = 0; i < n; ++i) { |
150 | if (S_ISDIR(entries[i].mode)) | 153 | if (S_ISDIR(entries[i].mode)) |
151 | ++count; | 154 | ++count; |
@@ -3068,8 +3071,7 @@ static int proc_pid_instantiate(struct inode *dir, | |||
3068 | inode->i_fop = &proc_tgid_base_operations; | 3071 | inode->i_fop = &proc_tgid_base_operations; |
3069 | inode->i_flags|=S_IMMUTABLE; | 3072 | inode->i_flags|=S_IMMUTABLE; |
3070 | 3073 | ||
3071 | set_nlink(inode, 2 + pid_entry_count_dirs(tgid_base_stuff, | 3074 | set_nlink(inode, nlink_tgid); |
3072 | ARRAY_SIZE(tgid_base_stuff))); | ||
3073 | 3075 | ||
3074 | d_set_d_op(dentry, &pid_dentry_operations); | 3076 | d_set_d_op(dentry, &pid_dentry_operations); |
3075 | 3077 | ||
@@ -3361,8 +3363,7 @@ static int proc_task_instantiate(struct inode *dir, | |||
3361 | inode->i_fop = &proc_tid_base_operations; | 3363 | inode->i_fop = &proc_tid_base_operations; |
3362 | inode->i_flags|=S_IMMUTABLE; | 3364 | inode->i_flags|=S_IMMUTABLE; |
3363 | 3365 | ||
3364 | set_nlink(inode, 2 + pid_entry_count_dirs(tid_base_stuff, | 3366 | set_nlink(inode, nlink_tid); |
3365 | ARRAY_SIZE(tid_base_stuff))); | ||
3366 | 3367 | ||
3367 | d_set_d_op(dentry, &pid_dentry_operations); | 3368 | d_set_d_op(dentry, &pid_dentry_operations); |
3368 | 3369 | ||
@@ -3552,3 +3553,9 @@ static const struct file_operations proc_task_operations = { | |||
3552 | .iterate_shared = proc_task_readdir, | 3553 | .iterate_shared = proc_task_readdir, |
3553 | .llseek = generic_file_llseek, | 3554 | .llseek = generic_file_llseek, |
3554 | }; | 3555 | }; |
3556 | |||
3557 | void __init set_proc_pid_nlink(void) | ||
3558 | { | ||
3559 | nlink_tid = pid_entry_nlink(tid_base_stuff, ARRAY_SIZE(tid_base_stuff)); | ||
3560 | nlink_tgid = pid_entry_nlink(tgid_base_stuff, ARRAY_SIZE(tgid_base_stuff)); | ||
3561 | } | ||