[patch 1/8] procfs: Move /proc/pid/fd[info] handling code to fd.[ch]

2012-08-15 Thread Cyrill Gorcunov
This patch prepares the ground for further extension of
/proc/pid/fd[info] handling code by moving fdinfo handling
code into fs/proc/fd.c.

I think such move makes both fs/proc/base.c and fs/proc/fd.c
easier to read.

Signed-off-by: Cyrill Gorcunov 
Acked-by: Pavel Emelyanov 
CC: Al Viro 
CC: Alexey Dobriyan 
CC: Andrew Morton 
CC: James Bottomley 
---
 fs/proc/Makefile   |2 
 fs/proc/base.c |  388 -
 fs/proc/fd.c   |  351 +++
 fs/proc/fd.h   |   14 +
 fs/proc/internal.h |   48 ++
 5 files changed, 416 insertions(+), 387 deletions(-)

Index: linux-2.6.git/fs/proc/Makefile
===
--- linux-2.6.git.orig/fs/proc/Makefile
+++ linux-2.6.git/fs/proc/Makefile
@@ -8,7 +8,7 @@ proc-y  := nommu.o task_nommu.o
 proc-$(CONFIG_MMU) := mmu.o task_mmu.o
 
 proc-y   += inode.o root.o base.o generic.o array.o \
-   proc_tty.o
+   proc_tty.o fd.o
 proc-y += cmdline.o
 proc-y += consoles.o
 proc-y += cpuinfo.o
Index: linux-2.6.git/fs/proc/base.c
===
--- linux-2.6.git.orig/fs/proc/base.c
+++ linux-2.6.git/fs/proc/base.c
@@ -90,6 +90,7 @@
 #endif
 #include 
 #include "internal.h"
+#include "fd.h"
 
 /* NOTE:
  * Implementing inode permission operations in /proc is almost
@@ -136,8 +137,6 @@ struct pid_entry {
NULL, _single_file_operations, \
{ .proc_show = show } )
 
-static int proc_fd_permission(struct inode *inode, int mask);
-
 /*
  * Count the number of hardlinks for the pid_entry table, excluding the .
  * and .. links.
@@ -1492,7 +1491,7 @@ out:
return error;
 }
 
-static const struct inode_operations proc_pid_link_inode_operations = {
+const struct inode_operations proc_pid_link_inode_operations = {
.readlink   = proc_pid_readlink,
.follow_link= proc_pid_follow_link,
.setattr= proc_setattr,
@@ -1501,21 +1500,6 @@ static const struct inode_operations pro
 
 /* building an inode */
 
-static int task_dumpable(struct task_struct *task)
-{
-   int dumpable = 0;
-   struct mm_struct *mm;
-
-   task_lock(task);
-   mm = task->mm;
-   if (mm)
-   dumpable = get_dumpable(mm);
-   task_unlock(task);
-   if(dumpable == 1)
-   return 1;
-   return 0;
-}
-
 struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct 
*task)
 {
struct inode * inode;
@@ -1641,15 +1625,6 @@ int pid_revalidate(struct dentry *dentry
return 0;
 }
 
-static int pid_delete_dentry(const struct dentry * dentry)
-{
-   /* Is the task we represent dead?
-* If so, then don't put the dentry on the lru list,
-* kill it immediately.
-*/
-   return !proc_pid(dentry->d_inode)->tasks[PIDTYPE_PID].first;
-}
-
 const struct dentry_operations pid_dentry_operations =
 {
.d_revalidate   = pid_revalidate,
@@ -1712,289 +1687,6 @@ end_instantiate:
return filldir(dirent, name, len, filp->f_pos, ino, type);
 }
 
-static unsigned name_to_int(struct dentry *dentry)
-{
-   const char *name = dentry->d_name.name;
-   int len = dentry->d_name.len;
-   unsigned n = 0;
-
-   if (len > 1 && *name == '0')
-   goto out;
-   while (len-- > 0) {
-   unsigned c = *name++ - '0';
-   if (c > 9)
-   goto out;
-   if (n >= (~0U-9)/10)
-   goto out;
-   n *= 10;
-   n += c;
-   }
-   return n;
-out:
-   return ~0U;
-}
-
-#define PROC_FDINFO_MAX 64
-
-static int proc_fd_info(struct inode *inode, struct path *path, char *info)
-{
-   struct task_struct *task = get_proc_task(inode);
-   struct files_struct *files = NULL;
-   struct file *file;
-   int fd = proc_fd(inode);
-
-   if (task) {
-   files = get_files_struct(task);
-   put_task_struct(task);
-   }
-   if (files) {
-   /*
-* We are not taking a ref to the file structure, so we must
-* hold ->file_lock.
-*/
-   spin_lock(>file_lock);
-   file = fcheck_files(files, fd);
-   if (file) {
-   unsigned int f_flags;
-   struct fdtable *fdt;
-
-   fdt = files_fdtable(files);
-   f_flags = file->f_flags & ~O_CLOEXEC;
-   if (close_on_exec(fd, fdt))
-   f_flags |= O_CLOEXEC;
-
-   if (path) {
-   *path = file->f_path;
-   path_get(>f_path);
-   }
-   if (info)
-   snprintf(info, 

[patch 1/8] procfs: Move /proc/pid/fd[info] handling code to fd.[ch]

2012-08-15 Thread Cyrill Gorcunov
This patch prepares the ground for further extension of
/proc/pid/fd[info] handling code by moving fdinfo handling
code into fs/proc/fd.c.

I think such move makes both fs/proc/base.c and fs/proc/fd.c
easier to read.

Signed-off-by: Cyrill Gorcunov gorcu...@openvz.org
Acked-by: Pavel Emelyanov xe...@parallels.com
CC: Al Viro v...@zeniv.linux.org.uk
CC: Alexey Dobriyan adobri...@gmail.com
CC: Andrew Morton a...@linux-foundation.org
CC: James Bottomley jbottom...@parallels.com
---
 fs/proc/Makefile   |2 
 fs/proc/base.c |  388 -
 fs/proc/fd.c   |  351 +++
 fs/proc/fd.h   |   14 +
 fs/proc/internal.h |   48 ++
 5 files changed, 416 insertions(+), 387 deletions(-)

Index: linux-2.6.git/fs/proc/Makefile
===
--- linux-2.6.git.orig/fs/proc/Makefile
+++ linux-2.6.git/fs/proc/Makefile
@@ -8,7 +8,7 @@ proc-y  := nommu.o task_nommu.o
 proc-$(CONFIG_MMU) := mmu.o task_mmu.o
 
 proc-y   += inode.o root.o base.o generic.o array.o \
-   proc_tty.o
+   proc_tty.o fd.o
 proc-y += cmdline.o
 proc-y += consoles.o
 proc-y += cpuinfo.o
Index: linux-2.6.git/fs/proc/base.c
===
--- linux-2.6.git.orig/fs/proc/base.c
+++ linux-2.6.git/fs/proc/base.c
@@ -90,6 +90,7 @@
 #endif
 #include trace/events/oom.h
 #include internal.h
+#include fd.h
 
 /* NOTE:
  * Implementing inode permission operations in /proc is almost
@@ -136,8 +137,6 @@ struct pid_entry {
NULL, proc_single_file_operations, \
{ .proc_show = show } )
 
-static int proc_fd_permission(struct inode *inode, int mask);
-
 /*
  * Count the number of hardlinks for the pid_entry table, excluding the .
  * and .. links.
@@ -1492,7 +1491,7 @@ out:
return error;
 }
 
-static const struct inode_operations proc_pid_link_inode_operations = {
+const struct inode_operations proc_pid_link_inode_operations = {
.readlink   = proc_pid_readlink,
.follow_link= proc_pid_follow_link,
.setattr= proc_setattr,
@@ -1501,21 +1500,6 @@ static const struct inode_operations pro
 
 /* building an inode */
 
-static int task_dumpable(struct task_struct *task)
-{
-   int dumpable = 0;
-   struct mm_struct *mm;
-
-   task_lock(task);
-   mm = task-mm;
-   if (mm)
-   dumpable = get_dumpable(mm);
-   task_unlock(task);
-   if(dumpable == 1)
-   return 1;
-   return 0;
-}
-
 struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct 
*task)
 {
struct inode * inode;
@@ -1641,15 +1625,6 @@ int pid_revalidate(struct dentry *dentry
return 0;
 }
 
-static int pid_delete_dentry(const struct dentry * dentry)
-{
-   /* Is the task we represent dead?
-* If so, then don't put the dentry on the lru list,
-* kill it immediately.
-*/
-   return !proc_pid(dentry-d_inode)-tasks[PIDTYPE_PID].first;
-}
-
 const struct dentry_operations pid_dentry_operations =
 {
.d_revalidate   = pid_revalidate,
@@ -1712,289 +1687,6 @@ end_instantiate:
return filldir(dirent, name, len, filp-f_pos, ino, type);
 }
 
-static unsigned name_to_int(struct dentry *dentry)
-{
-   const char *name = dentry-d_name.name;
-   int len = dentry-d_name.len;
-   unsigned n = 0;
-
-   if (len  1  *name == '0')
-   goto out;
-   while (len--  0) {
-   unsigned c = *name++ - '0';
-   if (c  9)
-   goto out;
-   if (n = (~0U-9)/10)
-   goto out;
-   n *= 10;
-   n += c;
-   }
-   return n;
-out:
-   return ~0U;
-}
-
-#define PROC_FDINFO_MAX 64
-
-static int proc_fd_info(struct inode *inode, struct path *path, char *info)
-{
-   struct task_struct *task = get_proc_task(inode);
-   struct files_struct *files = NULL;
-   struct file *file;
-   int fd = proc_fd(inode);
-
-   if (task) {
-   files = get_files_struct(task);
-   put_task_struct(task);
-   }
-   if (files) {
-   /*
-* We are not taking a ref to the file structure, so we must
-* hold -file_lock.
-*/
-   spin_lock(files-file_lock);
-   file = fcheck_files(files, fd);
-   if (file) {
-   unsigned int f_flags;
-   struct fdtable *fdt;
-
-   fdt = files_fdtable(files);
-   f_flags = file-f_flags  ~O_CLOEXEC;
-   if (close_on_exec(fd, fdt))
-   f_flags |= O_CLOEXEC;
-
-   if (path) {
-   *path = file-f_path;
-   

Re: [patch 1/8] procfs: Move /proc/pid/fd[info] handling code to fd.[ch]

2012-08-14 Thread Pavel Emelyanov
On 08/14/2012 06:03 PM, Cyrill Gorcunov wrote:
> This patch prepares the ground for further extension of
> /proc/pid/fd[info] handling code by moving fdinfo handling
> code into fs/proc/fd.c.
> 
> I think such move makes both fs/proc/base.c and fs/proc/fd.c
> easier to read.
> 
> Signed-off-by: Cyrill Gorcunov 
> CC: Al Viro 
> CC: Alexey Dobriyan 
> CC: Andrew Morton 
> CC: Pavel Emelyanov 
> CC: James Bottomley 

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


[patch 1/8] procfs: Move /proc/pid/fd[info] handling code to fd.[ch]

2012-08-14 Thread Cyrill Gorcunov
This patch prepares the ground for further extension of
/proc/pid/fd[info] handling code by moving fdinfo handling
code into fs/proc/fd.c.

I think such move makes both fs/proc/base.c and fs/proc/fd.c
easier to read.

Signed-off-by: Cyrill Gorcunov 
CC: Al Viro 
CC: Alexey Dobriyan 
CC: Andrew Morton 
CC: Pavel Emelyanov 
CC: James Bottomley 
---
 fs/proc/Makefile   |2 
 fs/proc/base.c |  388 -
 fs/proc/fd.c   |  351 +++
 fs/proc/fd.h   |   14 +
 fs/proc/internal.h |   48 ++
 5 files changed, 416 insertions(+), 387 deletions(-)

Index: linux-2.6.git/fs/proc/Makefile
===
--- linux-2.6.git.orig/fs/proc/Makefile
+++ linux-2.6.git/fs/proc/Makefile
@@ -8,7 +8,7 @@ proc-y  := nommu.o task_nommu.o
 proc-$(CONFIG_MMU) := mmu.o task_mmu.o
 
 proc-y   += inode.o root.o base.o generic.o array.o \
-   proc_tty.o
+   proc_tty.o fd.o
 proc-y += cmdline.o
 proc-y += consoles.o
 proc-y += cpuinfo.o
Index: linux-2.6.git/fs/proc/base.c
===
--- linux-2.6.git.orig/fs/proc/base.c
+++ linux-2.6.git/fs/proc/base.c
@@ -90,6 +90,7 @@
 #endif
 #include 
 #include "internal.h"
+#include "fd.h"
 
 /* NOTE:
  * Implementing inode permission operations in /proc is almost
@@ -136,8 +137,6 @@ struct pid_entry {
NULL, _single_file_operations, \
{ .proc_show = show } )
 
-static int proc_fd_permission(struct inode *inode, int mask);
-
 /*
  * Count the number of hardlinks for the pid_entry table, excluding the .
  * and .. links.
@@ -1492,7 +1491,7 @@ out:
return error;
 }
 
-static const struct inode_operations proc_pid_link_inode_operations = {
+const struct inode_operations proc_pid_link_inode_operations = {
.readlink   = proc_pid_readlink,
.follow_link= proc_pid_follow_link,
.setattr= proc_setattr,
@@ -1501,21 +1500,6 @@ static const struct inode_operations pro
 
 /* building an inode */
 
-static int task_dumpable(struct task_struct *task)
-{
-   int dumpable = 0;
-   struct mm_struct *mm;
-
-   task_lock(task);
-   mm = task->mm;
-   if (mm)
-   dumpable = get_dumpable(mm);
-   task_unlock(task);
-   if(dumpable == 1)
-   return 1;
-   return 0;
-}
-
 struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct 
*task)
 {
struct inode * inode;
@@ -1641,15 +1625,6 @@ int pid_revalidate(struct dentry *dentry
return 0;
 }
 
-static int pid_delete_dentry(const struct dentry * dentry)
-{
-   /* Is the task we represent dead?
-* If so, then don't put the dentry on the lru list,
-* kill it immediately.
-*/
-   return !proc_pid(dentry->d_inode)->tasks[PIDTYPE_PID].first;
-}
-
 const struct dentry_operations pid_dentry_operations =
 {
.d_revalidate   = pid_revalidate,
@@ -1712,289 +1687,6 @@ end_instantiate:
return filldir(dirent, name, len, filp->f_pos, ino, type);
 }
 
-static unsigned name_to_int(struct dentry *dentry)
-{
-   const char *name = dentry->d_name.name;
-   int len = dentry->d_name.len;
-   unsigned n = 0;
-
-   if (len > 1 && *name == '0')
-   goto out;
-   while (len-- > 0) {
-   unsigned c = *name++ - '0';
-   if (c > 9)
-   goto out;
-   if (n >= (~0U-9)/10)
-   goto out;
-   n *= 10;
-   n += c;
-   }
-   return n;
-out:
-   return ~0U;
-}
-
-#define PROC_FDINFO_MAX 64
-
-static int proc_fd_info(struct inode *inode, struct path *path, char *info)
-{
-   struct task_struct *task = get_proc_task(inode);
-   struct files_struct *files = NULL;
-   struct file *file;
-   int fd = proc_fd(inode);
-
-   if (task) {
-   files = get_files_struct(task);
-   put_task_struct(task);
-   }
-   if (files) {
-   /*
-* We are not taking a ref to the file structure, so we must
-* hold ->file_lock.
-*/
-   spin_lock(>file_lock);
-   file = fcheck_files(files, fd);
-   if (file) {
-   unsigned int f_flags;
-   struct fdtable *fdt;
-
-   fdt = files_fdtable(files);
-   f_flags = file->f_flags & ~O_CLOEXEC;
-   if (close_on_exec(fd, fdt))
-   f_flags |= O_CLOEXEC;
-
-   if (path) {
-   *path = file->f_path;
-   path_get(>f_path);
-   }
-   if (info)
-   snprintf(info, 

[patch 1/8] procfs: Move /proc/pid/fd[info] handling code to fd.[ch]

2012-08-14 Thread Cyrill Gorcunov
This patch prepares the ground for further extension of
/proc/pid/fd[info] handling code by moving fdinfo handling
code into fs/proc/fd.c.

I think such move makes both fs/proc/base.c and fs/proc/fd.c
easier to read.

Signed-off-by: Cyrill Gorcunov gorcu...@openvz.org
CC: Al Viro v...@zeniv.linux.org.uk
CC: Alexey Dobriyan adobri...@gmail.com
CC: Andrew Morton a...@linux-foundation.org
CC: Pavel Emelyanov xe...@parallels.com
CC: James Bottomley jbottom...@parallels.com
---
 fs/proc/Makefile   |2 
 fs/proc/base.c |  388 -
 fs/proc/fd.c   |  351 +++
 fs/proc/fd.h   |   14 +
 fs/proc/internal.h |   48 ++
 5 files changed, 416 insertions(+), 387 deletions(-)

Index: linux-2.6.git/fs/proc/Makefile
===
--- linux-2.6.git.orig/fs/proc/Makefile
+++ linux-2.6.git/fs/proc/Makefile
@@ -8,7 +8,7 @@ proc-y  := nommu.o task_nommu.o
 proc-$(CONFIG_MMU) := mmu.o task_mmu.o
 
 proc-y   += inode.o root.o base.o generic.o array.o \
-   proc_tty.o
+   proc_tty.o fd.o
 proc-y += cmdline.o
 proc-y += consoles.o
 proc-y += cpuinfo.o
Index: linux-2.6.git/fs/proc/base.c
===
--- linux-2.6.git.orig/fs/proc/base.c
+++ linux-2.6.git/fs/proc/base.c
@@ -90,6 +90,7 @@
 #endif
 #include trace/events/oom.h
 #include internal.h
+#include fd.h
 
 /* NOTE:
  * Implementing inode permission operations in /proc is almost
@@ -136,8 +137,6 @@ struct pid_entry {
NULL, proc_single_file_operations, \
{ .proc_show = show } )
 
-static int proc_fd_permission(struct inode *inode, int mask);
-
 /*
  * Count the number of hardlinks for the pid_entry table, excluding the .
  * and .. links.
@@ -1492,7 +1491,7 @@ out:
return error;
 }
 
-static const struct inode_operations proc_pid_link_inode_operations = {
+const struct inode_operations proc_pid_link_inode_operations = {
.readlink   = proc_pid_readlink,
.follow_link= proc_pid_follow_link,
.setattr= proc_setattr,
@@ -1501,21 +1500,6 @@ static const struct inode_operations pro
 
 /* building an inode */
 
-static int task_dumpable(struct task_struct *task)
-{
-   int dumpable = 0;
-   struct mm_struct *mm;
-
-   task_lock(task);
-   mm = task-mm;
-   if (mm)
-   dumpable = get_dumpable(mm);
-   task_unlock(task);
-   if(dumpable == 1)
-   return 1;
-   return 0;
-}
-
 struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct 
*task)
 {
struct inode * inode;
@@ -1641,15 +1625,6 @@ int pid_revalidate(struct dentry *dentry
return 0;
 }
 
-static int pid_delete_dentry(const struct dentry * dentry)
-{
-   /* Is the task we represent dead?
-* If so, then don't put the dentry on the lru list,
-* kill it immediately.
-*/
-   return !proc_pid(dentry-d_inode)-tasks[PIDTYPE_PID].first;
-}
-
 const struct dentry_operations pid_dentry_operations =
 {
.d_revalidate   = pid_revalidate,
@@ -1712,289 +1687,6 @@ end_instantiate:
return filldir(dirent, name, len, filp-f_pos, ino, type);
 }
 
-static unsigned name_to_int(struct dentry *dentry)
-{
-   const char *name = dentry-d_name.name;
-   int len = dentry-d_name.len;
-   unsigned n = 0;
-
-   if (len  1  *name == '0')
-   goto out;
-   while (len--  0) {
-   unsigned c = *name++ - '0';
-   if (c  9)
-   goto out;
-   if (n = (~0U-9)/10)
-   goto out;
-   n *= 10;
-   n += c;
-   }
-   return n;
-out:
-   return ~0U;
-}
-
-#define PROC_FDINFO_MAX 64
-
-static int proc_fd_info(struct inode *inode, struct path *path, char *info)
-{
-   struct task_struct *task = get_proc_task(inode);
-   struct files_struct *files = NULL;
-   struct file *file;
-   int fd = proc_fd(inode);
-
-   if (task) {
-   files = get_files_struct(task);
-   put_task_struct(task);
-   }
-   if (files) {
-   /*
-* We are not taking a ref to the file structure, so we must
-* hold -file_lock.
-*/
-   spin_lock(files-file_lock);
-   file = fcheck_files(files, fd);
-   if (file) {
-   unsigned int f_flags;
-   struct fdtable *fdt;
-
-   fdt = files_fdtable(files);
-   f_flags = file-f_flags  ~O_CLOEXEC;
-   if (close_on_exec(fd, fdt))
-   f_flags |= O_CLOEXEC;
-
-   if (path) {
-   *path = file-f_path;
-   

Re: [patch 1/8] procfs: Move /proc/pid/fd[info] handling code to fd.[ch]

2012-08-14 Thread Pavel Emelyanov
On 08/14/2012 06:03 PM, Cyrill Gorcunov wrote:
 This patch prepares the ground for further extension of
 /proc/pid/fd[info] handling code by moving fdinfo handling
 code into fs/proc/fd.c.
 
 I think such move makes both fs/proc/base.c and fs/proc/fd.c
 easier to read.
 
 Signed-off-by: Cyrill Gorcunov gorcu...@openvz.org
 CC: Al Viro v...@zeniv.linux.org.uk
 CC: Alexey Dobriyan adobri...@gmail.com
 CC: Andrew Morton a...@linux-foundation.org
 CC: Pavel Emelyanov xe...@parallels.com
 CC: James Bottomley jbottom...@parallels.com

Acked-by: Pavel Emelyanov xe...@parallels.com
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/