PERFORCE change 167036 for review

Edward Tomasz Napierala trasz at FreeBSD.org
Wed Aug 5 17:34:56 UTC 2009


http://perforce.freebsd.org/chv.cgi?CH=167036

Change 167036 by trasz at trasz_anger on 2009/08/05 17:34:09

	When changing loginclass, update process limits properly.

Affected files ...

.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_hrl.c#44 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_loginclass.c#4 edit
.. //depot/projects/soc2009/trasz_limits/sys/sys/hrl.h#28 edit

Differences ...

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

@@ -1514,6 +1514,42 @@
 }
 
 /*
+ * Called after loginclass change, to adjust p_limits.
+ */
+void
+hrl_proc_loginclass_changed(struct proc *p)
+{
+	int error;
+	struct hrl_limit *limit;
+
+	PROC_LOCK_ASSERT(p, MA_OWNED);
+
+	mtx_lock(&hrl_lock);
+
+	/*
+	 * Remove rules for the old loginclass.
+	 */
+	LIST_FOREACH(limit, &p->p_limits, hl_next) {
+		if (limit->hl_rule->hr_subject != HRL_SUBJECT_LOGINCLASS)
+			continue;
+
+		LIST_REMOVE(limit, hl_next);
+		hrl_rule_release(limit->hl_rule);
+		uma_zfree(hrl_limit_zone, limit);
+	}
+	
+	/*
+	 * Now add rules for the current loginclass.
+	 */
+	LIST_FOREACH(limit, &p->p_loginclass->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);
+}
+
+/*
  * Inherit resource usage information and copy limits from the parent
  * process to the child.
  */
@@ -1565,15 +1601,12 @@
 {
 	struct hrl_limit *limit;
 
-restart:
 	mtx_lock(&hrl_lock);
 	while (!LIST_EMPTY(&p->p_limits)) {
 		limit = LIST_FIRST(&p->p_limits);
 		LIST_REMOVE(limit, hl_next);
-		mtx_unlock(&hrl_lock);
 		hrl_rule_release(limit->hl_rule);
 		uma_zfree(hrl_limit_zone, limit);
-		goto restart;
 	}
 	mtx_unlock(&hrl_lock);
 }

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

@@ -194,6 +194,7 @@
 	PROC_LOCK(p);
 	oldlc = p->p_loginclass;
 	p->p_loginclass = newlc;
+	hrl_proc_loginclass_changed(p);
 	PROC_UNLOCK(p);
 
 	loginclass_release(oldlc);

==== //depot/projects/soc2009/trasz_limits/sys/sys/hrl.h#28 (text+ko) ====

@@ -138,6 +138,10 @@
 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);
+
 struct hrl_rule	*hrl_rule_alloc(int flags);
 struct hrl_rule	*hrl_rule_duplicate(const struct hrl_rule *rule, int flags);
 void	hrl_rule_acquire(struct hrl_rule *rule);


More information about the p4-projects mailing list