提交 6e66b52b 编写于 作者: E Eric W. Biederman 提交者: Linus Torvalds

[PATCH] proc: Fix the link count for /proc/<pid>/task

Use getattr to get an accurate link count when needed.  This is cheaper and
more accurate than trying to derive it by walking the thread list of a
process.

Especially as it happens when needed stat instead of at readdir time.
Signed-off-by: NEric W. Biederman <ebiederm@xmission.com>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 0f2fe20f
...@@ -1532,6 +1532,7 @@ static struct dentry *proc_lookupfd(struct inode * dir, struct dentry * dentry, ...@@ -1532,6 +1532,7 @@ static struct dentry *proc_lookupfd(struct inode * dir, struct dentry * dentry,
static int proc_task_readdir(struct file * filp, void * dirent, filldir_t filldir); static int proc_task_readdir(struct file * filp, void * dirent, filldir_t filldir);
static struct dentry *proc_task_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd); static struct dentry *proc_task_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *nd);
static int proc_task_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
static struct file_operations proc_fd_operations = { static struct file_operations proc_fd_operations = {
.read = generic_read_dir, .read = generic_read_dir,
...@@ -1552,6 +1553,7 @@ static struct inode_operations proc_fd_inode_operations = { ...@@ -1552,6 +1553,7 @@ static struct inode_operations proc_fd_inode_operations = {
static struct inode_operations proc_task_inode_operations = { static struct inode_operations proc_task_inode_operations = {
.lookup = proc_task_lookup, .lookup = proc_task_lookup,
.getattr = proc_task_getattr,
}; };
#ifdef CONFIG_SECURITY #ifdef CONFIG_SECURITY
...@@ -1658,7 +1660,7 @@ static struct dentry *proc_pident_lookup(struct inode *dir, ...@@ -1658,7 +1660,7 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
*/ */
switch(p->type) { switch(p->type) {
case PROC_TGID_TASK: case PROC_TGID_TASK:
inode->i_nlink = 2 + get_tid_list(2, NULL, dir); inode->i_nlink = 2;
inode->i_op = &proc_task_inode_operations; inode->i_op = &proc_task_inode_operations;
inode->i_fop = &proc_task_operations; inode->i_fop = &proc_task_operations;
break; break;
...@@ -2261,7 +2263,6 @@ static int proc_task_readdir(struct file * filp, void * dirent, filldir_t filldi ...@@ -2261,7 +2263,6 @@ static int proc_task_readdir(struct file * filp, void * dirent, filldir_t filldi
} }
nr_tids = get_tid_list(pos, tid_array, inode); nr_tids = get_tid_list(pos, tid_array, inode);
inode->i_nlink = pos + nr_tids;
for (i = 0; i < nr_tids; i++) { for (i = 0; i < nr_tids; i++) {
unsigned long j = PROC_NUMBUF; unsigned long j = PROC_NUMBUF;
...@@ -2281,3 +2282,19 @@ static int proc_task_readdir(struct file * filp, void * dirent, filldir_t filldi ...@@ -2281,3 +2282,19 @@ static int proc_task_readdir(struct file * filp, void * dirent, filldir_t filldi
filp->f_pos = pos; filp->f_pos = pos;
return retval; return retval;
} }
static int proc_task_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
{
struct inode *inode = dentry->d_inode;
struct task_struct *p = proc_task(inode);
generic_fillattr(inode, stat);
if (pid_alive(p)) {
task_lock(p);
if (p->signal)
stat->nlink += atomic_read(&p->signal->count);
task_unlock(p);
}
return 0;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册