diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2011-12-06 12:21:54 -0500 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2012-01-03 22:57:13 -0500 |
commit | 0226f4923f6c9b40cfa1c1c1b19a6ac6b3924ead (patch) | |
tree | cb0f26e6329e2222a9f3b8f85887f63980a01d37 /fs | |
parent | 3a2393d71d77b034669d495b49c212a87e04abdc (diff) |
vfs: take /proc/*/mounts and friends to fs/proc_namespace.c
rationale: that stuff is far tighter bound to fs/namespace.c than to
the guts of procfs proper.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/Makefile | 2 | ||||
-rw-r--r-- | fs/mount.h | 24 | ||||
-rw-r--r-- | fs/namespace.c | 218 | ||||
-rw-r--r-- | fs/proc/base.c | 114 | ||||
-rw-r--r-- | fs/proc_namespace.c | 331 |
5 files changed, 364 insertions, 325 deletions
diff --git a/fs/Makefile b/fs/Makefile index d2c3353d5477..310cfc4e69d3 100644 --- a/fs/Makefile +++ b/fs/Makefile | |||
@@ -19,6 +19,8 @@ else | |||
19 | obj-y += no-block.o | 19 | obj-y += no-block.o |
20 | endif | 20 | endif |
21 | 21 | ||
22 | obj-$(CONFIG_PROC_FS) += proc_namespace.o | ||
23 | |||
22 | obj-$(CONFIG_BLK_DEV_INTEGRITY) += bio-integrity.o | 24 | obj-$(CONFIG_BLK_DEV_INTEGRITY) += bio-integrity.o |
23 | obj-y += notify/ | 25 | obj-y += notify/ |
24 | obj-$(CONFIG_EPOLL) += eventpoll.o | 26 | obj-$(CONFIG_EPOLL) += eventpoll.o |
diff --git a/fs/mount.h b/fs/mount.h index e094c863c8af..c6e99e03350a 100644 --- a/fs/mount.h +++ b/fs/mount.h | |||
@@ -1,4 +1,14 @@ | |||
1 | #include <linux/mount.h> | 1 | #include <linux/mount.h> |
2 | #include <linux/seq_file.h> | ||
3 | #include <linux/poll.h> | ||
4 | |||
5 | struct mnt_namespace { | ||
6 | atomic_t count; | ||
7 | struct vfsmount * root; | ||
8 | struct list_head list; | ||
9 | wait_queue_head_t poll; | ||
10 | int event; | ||
11 | }; | ||
2 | 12 | ||
3 | struct mnt_pcp { | 13 | struct mnt_pcp { |
4 | int mnt_count; | 14 | int mnt_count; |
@@ -49,3 +59,17 @@ static inline int mnt_has_parent(struct mount *mnt) | |||
49 | } | 59 | } |
50 | 60 | ||
51 | extern struct mount *__lookup_mnt(struct vfsmount *, struct dentry *, int); | 61 | extern struct mount *__lookup_mnt(struct vfsmount *, struct dentry *, int); |
62 | |||
63 | static inline void get_mnt_ns(struct mnt_namespace *ns) | ||
64 | { | ||
65 | atomic_inc(&ns->count); | ||
66 | } | ||
67 | |||
68 | struct proc_mounts { | ||
69 | struct seq_file m; /* must be the first element */ | ||
70 | struct mnt_namespace *ns; | ||
71 | struct path root; | ||
72 | int (*show)(struct seq_file *, struct vfsmount *); | ||
73 | }; | ||
74 | |||
75 | extern const struct seq_operations mounts_op; | ||
diff --git a/fs/namespace.c b/fs/namespace.c index cd6389387d1f..21a8261256dd 100644 --- a/fs/namespace.c +++ b/fs/namespace.c | |||
@@ -898,10 +898,10 @@ void replace_mount_options(struct super_block *sb, char *options) | |||
898 | EXPORT_SYMBOL(replace_mount_options); | 898 | EXPORT_SYMBOL(replace_mount_options); |
899 | 899 | ||
900 | #ifdef CONFIG_PROC_FS | 900 | #ifdef CONFIG_PROC_FS |
901 | /* iterator */ | 901 | /* iterator; we want it to have access to namespace_sem, thus here... */ |
902 | static void *m_start(struct seq_file *m, loff_t *pos) | 902 | static void *m_start(struct seq_file *m, loff_t *pos) |
903 | { | 903 | { |
904 | struct proc_mounts *p = m->private; | 904 | struct proc_mounts *p = container_of(m, struct proc_mounts, m); |
905 | 905 | ||
906 | down_read(&namespace_sem); | 906 | down_read(&namespace_sem); |
907 | return seq_list_start(&p->ns->list, *pos); | 907 | return seq_list_start(&p->ns->list, *pos); |
@@ -909,7 +909,7 @@ static void *m_start(struct seq_file *m, loff_t *pos) | |||
909 | 909 | ||
910 | static void *m_next(struct seq_file *m, void *v, loff_t *pos) | 910 | static void *m_next(struct seq_file *m, void *v, loff_t *pos) |
911 | { | 911 | { |
912 | struct proc_mounts *p = m->private; | 912 | struct proc_mounts *p = container_of(m, struct proc_mounts, m); |
913 | 913 | ||
914 | return seq_list_next(v, &p->ns->list, pos); | 914 | return seq_list_next(v, &p->ns->list, pos); |
915 | } | 915 | } |
@@ -919,222 +919,18 @@ static void m_stop(struct seq_file *m, void *v) | |||
919 | up_read(&namespace_sem); | 919 | up_read(&namespace_sem); |
920 | } | 920 | } |
921 | 921 | ||
922 | int mnt_had_events(struct proc_mounts *p) | 922 | static int m_show(struct seq_file *m, void *v) |
923 | { | ||
924 | struct mnt_namespace *ns = p->ns; | ||
925 | int res = 0; | ||
926 | |||
927 | br_read_lock(vfsmount_lock); | ||
928 | if (p->m.poll_event != ns->event) { | ||
929 | p->m.poll_event = ns->event; | ||
930 | res = 1; | ||
931 | } | ||
932 | br_read_unlock(vfsmount_lock); | ||
933 | |||
934 | return res; | ||
935 | } | ||
936 | |||
937 | struct proc_fs_info { | ||
938 | int flag; | ||
939 | const char *str; | ||
940 | }; | ||
941 | |||
942 | static int show_sb_opts(struct seq_file *m, struct super_block *sb) | ||
943 | { | ||
944 | static const struct proc_fs_info fs_info[] = { | ||
945 | { MS_SYNCHRONOUS, ",sync" }, | ||
946 | { MS_DIRSYNC, ",dirsync" }, | ||
947 | { MS_MANDLOCK, ",mand" }, | ||
948 | { 0, NULL } | ||
949 | }; | ||
950 | const struct proc_fs_info *fs_infop; | ||
951 | |||
952 | for (fs_infop = fs_info; fs_infop->flag; fs_infop++) { | ||
953 | if (sb->s_flags & fs_infop->flag) | ||
954 | seq_puts(m, fs_infop->str); | ||
955 | } | ||
956 | |||
957 | return security_sb_show_options(m, sb); | ||
958 | } | ||
959 | |||
960 | static void show_mnt_opts(struct seq_file *m, struct vfsmount *mnt) | ||
961 | { | ||
962 | static const struct proc_fs_info mnt_info[] = { | ||
963 | { MNT_NOSUID, ",nosuid" }, | ||
964 | { MNT_NODEV, ",nodev" }, | ||
965 | { MNT_NOEXEC, ",noexec" }, | ||
966 | { MNT_NOATIME, ",noatime" }, | ||
967 | { MNT_NODIRATIME, ",nodiratime" }, | ||
968 | { MNT_RELATIME, ",relatime" }, | ||
969 | { 0, NULL } | ||
970 | }; | ||
971 | const struct proc_fs_info *fs_infop; | ||
972 | |||
973 | for (fs_infop = mnt_info; fs_infop->flag; fs_infop++) { | ||
974 | if (mnt->mnt_flags & fs_infop->flag) | ||
975 | seq_puts(m, fs_infop->str); | ||
976 | } | ||
977 | } | ||
978 | |||
979 | static void show_type(struct seq_file *m, struct super_block *sb) | ||
980 | { | ||
981 | mangle(m, sb->s_type->name); | ||
982 | if (sb->s_subtype && sb->s_subtype[0]) { | ||
983 | seq_putc(m, '.'); | ||
984 | mangle(m, sb->s_subtype); | ||
985 | } | ||
986 | } | ||
987 | |||
988 | static int show_vfsmnt(struct seq_file *m, void *v) | ||
989 | { | 923 | { |
924 | struct proc_mounts *p = container_of(m, struct proc_mounts, m); | ||
990 | struct mount *r = list_entry(v, struct mount, mnt_list); | 925 | struct mount *r = list_entry(v, struct mount, mnt_list); |
991 | struct vfsmount *mnt = &r->mnt; | 926 | return p->show(m, &r->mnt); |
992 | int err = 0; | ||
993 | struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt }; | ||
994 | |||
995 | if (mnt->mnt_sb->s_op->show_devname) { | ||
996 | err = mnt->mnt_sb->s_op->show_devname(m, mnt); | ||
997 | if (err) | ||
998 | goto out; | ||
999 | } else { | ||
1000 | mangle(m, r->mnt_devname ? r->mnt_devname : "none"); | ||
1001 | } | ||
1002 | seq_putc(m, ' '); | ||
1003 | seq_path(m, &mnt_path, " \t\n\\"); | ||
1004 | seq_putc(m, ' '); | ||
1005 | show_type(m, mnt->mnt_sb); | ||
1006 | seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw"); | ||
1007 | err = show_sb_opts(m, mnt->mnt_sb); | ||
1008 | if (err) | ||
1009 | goto out; | ||
1010 | show_mnt_opts(m, mnt); | ||
1011 | if (mnt->mnt_sb->s_op->show_options) | ||
1012 | err = mnt->mnt_sb->s_op->show_options(m, mnt); | ||
1013 | seq_puts(m, " 0 0\n"); | ||
1014 | out: | ||
1015 | return err; | ||
1016 | } | 927 | } |
1017 | 928 | ||
1018 | const struct seq_operations mounts_op = { | 929 | const struct seq_operations mounts_op = { |
1019 | .start = m_start, | 930 | .start = m_start, |
1020 | .next = m_next, | 931 | .next = m_next, |
1021 | .stop = m_stop, | 932 | .stop = m_stop, |
1022 | .show = show_vfsmnt | 933 | .show = m_show, |
1023 | }; | ||
1024 | |||
1025 | static int show_mountinfo(struct seq_file *m, void *v) | ||
1026 | { | ||
1027 | struct proc_mounts *p = m->private; | ||
1028 | struct mount *r = list_entry(v, struct mount, mnt_list); | ||
1029 | struct vfsmount *mnt = &r->mnt; | ||
1030 | struct super_block *sb = mnt->mnt_sb; | ||
1031 | struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt }; | ||
1032 | struct path root = p->root; | ||
1033 | int err = 0; | ||
1034 | |||
1035 | seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id, | ||
1036 | MAJOR(sb->s_dev), MINOR(sb->s_dev)); | ||
1037 | if (sb->s_op->show_path) | ||
1038 | err = sb->s_op->show_path(m, mnt); | ||
1039 | else | ||
1040 | seq_dentry(m, mnt->mnt_root, " \t\n\\"); | ||
1041 | if (err) | ||
1042 | goto out; | ||
1043 | seq_putc(m, ' '); | ||
1044 | |||
1045 | /* mountpoints outside of chroot jail will give SEQ_SKIP on this */ | ||
1046 | err = seq_path_root(m, &mnt_path, &root, " \t\n\\"); | ||
1047 | if (err) | ||
1048 | goto out; | ||
1049 | |||
1050 | seq_puts(m, mnt->mnt_flags & MNT_READONLY ? " ro" : " rw"); | ||
1051 | show_mnt_opts(m, mnt); | ||
1052 | |||
1053 | /* Tagged fields ("foo:X" or "bar") */ | ||
1054 | if (IS_MNT_SHARED(r)) | ||
1055 | seq_printf(m, " shared:%i", r->mnt_group_id); | ||
1056 | if (IS_MNT_SLAVE(r)) { | ||
1057 | int master = r->mnt_master->mnt_group_id; | ||
1058 | int dom = get_dominating_id(r, &p->root); | ||
1059 | seq_printf(m, " master:%i", master); | ||
1060 | if (dom && dom != master) | ||
1061 | seq_printf(m, " propagate_from:%i", dom); | ||
1062 | } | ||
1063 | if (IS_MNT_UNBINDABLE(r)) | ||
1064 | seq_puts(m, " unbindable"); | ||
1065 | |||
1066 | /* Filesystem specific data */ | ||
1067 | seq_puts(m, " - "); | ||
1068 | show_type(m, sb); | ||
1069 | seq_putc(m, ' '); | ||
1070 | if (sb->s_op->show_devname) | ||
1071 | err = sb->s_op->show_devname(m, mnt); | ||
1072 | else | ||
1073 | mangle(m, r->mnt_devname ? r->mnt_devname : "none"); | ||
1074 | if (err) | ||
1075 | goto out; | ||
1076 | seq_puts(m, sb->s_flags & MS_RDONLY ? " ro" : " rw"); | ||
1077 | err = show_sb_opts(m, sb); | ||
1078 | if (err) | ||
1079 | goto out; | ||
1080 | if (sb->s_op->show_options) | ||
1081 | err = sb->s_op->show_options(m, mnt); | ||
1082 | seq_putc(m, '\n'); | ||
1083 | out: | ||
1084 | return err; | ||
1085 | } | ||
1086 | |||
1087 | const struct seq_operations mountinfo_op = { | ||
1088 | .start = m_start, | ||
1089 | .next = m_next, | ||
1090 | .stop = m_stop, | ||
1091 | .show = show_mountinfo, | ||
1092 | }; | ||
1093 | |||
1094 | static int show_vfsstat(struct seq_file *m, void *v) | ||
1095 | { | ||
1096 | struct mount *r = list_entry(v, struct mount, mnt_list); | ||
1097 | struct vfsmount *mnt = &r->mnt; | ||
1098 | struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt }; | ||
1099 | int err = 0; | ||
1100 | |||
1101 | /* device */ | ||
1102 | if (mnt->mnt_sb->s_op->show_devname) { | ||
1103 | seq_puts(m, "device "); | ||
1104 | err = mnt->mnt_sb->s_op->show_devname(m, mnt); | ||
1105 | } else { | ||
1106 | if (r->mnt_devname) { | ||
1107 | seq_puts(m, "device "); | ||
1108 | mangle(m, r->mnt_devname); | ||
1109 | } else | ||
1110 | seq_puts(m, "no device"); | ||
1111 | } | ||
1112 | |||
1113 | /* mount point */ | ||
1114 | seq_puts(m, " mounted on "); | ||
1115 | seq_path(m, &mnt_path, " \t\n\\"); | ||
1116 | seq_putc(m, ' '); | ||
1117 | |||
1118 | /* file system type */ | ||
1119 | seq_puts(m, "with fstype "); | ||
1120 | show_type(m, mnt->mnt_sb); | ||
1121 | |||
1122 | /* optional statistics */ | ||
1123 | if (mnt->mnt_sb->s_op->show_stats) { | ||
1124 | seq_putc(m, ' '); | ||
1125 | if (!err) | ||
1126 | err = mnt->mnt_sb->s_op->show_stats(m, mnt); | ||
1127 | } | ||
1128 | |||
1129 | seq_putc(m, '\n'); | ||
1130 | return err; | ||
1131 | } | ||
1132 | |||
1133 | const struct seq_operations mountstats_op = { | ||
1134 | .start = m_start, | ||
1135 | .next = m_next, | ||
1136 | .stop = m_stop, | ||
1137 | .show = show_vfsstat, | ||
1138 | }; | 934 | }; |
1139 | #endif /* CONFIG_PROC_FS */ | 935 | #endif /* CONFIG_PROC_FS */ |
1140 | 936 | ||
diff --git a/fs/proc/base.c b/fs/proc/base.c index 851ba3dcdc29..07446b55b7cc 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -631,120 +631,6 @@ static const struct inode_operations proc_def_inode_operations = { | |||
631 | .setattr = proc_setattr, | 631 | .setattr = proc_setattr, |
632 | }; | 632 | }; |
633 | 633 | ||
634 | static int mounts_open_common(struct inode *inode, struct file *file, | ||
635 | const struct seq_operations *op) | ||
636 | { | ||
637 | struct task_struct *task = get_proc_task(inode); | ||
638 | struct nsproxy *nsp; | ||
639 | struct mnt_namespace *ns = NULL; | ||
640 | struct path root; | ||
641 | struct proc_mounts *p; | ||
642 | int ret = -EINVAL; | ||
643 | |||
644 | if (task) { | ||
645 | rcu_read_lock(); | ||
646 | nsp = task_nsproxy(task); | ||
647 | if (nsp) { | ||
648 | ns = nsp->mnt_ns; | ||
649 | if (ns) | ||
650 | get_mnt_ns(ns); | ||
651 | } | ||
652 | rcu_read_unlock(); | ||
653 | if (ns && get_task_root(task, &root) == 0) | ||
654 | ret = 0; | ||
655 | put_task_struct(task); | ||
656 | } | ||
657 | |||
658 | if (!ns) | ||
659 | goto err; | ||
660 | if (ret) | ||
661 | goto err_put_ns; | ||
662 | |||
663 | ret = -ENOMEM; | ||
664 | p = kmalloc(sizeof(struct proc_mounts), GFP_KERNEL); | ||
665 | if (!p) | ||
666 | goto err_put_path; | ||
667 | |||
668 | file->private_data = &p->m; | ||
669 | ret = seq_open(file, op); | ||
670 | if (ret) | ||
671 | goto err_free; | ||
672 | |||
673 | p->m.private = p; | ||
674 | p->ns = ns; | ||
675 | p->root = root; | ||
676 | p->m.poll_event = ns->event; | ||
677 | |||
678 | return 0; | ||
679 | |||
680 | err_free: | ||
681 | kfree(p); | ||
682 | err_put_path: | ||
683 | path_put(&root); | ||
684 | err_put_ns: | ||
685 | put_mnt_ns(ns); | ||
686 | err: | ||
687 | return ret; | ||
688 | } | ||
689 | |||
690 | static int mounts_release(struct inode *inode, struct file *file) | ||
691 | { | ||
692 | struct proc_mounts *p = file->private_data; | ||
693 | path_put(&p->root); | ||
694 | put_mnt_ns(p->ns); | ||
695 | return seq_release(inode, file); | ||
696 | } | ||
697 | |||
698 | static unsigned mounts_poll(struct file *file, poll_table *wait) | ||
699 | { | ||
700 | struct proc_mounts *p = file->private_data; | ||
701 | unsigned res = POLLIN | POLLRDNORM; | ||
702 | |||
703 | poll_wait(file, &p->ns->poll, wait); | ||
704 | if (mnt_had_events(p)) | ||
705 | res |= POLLERR | POLLPRI; | ||
706 | |||
707 | return res; | ||
708 | } | ||
709 | |||
710 | static int mounts_open(struct inode *inode, struct file *file) | ||
711 | { | ||
712 | return mounts_open_common(inode, file, &mounts_op); | ||
713 | } | ||
714 | |||
715 | static const struct file_operations proc_mounts_operations = { | ||
716 | .open = mounts_open, | ||
717 | .read = seq_read, | ||
718 | .llseek = seq_lseek, | ||
719 | .release = mounts_release, | ||
720 | .poll = mounts_poll, | ||
721 | }; | ||
722 | |||
723 | static int mountinfo_open(struct inode *inode, struct file *file) | ||
724 | { | ||
725 | return mounts_open_common(inode, file, &mountinfo_op); | ||
726 | } | ||
727 | |||
728 | static const struct file_operations proc_mountinfo_operations = { | ||
729 | .open = mountinfo_open, | ||
730 | .read = seq_read, | ||
731 | .llseek = seq_lseek, | ||
732 | .release = mounts_release, | ||
733 | .poll = mounts_poll, | ||
734 | }; | ||
735 | |||
736 | static int mountstats_open(struct inode *inode, struct file *file) | ||
737 | { | ||
738 | return mounts_open_common(inode, file, &mountstats_op); | ||
739 | } | ||
740 | |||
741 | static const struct file_operations proc_mountstats_operations = { | ||
742 | .open = mountstats_open, | ||
743 | .read = seq_read, | ||
744 | .llseek = seq_lseek, | ||
745 | .release = mounts_release, | ||
746 | }; | ||
747 | |||
748 | #define PROC_BLOCK_SIZE (3*1024) /* 4K page size but our output routines use some slack for overruns */ | 634 | #define PROC_BLOCK_SIZE (3*1024) /* 4K page size but our output routines use some slack for overruns */ |
749 | 635 | ||
750 | static ssize_t proc_info_read(struct file * file, char __user * buf, | 636 | static ssize_t proc_info_read(struct file * file, char __user * buf, |
diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c new file mode 100644 index 000000000000..9dcd9543ca12 --- /dev/null +++ b/fs/proc_namespace.c | |||
@@ -0,0 +1,331 @@ | |||
1 | /* | ||
2 | * fs/proc_namespace.c - handling of /proc/<pid>/{mounts,mountinfo,mountstats} | ||
3 | * | ||
4 | * In fact, that's a piece of procfs; it's *almost* isolated from | ||
5 | * the rest of fs/proc, but has rather close relationships with | ||
6 | * fs/namespace.c, thus here instead of fs/proc | ||
7 | * | ||
8 | */ | ||
9 | #include <linux/mnt_namespace.h> | ||
10 | #include <linux/nsproxy.h> | ||
11 | #include <linux/security.h> | ||
12 | #include <linux/fs_struct.h> | ||
13 | #include "proc/internal.h" /* only for get_proc_task() in ->open() */ | ||
14 | |||
15 | #include "pnode.h" | ||
16 | #include "internal.h" | ||
17 | |||
18 | static unsigned mounts_poll(struct file *file, poll_table *wait) | ||
19 | { | ||
20 | struct proc_mounts *p = file->private_data; | ||
21 | struct mnt_namespace *ns = p->ns; | ||
22 | unsigned res = POLLIN | POLLRDNORM; | ||
23 | |||
24 | poll_wait(file, &p->ns->poll, wait); | ||
25 | |||
26 | br_read_lock(vfsmount_lock); | ||
27 | if (p->m.poll_event != ns->event) { | ||
28 | p->m.poll_event = ns->event; | ||
29 | res |= POLLERR | POLLPRI; | ||
30 | } | ||
31 | br_read_unlock(vfsmount_lock); | ||
32 | |||
33 | return res; | ||
34 | } | ||
35 | |||
36 | struct proc_fs_info { | ||
37 | int flag; | ||
38 | const char *str; | ||
39 | }; | ||
40 | |||
41 | static int show_sb_opts(struct seq_file *m, struct super_block *sb) | ||
42 | { | ||
43 | static const struct proc_fs_info fs_info[] = { | ||
44 | { MS_SYNCHRONOUS, ",sync" }, | ||
45 | { MS_DIRSYNC, ",dirsync" }, | ||
46 | { MS_MANDLOCK, ",mand" }, | ||
47 | { 0, NULL } | ||
48 | }; | ||
49 | const struct proc_fs_info *fs_infop; | ||
50 | |||
51 | for (fs_infop = fs_info; fs_infop->flag; fs_infop++) { | ||
52 | if (sb->s_flags & fs_infop->flag) | ||
53 | seq_puts(m, fs_infop->str); | ||
54 | } | ||
55 | |||
56 | return security_sb_show_options(m, sb); | ||
57 | } | ||
58 | |||
59 | static void show_mnt_opts(struct seq_file *m, struct vfsmount *mnt) | ||
60 | { | ||
61 | static const struct proc_fs_info mnt_info[] = { | ||
62 | { MNT_NOSUID, ",nosuid" }, | ||
63 | { MNT_NODEV, ",nodev" }, | ||
64 | { MNT_NOEXEC, ",noexec" }, | ||
65 | { MNT_NOATIME, ",noatime" }, | ||
66 | { MNT_NODIRATIME, ",nodiratime" }, | ||
67 | { MNT_RELATIME, ",relatime" }, | ||
68 | { 0, NULL } | ||
69 | }; | ||
70 | const struct proc_fs_info *fs_infop; | ||
71 | |||
72 | for (fs_infop = mnt_info; fs_infop->flag; fs_infop++) { | ||
73 | if (mnt->mnt_flags & fs_infop->flag) | ||
74 | seq_puts(m, fs_infop->str); | ||
75 | } | ||
76 | } | ||
77 | |||
78 | static inline void mangle(struct seq_file *m, const char *s) | ||
79 | { | ||
80 | seq_escape(m, s, " \t\n\\"); | ||
81 | } | ||
82 | |||
83 | static void show_type(struct seq_file *m, struct super_block *sb) | ||
84 | { | ||
85 | mangle(m, sb->s_type->name); | ||
86 | if (sb->s_subtype && sb->s_subtype[0]) { | ||
87 | seq_putc(m, '.'); | ||
88 | mangle(m, sb->s_subtype); | ||
89 | } | ||
90 | } | ||
91 | |||
92 | static int show_vfsmnt(struct seq_file *m, struct vfsmount *mnt) | ||
93 | { | ||
94 | struct mount *r = real_mount(mnt); | ||
95 | int err = 0; | ||
96 | struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt }; | ||
97 | |||
98 | if (mnt->mnt_sb->s_op->show_devname) { | ||
99 | err = mnt->mnt_sb->s_op->show_devname(m, mnt); | ||
100 | if (err) | ||
101 | goto out; | ||
102 | } else { | ||
103 | mangle(m, r->mnt_devname ? r->mnt_devname : "none"); | ||
104 | } | ||
105 | seq_putc(m, ' '); | ||
106 | seq_path(m, &mnt_path, " \t\n\\"); | ||
107 | seq_putc(m, ' '); | ||
108 | show_type(m, mnt->mnt_sb); | ||
109 | seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw"); | ||
110 | err = show_sb_opts(m, mnt->mnt_sb); | ||
111 | if (err) | ||
112 | goto out; | ||
113 | show_mnt_opts(m, mnt); | ||
114 | if (mnt->mnt_sb->s_op->show_options) | ||
115 | err = mnt->mnt_sb->s_op->show_options(m, mnt); | ||
116 | seq_puts(m, " 0 0\n"); | ||
117 | out: | ||
118 | return err; | ||
119 | } | ||
120 | |||
121 | static int show_mountinfo(struct seq_file *m, struct vfsmount *mnt) | ||
122 | { | ||
123 | struct proc_mounts *p = m->private; | ||
124 | struct mount *r = real_mount(mnt); | ||
125 | struct super_block *sb = mnt->mnt_sb; | ||
126 | struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt }; | ||
127 | struct path root = p->root; | ||
128 | int err = 0; | ||
129 | |||
130 | seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id, | ||
131 | MAJOR(sb->s_dev), MINOR(sb->s_dev)); | ||
132 | if (sb->s_op->show_path) | ||
133 | err = sb->s_op->show_path(m, mnt); | ||
134 | else | ||
135 | seq_dentry(m, mnt->mnt_root, " \t\n\\"); | ||
136 | if (err) | ||
137 | goto out; | ||
138 | seq_putc(m, ' '); | ||
139 | |||
140 | /* mountpoints outside of chroot jail will give SEQ_SKIP on this */ | ||
141 | err = seq_path_root(m, &mnt_path, &root, " \t\n\\"); | ||
142 | if (err) | ||
143 | goto out; | ||
144 | |||
145 | seq_puts(m, mnt->mnt_flags & MNT_READONLY ? " ro" : " rw"); | ||
146 | show_mnt_opts(m, mnt); | ||
147 | |||
148 | /* Tagged fields ("foo:X" or "bar") */ | ||
149 | if (IS_MNT_SHARED(r)) | ||
150 | seq_printf(m, " shared:%i", r->mnt_group_id); | ||
151 | if (IS_MNT_SLAVE(r)) { | ||
152 | int master = r->mnt_master->mnt_group_id; | ||
153 | int dom = get_dominating_id(r, &p->root); | ||
154 | seq_printf(m, " master:%i", master); | ||
155 | if (dom && dom != master) | ||
156 | seq_printf(m, " propagate_from:%i", dom); | ||
157 | } | ||
158 | if (IS_MNT_UNBINDABLE(r)) | ||
159 | seq_puts(m, " unbindable"); | ||
160 | |||
161 | /* Filesystem specific data */ | ||
162 | seq_puts(m, " - "); | ||
163 | show_type(m, sb); | ||
164 | seq_putc(m, ' '); | ||
165 | if (sb->s_op->show_devname) | ||
166 | err = sb->s_op->show_devname(m, mnt); | ||
167 | else | ||
168 | mangle(m, r->mnt_devname ? r->mnt_devname : "none"); | ||
169 | if (err) | ||
170 | goto out; | ||
171 | seq_puts(m, sb->s_flags & MS_RDONLY ? " ro" : " rw"); | ||
172 | err = show_sb_opts(m, sb); | ||
173 | if (err) | ||
174 | goto out; | ||
175 | if (sb->s_op->show_options) | ||
176 | err = sb->s_op->show_options(m, mnt); | ||
177 | seq_putc(m, '\n'); | ||
178 | out: | ||
179 | return err; | ||
180 | } | ||
181 | |||
182 | static int show_vfsstat(struct seq_file *m, struct vfsmount *mnt) | ||
183 | { | ||
184 | struct mount *r = real_mount(mnt); | ||
185 | struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt }; | ||
186 | int err = 0; | ||
187 | |||
188 | /* device */ | ||
189 | if (mnt->mnt_sb->s_op->show_devname) { | ||
190 | seq_puts(m, "device "); | ||
191 | err = mnt->mnt_sb->s_op->show_devname(m, mnt); | ||
192 | } else { | ||
193 | if (r->mnt_devname) { | ||
194 | seq_puts(m, "device "); | ||
195 | mangle(m, r->mnt_devname); | ||
196 | } else | ||
197 | seq_puts(m, "no device"); | ||
198 | } | ||
199 | |||
200 | /* mount point */ | ||
201 | seq_puts(m, " mounted on "); | ||
202 | seq_path(m, &mnt_path, " \t\n\\"); | ||
203 | seq_putc(m, ' '); | ||
204 | |||
205 | /* file system type */ | ||
206 | seq_puts(m, "with fstype "); | ||
207 | show_type(m, mnt->mnt_sb); | ||
208 | |||
209 | /* optional statistics */ | ||
210 | if (mnt->mnt_sb->s_op->show_stats) { | ||
211 | seq_putc(m, ' '); | ||
212 | if (!err) | ||
213 | err = mnt->mnt_sb->s_op->show_stats(m, mnt); | ||
214 | } | ||
215 | |||
216 | seq_putc(m, '\n'); | ||
217 | return err; | ||
218 | } | ||
219 | |||
220 | static int mounts_open_common(struct inode *inode, struct file *file, | ||
221 | int (*show)(struct seq_file *, struct vfsmount *)) | ||
222 | { | ||
223 | struct task_struct *task = get_proc_task(inode); | ||
224 | struct nsproxy *nsp; | ||
225 | struct mnt_namespace *ns = NULL; | ||
226 | struct path root; | ||
227 | struct proc_mounts *p; | ||
228 | int ret = -EINVAL; | ||
229 | |||
230 | if (!task) | ||
231 | goto err; | ||
232 | |||
233 | rcu_read_lock(); | ||
234 | nsp = task_nsproxy(task); | ||
235 | if (!nsp) { | ||
236 | rcu_read_unlock(); | ||
237 | put_task_struct(task); | ||
238 | goto err; | ||
239 | } | ||
240 | ns = nsp->mnt_ns; | ||
241 | if (!ns) { | ||
242 | rcu_read_unlock(); | ||
243 | put_task_struct(task); | ||
244 | goto err; | ||
245 | } | ||
246 | get_mnt_ns(ns); | ||
247 | rcu_read_unlock(); | ||
248 | task_lock(task); | ||
249 | if (!task->fs) { | ||
250 | task_unlock(task); | ||
251 | put_task_struct(task); | ||
252 | ret = -ENOENT; | ||
253 | goto err_put_ns; | ||
254 | } | ||
255 | get_fs_root(task->fs, &root); | ||
256 | task_unlock(task); | ||
257 | put_task_struct(task); | ||
258 | |||
259 | ret = -ENOMEM; | ||
260 | p = kmalloc(sizeof(struct proc_mounts), GFP_KERNEL); | ||
261 | if (!p) | ||
262 | goto err_put_path; | ||
263 | |||
264 | file->private_data = &p->m; | ||
265 | ret = seq_open(file, &mounts_op); | ||
266 | if (ret) | ||
267 | goto err_free; | ||
268 | |||
269 | p->m.private = p; | ||
270 | p->ns = ns; | ||
271 | p->root = root; | ||
272 | p->m.poll_event = ns->event; | ||
273 | p->show = show; | ||
274 | |||
275 | return 0; | ||
276 | |||
277 | err_free: | ||
278 | kfree(p); | ||
279 | err_put_path: | ||
280 | path_put(&root); | ||
281 | err_put_ns: | ||
282 | put_mnt_ns(ns); | ||
283 | err: | ||
284 | return ret; | ||
285 | } | ||
286 | |||
287 | static int mounts_release(struct inode *inode, struct file *file) | ||
288 | { | ||
289 | struct proc_mounts *p = file->private_data; | ||
290 | path_put(&p->root); | ||
291 | put_mnt_ns(p->ns); | ||
292 | return seq_release(inode, file); | ||
293 | } | ||
294 | |||
295 | static int mounts_open(struct inode *inode, struct file *file) | ||
296 | { | ||
297 | return mounts_open_common(inode, file, show_vfsmnt); | ||
298 | } | ||
299 | |||
300 | static int mountinfo_open(struct inode *inode, struct file *file) | ||
301 | { | ||
302 | return mounts_open_common(inode, file, show_mountinfo); | ||
303 | } | ||
304 | |||
305 | static int mountstats_open(struct inode *inode, struct file *file) | ||
306 | { | ||
307 | return mounts_open_common(inode, file, show_vfsstat); | ||
308 | } | ||
309 | |||
310 | const struct file_operations proc_mounts_operations = { | ||
311 | .open = mounts_open, | ||
312 | .read = seq_read, | ||
313 | .llseek = seq_lseek, | ||
314 | .release = mounts_release, | ||
315 | .poll = mounts_poll, | ||
316 | }; | ||
317 | |||
318 | const struct file_operations proc_mountinfo_operations = { | ||
319 | .open = mountinfo_open, | ||
320 | .read = seq_read, | ||
321 | .llseek = seq_lseek, | ||
322 | .release = mounts_release, | ||
323 | .poll = mounts_poll, | ||
324 | }; | ||
325 | |||
326 | const struct file_operations proc_mountstats_operations = { | ||
327 | .open = mountstats_open, | ||
328 | .read = seq_read, | ||
329 | .llseek = seq_lseek, | ||
330 | .release = mounts_release, | ||
331 | }; | ||