aboutsummaryrefslogtreecommitdiffstats
path: root/fs/proc
diff options
context:
space:
mode:
Diffstat (limited to 'fs/proc')
-rw-r--r--fs/proc/Makefile1
-rw-r--r--fs/proc/array.c17
-rw-r--r--fs/proc/base.c2
-rw-r--r--fs/proc/internal.h5
-rw-r--r--fs/proc/proc_misc.c15
-rw-r--r--fs/proc/proc_net.c200
-rw-r--r--fs/proc/root.c8
7 files changed, 236 insertions, 12 deletions
diff --git a/fs/proc/Makefile b/fs/proc/Makefile
index bce38e3f06cb..ebaba0213546 100644
--- a/fs/proc/Makefile
+++ b/fs/proc/Makefile
@@ -11,6 +11,7 @@ proc-y += inode.o root.o base.o generic.o array.o \
11 proc_tty.o proc_misc.o 11 proc_tty.o proc_misc.o
12 12
13proc-$(CONFIG_PROC_SYSCTL) += proc_sysctl.o 13proc-$(CONFIG_PROC_SYSCTL) += proc_sysctl.o
14proc-$(CONFIG_NET) += proc_net.o
14proc-$(CONFIG_PROC_KCORE) += kcore.o 15proc-$(CONFIG_PROC_KCORE) += kcore.o
15proc-$(CONFIG_PROC_VMCORE) += vmcore.o 16proc-$(CONFIG_PROC_VMCORE) += vmcore.o
16proc-$(CONFIG_PROC_DEVICETREE) += proc_devtree.o 17proc-$(CONFIG_PROC_DEVICETREE) += proc_devtree.o
diff --git a/fs/proc/array.c b/fs/proc/array.c
index ee4814dd98f9..27b59f5f3bd1 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -370,6 +370,11 @@ static cputime_t task_stime(struct task_struct *p)
370} 370}
371#endif 371#endif
372 372
373static cputime_t task_gtime(struct task_struct *p)
374{
375 return p->gtime;
376}
377
373static int do_task_stat(struct task_struct *task, char *buffer, int whole) 378static int do_task_stat(struct task_struct *task, char *buffer, int whole)
374{ 379{
375 unsigned long vsize, eip, esp, wchan = ~0UL; 380 unsigned long vsize, eip, esp, wchan = ~0UL;
@@ -385,6 +390,7 @@ static int do_task_stat(struct task_struct *task, char *buffer, int whole)
385 unsigned long cmin_flt = 0, cmaj_flt = 0; 390 unsigned long cmin_flt = 0, cmaj_flt = 0;
386 unsigned long min_flt = 0, maj_flt = 0; 391 unsigned long min_flt = 0, maj_flt = 0;
387 cputime_t cutime, cstime, utime, stime; 392 cputime_t cutime, cstime, utime, stime;
393 cputime_t cgtime, gtime;
388 unsigned long rsslim = 0; 394 unsigned long rsslim = 0;
389 char tcomm[sizeof(task->comm)]; 395 char tcomm[sizeof(task->comm)];
390 unsigned long flags; 396 unsigned long flags;
@@ -403,6 +409,7 @@ static int do_task_stat(struct task_struct *task, char *buffer, int whole)
403 sigemptyset(&sigign); 409 sigemptyset(&sigign);
404 sigemptyset(&sigcatch); 410 sigemptyset(&sigcatch);
405 cutime = cstime = utime = stime = cputime_zero; 411 cutime = cstime = utime = stime = cputime_zero;
412 cgtime = gtime = cputime_zero;
406 413
407 rcu_read_lock(); 414 rcu_read_lock();
408 if (lock_task_sighand(task, &flags)) { 415 if (lock_task_sighand(task, &flags)) {
@@ -420,6 +427,7 @@ static int do_task_stat(struct task_struct *task, char *buffer, int whole)
420 cmaj_flt = sig->cmaj_flt; 427 cmaj_flt = sig->cmaj_flt;
421 cutime = sig->cutime; 428 cutime = sig->cutime;
422 cstime = sig->cstime; 429 cstime = sig->cstime;
430 cgtime = sig->cgtime;
423 rsslim = sig->rlim[RLIMIT_RSS].rlim_cur; 431 rsslim = sig->rlim[RLIMIT_RSS].rlim_cur;
424 432
425 /* add up live thread stats at the group level */ 433 /* add up live thread stats at the group level */
@@ -430,6 +438,7 @@ static int do_task_stat(struct task_struct *task, char *buffer, int whole)
430 maj_flt += t->maj_flt; 438 maj_flt += t->maj_flt;
431 utime = cputime_add(utime, task_utime(t)); 439 utime = cputime_add(utime, task_utime(t));
432 stime = cputime_add(stime, task_stime(t)); 440 stime = cputime_add(stime, task_stime(t));
441 gtime = cputime_add(gtime, task_gtime(t));
433 t = next_thread(t); 442 t = next_thread(t);
434 } while (t != task); 443 } while (t != task);
435 444
@@ -437,6 +446,7 @@ static int do_task_stat(struct task_struct *task, char *buffer, int whole)
437 maj_flt += sig->maj_flt; 446 maj_flt += sig->maj_flt;
438 utime = cputime_add(utime, sig->utime); 447 utime = cputime_add(utime, sig->utime);
439 stime = cputime_add(stime, sig->stime); 448 stime = cputime_add(stime, sig->stime);
449 gtime += cputime_add(gtime, sig->gtime);
440 } 450 }
441 451
442 sid = signal_session(sig); 452 sid = signal_session(sig);
@@ -454,6 +464,7 @@ static int do_task_stat(struct task_struct *task, char *buffer, int whole)
454 maj_flt = task->maj_flt; 464 maj_flt = task->maj_flt;
455 utime = task_utime(task); 465 utime = task_utime(task);
456 stime = task_stime(task); 466 stime = task_stime(task);
467 gtime = task_gtime(task);
457 } 468 }
458 469
459 /* scale priority and nice values from timeslices to -20..20 */ 470 /* scale priority and nice values from timeslices to -20..20 */
@@ -471,7 +482,7 @@ static int do_task_stat(struct task_struct *task, char *buffer, int whole)
471 482
472 res = sprintf(buffer, "%d (%s) %c %d %d %d %d %d %u %lu \ 483 res = sprintf(buffer, "%d (%s) %c %d %d %d %d %d %u %lu \
473%lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \ 484%lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
474%lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu\n", 485%lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
475 task->pid, 486 task->pid,
476 tcomm, 487 tcomm,
477 state, 488 state,
@@ -516,7 +527,9 @@ static int do_task_stat(struct task_struct *task, char *buffer, int whole)
516 task_cpu(task), 527 task_cpu(task),
517 task->rt_priority, 528 task->rt_priority,
518 task->policy, 529 task->policy,
519 (unsigned long long)delayacct_blkio_ticks(task)); 530 (unsigned long long)delayacct_blkio_ticks(task),
531 cputime_to_clock_t(gtime),
532 cputime_to_clock_t(cgtime));
520 if (mm) 533 if (mm)
521 mmput(mm); 534 mmput(mm);
522 return res; 535 return res;
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 19489b0d5554..e5d0953d4db1 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -304,7 +304,7 @@ static int proc_pid_schedstat(struct task_struct *task, char *buffer)
304 return sprintf(buffer, "%llu %llu %lu\n", 304 return sprintf(buffer, "%llu %llu %lu\n",
305 task->sched_info.cpu_time, 305 task->sched_info.cpu_time,
306 task->sched_info.run_delay, 306 task->sched_info.run_delay,
307 task->sched_info.pcnt); 307 task->sched_info.pcount);
308} 308}
309#endif 309#endif
310 310
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index b215c3524fa6..1820eb2ef762 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -16,6 +16,11 @@ extern int proc_sys_init(void);
16#else 16#else
17static inline void proc_sys_init(void) { } 17static inline void proc_sys_init(void) { }
18#endif 18#endif
19#ifdef CONFIG_NET
20extern int proc_net_init(void);
21#else
22static inline int proc_net_init(void) { return 0; }
23#endif
19 24
20struct vmalloc_info { 25struct vmalloc_info {
21 unsigned long used; 26 unsigned long used;
diff --git a/fs/proc/proc_misc.c b/fs/proc/proc_misc.c
index c9d6d5f400ad..0071939c0095 100644
--- a/fs/proc/proc_misc.c
+++ b/fs/proc/proc_misc.c
@@ -442,6 +442,7 @@ static int show_stat(struct seq_file *p, void *v)
442 int i; 442 int i;
443 unsigned long jif; 443 unsigned long jif;
444 cputime64_t user, nice, system, idle, iowait, irq, softirq, steal; 444 cputime64_t user, nice, system, idle, iowait, irq, softirq, steal;
445 cputime64_t guest;
445 u64 sum = 0; 446 u64 sum = 0;
446 struct timespec boottime; 447 struct timespec boottime;
447 unsigned int *per_irq_sum; 448 unsigned int *per_irq_sum;
@@ -452,6 +453,7 @@ static int show_stat(struct seq_file *p, void *v)
452 453
453 user = nice = system = idle = iowait = 454 user = nice = system = idle = iowait =
454 irq = softirq = steal = cputime64_zero; 455 irq = softirq = steal = cputime64_zero;
456 guest = cputime64_zero;
455 getboottime(&boottime); 457 getboottime(&boottime);
456 jif = boottime.tv_sec; 458 jif = boottime.tv_sec;
457 459
@@ -466,6 +468,7 @@ static int show_stat(struct seq_file *p, void *v)
466 irq = cputime64_add(irq, kstat_cpu(i).cpustat.irq); 468 irq = cputime64_add(irq, kstat_cpu(i).cpustat.irq);
467 softirq = cputime64_add(softirq, kstat_cpu(i).cpustat.softirq); 469 softirq = cputime64_add(softirq, kstat_cpu(i).cpustat.softirq);
468 steal = cputime64_add(steal, kstat_cpu(i).cpustat.steal); 470 steal = cputime64_add(steal, kstat_cpu(i).cpustat.steal);
471 guest = cputime64_add(guest, kstat_cpu(i).cpustat.guest);
469 for (j = 0; j < NR_IRQS; j++) { 472 for (j = 0; j < NR_IRQS; j++) {
470 unsigned int temp = kstat_cpu(i).irqs[j]; 473 unsigned int temp = kstat_cpu(i).irqs[j];
471 sum += temp; 474 sum += temp;
@@ -473,7 +476,7 @@ static int show_stat(struct seq_file *p, void *v)
473 } 476 }
474 } 477 }
475 478
476 seq_printf(p, "cpu %llu %llu %llu %llu %llu %llu %llu %llu\n", 479 seq_printf(p, "cpu %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
477 (unsigned long long)cputime64_to_clock_t(user), 480 (unsigned long long)cputime64_to_clock_t(user),
478 (unsigned long long)cputime64_to_clock_t(nice), 481 (unsigned long long)cputime64_to_clock_t(nice),
479 (unsigned long long)cputime64_to_clock_t(system), 482 (unsigned long long)cputime64_to_clock_t(system),
@@ -481,7 +484,8 @@ static int show_stat(struct seq_file *p, void *v)
481 (unsigned long long)cputime64_to_clock_t(iowait), 484 (unsigned long long)cputime64_to_clock_t(iowait),
482 (unsigned long long)cputime64_to_clock_t(irq), 485 (unsigned long long)cputime64_to_clock_t(irq),
483 (unsigned long long)cputime64_to_clock_t(softirq), 486 (unsigned long long)cputime64_to_clock_t(softirq),
484 (unsigned long long)cputime64_to_clock_t(steal)); 487 (unsigned long long)cputime64_to_clock_t(steal),
488 (unsigned long long)cputime64_to_clock_t(guest));
485 for_each_online_cpu(i) { 489 for_each_online_cpu(i) {
486 490
487 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */ 491 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
@@ -493,7 +497,9 @@ static int show_stat(struct seq_file *p, void *v)
493 irq = kstat_cpu(i).cpustat.irq; 497 irq = kstat_cpu(i).cpustat.irq;
494 softirq = kstat_cpu(i).cpustat.softirq; 498 softirq = kstat_cpu(i).cpustat.softirq;
495 steal = kstat_cpu(i).cpustat.steal; 499 steal = kstat_cpu(i).cpustat.steal;
496 seq_printf(p, "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu\n", 500 guest = kstat_cpu(i).cpustat.guest;
501 seq_printf(p,
502 "cpu%d %llu %llu %llu %llu %llu %llu %llu %llu %llu\n",
497 i, 503 i,
498 (unsigned long long)cputime64_to_clock_t(user), 504 (unsigned long long)cputime64_to_clock_t(user),
499 (unsigned long long)cputime64_to_clock_t(nice), 505 (unsigned long long)cputime64_to_clock_t(nice),
@@ -502,7 +508,8 @@ static int show_stat(struct seq_file *p, void *v)
502 (unsigned long long)cputime64_to_clock_t(iowait), 508 (unsigned long long)cputime64_to_clock_t(iowait),
503 (unsigned long long)cputime64_to_clock_t(irq), 509 (unsigned long long)cputime64_to_clock_t(irq),
504 (unsigned long long)cputime64_to_clock_t(softirq), 510 (unsigned long long)cputime64_to_clock_t(softirq),
505 (unsigned long long)cputime64_to_clock_t(steal)); 511 (unsigned long long)cputime64_to_clock_t(steal),
512 (unsigned long long)cputime64_to_clock_t(guest));
506 } 513 }
507 seq_printf(p, "intr %llu", (unsigned long long)sum); 514 seq_printf(p, "intr %llu", (unsigned long long)sum);
508 515
diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
new file mode 100644
index 000000000000..2e91fb756e9a
--- /dev/null
+++ b/fs/proc/proc_net.c
@@ -0,0 +1,200 @@
1/*
2 * linux/fs/proc/net.c
3 *
4 * Copyright (C) 2007
5 *
6 * Author: Eric Biederman <ebiederm@xmission.com>
7 *
8 * proc net directory handling functions
9 */
10
11#include <asm/uaccess.h>
12
13#include <linux/errno.h>
14#include <linux/time.h>
15#include <linux/proc_fs.h>
16#include <linux/stat.h>
17#include <linux/init.h>
18#include <linux/sched.h>
19#include <linux/module.h>
20#include <linux/bitops.h>
21#include <linux/smp_lock.h>
22#include <linux/mount.h>
23#include <linux/nsproxy.h>
24#include <net/net_namespace.h>
25
26#include "internal.h"
27
28
29struct proc_dir_entry *proc_net_create(struct net *net,
30 const char *name, mode_t mode, get_info_t *get_info)
31{
32 return create_proc_info_entry(name,mode, net->proc_net, get_info);
33}
34EXPORT_SYMBOL_GPL(proc_net_create);
35
36struct proc_dir_entry *proc_net_fops_create(struct net *net,
37 const char *name, mode_t mode, const struct file_operations *fops)
38{
39 struct proc_dir_entry *res;
40
41 res = create_proc_entry(name, mode, net->proc_net);
42 if (res)
43 res->proc_fops = fops;
44 return res;
45}
46EXPORT_SYMBOL_GPL(proc_net_fops_create);
47
48void proc_net_remove(struct net *net, const char *name)
49{
50 remove_proc_entry(name, net->proc_net);
51}
52EXPORT_SYMBOL_GPL(proc_net_remove);
53
54struct net *get_proc_net(const struct inode *inode)
55{
56 return maybe_get_net(PDE_NET(PDE(inode)));
57}
58EXPORT_SYMBOL_GPL(get_proc_net);
59
60static struct proc_dir_entry *proc_net_shadow;
61
62static struct dentry *proc_net_shadow_dentry(struct dentry *parent,
63 struct proc_dir_entry *de)
64{
65 struct dentry *shadow = NULL;
66 struct inode *inode;
67 if (!de)
68 goto out;
69 de_get(de);
70 inode = proc_get_inode(parent->d_inode->i_sb, de->low_ino, de);
71 if (!inode)
72 goto out_de_put;
73 shadow = d_alloc_name(parent, de->name);
74 if (!shadow)
75 goto out_iput;
76 shadow->d_op = parent->d_op; /* proc_dentry_operations */
77 d_instantiate(shadow, inode);
78out:
79 return shadow;
80out_iput:
81 iput(inode);
82out_de_put:
83 de_put(de);
84 goto out;
85}
86
87static void *proc_net_follow_link(struct dentry *parent, struct nameidata *nd)
88{
89 struct net *net = current->nsproxy->net_ns;
90 struct dentry *shadow;
91 shadow = proc_net_shadow_dentry(parent, net->proc_net);
92 if (!shadow)
93 return ERR_PTR(-ENOENT);
94
95 dput(nd->dentry);
96 /* My dentry count is 1 and that should be enough as the
97 * shadow dentry is thrown away immediately.
98 */
99 nd->dentry = shadow;
100 return NULL;
101}
102
103static struct dentry *proc_net_lookup(struct inode *dir, struct dentry *dentry,
104 struct nameidata *nd)
105{
106 struct net *net = current->nsproxy->net_ns;
107 struct dentry *shadow;
108
109 shadow = proc_net_shadow_dentry(nd->dentry, net->proc_net);
110 if (!shadow)
111 return ERR_PTR(-ENOENT);
112
113 dput(nd->dentry);
114 nd->dentry = shadow;
115
116 return shadow->d_inode->i_op->lookup(shadow->d_inode, dentry, nd);
117}
118
119static int proc_net_setattr(struct dentry *dentry, struct iattr *iattr)
120{
121 struct net *net = current->nsproxy->net_ns;
122 struct dentry *shadow;
123 int ret;
124
125 shadow = proc_net_shadow_dentry(dentry->d_parent, net->proc_net);
126 if (!shadow)
127 return -ENOENT;
128 ret = shadow->d_inode->i_op->setattr(shadow, iattr);
129 dput(shadow);
130 return ret;
131}
132
133static const struct file_operations proc_net_dir_operations = {
134 .read = generic_read_dir,
135};
136
137static struct inode_operations proc_net_dir_inode_operations = {
138 .follow_link = proc_net_follow_link,
139 .lookup = proc_net_lookup,
140 .setattr = proc_net_setattr,
141};
142
143static __net_init int proc_net_ns_init(struct net *net)
144{
145 struct proc_dir_entry *root, *netd, *net_statd;
146 int err;
147
148 err = -ENOMEM;
149 root = kzalloc(sizeof(*root), GFP_KERNEL);
150 if (!root)
151 goto out;
152
153 err = -EEXIST;
154 netd = proc_mkdir("net", root);
155 if (!netd)
156 goto free_root;
157
158 err = -EEXIST;
159 net_statd = proc_mkdir("stat", netd);
160 if (!net_statd)
161 goto free_net;
162
163 root->data = net;
164 netd->data = net;
165 net_statd->data = net;
166
167 net->proc_net_root = root;
168 net->proc_net = netd;
169 net->proc_net_stat = net_statd;
170 err = 0;
171
172out:
173 return err;
174free_net:
175 remove_proc_entry("net", root);
176free_root:
177 kfree(root);
178 goto out;
179}
180
181static __net_exit void proc_net_ns_exit(struct net *net)
182{
183 remove_proc_entry("stat", net->proc_net);
184 remove_proc_entry("net", net->proc_net_root);
185 kfree(net->proc_net_root);
186}
187
188struct pernet_operations __net_initdata proc_net_ns_ops = {
189 .init = proc_net_ns_init,
190 .exit = proc_net_ns_exit,
191};
192
193int __init proc_net_init(void)
194{
195 proc_net_shadow = proc_mkdir("net", NULL);
196 proc_net_shadow->proc_iops = &proc_net_dir_inode_operations;
197 proc_net_shadow->proc_fops = &proc_net_dir_operations;
198
199 return register_pernet_subsys(&proc_net_ns_ops);
200}
diff --git a/fs/proc/root.c b/fs/proc/root.c
index 41f17037f738..cf3046638b09 100644
--- a/fs/proc/root.c
+++ b/fs/proc/root.c
@@ -21,7 +21,7 @@
21 21
22#include "internal.h" 22#include "internal.h"
23 23
24struct proc_dir_entry *proc_net, *proc_net_stat, *proc_bus, *proc_root_fs, *proc_root_driver; 24struct proc_dir_entry *proc_bus, *proc_root_fs, *proc_root_driver;
25 25
26static int proc_get_sb(struct file_system_type *fs_type, 26static int proc_get_sb(struct file_system_type *fs_type,
27 int flags, const char *dev_name, void *data, struct vfsmount *mnt) 27 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
@@ -61,8 +61,8 @@ void __init proc_root_init(void)
61 return; 61 return;
62 } 62 }
63 proc_misc_init(); 63 proc_misc_init();
64 proc_net = proc_mkdir("net", NULL); 64
65 proc_net_stat = proc_mkdir("net/stat", NULL); 65 proc_net_init();
66 66
67#ifdef CONFIG_SYSVIPC 67#ifdef CONFIG_SYSVIPC
68 proc_mkdir("sysvipc", NULL); 68 proc_mkdir("sysvipc", NULL);
@@ -159,7 +159,5 @@ EXPORT_SYMBOL(create_proc_entry);
159EXPORT_SYMBOL(remove_proc_entry); 159EXPORT_SYMBOL(remove_proc_entry);
160EXPORT_SYMBOL(proc_root); 160EXPORT_SYMBOL(proc_root);
161EXPORT_SYMBOL(proc_root_fs); 161EXPORT_SYMBOL(proc_root_fs);
162EXPORT_SYMBOL(proc_net);
163EXPORT_SYMBOL(proc_net_stat);
164EXPORT_SYMBOL(proc_bus); 162EXPORT_SYMBOL(proc_bus);
165EXPORT_SYMBOL(proc_root_driver); 163EXPORT_SYMBOL(proc_root_driver);