[PATCH] mark f_ops const in the inode
[pandora-kernel.git] / fs / proc / base.c
index 3b33f94..8f1f49c 100644 (file)
@@ -55,6 +55,7 @@
 #include <linux/proc_fs.h>
 #include <linux/stat.h>
 #include <linux/init.h>
+#include <linux/capability.h>
 #include <linux/file.h>
 #include <linux/string.h>
 #include <linux/seq_file.h>
@@ -70,6 +71,7 @@
 #include <linux/seccomp.h>
 #include <linux/cpuset.h>
 #include <linux/audit.h>
+#include <linux/poll.h>
 #include "internal.h"
 
 /*
@@ -102,8 +104,11 @@ enum pid_directory_inos {
        PROC_TGID_MAPS,
        PROC_TGID_NUMA_MAPS,
        PROC_TGID_MOUNTS,
+       PROC_TGID_MOUNTSTATS,
        PROC_TGID_WCHAN,
+#ifdef CONFIG_MMU
        PROC_TGID_SMAPS,
+#endif
 #ifdef CONFIG_SCHEDSTATS
        PROC_TGID_SCHEDSTAT,
 #endif
@@ -140,8 +145,11 @@ enum pid_directory_inos {
        PROC_TID_MAPS,
        PROC_TID_NUMA_MAPS,
        PROC_TID_MOUNTS,
+       PROC_TID_MOUNTSTATS,
        PROC_TID_WCHAN,
+#ifdef CONFIG_MMU
        PROC_TID_SMAPS,
+#endif
 #ifdef CONFIG_SCHEDSTATS
        PROC_TID_SCHEDSTAT,
 #endif
@@ -195,7 +203,10 @@ static struct pid_entry tgid_base_stuff[] = {
        E(PROC_TGID_ROOT,      "root",    S_IFLNK|S_IRWXUGO),
        E(PROC_TGID_EXE,       "exe",     S_IFLNK|S_IRWXUGO),
        E(PROC_TGID_MOUNTS,    "mounts",  S_IFREG|S_IRUGO),
+       E(PROC_TGID_MOUNTSTATS, "mountstats", S_IFREG|S_IRUSR),
+#ifdef CONFIG_MMU
        E(PROC_TGID_SMAPS,     "smaps",   S_IFREG|S_IRUGO),
+#endif
 #ifdef CONFIG_SECURITY
        E(PROC_TGID_ATTR,      "attr",    S_IFDIR|S_IRUGO|S_IXUGO),
 #endif
@@ -235,7 +246,9 @@ static struct pid_entry tid_base_stuff[] = {
        E(PROC_TID_ROOT,       "root",    S_IFLNK|S_IRWXUGO),
        E(PROC_TID_EXE,        "exe",     S_IFLNK|S_IRWXUGO),
        E(PROC_TID_MOUNTS,     "mounts",  S_IFREG|S_IRUGO),
+#ifdef CONFIG_MMU
        E(PROC_TID_SMAPS,      "smaps",   S_IFREG|S_IRUGO),
+#endif
 #ifdef CONFIG_SECURITY
        E(PROC_TID_ATTR,       "attr",    S_IFDIR|S_IRUGO|S_IXUGO),
 #endif
@@ -630,6 +643,7 @@ static struct file_operations proc_numa_maps_operations = {
 };
 #endif
 
+#ifdef CONFIG_MMU
 extern struct seq_operations proc_pid_smaps_op;
 static int smaps_open(struct inode *inode, struct file *file)
 {
@@ -648,12 +662,84 @@ static struct file_operations proc_smaps_operations = {
        .llseek         = seq_lseek,
        .release        = seq_release,
 };
+#endif
 
 extern struct seq_operations mounts_op;
+struct proc_mounts {
+       struct seq_file m;
+       int event;
+};
+
 static int mounts_open(struct inode *inode, struct file *file)
 {
        struct task_struct *task = proc_task(inode);
-       int ret = seq_open(file, &mounts_op);
+       struct namespace *namespace;
+       struct proc_mounts *p;
+       int ret = -EINVAL;
+
+       task_lock(task);
+       namespace = task->namespace;
+       if (namespace)
+               get_namespace(namespace);
+       task_unlock(task);
+
+       if (namespace) {
+               ret = -ENOMEM;
+               p = kmalloc(sizeof(struct proc_mounts), GFP_KERNEL);
+               if (p) {
+                       file->private_data = &p->m;
+                       ret = seq_open(file, &mounts_op);
+                       if (!ret) {
+                               p->m.private = namespace;
+                               p->event = namespace->event;
+                               return 0;
+                       }
+                       kfree(p);
+               }
+               put_namespace(namespace);
+       }
+       return ret;
+}
+
+static int mounts_release(struct inode *inode, struct file *file)
+{
+       struct seq_file *m = file->private_data;
+       struct namespace *namespace = m->private;
+       put_namespace(namespace);
+       return seq_release(inode, file);
+}
+
+static unsigned mounts_poll(struct file *file, poll_table *wait)
+{
+       struct proc_mounts *p = file->private_data;
+       struct namespace *ns = p->m.private;
+       unsigned res = 0;
+
+       poll_wait(file, &ns->poll, wait);
+
+       spin_lock(&vfsmount_lock);
+       if (p->event != ns->event) {
+               p->event = ns->event;
+               res = POLLERR;
+       }
+       spin_unlock(&vfsmount_lock);
+
+       return res;
+}
+
+static struct file_operations proc_mounts_operations = {
+       .open           = mounts_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = mounts_release,
+       .poll           = mounts_poll,
+};
+
+extern struct seq_operations mountstats_op;
+static int mountstats_open(struct inode *inode, struct file *file)
+{
+       struct task_struct *task = proc_task(inode);
+       int ret = seq_open(file, &mountstats_op);
 
        if (!ret) {
                struct seq_file *m = file->private_data;
@@ -674,16 +760,8 @@ static int mounts_open(struct inode *inode, struct file *file)
        return ret;
 }
 
-static int mounts_release(struct inode *inode, struct file *file)
-{
-       struct seq_file *m = file->private_data;
-       struct namespace *namespace = m->private;
-       put_namespace(namespace);
-       return seq_release(inode, file);
-}
-
-static struct file_operations proc_mounts_operations = {
-       .open           = mounts_open,
+static struct file_operations proc_mountstats_operations = {
+       .open           = mountstats_open,
        .read           = seq_read,
        .llseek         = seq_lseek,
        .release        = mounts_release,
@@ -1681,10 +1759,16 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
                case PROC_TGID_MOUNTS:
                        inode->i_fop = &proc_mounts_operations;
                        break;
+#ifdef CONFIG_MMU
                case PROC_TID_SMAPS:
                case PROC_TGID_SMAPS:
                        inode->i_fop = &proc_smaps_operations;
                        break;
+#endif
+               case PROC_TID_MOUNTSTATS:
+               case PROC_TGID_MOUNTSTATS:
+                       inode->i_fop = &proc_mountstats_operations;
+                       break;
 #ifdef CONFIG_SECURITY
                case PROC_TID_ATTR:
                        inode->i_nlink = 2;