From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andreas Gruenbacher Subject: [d_path 5/7] Remove duplicate proc code Date: Fri, 20 Apr 2007 01:23:08 +0200 Message-ID: <20070419234704.340406253@schurl.suse.de> References: <20070412090809.917795000@suse.de> <200704170335.21805.agruen@suse.de> <20070417182126.2327d89d@the-village.bc.nu> <20070419232303.300441585@schurl.suse.de> Cc: jjohansen@suse.de, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fsdevel@vger.kernel.org, chrisw@sous-sol.org, Andrew Morton To: Alan Cox Return-path: In-Reply-To: <20070417182126.2327d89d@the-village.bc.nu> Content-Disposition: inline; filename=proc-mounts-cleanup.diff Sender: linux-security-module-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org Remove some duplicate code in generating the contents of /proc/mounts and /proc/$pid/mountstats. Signed-off-by: Andreas Gruenbacher --- 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 SUSE Labs, SUSE LINUX Products GmbH GF: Markus Rex, HRB 16746 (AG Nuernberg) GPG: AF77 FAD1 1819 D442 400F 4BC8 409A 6903 4FDD EE02