Date: Sat, 15 Aug 2009 17:14:40 GMT From: Edward Tomasz Napierala <trasz@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 167373 for review Message-ID: <200908151714.n7FHEegC001549@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=167373 Change 167373 by trasz@trasz_anger on 2009/08/15 17:14:28 Refactor things. Affected files ... .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_hrl.c#58 edit .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_loginclass.c#10 edit .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_prot.c#21 edit .. //depot/projects/soc2009/trasz_limits/sys/sys/hrl.h#33 edit Differences ... ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_hrl.c#58 (text+ko) ==== @@ -640,7 +640,7 @@ mtx_unlock(&hrl_lock); } -void +static void hrl_usage_add(struct hrl_usage *dest, const struct hrl_usage *src) { int i; @@ -662,7 +662,7 @@ mtx_unlock(&hrl_lock); } -void +static void hrl_usage_subtract(struct hrl_usage *dest, const struct hrl_usage *src) { int i; @@ -1637,13 +1637,14 @@ } /* - * Called after loginclass change, to adjust p_limits. + * Called just before loginclass change, to adjust p_limits and lc_usage. */ void -hrl_proc_loginclass_changed(struct proc *p) +hrl_proc_loginclass_changing(struct proc *p, struct loginclass *newlc) { int error; struct hrl_limit *limit; + struct loginclass *lc = p->p_loginclass; PROC_LOCK_ASSERT(p, MA_OWNED); @@ -1664,12 +1665,18 @@ /* * Now add rules for the current loginclass. */ - LIST_FOREACH(limit, &p->p_loginclass->lc_limits, hl_next) { + LIST_FOREACH(limit, &newlc->lc_limits, hl_next) { error = hrl_limit_add_locked(&p->p_limits, limit->hl_rule); KASSERT(error == 0, ("XXX: better error handling needed")); } mtx_unlock(&hrl_lock); + + /* + * Adjust loginclass resource usage information. + */ + hrl_usage_subtract(&lc->lc_usage, &p->p_usage); + hrl_usage_add(&newlc->lc_usage, &p->p_usage); } /* @@ -1681,11 +1688,11 @@ * XXX: What about jails? */ void -hrl_proc_ucred_changed(struct proc *p) +hrl_proc_ucred_changing(struct proc *p, struct ucred *newcred) { int error, i; - struct ucred *cred = p->p_ucred; struct hrl_limit *limit; + struct uidinfo *olduip, *newuip; PROC_LOCK_ASSERT(p, MA_OWNED); @@ -1707,14 +1714,14 @@ /* * Now add rules for the current user credentials. */ - LIST_FOREACH(limit, &cred->cr_ruidinfo->ui_limits, hl_next) { + LIST_FOREACH(limit, &newcred->cr_ruidinfo->ui_limits, hl_next) { error = hrl_limit_add_locked(&p->p_limits, limit->hl_rule); KASSERT(error == 0, ("XXX: better error handling needed")); } if (hrl_group_accounting) { - for (i = 0; i < cred->cr_ngroups; i++) { + for (i = 0; i < newcred->cr_ngroups; i++) { LIST_FOREACH(limit, - &cred->cr_gidinfos[i]->gi_limits, hl_next) { + &newcred->cr_gidinfos[i]->gi_limits, hl_next) { error = hrl_limit_add_locked(&p->p_limits, limit->hl_rule); KASSERT(error == 0, @@ -1724,6 +1731,28 @@ } mtx_unlock(&hrl_lock); + + /* + * Fix up per-ruid resource consumption. + */ + newuip = newcred->cr_ruidinfo; + olduip = p->p_ucred->cr_ruidinfo; + if (newuip != olduip) { + hrl_usage_subtract(&olduip->ui_usage, &p->p_usage); + hrl_usage_add(&newuip->ui_usage, &p->p_usage); + } + + /* + * Fix up per-group resource consumption. + */ + if (hrl_group_accounting) { + for (i = 0; i < p->p_ucred->cr_ngroups; i++) + hrl_usage_subtract( + &p->p_ucred->cr_gidinfos[i]->gi_usage, &p->p_usage); + for (i = 0; i < newcred->cr_ngroups; i++) + hrl_usage_add( + &newcred->cr_gidinfos[i]->gi_usage, &p->p_usage); + } } /* ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_loginclass.c#10 (text+ko) ==== @@ -200,11 +200,9 @@ newlc = loginclass_find(lcname); PROC_LOCK(p); + hrl_proc_loginclass_changing(p, newlc); oldlc = p->p_loginclass; p->p_loginclass = newlc; - hrl_usage_subtract(&oldlc->lc_usage, &p->p_usage); - hrl_usage_add(&newlc->lc_usage, &p->p_usage); - hrl_proc_loginclass_changed(p); PROC_UNLOCK(p); loginclass_release(oldlc); ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_prot.c#21 (text+ko) ==== @@ -2190,33 +2190,10 @@ void change_cred(struct proc *p, struct ucred *newcred) { - int i; - struct uidinfo *olduip, *newuip; - PROC_LOCK_ASSERT(p, MA_OWNED); - /* - * Fix up per-ruid resource consumption. - */ - newuip = newcred->cr_ruidinfo; - olduip = p->p_ucred->cr_ruidinfo; - if (newuip != olduip) { - hrl_usage_subtract(&olduip->ui_usage, &p->p_usage); - hrl_usage_add(&newuip->ui_usage, &p->p_usage); - } - - /* - * Fix up per-group resource consumption. - */ - if (hrl_group_accounting) { - for (i = 0; i < p->p_ucred->cr_ngroups; i++) - hrl_usage_subtract(&p->p_ucred->cr_gidinfos[i]->gi_usage, &p->p_usage); - for (i = 0; i < newcred->cr_ngroups; i++) - hrl_usage_add(&newcred->cr_gidinfos[i]->gi_usage, &p->p_usage); - } - + hrl_proc_ucred_changing(p, newcred); p->p_ucred = newcred; - hrl_proc_ucred_changed(p); } /*- ==== //depot/projects/soc2009/trasz_limits/sys/sys/hrl.h#33 (text+ko) ==== @@ -129,18 +129,18 @@ #ifdef _KERNEL +struct loginclass; struct proc; +struct ucred; int hrl_alloc(struct proc *p, int object, uint64_t amount); int hrl_allocated(struct proc *p, int object, uint64_t amount); void hrl_free(struct proc *p, int object, uint64_t amount); -void hrl_usage_add(struct hrl_usage *dest, const struct hrl_usage *src); -void hrl_usage_subtract(struct hrl_usage *dest, const struct hrl_usage *src); void hrl_proc_exiting(struct proc *p); -void hrl_proc_loginclass_changed(struct proc *p); -void hrl_proc_ucred_changed(struct proc *p); +void hrl_proc_loginclass_changing(struct proc *p, struct loginclass *newlc); +void hrl_proc_ucred_changing(struct proc *p, struct ucred *newcred); struct hrl_rule *hrl_rule_alloc(int flags); struct hrl_rule *hrl_rule_duplicate(const struct hrl_rule *rule, int flags);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200908151714.n7FHEegC001549>