bsdacct: make check timer accept a bsd_acct_struct argument
[linux-2.6-block.git] / kernel / acct.c
index cf19547cc9e42d346c49b0e51e89aa5fb19364d6..05f8bc094a4ba8b963afc5def9a4b8d68e904a23 100644 (file)
@@ -58,6 +58,7 @@
 #include <asm/uaccess.h>
 #include <asm/div64.h>
 #include <linux/blkdev.h> /* sector_div */
+#include <linux/pid_namespace.h>
 
 /*
  * These constants control the amount of freespace that suspend and
@@ -74,30 +75,32 @@ int acct_parm[3] = {4, 2, 30};
 /*
  * External references and all of the globals.
  */
-static void do_acct_process(struct file *);
+static void do_acct_process(struct pid_namespace *ns, struct file *);
 
 /*
  * This structure is used so that all the data protected by lock
  * can be placed in the same cache line as the lock.  This primes
  * the cache line to have the data after getting the lock.
  */
-struct acct_glbs {
+struct bsd_acct_struct {
        spinlock_t              lock;
        volatile int            active;
        volatile int            needcheck;
        struct file             *file;
+       struct pid_namespace    *ns;
        struct timer_list       timer;
 };
 
-static struct acct_glbs acct_globals __cacheline_aligned =
+static struct bsd_acct_struct acct_globals __cacheline_aligned =
        {__SPIN_LOCK_UNLOCKED(acct_globals.lock)};
 
 /*
  * Called whenever the timer says to check the free space.
  */
-static void acct_timeout(unsigned long unused)
+static void acct_timeout(unsigned long x)
 {
-       acct_globals.needcheck = 1;
+       struct bsd_acct_struct *acct = (struct bsd_acct_struct *)x;
+       acct->needcheck = 1;
 }
 
 /*
@@ -175,9 +178,11 @@ out:
 static void acct_file_reopen(struct file *file)
 {
        struct file *old_acct = NULL;
+       struct pid_namespace *old_ns = NULL;
 
        if (acct_globals.file) {
                old_acct = acct_globals.file;
+               old_ns = acct_globals.ns;
                del_timer(&acct_globals.timer);
                acct_globals.active = 0;
                acct_globals.needcheck = 0;
@@ -185,19 +190,21 @@ static void acct_file_reopen(struct file *file)
        }
        if (file) {
                acct_globals.file = file;
+               acct_globals.ns = get_pid_ns(task_active_pid_ns(current));
                acct_globals.needcheck = 0;
                acct_globals.active = 1;
                /* It's been deleted if it was used before so this is safe */
-               init_timer(&acct_globals.timer);
-               acct_globals.timer.function = acct_timeout;
+               setup_timer(&acct_globals.timer, acct_timeout,
+                               (unsigned long)&acct_globals);
                acct_globals.timer.expires = jiffies + ACCT_TIMEOUT*HZ;
                add_timer(&acct_globals.timer);
        }
        if (old_acct) {
                mnt_unpin(old_acct->f_path.mnt);
                spin_unlock(&acct_globals.lock);
-               do_acct_process(old_acct);
+               do_acct_process(old_ns, old_acct);
                filp_close(old_acct, NULL);
+               put_pid_ns(old_ns);
                spin_lock(&acct_globals.lock);
        }
 }
@@ -419,7 +426,7 @@ static u32 encode_float(u64 value)
 /*
  *  do_acct_process does all actual work. Caller holds the reference to file.
  */
-static void do_acct_process(struct file *file)
+static void do_acct_process(struct pid_namespace *ns, struct file *file)
 {
        struct pacct_struct *pacct = &current->signal->pacct;
        acct_t ac;
@@ -481,8 +488,10 @@ static void do_acct_process(struct file *file)
        ac.ac_gid16 = current->gid;
 #endif
 #if ACCT_VERSION==3
-       ac.ac_pid = current->tgid;
-       ac.ac_ppid = current->parent->tgid;
+       ac.ac_pid = task_tgid_nr_ns(current, ns);
+       rcu_read_lock();
+       ac.ac_ppid = task_tgid_nr_ns(rcu_dereference(current->real_parent), ns);
+       rcu_read_unlock();
 #endif
 
        spin_lock_irq(&current->sighand->siglock);
@@ -571,13 +580,13 @@ void acct_collect(long exitcode, int group_dead)
 
 /**
  * acct_process - now just a wrapper around do_acct_process
- * @exitcode: task exit code
  *
  * handles process accounting for an exiting task
  */
 void acct_process(void)
 {
        struct file *file = NULL;
+       struct pid_namespace *ns;
 
        /*
         * accelerate the common fastpath:
@@ -592,8 +601,10 @@ void acct_process(void)
                return;
        }
        get_file(file);
+       ns = get_pid_ns(acct_globals.ns);
        spin_unlock(&acct_globals.lock);
 
-       do_acct_process(file);
+       do_acct_process(ns, file);
        fput(file);
+       put_pid_ns(ns);
 }