login
Header Space

 
 

[d_path 5/7] Remove duplicate proc code

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Alan Cox <alan@...>
Cc: <jjohansen@...>, <linux-kernel@...>, <linux-security-module@...>, <linux-fsdevel@...>, <chrisw@...>, Andrew Morton <akpm@...>
Date: Thursday, April 19, 2007 - 7:23 pm

Remove some duplicate code in generating the contents of /proc/mounts and
/proc/$pid/mountstats.

Signed-off-by: Andreas Gruenbacher <agruen@suse.de>

---
 fs/proc/base.c |   45 +++++++++++++++------------------------------
 1 file changed, 15 insertions(+), 30 deletions(-)

--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -359,7 +359,8 @@ struct proc_mounts {
 	int event;
 };
 
-static int mounts_open(struct inode *inode, struct file *file)
+static int __mounts_open(struct inode *inode, struct file *file,
+			 struct seq_operations *seq_ops)
 {
 	struct task_struct *task = get_proc_task(inode);
 	struct mnt_namespace *ns = NULL;
@@ -382,7 +383,7 @@ static int mounts_open(struct inode *ino
 		p = kmalloc(sizeof(struct proc_mounts), GFP_KERNEL);
 		if (p) {
 			file->private_data = &p->m;
-			ret = seq_open(file, &mounts_op);
+			ret = seq_open(file, seq_ops);
 			if (!ret) {
 				p->m.private = ns;
 				p->event = ns->event;
@@ -395,17 +396,25 @@ static int mounts_open(struct inode *ino
 	return ret;
 }
 
+static int mounts_open(struct inode *inode, struct file *file)
+{
+	return __mounts_open(inode, file, &mounts_op);
+}
+
 static int mounts_release(struct inode *inode, struct file *file)
 {
-	struct seq_file *m = file->private_data;
-	struct mnt_namespace *ns = m->private;
+	struct proc_mounts *p =
+		container_of(file->private_data, struct proc_mounts, m);
+	struct mnt_namespace *ns = p->m.private;
+
 	put_mnt_ns(ns);
 	return seq_release(inode, file);
 }
 
 static unsigned mounts_poll(struct file *file, poll_table *wait)
 {
-	struct proc_mounts *p = file->private_data;
+	struct proc_mounts *p =
+		container_of(file->private_data, struct proc_mounts, m);
 	struct mnt_namespace *ns = p->m.private;
 	unsigned res = 0;
 
@@ -432,31 +441,7 @@ static const struct file_operations proc
 extern struct seq_operations mountstats_op;
 static int mountstats_open(struct inode *inode, struct file *file)
 {
-	int ret = seq_open(file, &mountstats_op);
-
-	if (!ret) {
-		struct seq_file *m = file->private_data;
-		struct mnt_namespace *mnt_ns = NULL;
-		struct task_struct *task = get_proc_task(inode);
-
-		if (task) {
-			task_lock(task);
-			if (task->nsproxy)
-				mnt_ns = task->nsproxy->mnt_ns;
-			if (mnt_ns)
-				get_mnt_ns(mnt_ns);
-			task_unlock(task);
-			put_task_struct(task);
-		}
-
-		if (mnt_ns)
-			m->private = mnt_ns;
-		else {
-			seq_release(inode, file);
-			ret = -EINVAL;
-		}
-	}
-	return ret;
+	return __mounts_open(inode, file, &mountstats_op);
 }
 
 static const struct file_operations proc_mountstats_operations = {

-- 
Andreas Gruenbacher <agruen@suse.de>
SUSE Labs, SUSE LINUX Products GmbH
GF: Markus Rex, HRB 16746 (AG Nuernberg)

GPG: AF77 FAD1 1819 D442 400F  4BC8 409A 6903 4FDD EE02

-
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [AppArmor 31/41] Fix __d_path() for lazy unmounts and ma..., Andreas Gruenbacher, (Sun Apr 15, 1:40 pm)
Re: [AppArmor 31/41] Fix __d_path() for lazy unmounts and ma..., Andreas Gruenbacher, (Mon Apr 16, 9:35 pm)
[d_path 0/7] Fixes to d_path: Respin, Andreas Gruenbacher, (Thu Apr 19, 7:23 pm)
Re: [d_path 0/7] Fixes to d_path: Respin, Alan Cox, (Fri Apr 20, 5:30 am)
Re: [d_path 0/7] Fixes to d_path: Respin, Andreas Gruenbacher, (Fri Apr 20, 7:45 am)
Re: [d_path 0/7] Fixes to d_path: Respin, Ulrich Drepper, (Fri Apr 20, 11:15 am)
Re: [d_path 0/7] Fixes to d_path: Respin, Andreas Gruenbacher, (Fri Apr 20, 11:21 am)
Re: [d_path 0/7] Fixes to d_path: Respin, Ulrich Drepper, (Fri Apr 20, 11:24 am)
Re: [d_path 0/7] Fixes to d_path: Respin, Andreas Gruenbacher, (Fri Apr 20, 12:40 pm)
Re: [d_path 0/7] Fixes to d_path: Respin, Ulrich Drepper, (Fri Apr 20, 3:17 pm)
Re: [d_path 0/7] Fixes to d_path: Respin, Andreas Gruenbacher, (Sat Apr 21, 3:04 pm)
Re: [d_path 0/7] Fixes to d_path: Respin, Christoph Hellwig, (Sun Apr 22, 5:10 am)
Re: [d_path 0/7] Fixes to d_path: Respin, Andreas Gruenbacher, (Sun Apr 22, 11:48 am)
Re: [d_path 0/7] Fixes to d_path: Respin, Ulrich Drepper, (Sat Apr 21, 3:46 pm)
Re: [d_path 0/7] Fixes to d_path: Respin, Miklos Szeredi, (Fri Apr 20, 4:44 pm)
[d_path 2/7] Make d_path() consistent across mount operations, Andreas Gruenbacher, (Thu Apr 19, 7:23 pm)
[d_path 4/7] Make getcwd() only return valid paths, Andreas Gruenbacher, (Thu Apr 19, 7:23 pm)
[d_path 5/7] Remove duplicate proc code, Andreas Gruenbacher, (Thu Apr 19, 7:23 pm)
[d_path 3/7] Add d_namespace_path() to compute namespace rel..., Andreas Gruenbacher, (Thu Apr 19, 7:23 pm)
Re: [d_path 3/7] Add d_namespace_path() to compute namespace..., Andreas Gruenbacher, (Sat Apr 21, 12:16 pm)
[d_path 7/7] Distinguish between connected and disconnected ..., Andreas Gruenbacher, (Thu Apr 19, 7:23 pm)
[d_path 1/7] Fix __d_path() for lazy unmounts and make it un..., Andreas Gruenbacher, (Thu Apr 19, 7:23 pm)
[d_path 6/7] Filter out disconnected paths from /proc/mounts, Andreas Gruenbacher, (Thu Apr 19, 7:23 pm)
speck-geostationary