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

From: Eric W. Biederman
Date: Thu Feb 23 2006 - 11:09:37 EST



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.

Signed-off-by: Eric W. Biederman <ebiederm@xxxxxxxxxxxx>


---

fs/proc/base.c | 21 +++++++++++++++++++--
1 files changed, 19 insertions(+), 2 deletions(-)

eec5c7327c53b862025a595985a72fa01509c5e4
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 81c2f2a..1a39258 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1466,6 +1466,7 @@ out:

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 int proc_task_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);

static struct file_operations proc_fd_operations = {
.read = generic_read_dir,
@@ -1486,6 +1487,7 @@ static struct inode_operations proc_fd_i

static struct inode_operations proc_task_inode_operations = {
.lookup = proc_task_lookup,
+ .getattr = proc_task_getattr,
};

#ifdef CONFIG_SECURITY
@@ -1592,7 +1594,7 @@ static struct dentry *proc_pident_lookup
*/
switch(p->type) {
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_fop = &proc_task_operations;
break;
@@ -2189,7 +2191,6 @@ static int proc_task_readdir(struct file
}

nr_tids = get_tid_list(pos, tid_array, inode);
- inode->i_nlink = pos + nr_tids;

for (i = 0; i < nr_tids; i++) {
unsigned long j = PROC_NUMBUF;
@@ -2209,3 +2210,19 @@ out:
filp->f_pos = pos;
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;
+}
--
1.2.2.g709a

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/