nohz: Fix stale jiffies update in tick_nohz_restart()
[linux-flexiantxendom0-3.2.10.git] / kernel / acct.c
index 9f33910..02e6167 100644 (file)
@@ -84,11 +84,10 @@ static void do_acct_process(struct bsd_acct_struct *acct,
  * the cache line to have the data after getting the lock.
  */
 struct bsd_acct_struct {
-       volatile int            active;
-       volatile int            needcheck;
+       int                     active;
+       unsigned long           needcheck;
        struct file             *file;
        struct pid_namespace    *ns;
-       struct timer_list       timer;
        struct list_head        list;
 };
 
@@ -96,15 +95,6 @@ static DEFINE_SPINLOCK(acct_lock);
 static LIST_HEAD(acct_list);
 
 /*
- * Called whenever the timer says to check the free space.
- */
-static void acct_timeout(unsigned long x)
-{
-       struct bsd_acct_struct *acct = (struct bsd_acct_struct *)x;
-       acct->needcheck = 1;
-}
-
-/*
  * Check the amount of free space and suspend/resume accordingly.
  */
 static int check_free_space(struct bsd_acct_struct *acct, struct file *file)
@@ -112,23 +102,23 @@ static int check_free_space(struct bsd_acct_struct *acct, struct file *file)
        struct kstatfs sbuf;
        int res;
        int act;
-       sector_t resume;
-       sector_t suspend;
+       u64 resume;
+       u64 suspend;
 
        spin_lock(&acct_lock);
        res = acct->active;
-       if (!file || !acct->needcheck)
+       if (!file || time_is_before_jiffies(acct->needcheck))
                goto out;
        spin_unlock(&acct_lock);
 
        /* May block */
-       if (vfs_statfs(file->f_path.dentry, &sbuf))
+       if (vfs_statfs(&file->f_path, &sbuf))
                return res;
        suspend = sbuf.f_blocks * SUSPEND;
        resume = sbuf.f_blocks * RESUME;
 
-       sector_div(suspend, 100);
-       sector_div(resume, 100);
+       do_div(suspend, 100);
+       do_div(resume, 100);
 
        if (sbuf.f_bavail <= suspend)
                act = -1;
@@ -160,10 +150,7 @@ static int check_free_space(struct bsd_acct_struct *acct, struct file *file)
                }
        }
 
-       del_timer(&acct->timer);
-       acct->needcheck = 0;
-       acct->timer.expires = jiffies + ACCT_TIMEOUT*HZ;
-       add_timer(&acct->timer);
+       acct->needcheck = jiffies + ACCT_TIMEOUT*HZ;
        res = acct->active;
 out:
        spin_unlock(&acct_lock);
@@ -185,9 +172,7 @@ static void acct_file_reopen(struct bsd_acct_struct *acct, struct file *file,
        if (acct->file) {
                old_acct = acct->file;
                old_ns = acct->ns;
-               del_timer(&acct->timer);
                acct->active = 0;
-               acct->needcheck = 0;
                acct->file = NULL;
                acct->ns = NULL;
                list_del(&acct->list);
@@ -195,13 +180,9 @@ static void acct_file_reopen(struct bsd_acct_struct *acct, struct file *file,
        if (file) {
                acct->file = file;
                acct->ns = ns;
-               acct->needcheck = 0;
+               acct->needcheck = jiffies + ACCT_TIMEOUT*HZ;
                acct->active = 1;
                list_add(&acct->list, &acct_list);
-               /* It's been deleted if it was used before so this is safe */
-               setup_timer(&acct->timer, acct_timeout, (unsigned long)acct);
-               acct->timer.expires = jiffies + ACCT_TIMEOUT*HZ;
-               add_timer(&acct->timer);
        }
        if (old_acct) {
                mnt_unpin(old_acct->f_path.mnt);
@@ -216,7 +197,6 @@ static int acct_on(char *name)
 {
        struct file *file;
        struct vfsmount *mnt;
-       int error;
        struct pid_namespace *ns;
        struct bsd_acct_struct *acct = NULL;
 
@@ -244,13 +224,6 @@ static int acct_on(char *name)
                }
        }
 
-       error = security_acct(file);
-       if (error) {
-               kfree(acct);
-               filp_close(file, NULL);
-               return error;
-       }
-
        spin_lock(&acct_lock);
        if (ns->bacct == NULL) {
                ns->bacct = acct;
@@ -281,7 +254,7 @@ static int acct_on(char *name)
  */
 SYSCALL_DEFINE1(acct, const char __user *, name)
 {
-       int error;
+       int error = 0;
 
        if (!capable(CAP_SYS_PACCT))
                return -EPERM;
@@ -299,13 +272,11 @@ SYSCALL_DEFINE1(acct, const char __user *, name)
                if (acct == NULL)
                        return 0;
 
-               error = security_acct(NULL);
-               if (!error) {
-                       spin_lock(&acct_lock);
-                       acct_file_reopen(acct, NULL, NULL);
-                       spin_unlock(&acct_lock);
-               }
+               spin_lock(&acct_lock);
+               acct_file_reopen(acct, NULL, NULL);
+               spin_unlock(&acct_lock);
        }
+
        return error;
 }
 
@@ -344,7 +315,7 @@ void acct_auto_close(struct super_block *sb)
        spin_lock(&acct_lock);
 restart:
        list_for_each_entry(acct, &acct_list, list)
-               if (acct->file && acct->file->f_path.mnt->mnt_sb == sb) {
+               if (acct->file && acct->file->f_path.dentry->d_sb == sb) {
                        acct_file_reopen(acct, NULL, NULL);
                        goto restart;
                }
@@ -353,17 +324,17 @@ restart:
 
 void acct_exit_ns(struct pid_namespace *ns)
 {
-       struct bsd_acct_struct *acct;
+       struct bsd_acct_struct *acct = ns->bacct;
 
-       spin_lock(&acct_lock);
-       acct = ns->bacct;
-       if (acct != NULL) {
-               if (acct->file != NULL)
-                       acct_file_reopen(acct, NULL, NULL);
+       if (acct == NULL)
+               return;
 
-               kfree(acct);
-       }
+       spin_lock(&acct_lock);
+       if (acct->file != NULL)
+               acct_file_reopen(acct, NULL, NULL);
        spin_unlock(&acct_lock);
+
+       kfree(acct);
 }
 
 /*
@@ -491,19 +462,23 @@ static void do_acct_process(struct bsd_acct_struct *acct,
        u64 run_time;
        struct timespec uptime;
        struct tty_struct *tty;
+       const struct cred *orig_cred;
+
+       /* Perform file operations on behalf of whoever enabled accounting */
+       orig_cred = override_creds(file->f_cred);
 
        /*
         * First check to see if there is enough free_space to continue
         * the process accounting system.
         */
        if (!check_free_space(acct, file))
-               return;
+               goto out;
 
        /*
         * Fill the accounting struct with the needed info as recorded
         * by the different kernel functions.
         */
-       memset((caddr_t)&ac, 0, sizeof(acct_t));
+       memset(&ac, 0, sizeof(acct_t));
 
        ac.ac_version = ACCT_VERSION | ACCT_BYTEORDER;
        strlcpy(ac.ac_comm, current->comm, sizeof(ac.ac_comm));
@@ -532,7 +507,8 @@ static void do_acct_process(struct bsd_acct_struct *acct,
        do_div(elapsed, AHZ);
        ac.ac_btime = get_seconds() - elapsed;
        /* we really need to bite the bullet and change layout */
-       current_uid_gid(&ac.ac_uid, &ac.ac_gid);
+       ac.ac_uid = orig_cred->uid;
+       ac.ac_gid = orig_cred->gid;
 #if ACCT_VERSION==2
        ac.ac_ahz = AHZ;
 #endif
@@ -578,16 +554,8 @@ static void do_acct_process(struct bsd_acct_struct *acct,
                               sizeof(acct_t), &file->f_pos);
        current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
        set_fs(fs);
-}
-
-/**
- * acct_init_pacct - initialize a new pacct_struct
- * @pacct: per-process accounting info struct to initialize
- */
-void acct_init_pacct(struct pacct_struct *pacct)
-{
-       memset(pacct, 0, sizeof(struct pacct_struct));
-       pacct->ac_utime = pacct->ac_stime = cputime_zero;
+out:
+       revert_creds(orig_cred);
 }
 
 /**
@@ -625,8 +593,8 @@ void acct_collect(long exitcode, int group_dead)
                pacct->ac_flag |= ACORE;
        if (current->flags & PF_SIGNALED)
                pacct->ac_flag |= AXSIG;
-       pacct->ac_utime = cputime_add(pacct->ac_utime, current->utime);
-       pacct->ac_stime = cputime_add(pacct->ac_stime, current->stime);
+       pacct->ac_utime += current->utime;
+       pacct->ac_stime += current->stime;
        pacct->ac_minflt += current->min_flt;
        pacct->ac_majflt += current->maj_flt;
        spin_unlock_irq(&current->sighand->siglock);