aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2014-04-26 23:45:53 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2014-08-07 14:40:07 -0400
commitcdd37e23092c3c6fbbb2e611f8c3d18e676bf28f (patch)
tree943436b3c2410d4b80c147bf08e507082b9ae387 /kernel
parented44724b79d8e03a40665436019cf22baba80d30 (diff)
separate namespace-independent parts of filling acct_t
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/acct.c98
1 files changed, 51 insertions, 47 deletions
diff --git a/kernel/acct.c b/kernel/acct.c
index 8082d9875d6b..efa891beeaa3 100644
--- a/kernel/acct.c
+++ b/kernel/acct.c
@@ -448,42 +448,20 @@ static u32 encode_float(u64 value)
448 * do_exit() or when switching to a different output file. 448 * do_exit() or when switching to a different output file.
449 */ 449 */
450 450
451/* 451static void fill_ac(acct_t *ac)
452 * do_acct_process does all actual work. Caller holds the reference to file.
453 */
454static void do_acct_process(struct bsd_acct_struct *acct,
455 struct pid_namespace *ns, struct file *file)
456{ 452{
457 struct pacct_struct *pacct = &current->signal->pacct; 453 struct pacct_struct *pacct = &current->signal->pacct;
458 acct_t ac;
459 unsigned long flim;
460 u64 elapsed, run_time; 454 u64 elapsed, run_time;
461 struct tty_struct *tty; 455 struct tty_struct *tty;
462 const struct cred *orig_cred;
463
464 /*
465 * Accounting records are not subject to resource limits.
466 */
467 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
468 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
469 /* Perform file operations on behalf of whoever enabled accounting */
470 orig_cred = override_creds(file->f_cred);
471
472 /*
473 * First check to see if there is enough free_space to continue
474 * the process accounting system.
475 */
476 if (!check_free_space(acct, file))
477 goto out;
478 456
479 /* 457 /*
480 * Fill the accounting struct with the needed info as recorded 458 * Fill the accounting struct with the needed info as recorded
481 * by the different kernel functions. 459 * by the different kernel functions.
482 */ 460 */
483 memset(&ac, 0, sizeof(acct_t)); 461 memset(ac, 0, sizeof(acct_t));
484 462
485 ac.ac_version = ACCT_VERSION | ACCT_BYTEORDER; 463 ac->ac_version = ACCT_VERSION | ACCT_BYTEORDER;
486 strlcpy(ac.ac_comm, current->comm, sizeof(ac.ac_comm)); 464 strlcpy(ac->ac_comm, current->comm, sizeof(ac->ac_comm));
487 465
488 /* calculate run_time in nsec*/ 466 /* calculate run_time in nsec*/
489 run_time = ktime_get_ns(); 467 run_time = ktime_get_ns();
@@ -491,27 +469,66 @@ static void do_acct_process(struct bsd_acct_struct *acct,
491 /* convert nsec -> AHZ */ 469 /* convert nsec -> AHZ */
492 elapsed = nsec_to_AHZ(run_time); 470 elapsed = nsec_to_AHZ(run_time);
493#if ACCT_VERSION==3 471#if ACCT_VERSION==3
494 ac.ac_etime = encode_float(elapsed); 472 ac->ac_etime = encode_float(elapsed);
495#else 473#else
496 ac.ac_etime = encode_comp_t(elapsed < (unsigned long) -1l ? 474 ac->ac_etime = encode_comp_t(elapsed < (unsigned long) -1l ?
497 (unsigned long) elapsed : (unsigned long) -1l); 475 (unsigned long) elapsed : (unsigned long) -1l);
498#endif 476#endif
499#if ACCT_VERSION==1 || ACCT_VERSION==2 477#if ACCT_VERSION==1 || ACCT_VERSION==2
500 { 478 {
501 /* new enlarged etime field */ 479 /* new enlarged etime field */
502 comp2_t etime = encode_comp2_t(elapsed); 480 comp2_t etime = encode_comp2_t(elapsed);
503 ac.ac_etime_hi = etime >> 16; 481 ac->ac_etime_hi = etime >> 16;
504 ac.ac_etime_lo = (u16) etime; 482 ac->ac_etime_lo = (u16) etime;
505 } 483 }
506#endif 484#endif
507 do_div(elapsed, AHZ); 485 do_div(elapsed, AHZ);
508 ac.ac_btime = get_seconds() - elapsed; 486 ac->ac_btime = get_seconds() - elapsed;
487#if ACCT_VERSION==2
488 ac->ac_ahz = AHZ;
489#endif
490
491 spin_lock_irq(&current->sighand->siglock);
492 tty = current->signal->tty; /* Safe as we hold the siglock */
493 ac->ac_tty = tty ? old_encode_dev(tty_devnum(tty)) : 0;
494 ac->ac_utime = encode_comp_t(jiffies_to_AHZ(cputime_to_jiffies(pacct->ac_utime)));
495 ac->ac_stime = encode_comp_t(jiffies_to_AHZ(cputime_to_jiffies(pacct->ac_stime)));
496 ac->ac_flag = pacct->ac_flag;
497 ac->ac_mem = encode_comp_t(pacct->ac_mem);
498 ac->ac_minflt = encode_comp_t(pacct->ac_minflt);
499 ac->ac_majflt = encode_comp_t(pacct->ac_majflt);
500 ac->ac_exitcode = pacct->ac_exitcode;
501 spin_unlock_irq(&current->sighand->siglock);
502}
503/*
504 * do_acct_process does all actual work. Caller holds the reference to file.
505 */
506static void do_acct_process(struct bsd_acct_struct *acct,
507 struct pid_namespace *ns, struct file *file)
508{
509 acct_t ac;
510 unsigned long flim;
511 const struct cred *orig_cred;
512
513 /*
514 * Accounting records are not subject to resource limits.
515 */
516 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
517 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
518 /* Perform file operations on behalf of whoever enabled accounting */
519 orig_cred = override_creds(file->f_cred);
520
521 /*
522 * First check to see if there is enough free_space to continue
523 * the process accounting system.
524 */
525 if (!check_free_space(acct, file))
526 goto out;
527
528 fill_ac(&ac);
509 /* we really need to bite the bullet and change layout */ 529 /* we really need to bite the bullet and change layout */
510 ac.ac_uid = from_kuid_munged(file->f_cred->user_ns, orig_cred->uid); 530 ac.ac_uid = from_kuid_munged(file->f_cred->user_ns, orig_cred->uid);
511 ac.ac_gid = from_kgid_munged(file->f_cred->user_ns, orig_cred->gid); 531 ac.ac_gid = from_kgid_munged(file->f_cred->user_ns, orig_cred->gid);
512#if ACCT_VERSION==2
513 ac.ac_ahz = AHZ;
514#endif
515#if ACCT_VERSION==1 || ACCT_VERSION==2 532#if ACCT_VERSION==1 || ACCT_VERSION==2
516 /* backward-compatible 16 bit fields */ 533 /* backward-compatible 16 bit fields */
517 ac.ac_uid16 = ac.ac_uid; 534 ac.ac_uid16 = ac.ac_uid;
@@ -523,19 +540,6 @@ static void do_acct_process(struct bsd_acct_struct *acct,
523 ac.ac_ppid = task_tgid_nr_ns(rcu_dereference(current->real_parent), ns); 540 ac.ac_ppid = task_tgid_nr_ns(rcu_dereference(current->real_parent), ns);
524 rcu_read_unlock(); 541 rcu_read_unlock();
525#endif 542#endif
526
527 spin_lock_irq(&current->sighand->siglock);
528 tty = current->signal->tty; /* Safe as we hold the siglock */
529 ac.ac_tty = tty ? old_encode_dev(tty_devnum(tty)) : 0;
530 ac.ac_utime = encode_comp_t(jiffies_to_AHZ(cputime_to_jiffies(pacct->ac_utime)));
531 ac.ac_stime = encode_comp_t(jiffies_to_AHZ(cputime_to_jiffies(pacct->ac_stime)));
532 ac.ac_flag = pacct->ac_flag;
533 ac.ac_mem = encode_comp_t(pacct->ac_mem);
534 ac.ac_minflt = encode_comp_t(pacct->ac_minflt);
535 ac.ac_majflt = encode_comp_t(pacct->ac_majflt);
536 ac.ac_exitcode = pacct->ac_exitcode;
537 spin_unlock_irq(&current->sighand->siglock);
538
539 /* 543 /*
540 * Get freeze protection. If the fs is frozen, just skip the write 544 * Get freeze protection. If the fs is frozen, just skip the write
541 * as we could deadlock the system otherwise. 545 * as we could deadlock the system otherwise.