提交 5381e169 编写于 作者: O Oleg Nesterov 提交者: Linus Torvalds

proc: introduce proc_mem_open()

Extract the mm_access() code from __mem_open() into the new helper,
proc_mem_open(), the next patch will add another caller.
Signed-off-by: NOleg Nesterov <oleg@redhat.com>
Acked-by: NKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: NCyrill Gorcunov <gorcunov@openvz.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 4db7d0ee
...@@ -632,29 +632,35 @@ static const struct file_operations proc_single_file_operations = { ...@@ -632,29 +632,35 @@ static const struct file_operations proc_single_file_operations = {
.release = single_release, .release = single_release,
}; };
static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode)
{ {
struct task_struct *task = get_proc_task(file_inode(file)); struct task_struct *task = get_proc_task(inode);
struct mm_struct *mm; struct mm_struct *mm = ERR_PTR(-ESRCH);
if (!task) if (task) {
return -ESRCH; mm = mm_access(task, mode);
put_task_struct(task);
mm = mm_access(task, mode); if (!IS_ERR_OR_NULL(mm)) {
put_task_struct(task); /* ensure this mm_struct can't be freed */
atomic_inc(&mm->mm_count);
/* but do not pin its memory */
mmput(mm);
}
}
return mm;
}
static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
{
struct mm_struct *mm = proc_mem_open(inode, mode);
if (IS_ERR(mm)) if (IS_ERR(mm))
return PTR_ERR(mm); return PTR_ERR(mm);
if (mm) {
/* ensure this mm_struct can't be freed */
atomic_inc(&mm->mm_count);
/* but do not pin its memory */
mmput(mm);
}
file->private_data = mm; file->private_data = mm;
return 0; return 0;
} }
......
...@@ -278,6 +278,8 @@ struct proc_maps_private { ...@@ -278,6 +278,8 @@ struct proc_maps_private {
#endif #endif
}; };
struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode);
extern const struct file_operations proc_pid_maps_operations; extern const struct file_operations proc_pid_maps_operations;
extern const struct file_operations proc_tid_maps_operations; extern const struct file_operations proc_tid_maps_operations;
extern const struct file_operations proc_pid_numa_maps_operations; extern const struct file_operations proc_pid_numa_maps_operations;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册