PERFORCE change 188271 for review

Edward Tomasz Napierala trasz at FreeBSD.org
Fri Jan 28 18:25:12 UTC 2011


http://p4web.freebsd.org/@@188271?ac=10

Change 188271 by trasz at trasz_victim on 2011/01/28 18:24:49

	Misc. fixes.

Affected files ...

.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#67 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_rctl.c#19 edit
.. //depot/projects/soc2009/trasz_limits/sys/sys/rctl.h#8 edit

Differences ...

==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#67 (text+ko) ====

@@ -166,6 +166,7 @@
 	case RUSAGE_RSS:
 	case RUSAGE_WALLCLOCK:
 	case RUSAGE_PCTCPU:
+	case RUSAGE_CPU:
 		return (0);
 	default:
 		return (1);
@@ -356,7 +357,6 @@
 	PROC_LOCK_ASSERT(p, MA_OWNED);
 	KASSERT(amount >= 0, ("rusage_add: invalid amount for resource %d: %ju",
 	    resource, amount));
-	KASSERT(p->p_container != NULL, ("rusage_add: NULL container for proc %p", p));
 
 	mtx_lock(&container_lock);
 #ifdef RCTL
@@ -424,7 +424,6 @@
 	PROC_LOCK_ASSERT(p, MA_OWNED);
 	KASSERT(amount >= 0, ("rusage_add_force: invalid amount for resource %d: %ju",
 	    resource, amount));
-	KASSERT(p->p_container != NULL, ("rusage_add_force: NULL container for proc %p", p));
 
 	mtx_lock(&container_lock);
 	container_alloc_resource(p->p_container, resource, amount);
@@ -451,7 +450,6 @@
 	PROC_LOCK_ASSERT(p, MA_OWNED);
 	KASSERT(amount >= 0, ("rusage_set: invalid amount for resource %d: %ju",
 	    resource, amount));
-	KASSERT(p->p_container != NULL, ("rusage_set_locked: NULL container for proc %p", p));
 
 	diff = amount - p->p_container->c_resources[resource];
 #ifdef notyet
@@ -511,7 +509,6 @@
 	PROC_LOCK_ASSERT(p, MA_OWNED);
 	KASSERT(amount >= 0, ("rusage_set_force: invalid amount for resource %d: %ju",
 	    resource, amount));
-	KASSERT(p->p_container != NULL, ("rusage_set_force: NULL container for proc %p", p));
 
 	mtx_lock(&container_lock);
 	diff = amount - p->p_container->c_resources[resource];
@@ -575,7 +572,6 @@
 	PROC_LOCK_ASSERT(p, MA_OWNED);
 	KASSERT(amount >= 0, ("rusage_sub: invalid amount for resource %d: %ju",
 	    resource, amount));
-	KASSERT(p->p_container != NULL, ("rusage_sub: NULL container for proc %p", p));
 	KASSERT(rusage_is_reclaimable(resource),
 	    ("rusage_sub: called for non-reclaimable resource %d", resource));
 
@@ -646,29 +642,24 @@
 	PROC_LOCK(child);
 	mtx_lock(&container_lock);
 
-	if (parent->p_container != NULL) {
-		/*
-		 * Inherit resource usage.
-		 */
-		for (i = 0; i <= RUSAGE_MAX; i++) {
-			if (parent->p_container->c_resources[i] == 0 ||
-			    !rusage_is_inheritable(i))
-				continue;
+	/*
+	 * Inherit resource usage.
+	 */
+	for (i = 0; i <= RUSAGE_MAX; i++) {
+		if (parent->p_container->c_resources[i] == 0 ||
+		    !rusage_is_inheritable(i))
+			continue;
 
-			error = rusage_set_locked(child, i, parent->p_container->c_resources[i]);
-			if (error != 0) {
-				/*
-				 * XXX: The only purpose of these two lines is to prevent from
-				 * tripping checks in container_destroy().
-				 */
-				for (i = 0; i <= RUSAGE_MAX; i++)
-					rusage_set_locked(child, i, 0);
-				goto out;
-			}
+		error = rusage_set_locked(child, i, parent->p_container->c_resources[i]);
+		if (error != 0) {
+			/*
+			 * XXX: The only purpose of these two lines is to prevent from
+			 * tripping checks in container_destroy().
+			 */
+			for (i = 0; i <= RUSAGE_MAX; i++)
+				rusage_set_locked(child, i, 0);
+			goto out;
 		}
-	} else {
-		KASSERT(parent->p_flag & P_SYSTEM,
-		    ("non-system process without container; p = %p", parent));
 	}
 
 #ifdef RCTL

==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_rctl.c#19 (text+ko) ====

@@ -124,7 +124,6 @@
 
 static struct dict actionnames[] = {
 	{ "deny", RCTL_ACTION_DENY },
-	{ "delay", RCTL_ACTION_DELAY },
 	{ "log", RCTL_ACTION_LOG },
 	{ "sighup", RCTL_ACTION_SIGHUP },
 	{ "sigint", RCTL_ACTION_SIGINT },
@@ -889,7 +888,7 @@
 }
 
 /*
- * Link a rule with subjects to which it applies.
+ * Link a rule with all the subjects it applies to.
  */
 int
 rctl_rule_add(struct rctl_rule *rule)
@@ -904,8 +903,21 @@
 
 	KASSERT(rctl_rule_fully_specified(rule), ("rule not fully specified"));
 
-	if (rule->rr_action == RCTL_ACTION_DELAY)
-		return (EOPNOTSUPP);
+	/*
+	 * Some rules just don't make sense.  Note that the one below
+	 * cannot be rewritten using rusage_is_deniable(); the RUSAGE_PCTCPU,
+	 * for example, is not deniable in the containers sense, but the
+	 * limit is enforced in a different way, so "deny" rules for %CPU
+	 * do make sense.
+	 */
+	if (rule->rr_action == RCTL_ACTION_DENY &&
+	    (rule->rr_resource == RUSAGE_CPU ||
+	    rule->rr_resource == RUSAGE_WALLCLOCK))
+		return (EINVAL);
+
+	if (rule->rr_per == RCTL_SUBJECT_TYPE_PROCESS &&
+	    rusage_is_sloppy(rule->rr_resource))
+		return (EINVAL);
 
 	/*
 	 * Make sure there are no duplicated rules.  Also, for the "deny"
@@ -1420,15 +1432,6 @@
 	    rule->rr_subject_type != RCTL_SUBJECT_TYPE_UNDEFINED)
 		rule->rr_per = rule->rr_subject_type;
 
-	/*
-	 * Some rules just don't make sense.
-	 */
-	if (rule->rr_resource == RUSAGE_CPU &&
-	    rule->rr_action == RCTL_ACTION_DENY) {
-		error = EINVAL;
-		goto out;
-	}
-
 	if (!rctl_rule_fully_specified(rule)) {
 		error = EINVAL;
 		goto out;

==== //depot/projects/soc2009/trasz_limits/sys/sys/rctl.h#8 (text+ko) ====

@@ -48,6 +48,8 @@
  * Resource Limits.
  */
 
+#ifdef _KERNEL
+
 /*
  * 'rctl_rule' describes a single limit configured by the system
  * administrator or a temporary limit set using setrlimit(2).
@@ -98,7 +100,6 @@
 
 #define	RCTL_ACTION_UNDEFINED		-1
 #define	RCTL_ACTION_DENY		0x0000
-#define	RCTL_ACTION_DELAY		0x0001
 #define	RCTL_ACTION_LOG			0x0002
 #define	RCTL_ACTION_SIGHUP		0x0003
 #define	RCTL_ACTION_SIGINT		0x0004
@@ -110,10 +111,7 @@
 
 #define	RCTL_AMOUNT_UNDEFINED		-1
 
-#ifdef _KERNEL
-
 void	rctl_proc_ucred_changed(struct proc *p, struct ucred *newcred);
-
 struct rctl_rule	*rctl_rule_alloc(int flags);
 struct rctl_rule	*rctl_rule_duplicate(const struct rctl_rule *rule, int flags);
 void	rctl_rule_acquire(struct rctl_rule *rule);


More information about the p4-projects mailing list