Commit cdd37e23092c3c6fbbb2e611f8c3d18e676bf28f
1 parent
ed44724b79
Exists in
smarc_imx_lf-5.15.y
and in
32 other branches
separate namespace-independent parts of filling acct_t
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Showing 1 changed file with 51 additions and 47 deletions Side-by-side Diff
kernel/acct.c
... | ... | @@ -448,42 +448,20 @@ |
448 | 448 | * do_exit() or when switching to a different output file. |
449 | 449 | */ |
450 | 450 | |
451 | -/* | |
452 | - * do_acct_process does all actual work. Caller holds the reference to file. | |
453 | - */ | |
454 | -static void do_acct_process(struct bsd_acct_struct *acct, | |
455 | - struct pid_namespace *ns, struct file *file) | |
451 | +static void fill_ac(acct_t *ac) | |
456 | 452 | { |
457 | 453 | struct pacct_struct *pacct = ¤t->signal->pacct; |
458 | - acct_t ac; | |
459 | - unsigned long flim; | |
460 | 454 | u64 elapsed, run_time; |
461 | 455 | struct tty_struct *tty; |
462 | - const struct cred *orig_cred; | |
463 | 456 | |
464 | 457 | /* |
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 | - | |
479 | - /* | |
480 | 458 | * Fill the accounting struct with the needed info as recorded |
481 | 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; | |
486 | - strlcpy(ac.ac_comm, current->comm, sizeof(ac.ac_comm)); | |
463 | + ac->ac_version = ACCT_VERSION | ACCT_BYTEORDER; | |
464 | + strlcpy(ac->ac_comm, current->comm, sizeof(ac->ac_comm)); | |
487 | 465 | |
488 | 466 | /* calculate run_time in nsec*/ |
489 | 467 | run_time = ktime_get_ns(); |
490 | 468 | |
491 | 469 | |
492 | 470 | |
493 | 471 | |
... | ... | @@ -491,27 +469,66 @@ |
491 | 469 | /* convert nsec -> AHZ */ |
492 | 470 | elapsed = nsec_to_AHZ(run_time); |
493 | 471 | #if ACCT_VERSION==3 |
494 | - ac.ac_etime = encode_float(elapsed); | |
472 | + ac->ac_etime = encode_float(elapsed); | |
495 | 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 | 475 | (unsigned long) elapsed : (unsigned long) -1l); |
498 | 476 | #endif |
499 | 477 | #if ACCT_VERSION==1 || ACCT_VERSION==2 |
500 | 478 | { |
501 | 479 | /* new enlarged etime field */ |
502 | 480 | comp2_t etime = encode_comp2_t(elapsed); |
503 | - ac.ac_etime_hi = etime >> 16; | |
504 | - ac.ac_etime_lo = (u16) etime; | |
481 | + ac->ac_etime_hi = etime >> 16; | |
482 | + ac->ac_etime_lo = (u16) etime; | |
505 | 483 | } |
506 | 484 | #endif |
507 | 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(¤t->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(¤t->sighand->siglock); | |
502 | +} | |
503 | +/* | |
504 | + * do_acct_process does all actual work. Caller holds the reference to file. | |
505 | + */ | |
506 | +static 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 | 529 | /* we really need to bite the bullet and change layout */ |
510 | 530 | ac.ac_uid = from_kuid_munged(file->f_cred->user_ns, orig_cred->uid); |
511 | 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 | 532 | #if ACCT_VERSION==1 || ACCT_VERSION==2 |
516 | 533 | /* backward-compatible 16 bit fields */ |
517 | 534 | ac.ac_uid16 = ac.ac_uid; |
... | ... | @@ -523,19 +540,6 @@ |
523 | 540 | ac.ac_ppid = task_tgid_nr_ns(rcu_dereference(current->real_parent), ns); |
524 | 541 | rcu_read_unlock(); |
525 | 542 | #endif |
526 | - | |
527 | - spin_lock_irq(¤t->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(¤t->sighand->siglock); | |
538 | - | |
539 | 543 | /* |
540 | 544 | * Get freeze protection. If the fs is frozen, just skip the write |
541 | 545 | * as we could deadlock the system otherwise. |