PERFORCE change 166922 for review
Edward Tomasz Napierala
trasz at FreeBSD.org
Sun Aug 2 11:56:27 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=166922
Change 166922 by trasz at trasz_anger on 2009/08/02 11:56:19
Fix adding new rules via setrlimit(2).
Affected files ...
.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_hrl.c#36 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_resource.c#16 edit
Differences ...
==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_hrl.c#36 (text+ko) ====
@@ -734,7 +734,14 @@
struct hrl_rule *rule;
rule = uma_zalloc(hrl_rule_zone, M_WAITOK);
+ rule->hr_subject = HRL_SUBJECT_UNDEFINED;
+ rule->hr_subject_id = HRL_SUBJECT_ID_UNDEFINED;
+ rule->hr_per = HRL_SUBJECT_UNDEFINED;
+ rule->hr_resource = HRL_RESOURCE_UNDEFINED;
+ rule->hr_action = HRL_ACTION_UNDEFINED;
+ rule->hr_amount = -1;
refcount_init(&rule->hr_refcount, 1);
+
return (rule);
}
@@ -743,13 +750,14 @@
{
struct hrl_rule *copy;
- copy = hrl_rule_alloc();
+ copy = uma_zalloc(hrl_rule_zone, M_WAITOK);
copy->hr_subject = rule->hr_subject;
copy->hr_subject_id = rule->hr_subject_id;
copy->hr_per = rule->hr_per;
copy->hr_resource = rule->hr_resource;
copy->hr_action = rule->hr_action;
copy->hr_amount = rule->hr_amount;
+ refcount_init(©->hr_refcount, 1);
return (copy);
}
==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_resource.c#16 (text+ko) ====
@@ -712,23 +712,32 @@
panic("hrl_handle_setrlimit: unknown limit %d", which);
}
+ /*
+ * Remove a previous limit that might exist for the resource
+ * with a different hr_amount.
+ */
+ hrl_rule_remove(rule);
+
+ /*
+ * For rules with action different than "deny", we add another
+ * rule, "deny".
+ */
+ if (rule->hr_action != HRL_ACTION_DENY) {
+ rule2 = hrl_rule_duplicate(rule);
+ rule2->hr_action = HRL_ACTION_DENY;
+ hrl_rule_remove(rule2);
+
+ if (lim->rlim_cur != RLIM_INFINITY) {
+ rule2->hr_amount = lim->rlim_cur;
+ hrl_rule_add(rule2);
+ }
+ hrl_rule_release(rule2);
+ }
+
if (lim->rlim_cur != RLIM_INFINITY) {
rule->hr_amount = lim->rlim_cur;
hrl_rule_add(rule);
- if (rule->hr_action != HRL_ACTION_DENY) {
- rule2 = hrl_rule_duplicate(rule);
- rule2->hr_action = HRL_ACTION_DENY;
- hrl_rule_add(rule2);
- hrl_rule_release(rule2);
- }
- } else {
- hrl_rule_remove(rule);
- if (rule->hr_action != HRL_ACTION_DENY) {
- rule->hr_action = HRL_ACTION_DENY;
- hrl_rule_remove(rule);
- }
}
-
hrl_rule_release(rule);
}
More information about the p4-projects
mailing list