From owner-p4-projects@FreeBSD.ORG Mon Jun 8 12:36:36 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 748B01065673; Mon, 8 Jun 2009 12:36:36 +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 33F5F106564A for ; Mon, 8 Jun 2009 12:36:36 +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 210288FC17 for ; Mon, 8 Jun 2009 12:36:36 +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 n58Caa06023511 for ; Mon, 8 Jun 2009 12:36:36 GMT (envelope-from trasz@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n58CaaUb023509 for perforce@freebsd.org; Mon, 8 Jun 2009 12:36:36 GMT (envelope-from trasz@freebsd.org) Date: Mon, 8 Jun 2009 12:36:36 GMT Message-Id: <200906081236.n58CaaUb023509@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 163778 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, 08 Jun 2009 12:36:37 -0000 http://perforce.freebsd.org/chv.cgi?CH=163778 Change 163778 by trasz@trasz_victim on 2009/06/08 12:36:08 Minor renaming. Affected files ... .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_hrl.c#5 edit .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_resource.c#4 edit .. //depot/projects/soc2009/trasz_limits/sys/sys/hrl.h#4 edit .. //depot/projects/soc2009/trasz_limits/usr.sbin/hrl/hrl.c#4 edit Differences ... ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_hrl.c#5 (text+ko) ==== @@ -45,7 +45,7 @@ #include struct hrl_node { - struct hrl_limit hn_limit; + struct hrl_rule hn_rule; RB_ENTRY(hrl_node) hn_next; }; @@ -56,29 +56,29 @@ static int hn_compare(const struct hrl_node *a, const struct hrl_node *b) { - if (a->hn_limit.hl_subject < b->hn_limit.hl_subject) + if (a->hn_rule.hr_subject < b->hn_rule.hr_subject) return (-1); - else if (a->hn_limit.hl_subject > b->hn_limit.hl_subject) + else if (a->hn_rule.hr_subject > b->hn_rule.hr_subject) return (1); - if (a->hn_limit.hl_subject_id < b->hn_limit.hl_subject_id) + if (a->hn_rule.hr_subject_id < b->hn_rule.hr_subject_id) return (-1); - else if (a->hn_limit.hl_subject_id > b->hn_limit.hl_subject_id) + else if (a->hn_rule.hr_subject_id > b->hn_rule.hr_subject_id) return (1); - if (a->hn_limit.hl_per < b->hn_limit.hl_per) + if (a->hn_rule.hr_per < b->hn_rule.hr_per) return (-1); - else if (a->hn_limit.hl_per > b->hn_limit.hl_per) + else if (a->hn_rule.hr_per > b->hn_rule.hr_per) return (1); - if (a->hn_limit.hl_object < b->hn_limit.hl_object) + if (a->hn_rule.hr_resource < b->hn_rule.hr_resource) return (-1); - else if (a->hn_limit.hl_object > b->hn_limit.hl_object) + else if (a->hn_rule.hr_resource > b->hn_rule.hr_resource) return (1); - if (a->hn_limit.hl_action < b->hn_limit.hl_action) + if (a->hn_rule.hr_action < b->hn_rule.hr_action) return (-1); - else if (a->hn_limit.hl_action > b->hn_limit.hl_action) + else if (a->hn_rule.hr_action > b->hn_rule.hr_action) return (1); return (0); @@ -100,7 +100,7 @@ MALLOC_DEFINE(M_HRL, "hrl", "Hierarchical Resource Limits"); int -hrl_alloc(int object, uint64_t amount) +hrl_alloc(int resource, uint64_t amount) { KASSERT(amount > 0, ("invalid amount")); @@ -109,22 +109,22 @@ } void -hrl_free(int object, uint64_t amount) +hrl_free(int resource, uint64_t amount) { KASSERT(amount > 0, ("invalid amount")); } void -hrl_adjust(int subject, id_t subject_id, int per, int object, int action, int64_t amount) +hrl_adjust(int subject, id_t subject_id, int per, int resource, int action, int64_t amount) { struct hrl_node searched, *node, *existing; - searched.hn_limit.hl_subject = subject; - searched.hn_limit.hl_subject_id = subject_id; - searched.hn_limit.hl_per = per; - searched.hn_limit.hl_object = object; - searched.hn_limit.hl_action = action; + searched.hn_rule.hr_subject = subject; + searched.hn_rule.hr_subject_id = subject_id; + searched.hn_rule.hr_per = per; + searched.hn_rule.hr_resource = resource; + searched.hn_rule.hr_action = action; /* * Removing a limit. @@ -151,9 +151,9 @@ mtx_lock(&hrl_lock); existing = RB_INSERT(hrl_tree, &hrls, node); if (existing != NULL) { - existing->hn_limit.hl_amount = amount; + existing->hn_rule.hr_amount = amount; } else { - node->hn_limit.hl_amount = amount; + node->hn_rule.hr_amount = amount; nhrls++; } mtx_unlock(&hrl_lock); @@ -167,20 +167,20 @@ #if 0 static int -hrl_check(struct hrl_limit *limits, int nlimits) +hrl_check(struct hrl_rule *limits, int nlimits) { int i; for (i = 0; i < nlimits; i++) { - if (limits[i].hl_subject <= 0 || limits[i].hl_subject > HRL_SUBJECT_MAX) + if (limits[i].hr_subject <= 0 || limits[i].hr_subject > HRL_SUBJECT_MAX) return (EINVAL); - if (limits[i].hl_per <= 0 || limits[i].hl_per > HRL_SUBJECT_MAX) + if (limits[i].hr_per <= 0 || limits[i].hr_per > HRL_SUBJECT_MAX) return (EINVAL); - if (limits[i].hl_object <= 0 || limits[i].hl_object > HRL_OBJECT_MAX) + if (limits[i].hr_resource <= 0 || limits[i].hr_resource > HRL_RESOURCE_MAX) return (EINVAL); - if (limits[i].hl_action <= 0 || limits[i].hl_action > HRL_ACTION_MAX) + if (limits[i].hr_action <= 0 || limits[i].hr_action > HRL_ACTION_MAX) return (EINVAL); - if (limits[i].hl_amount <= 0) + if (limits[i].hr_amount <= 0) return (EINVAL); } @@ -194,7 +194,7 @@ #if 0 int error; size_t buflen; - struct hrl_limit *newlimits; + struct hrl_rule *newlimits; error = priv_check(td, PRIV_HRL_GET); if (error) @@ -220,7 +220,7 @@ return (0); } - buflen = sizeof(struct hrl_limit) * uap->nentries; + buflen = sizeof(struct hrl_rule) * uap->nentries; newlimits = malloc(buflen, M_HRL, M_WAITOK); error = copyin(uap->bufp, newlimits, buflen); @@ -257,7 +257,7 @@ int error = 0, copied = 0; size_t buflen; struct hrl_node *node; - struct hrl_limit *buf; + struct hrl_rule *buf; if (uap->nentries == 0 && uap->bufp == NULL) { mtx_lock(&hrl_lock); @@ -270,7 +270,7 @@ if (uap->nentries < 0 || uap->nentries >= HRL_MAX_LIMITS) return (EINVAL); - buflen = sizeof(struct hrl_limit) * uap->nentries; + buflen = sizeof(struct hrl_rule) * uap->nentries; buf = malloc(buflen, M_HRL, M_WAITOK); /* @@ -287,14 +287,14 @@ error = EFBIG; break; } - *(buf + copied) = node->hn_limit; + *(buf + copied) = node->hn_rule; copied++; } mtx_unlock(&hrl_lock); if (error) goto out; - error = copyout(buf, uap->bufp, sizeof(struct hrl_limit) * copied); + error = copyout(buf, uap->bufp, sizeof(struct hrl_rule) * copied); if (error) goto out; @@ -315,22 +315,21 @@ struct hrl_node *node, *next; /* - * Go through all the limits, looking for the ones with subject - * equal to the exiting process, and remove them. + * Remove temporary rules created via setrlimit(2). * - * XXX: What are we gonna do - insert a HRL entry for every process - * that inherits a limit set with setrlimit(2), or do some - * magic here, moving limits from the parent process that's - * exiting to its children? + * XXX: What are we gonna do with a children of a process that + * called setrlimit(2) - just copy the limits for every one + * of them, or do some magic here, moving limits from the + * parent process that's exiting to its children? */ restart: mtx_lock(&hrl_lock); for (node = RB_MIN(hrl_tree, &hrls); node != NULL; node = next) { next = RB_NEXT(hrl_tree, &hrls, node); - if (node->hn_limit.hl_subject != HRL_SUBJECT_PROCESS) + if (node->hn_rule.hr_subject != HRL_SUBJECT_PROCESS) continue; - if (node->hn_limit.hl_subject_id != p->p_pid) + if (node->hn_rule.hr_subject_id != p->p_pid) continue; node = RB_REMOVE(hrl_tree, &hrls, node); ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_resource.c#4 (text+ko) ==== @@ -646,7 +646,7 @@ static void hrl_handle_setrlimit(u_int which, struct rlimit *lim, struct thread *td) { - int object, subject, action = -1; + int resource, subject, action = -1; id_t id; /* @@ -657,47 +657,47 @@ switch (which) { case RLIMIT_CPU: - object = HRL_OBJECT_CPUTIME; + resource = HRL_RESOURCE_CPUTIME; action = HRL_ACTION_SIGXCPU; break; case RLIMIT_FSIZE: - object = HRL_OBJECT_FILESIZE; + resource = HRL_RESOURCE_FILESIZE; break; case RLIMIT_DATA: - object = HRL_OBJECT_DATASIZE; + resource = HRL_RESOURCE_DATASIZE; break; case RLIMIT_STACK: - object = HRL_OBJECT_STACKSIZE; + resource = HRL_RESOURCE_STACKSIZE; action = HRL_ACTION_SIGSEGV; break; case RLIMIT_CORE: - object = HRL_OBJECT_COREDUMPSIZE; + resource = HRL_RESOURCE_COREDUMPSIZE; break; case RLIMIT_RSS: - object = HRL_OBJECT_MEMORYUSE; + resource = HRL_RESOURCE_MEMORYUSE; break; case RLIMIT_MEMLOCK: - object = HRL_OBJECT_MEMORYLOCKED; + resource = HRL_RESOURCE_MEMORYLOCKED; break; case RLIMIT_NPROC: - object = HRL_OBJECT_MAXPROCESSES; + resource = HRL_RESOURCE_MAXPROCESSES; subject = HRL_SUBJECT_USER; id = td->td_ucred->cr_uid; break; case RLIMIT_NOFILE: - object = HRL_OBJECT_OPENFILES; + resource = HRL_RESOURCE_OPENFILES; action = HRL_ACTION_SIGXFSZ; break; case RLIMIT_SBSIZE: - object = HRL_OBJECT_SBSIZE; + resource = HRL_RESOURCE_SBSIZE; subject = HRL_SUBJECT_USER; id = td->td_ucred->cr_uid; break; case RLIMIT_VMEM: - object = HRL_OBJECT_VMEMORYUSE; + resource = HRL_RESOURCE_VMEMORYUSE; break; case RLIMIT_NPTS: - object = HRL_OBJECT_PTY; + resource = HRL_RESOURCE_PTY; subject = HRL_SUBJECT_USER; id = td->td_ucred->cr_uid; break; @@ -706,15 +706,15 @@ } if (lim->rlim_cur != RLIM_INFINITY) { - hrl_adjust(subject, id, subject, object, HRL_ACTION_DENY, + hrl_adjust(subject, id, subject, resource, HRL_ACTION_DENY, lim->rlim_cur); if (action != -1) - hrl_adjust(subject, id, subject, object, action, + hrl_adjust(subject, id, subject, resource, action, lim->rlim_cur); } else { - hrl_adjust(subject, id, subject, object, HRL_ACTION_DENY, 0); + hrl_adjust(subject, id, subject, resource, HRL_ACTION_DENY, 0); if (action != -1) - hrl_adjust(subject, id, subject, object, action, 0); + hrl_adjust(subject, id, subject, resource, action, 0); } } ==== //depot/projects/soc2009/trasz_limits/sys/sys/hrl.h#4 (text+ko) ==== @@ -36,13 +36,22 @@ * Hierarchical Resource Limits. */ -struct hrl_limit { - int hl_subject; - id_t hl_subject_id; - int hl_per; - int hl_object; - int hl_action; - int64_t hl_amount; +/* + * 'hrl_rule' describes a single limit configured by the system + * administrator or a temporary limit set using setrlimit(2). + * The difference between 'subject' and 'per' is best described + * by example: to specify that every process of user with uid 1984 + * can consume 1gb of virtual memory, the 'hr_subject' would be + * HRL_SUBJECT_USER, 'hrl_subject_id' - 1984, and 'hr_per' - + * HRL_SUBJECT_PROCESS. + */ +struct hrl_rule { + int hr_subject; + id_t hr_subject_id; + int hr_per; + int hr_resource; + int hr_action; + int64_t hr_amount; }; #define HRL_SUBJECT_PROCESS 0x0001 @@ -53,22 +62,22 @@ #define HRL_SUBJECT_MAX HRL_SUBJECT_JAIL /* - * 'hl_per' takes the same flags as 'hl_subject'. + * 'hr_per' takes the same flags as 'hr_subject'. */ -#define HRL_OBJECT_CPUTIME 0x0001 -#define HRL_OBJECT_FILESIZE 0x0002 -#define HRL_OBJECT_DATASIZE 0x0003 -#define HRL_OBJECT_STACKSIZE 0x0004 -#define HRL_OBJECT_COREDUMPSIZE 0x0005 -#define HRL_OBJECT_MEMORYUSE 0x0006 -#define HRL_OBJECT_MEMORYLOCKED 0x0007 -#define HRL_OBJECT_MAXPROCESSES 0x0008 -#define HRL_OBJECT_OPENFILES 0x0009 -#define HRL_OBJECT_SBSIZE 0x000a -#define HRL_OBJECT_VMEMORYUSE 0x000b -#define HRL_OBJECT_PTY 0x000c -#define HRL_OBJECT_MAX HRL_OBJECT_PTY +#define HRL_RESOURCE_CPUTIME 0x0001 +#define HRL_RESOURCE_FILESIZE 0x0002 +#define HRL_RESOURCE_DATASIZE 0x0003 +#define HRL_RESOURCE_STACKSIZE 0x0004 +#define HRL_RESOURCE_COREDUMPSIZE 0x0005 +#define HRL_RESOURCE_MEMORYUSE 0x0006 +#define HRL_RESOURCE_MEMORYLOCKED 0x0007 +#define HRL_RESOURCE_MAXPROCESSES 0x0008 +#define HRL_RESOURCE_OPENFILES 0x0009 +#define HRL_RESOURCE_SBSIZE 0x000a +#define HRL_RESOURCE_VMEMORYUSE 0x000b +#define HRL_RESOURCE_PTY 0x000c +#define HRL_RESOURCE_MAX HRL_RESOURCE_PTY #define HRL_ACTION_DENY 0x0001 #define HRL_ACTION_DELAY 0x0002 @@ -88,13 +97,13 @@ int hrl_alloc(int object, uint64_t amount); void hrl_free(int object, uint64_t amount); -void hrl_adjust(int subject, id_t subject_id, int per, int object, int action, int64_t amount); +void hrl_adjust(int subject, id_t subject_id, int per, int resource, int action, int64_t amount); #else /* !_KERNEL */ __BEGIN_DECLS -int hrl_get(struct hrl_limit *bufp, int nentries, int *count); -int hrl_set(struct hrl_limit *bufp, int nentries); +int hrl_get(struct hrl_rule *bufp, int nentries, int *count); +int hrl_set(struct hrl_rule *bufp, int nentries); __END_DECLS #endif /* !_KERNEL */ ==== //depot/projects/soc2009/trasz_limits/usr.sbin/hrl/hrl.c#4 (text+ko) ==== @@ -71,48 +71,48 @@ } static void -print_object(int object) +print_resource(int resource) { - switch (object) { - case HRL_OBJECT_CPUTIME: + switch (resource) { + case HRL_RESOURCE_CPUTIME: printf("cputime"); break; - case HRL_OBJECT_FILESIZE: + case HRL_RESOURCE_FILESIZE: printf("filesize"); break; - case HRL_OBJECT_DATASIZE: + case HRL_RESOURCE_DATASIZE: printf("datasize"); break; - case HRL_OBJECT_STACKSIZE: + case HRL_RESOURCE_STACKSIZE: printf("stacksize"); break; - case HRL_OBJECT_COREDUMPSIZE: + case HRL_RESOURCE_COREDUMPSIZE: printf("coredumpsize"); break; - case HRL_OBJECT_MEMORYUSE: + case HRL_RESOURCE_MEMORYUSE: printf("memoryuse"); break; - case HRL_OBJECT_MEMORYLOCKED: + case HRL_RESOURCE_MEMORYLOCKED: printf("memorylocked"); break; - case HRL_OBJECT_MAXPROCESSES: + case HRL_RESOURCE_MAXPROCESSES: printf("maxprocesses"); break; - case HRL_OBJECT_OPENFILES: + case HRL_RESOURCE_OPENFILES: printf("openfiles"); break; - case HRL_OBJECT_SBSIZE: + case HRL_RESOURCE_SBSIZE: printf("sbsize"); break; - case HRL_OBJECT_VMEMORYUSE: + case HRL_RESOURCE_VMEMORYUSE: printf("vmemoryuse"); break; - case HRL_OBJECT_PTY: + case HRL_RESOURCE_PTY: printf("pty"); break; default: - printf("undefined<0x%x>", object); + printf("undefined<0x%x>", resource); } } @@ -205,16 +205,16 @@ printf("Defined resource limits:\n"); for (i = 0; i < nentries; i++) { - print_subject(limits[i].hl_subject, limits[i].hl_subject_id); + print_subject(limits[i].hr_subject, limits[i].hr_subject_id); printf(":"); - print_object(limits[i].hl_object); + print_resource(limits[i].hr_resource); printf(":"); - print_action(limits[i].hl_action); - printf(":"); - printf("%jd", limits[i].hl_amount); - if (limits[i].hl_subject != limits[i].hl_per) { + print_action(limits[i].hr_action); + printf("="); + printf("%jd", limits[i].hr_amount); + if (limits[i].hr_subject != limits[i].hr_per) { printf("/"); - print_per(limits[i].hl_per); + print_per(limits[i].hr_per); } printf("\n"); }