All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Eric W. Biederman" <ebiederm@xmission.com>
To: Andrew Morton <akpm@osdl.org>
Cc: <linux-kernel@vger.kernel.org>, <containers@lists.osdl.org>,
	"Eric W. Biederman" <ebiederm@xmission.com>
Subject: [PATCH 4/7] proc: Make the generation of the self symlink table driven.
Date: Tue, 15 Aug 2006 12:05:27 -0600	[thread overview]
Message-ID: <1155665132774-git-send-email-ebiederm@xmission.com> (raw)
In-Reply-To: <m1u04d98wa.fsf@ebiederm.dsl.xmission.com>

By not rolling our own inode we get a little more code reuse,
and things get a little simpler and we don't have special
cases to contend with later.

Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
---
 fs/proc/base.c |   41 ++++++++++++++++++-----------------------
 1 files changed, 18 insertions(+), 23 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index c46b42b..96e22d7 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1745,6 +1745,13 @@ static struct inode_operations proc_tgid
 	.setattr	= proc_setattr,
 };
 
+static struct pid_entry proc_base_stuff[] = {
+	NOD(PROC_TGID_INO,     "self",	S_IFLNK|S_IRWXUGO,
+		&proc_self_inode_operations, NULL, {}),
+	{}
+};
+
+
 /**
  * proc_flush_task -  Remove dcache entries for @task from the /proc dcache.
  *
@@ -1818,24 +1825,12 @@ struct dentry *proc_pid_lookup(struct in
 	struct dentry *result = ERR_PTR(-ENOENT);
 	struct task_struct *task;
 	struct inode *inode;
-	struct proc_inode *ei;
 	unsigned tgid;
 
-	if (dentry->d_name.len == 4 && !memcmp(dentry->d_name.name,"self",4)) {
-		inode = new_inode(dir->i_sb);
-		if (!inode)
-			return ERR_PTR(-ENOMEM);
-		ei = PROC_I(inode);
-		inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
-		inode->i_ino = fake_ino(0, PROC_TGID_INO);
-		ei->pde = NULL;
-		inode->i_mode = S_IFLNK|S_IRWXUGO;
-		inode->i_uid = inode->i_gid = 0;
-		inode->i_size = 64;
-		inode->i_op = &proc_self_inode_operations;
-		d_add(dentry, inode);
-		return NULL;
-	}
+	result = proc_pident_lookup(dir, dentry, proc_base_stuff);
+	if (!IS_ERR(result) || PTR_ERR(result) != -ENOENT)
+		goto out;
+
 	tgid = name_to_int(dentry);
 	if (tgid == ~0U)
 		goto out;
@@ -1950,14 +1945,13 @@ int proc_pid_readdir(struct file * filp,
 	struct task_struct *task;
 	int tgid;
 
-	if (!nr) {
-		ino_t ino = fake_ino(0,PROC_TGID_INO);
-		if (filldir(dirent, "self", 4, filp->f_pos, ino, DT_LNK) < 0)
-			return 0;
-		filp->f_pos++;
-		nr++;
+	for (;nr < (ARRAY_SIZE(proc_base_stuff) - 1); filp->f_pos++, nr++) {
+		struct pid_entry *p = &proc_base_stuff[nr];
+		if (filldir(dirent, p->name, p->len, filp->f_pos,
+			    fake_ino(0, p->type), p->mode >> 12) < 0)
+			goto out;
 	}
-	nr -= 1;
+	nr -= ARRAY_SIZE(proc_base_stuff) - 1;
 
 	/* f_version caches the tgid value that the last readdir call couldn't
 	 * return. lseek aka telldir automagically resets f_version to 0.
@@ -1980,6 +1974,7 @@ int proc_pid_readdir(struct file * filp,
 			break;
 		}
 	}
+out:
 	return 0;
 }
 
-- 
1.4.2.rc3.g7e18e-dirty


  parent reply	other threads:[~2006-08-15 18:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-15 18:00 The rest of my proc cleanup Eric W. Biederman
2006-08-15 18:05 ` [PATCH 1/7] proc: Reorder the functions in base.c Eric W. Biederman
2006-08-15 18:05 ` [PATCH 2/7] proc: Modify proc_pident_lookup to be completely table driven Eric W. Biederman
2006-08-15 18:31   ` Dave Hansen
2006-08-15 18:55     ` Eric W. Biederman
2006-08-16 14:48   ` Jan Engelhardt
2006-08-15 18:05 ` [PATCH 3/7] proc: Give the root directory a task Eric W. Biederman
2006-08-15 18:05 ` Eric W. Biederman [this message]
2006-08-19  8:06   ` [PATCH 4/7] proc: Make the generation of the self symlink table driven Andrew Morton
2006-08-19  9:07     ` Eric W. Biederman
2006-08-19 16:03       ` Andrew Morton
2006-08-19 19:04         ` Eric W. Biederman
2006-08-19  9:54     ` Eric W. Biederman
2006-08-15 18:05 ` [PATCH 5/7] proc: Factor out an instantiate method from every lookup method Eric W. Biederman
2006-08-16 14:52   ` Jan Engelhardt
2006-08-15 18:05 ` [PATCH 6/7] proc: Remove the hard coded inode numbers Eric W. Biederman
2006-08-15 18:05 ` [PATCH 7/7] proc: Merge proc_tid_attr and proc_tgid_attr Eric W. Biederman
2006-08-15 18:33 ` The rest of my proc cleanup Paul Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1155665132774-git-send-email-ebiederm@xmission.com \
    --to=ebiederm@xmission.com \
    --cc=akpm@osdl.org \
    --cc=containers@lists.osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.