Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Jun 2009 21:37:40 GMT
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 164469 for review
Message-ID:  <200906152137.n5FLbeQ6028707@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906152137.n5FLbeQ6028707>