diff options
author | trasz <trasz@FreeBSD.org> | 2011-03-29 17:47:25 +0000 |
---|---|---|
committer | trasz <trasz@FreeBSD.org> | 2011-03-29 17:47:25 +0000 |
commit | b8d3e8755df2ce0e93cf3b2ab68e0c4275c5565f (patch) | |
tree | 304753d7f5287660a242996801bd5664ee945d3a /sys/kern/kern_loginclass.c | |
parent | 056d03857b74836195225ca4b0216f0d197477b7 (diff) | |
download | FreeBSD-src-b8d3e8755df2ce0e93cf3b2ab68e0c4275c5565f.zip FreeBSD-src-b8d3e8755df2ce0e93cf3b2ab68e0c4275c5565f.tar.gz |
Add racct. It's an API to keep per-process, per-jail, per-loginclass
and per-loginclass resource accounting information, to be used by the new
resource limits code. It's connected to the build, but the code that
actually calls the new functions will come later.
Sponsored by: The FreeBSD Foundation
Reviewed by: kib (earlier version)
Diffstat (limited to 'sys/kern/kern_loginclass.c')
-rw-r--r-- | sys/kern/kern_loginclass.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/sys/kern/kern_loginclass.c b/sys/kern/kern_loginclass.c index cf644d5..d980246 100644 --- a/sys/kern/kern_loginclass.c +++ b/sys/kern/kern_loginclass.c @@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$"); #include <sys/priv.h> #include <sys/proc.h> #include <sys/queue.h> +#include <sys/racct.h> #include <sys/refcount.h> #include <sys/sysproto.h> #include <sys/systm.h> @@ -90,6 +91,7 @@ loginclass_free(struct loginclass *lc) mtx_lock(&loginclasses_lock); if (refcount_release(&lc->lc_refcount)) { + racct_destroy(&lc->lc_racct); LIST_REMOVE(lc, lc_next); mtx_unlock(&loginclasses_lock); free(lc, M_LOGINCLASS); @@ -115,6 +117,7 @@ loginclass_find(const char *name) return (NULL); newlc = malloc(sizeof(*newlc), M_LOGINCLASS, M_ZERO | M_WAITOK); + racct_create(&newlc->lc_racct); mtx_lock(&loginclasses_lock); LIST_FOREACH(lc, &loginclasses, lc_next) { @@ -124,6 +127,7 @@ loginclass_find(const char *name) /* Found loginclass with a matching name? */ loginclass_hold(lc); mtx_unlock(&loginclasses_lock); + racct_destroy(&newlc->lc_racct); free(newlc, M_LOGINCLASS); return (lc); } @@ -205,13 +209,27 @@ setloginclass(struct thread *td, struct setloginclass_args *uap) newcred->cr_loginclass = newlc; p->p_ucred = newcred; PROC_UNLOCK(p); - +#ifdef RACCT + racct_proc_ucred_changed(p, oldcred, newcred); +#endif loginclass_free(oldcred->cr_loginclass); crfree(oldcred); return (0); } +void +loginclass_racct_foreach(void (*callback)(struct racct *racct, + void *arg2, void *arg3), void *arg2, void *arg3) +{ + struct loginclass *lc; + + mtx_lock(&loginclasses_lock); + LIST_FOREACH(lc, &loginclasses, lc_next) + (callback)(lc->lc_racct, arg2, arg3); + mtx_unlock(&loginclasses_lock); +} + static void lc_init(void) { |