diff options
author | Pavel Emelyanov <xemul@openvz.org> | 2008-03-24 15:29:53 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-03-24 22:22:20 -0400 |
commit | 5f7b703fe2be40db5a2bf136ac9e44cf5db267cc (patch) | |
tree | aa7da3bcd7a1e50cf2be75f633ce19ae3bf0ae9c /kernel/acct.c | |
parent | a846a1954b6397e844fe1e258af7598897ec6159 (diff) |
bsd_acct: using task_struct->tgid is not right in pid-namespaces
In case we're accounting from a sub-namespace, the tgids reported will not
refer to the right namespace.
Save the pid_namespace we're accounting in on the acct_glbs and use it in
do_acct_process.
Two less :) places using the task_struct.tgid member.
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Cc: Oleg Nesterov <oleg@tv-sign.ru>
Cc: "Paul E. McKenney" <paulmck@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/acct.c')
-rw-r--r-- | kernel/acct.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/kernel/acct.c b/kernel/acct.c index 7ff5339a3f05..91e1cfd734d2 100644 --- a/kernel/acct.c +++ b/kernel/acct.c | |||
@@ -58,6 +58,7 @@ | |||
58 | #include <asm/uaccess.h> | 58 | #include <asm/uaccess.h> |
59 | #include <asm/div64.h> | 59 | #include <asm/div64.h> |
60 | #include <linux/blkdev.h> /* sector_div */ | 60 | #include <linux/blkdev.h> /* sector_div */ |
61 | #include <linux/pid_namespace.h> | ||
61 | 62 | ||
62 | /* | 63 | /* |
63 | * These constants control the amount of freespace that suspend and | 64 | * These constants control the amount of freespace that suspend and |
@@ -74,7 +75,7 @@ int acct_parm[3] = {4, 2, 30}; | |||
74 | /* | 75 | /* |
75 | * External references and all of the globals. | 76 | * External references and all of the globals. |
76 | */ | 77 | */ |
77 | static void do_acct_process(struct file *); | 78 | static void do_acct_process(struct pid_namespace *ns, struct file *); |
78 | 79 | ||
79 | /* | 80 | /* |
80 | * This structure is used so that all the data protected by lock | 81 | * This structure is used so that all the data protected by lock |
@@ -86,6 +87,7 @@ struct acct_glbs { | |||
86 | volatile int active; | 87 | volatile int active; |
87 | volatile int needcheck; | 88 | volatile int needcheck; |
88 | struct file *file; | 89 | struct file *file; |
90 | struct pid_namespace *ns; | ||
89 | struct timer_list timer; | 91 | struct timer_list timer; |
90 | }; | 92 | }; |
91 | 93 | ||
@@ -175,9 +177,11 @@ out: | |||
175 | static void acct_file_reopen(struct file *file) | 177 | static void acct_file_reopen(struct file *file) |
176 | { | 178 | { |
177 | struct file *old_acct = NULL; | 179 | struct file *old_acct = NULL; |
180 | struct pid_namespace *old_ns = NULL; | ||
178 | 181 | ||
179 | if (acct_globals.file) { | 182 | if (acct_globals.file) { |
180 | old_acct = acct_globals.file; | 183 | old_acct = acct_globals.file; |
184 | old_ns = acct_globals.ns; | ||
181 | del_timer(&acct_globals.timer); | 185 | del_timer(&acct_globals.timer); |
182 | acct_globals.active = 0; | 186 | acct_globals.active = 0; |
183 | acct_globals.needcheck = 0; | 187 | acct_globals.needcheck = 0; |
@@ -185,6 +189,7 @@ static void acct_file_reopen(struct file *file) | |||
185 | } | 189 | } |
186 | if (file) { | 190 | if (file) { |
187 | acct_globals.file = file; | 191 | acct_globals.file = file; |
192 | acct_globals.ns = get_pid_ns(task_active_pid_ns(current)); | ||
188 | acct_globals.needcheck = 0; | 193 | acct_globals.needcheck = 0; |
189 | acct_globals.active = 1; | 194 | acct_globals.active = 1; |
190 | /* It's been deleted if it was used before so this is safe */ | 195 | /* It's been deleted if it was used before so this is safe */ |
@@ -196,8 +201,9 @@ static void acct_file_reopen(struct file *file) | |||
196 | if (old_acct) { | 201 | if (old_acct) { |
197 | mnt_unpin(old_acct->f_path.mnt); | 202 | mnt_unpin(old_acct->f_path.mnt); |
198 | spin_unlock(&acct_globals.lock); | 203 | spin_unlock(&acct_globals.lock); |
199 | do_acct_process(old_acct); | 204 | do_acct_process(old_ns, old_acct); |
200 | filp_close(old_acct, NULL); | 205 | filp_close(old_acct, NULL); |
206 | put_pid_ns(old_ns); | ||
201 | spin_lock(&acct_globals.lock); | 207 | spin_lock(&acct_globals.lock); |
202 | } | 208 | } |
203 | } | 209 | } |
@@ -419,7 +425,7 @@ static u32 encode_float(u64 value) | |||
419 | /* | 425 | /* |
420 | * do_acct_process does all actual work. Caller holds the reference to file. | 426 | * do_acct_process does all actual work. Caller holds the reference to file. |
421 | */ | 427 | */ |
422 | static void do_acct_process(struct file *file) | 428 | static void do_acct_process(struct pid_namespace *ns, struct file *file) |
423 | { | 429 | { |
424 | struct pacct_struct *pacct = ¤t->signal->pacct; | 430 | struct pacct_struct *pacct = ¤t->signal->pacct; |
425 | acct_t ac; | 431 | acct_t ac; |
@@ -481,9 +487,9 @@ static void do_acct_process(struct file *file) | |||
481 | ac.ac_gid16 = current->gid; | 487 | ac.ac_gid16 = current->gid; |
482 | #endif | 488 | #endif |
483 | #if ACCT_VERSION==3 | 489 | #if ACCT_VERSION==3 |
484 | ac.ac_pid = current->tgid; | 490 | ac.ac_pid = task_tgid_nr_ns(current, ns); |
485 | rcu_read_lock(); | 491 | rcu_read_lock(); |
486 | ac.ac_ppid = rcu_dereference(current->real_parent)->tgid; | 492 | ac.ac_ppid = task_tgid_nr_ns(rcu_dereference(current->real_parent), ns); |
487 | rcu_read_unlock(); | 493 | rcu_read_unlock(); |
488 | #endif | 494 | #endif |
489 | 495 | ||
@@ -580,6 +586,7 @@ void acct_collect(long exitcode, int group_dead) | |||
580 | void acct_process(void) | 586 | void acct_process(void) |
581 | { | 587 | { |
582 | struct file *file = NULL; | 588 | struct file *file = NULL; |
589 | struct pid_namespace *ns; | ||
583 | 590 | ||
584 | /* | 591 | /* |
585 | * accelerate the common fastpath: | 592 | * accelerate the common fastpath: |
@@ -594,8 +601,10 @@ void acct_process(void) | |||
594 | return; | 601 | return; |
595 | } | 602 | } |
596 | get_file(file); | 603 | get_file(file); |
604 | ns = get_pid_ns(acct_globals.ns); | ||
597 | spin_unlock(&acct_globals.lock); | 605 | spin_unlock(&acct_globals.lock); |
598 | 606 | ||
599 | do_acct_process(file); | 607 | do_acct_process(ns, file); |
600 | fput(file); | 608 | fput(file); |
609 | put_pid_ns(ns); | ||
601 | } | 610 | } |