From owner-p4-projects@FreeBSD.ORG Mon Jun 15 21:37:41 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 03971106564A; Mon, 15 Jun 2009 21:37:40 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 57FE2106566C for ; Mon, 15 Jun 2009 21:37:40 +0000 (UTC) (envelope-from trasz@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 45FEF8FC23 for ; Mon, 15 Jun 2009 21:37:40 +0000 (UTC) (envelope-from trasz@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n5FLbe0S028709 for ; Mon, 15 Jun 2009 21:37:40 GMT (envelope-from trasz@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n5FLbeQ6028707 for perforce@freebsd.org; Mon, 15 Jun 2009 21:37:40 GMT (envelope-from trasz@freebsd.org) Date: Mon, 15 Jun 2009 21:37:40 GMT Message-Id: <200906152137.n5FLbeQ6028707@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to trasz@freebsd.org using -f From: Edward Tomasz Napierala To: Perforce Change Reviews Cc: Subject: PERFORCE change 164469 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Jun 2009 21:37:42 -0000 http://perforce.freebsd.org/chv.cgi?CH=164469 Change 164469 by trasz@trasz_victim on 2009/06/15 21:37:18 Working (apart from a little LOR) per-group accounting. Affected files ... .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_hrl.c#10 edit .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_resource.c#7 edit .. //depot/projects/soc2009/trasz_limits/sys/sys/resourcevar.h#5 edit Differences ... ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_hrl.c#10 (text+ko) ==== @@ -104,6 +104,8 @@ int hrl_alloc_proc(struct proc *p, int resource, uint64_t amount) { + int i; + struct ucred *cred; KASSERT(amount > 0, ("invalid amount")); @@ -111,8 +113,11 @@ * XXX: Obviously wrong, fix later. */ p->p_accounting.ha_resources[resource] += amount; - p->p_ucred->cr_ruidinfo->ui_accounting.ha_resources[resource] += amount; - p->p_ucred->cr_prison->pr_accounting.ha_resources[resource] += amount; + cred = p->p_ucred; + cred->cr_ruidinfo->ui_accounting.ha_resources[resource] += amount; + cred->cr_prison->pr_accounting.ha_resources[resource] += amount; + for (i = 0; i < cred->cr_ngroups; i++) + cred->cr_gidinfos[i]->gi_accounting.ha_resources[resource] += amount; /* * XXX: When denying, return proper errno - EFSIZ, ENOMEM etc. @@ -124,12 +129,17 @@ int hrl_allocated_proc(struct proc *p, int resource, uint64_t amount) { + int i; int64_t diff; + struct ucred *cred; diff = amount - p->p_accounting.ha_resources[resource]; p->p_accounting.ha_resources[resource] += diff; - p->p_ucred->cr_ruidinfo->ui_accounting.ha_resources[resource] += diff; - p->p_ucred->cr_prison->pr_accounting.ha_resources[resource] += diff; + cred = p->p_ucred; + cred->cr_ruidinfo->ui_accounting.ha_resources[resource] += diff; + cred->cr_prison->pr_accounting.ha_resources[resource] += diff; + for (i = 0; i < cred->cr_ngroups; i++) + cred->cr_gidinfos[i]->gi_accounting.ha_resources[resource] += diff; /* * XXX: Make sure process can lower its resource consumption, @@ -142,12 +152,17 @@ void hrl_free_proc(struct proc *p, int resource, uint64_t amount) { + int i; + struct ucred *cred; KASSERT(amount > 0, ("invalid amount")); p->p_accounting.ha_resources[resource] -= amount; - p->p_ucred->cr_ruidinfo->ui_accounting.ha_resources[resource] -= amount; - p->p_ucred->cr_prison->pr_accounting.ha_resources[resource] -= amount; + cred = p->p_ucred; + cred->cr_ruidinfo->ui_accounting.ha_resources[resource] -= amount; + cred->cr_prison->pr_accounting.ha_resources[resource] -= amount; + for (i = 0; i < cred->cr_ngroups; i++) + cred->cr_gidinfos[i]->gi_accounting.ha_resources[resource] -= amount; } int @@ -302,7 +317,7 @@ int error; struct uidinfo *uip; - uip = uifind(uid); + uip = uifind_existing(uid); if (uip == NULL) return (ESRCH); error = copyout(&uip->ui_accounting, bufp, sizeof(uip->ui_accounting)); @@ -317,7 +332,7 @@ int error; struct gidinfo *gip; - gip = gifind(gid); + gip = gifind_existing(gid); if (gip == NULL) return (ESRCH); error = copyout(&gip->gi_accounting, bufp, sizeof(gip->gi_accounting)); @@ -357,7 +372,7 @@ error = copyin(uap->inbufp, &id, sizeof(id_t)); if (error) return (error); - if (id <= 0) + if (id < 0) return (EINVAL); if (uap->outbuflen < sizeof(struct hrl_acc)) return (EFBIG); ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_resource.c#7 (text+ko) ==== @@ -1305,6 +1305,23 @@ return (uip); } +struct uidinfo * +uifind_existing(uid) + uid_t uid; +{ + struct uidinfo *uip; + + rw_rlock(&uihashtbl_lock); + uip = uilookup(uid); + if (uip == NULL) { + rw_unlock(&uihashtbl_lock); + return (NULL); + } + uihold(uip); + rw_unlock(&uihashtbl_lock); + return (uip); +} + /* * Place another refcount on a uidinfo struct. */ @@ -1433,6 +1450,23 @@ return (gip); } +struct gidinfo * +gifind_existing(gid) + gid_t gid; +{ + struct gidinfo *gip; + + rw_rlock(&gihashtbl_lock); + gip = gilookup(gid); + if (gip == NULL) { + rw_unlock(&gihashtbl_lock); + return (NULL); + } + gihold(gip); + rw_unlock(&gihashtbl_lock); + return (gip); +} + /* * Place another refcount on a gidinfo struct. */ ==== //depot/projects/soc2009/trasz_limits/sys/sys/resourcevar.h#5 (text+ko) ==== @@ -146,11 +146,15 @@ int suswintr(void *base, int word); struct uidinfo *uifind(uid_t uid); +struct uidinfo + *uifind_existing(uid_t uid); void uifree(struct uidinfo *uip); void uihashinit(void); void uihold(struct uidinfo *uip); struct gidinfo *gifind(gid_t gid); +struct gidinfo + *gifind_existing(gid_t gid); void gifree(struct gidinfo *gip); void gihashinit(void); void gihold(struct gidinfo *gip);