PERFORCE change 180350 for review
Edward Tomasz Napierala
trasz at FreeBSD.org
Wed Jun 30 18:07:45 UTC 2010
http://p4web.freebsd.org/@@180350?ac=10
Change 180350 by trasz at trasz_victim on 2010/06/30 18:07:01
Rename resource allocation and deallocation routines to rusage_add(),
rusage_sub() and rusage_set(). The reason for such a naming, instead
of e.g. container_rusage_add(), is that they might be reused for other
mechanisms, such as IRIX jobs, which are being implemented by Gabor,
which don't really require containers.
Affected files ...
.. //depot/projects/soc2009/trasz_limits/sys/compat/linux/linux_misc.c#12 edit
.. //depot/projects/soc2009/trasz_limits/sys/compat/svr4/imgact_svr4.c#6 edit
.. //depot/projects/soc2009/trasz_limits/sys/compat/svr4/svr4_filio.c#6 edit
.. //depot/projects/soc2009/trasz_limits/sys/fs/unionfs/union_subr.c#7 edit
.. //depot/projects/soc2009/trasz_limits/sys/i386/linux/imgact_linux.c#5 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/imgact_aout.c#6 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/imgact_elf.c#11 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/imgact_gzip.c#4 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/init_main.c#23 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#6 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_exit.c#21 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_fork.c#16 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_hrl.c#78 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_resource.c#35 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/tty_pts.c#16 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/vfs_vnops.c#16 edit
.. //depot/projects/soc2009/trasz_limits/sys/sys/container.h#4 edit
.. //depot/projects/soc2009/trasz_limits/sys/vm/vm_map.c#15 edit
.. //depot/projects/soc2009/trasz_limits/sys/vm/vm_unix.c#6 edit
Differences ...
==== //depot/projects/soc2009/trasz_limits/sys/compat/linux/linux_misc.c#12 (text+ko) ====
@@ -363,7 +363,7 @@
error = ENOMEM;
goto cleanup;
}
- error = hrl_allocated(td->td_proc, HRL_RESOURCE_DATASIZE,
+ error = rusage_set(td->td_proc, RUSAGE_DATASIZE,
a_out->a_data + bss_size);
if (error) {
error = ENOMEM;
==== //depot/projects/soc2009/trasz_limits/sys/compat/svr4/imgact_svr4.c#6 (text+ko) ====
@@ -109,7 +109,7 @@
*/
if (a_out->a_text > maxtsiz)
return (ENOMEM);
- error = hrl_allocated(imgp->proc, HRL_RESOURCE_DATASIZE,
+ error = rusage_set(imgp->proc, RUSAGE_DATASIZE,
a_out->a_data + bss_size);
if (error)
return (ENOMEM);
==== //depot/projects/soc2009/trasz_limits/sys/compat/svr4/svr4_filio.c#6 (text+ko) ====
@@ -78,7 +78,7 @@
}
PROC_UNLOCK(td->td_proc);
- hrl_alloc(td->td_proc, HRL_RESOURCE_FILEDESCRIPTORS, uap->nfds);
+ rusage_add(td->td_proc, RUSAGE_FILEDESCRIPTORS, uap->nfds);
pa.fds = uap->fds;
pa.nfds = uap->nfds;
@@ -105,7 +105,7 @@
forget to update it if I add more code */
}
done:
- hrl_free(td->td_proc, HRL_RESOURCE_FILEDESCRIPTORS, uap->nfds);
+ rusage_sub(td->td_proc, RUSAGE_FILEDESCRIPTORS, uap->nfds);
free(pfd, M_TEMP);
return error;
}
==== //depot/projects/soc2009/trasz_limits/sys/fs/unionfs/union_subr.c#7 (text+ko) ====
@@ -779,7 +779,7 @@
chgproccnt(cred->cr_ruidinfo, 1, 0);
#ifdef notyet
/* XXX: What about the return value? And what's the purpose of this, anyway? */
- hrl_alloc(HRL_RESOURCE_MAXPROCESSES, 1);
+ rusage_add(RUSAGE_MAXPROCESSES, 1);
#endif
change_euid(cred, rootinfo);
change_ruid(cred, rootinfo);
@@ -832,7 +832,7 @@
cnp->cn_cred = credbk;
chgproccnt(cred->cr_ruidinfo, -1, 0);
#ifdef notyet
- hrl_free(HRL_RESOURCE_MAXPROCESSES, 1);
+ rusage_sub(RUSAGE_MAXPROCESSES, 1);
#endif
crfree(cred);
==== //depot/projects/soc2009/trasz_limits/sys/i386/linux/imgact_linux.c#5 (text+ko) ====
@@ -107,7 +107,7 @@
*/
if (a_out->a_text > maxtsiz)
return (ENOMEM);
- error = hrl_allocated(imgp->proc, HRL_RESOURCE_DATASIZE,
+ error = rusage_set(imgp->proc, RUSAGE_DATASIZE,
a_out->a_data + bss_size);
if (error)
return (ENOMEM);
==== //depot/projects/soc2009/trasz_limits/sys/kern/imgact_aout.c#6 (text+ko) ====
@@ -188,7 +188,7 @@
if (/* text can't exceed maximum text size */
a_out->a_text > maxtsiz)
return (ENOMEM);
- error = hrl_allocated(imgp->proc, HRL_RESOURCE_DATASIZE,
+ error = rusage_set(imgp->proc, RUSAGE_DATASIZE,
a_out->a_data + bss_size);
if (error)
return (ENOMEM);
==== //depot/projects/soc2009/trasz_limits/sys/kern/imgact_elf.c#11 (text+ko) ====
@@ -874,11 +874,11 @@
*/
if (text_size > maxtsiz)
return (ENOMEM);
- error = hrl_allocated(imgp->proc, HRL_RESOURCE_DATASIZE,
+ error = rusage_set(imgp->proc, RUSAGE_DATASIZE,
data_size);
if (error)
return (ENOMEM);
- error = hrl_allocated(imgp->proc, HRL_RESOURCE_VMEMORYUSE,
+ error = rusage_set(imgp->proc, RUSAGE_VMEMORYUSE,
total_size);
if (error)
return (ENOMEM);
==== //depot/projects/soc2009/trasz_limits/sys/kern/imgact_gzip.c#4 (text+ko) ====
@@ -215,7 +215,7 @@
gz->where = __LINE__;
return (ENOMEM);
}
- error = hrl_allocated_proc(gz->ip->proc, HRL_RESOURCE_DATASIZE,
+ error = rusage_set(gz->ip->proc, RUSAGE_DATASIZE,
gz->a_out.a_data + gz->bss_size);
if (error)
return (ENOMEM);
==== //depot/projects/soc2009/trasz_limits/sys/kern/init_main.c#23 (text+ko) ====
@@ -563,8 +563,8 @@
* Charge root for one process.
*/
(void)chgproccnt(p->p_ucred->cr_ruidinfo, 1, 0);
- error = hrl_alloc(p, HRL_RESOURCE_MAXPROCESSES, 1);
- KASSERT(error == 0, ("hrl_alloc failed"));
+ error = rusage_add(p, RUSAGE_MAXPROCESSES, 1);
+ KASSERT(error == 0, ("rusage_add failed"));
}
SYSINIT(p0init, SI_SUB_INTRINSIC, SI_ORDER_FIRST, proc0_init, NULL);
==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#6 (text+ko) ====
@@ -64,7 +64,7 @@
mtx_assert(&container_lock, MA_OWNED);
- for (i = 0; i <= HRL_RESOURCE_MAX; i++) {
+ for (i = 0; i <= RUSAGE_MAX; i++) {
KASSERT(dest->c_resources[i] >= 0,
("resource usage propagation meltdown: dest < 0"));
KASSERT(src->c_resources[i] >= 0,
@@ -82,7 +82,7 @@
mtx_assert(&container_lock, MA_OWNED);
- for (i = 0; i <= HRL_RESOURCE_MAX; i++) {
+ for (i = 0; i <= RUSAGE_MAX; i++) {
KASSERT(dest->c_resources[i] >= 0,
("resource usage propagation meltdown: dest < 0"));
KASSERT(src->c_resources[i] >= 0,
@@ -156,7 +156,7 @@
{
int i;
- for (i = 0; i <= HRL_RESOURCE_MAX; i++)
+ for (i = 0; i <= RUSAGE_MAX; i++)
KASSERT(container->c_resources[i] == 0,
("container->c_resources[%d] != NULL", i));
for (i = 0; i <= CONTAINER_PARENTS_MAX; i++)
@@ -170,7 +170,7 @@
int i;
mtx_lock(&container_lock);
- for (i = 0; i <= HRL_RESOURCE_MAX; i++) {
+ for (i = 0; i <= RUSAGE_MAX; i++) {
if (container->c_resources[i] != 0)
printf("destroying non-empty container: "
"%ju allocated for resource %d",
@@ -195,7 +195,7 @@
mtx_assert(&container_lock, MA_OWNED);
KASSERT(container != NULL, ("NULL container"));
- for (resource = 0; resource <= HRL_RESOURCE_MAX; resource++) {
+ for (resource = 0; resource <= RUSAGE_MAX; resource++) {
KASSERT(container->c_resources[resource] >= 0,
("resource usage propagation meltdown: resource < 0"));
}
@@ -205,7 +205,7 @@
if (parent == NULL);
continue;
container_assert(parent);
- for (resource = 0; resource <= HRL_RESOURCE_MAX; resource++) {
+ for (resource = 0; resource <= RUSAGE_MAX; resource++) {
KASSERT(parent->c_resources[resource] >=
container->c_resources[resource],
("resource usage propagation meltdown: child > parent"));
@@ -244,17 +244,17 @@
* Return 0 if it's below limits, or errno, if it's not.
*/
int
-hrl_alloc(struct proc *p, int resource, uint64_t amount)
+rusage_add(struct proc *p, int resource, uint64_t amount)
{
#ifdef HRL
int error;
#endif
#if 0
- printf("hrl_alloc: allocating %ju of %s for %s (pid %d)\n", amount, hrl_resource_name(resource), p->p_comm, p->p_pid);
+ printf("rusage_add: allocating %ju of %s for %s (pid %d)\n", amount, hrl_resource_name(resource), p->p_comm, p->p_pid);
#endif
- KASSERT(amount > 0, ("hrl_alloc: invalid amount for resource %d: %ju",
+ KASSERT(amount > 0, ("rusage_add: invalid amount for resource %d: %ju",
resource, amount));
mtx_lock(&container_lock);
@@ -279,7 +279,7 @@
* even if it's above the limit.
*/
int
-hrl_allocated(struct proc *p, int resource, uint64_t amount)
+rusage_set(struct proc *p, int resource, uint64_t amount)
{
int64_t diff;
#ifdef HRL
@@ -287,10 +287,10 @@
#endif
#if 0
- printf("hrl_allocated: allocated %lld of %s for %s (pid %d)\n", amount, hrl_resource_name(resource), p->p_comm, p->p_pid);
+ printf("rusage_set: allocated %lld of %s for %s (pid %d)\n", amount, hrl_resource_name(resource), p->p_comm, p->p_pid);
#endif
- KASSERT(amount >= 0, ("hrl_allocated: invalid amount for resource %d: %ju",
+ KASSERT(amount >= 0, ("rusage_set: invalid amount for resource %d: %ju",
resource, amount));
mtx_lock(&container_lock);
@@ -314,19 +314,19 @@
* Decrease allocation of 'resource' by 'amount' for process 'p'.
*/
void
-hrl_free(struct proc *p, int resource, uint64_t amount)
+rusage_sub(struct proc *p, int resource, uint64_t amount)
{
#if 0
- printf("hrl_free: freeing %lld of %s for %s (pid %d)\n", amount, hrl_resource_name(resource), p->p_comm, p->p_pid);
+ printf("rusage_sub: freeing %lld of %s for %s (pid %d)\n", amount, hrl_resource_name(resource), p->p_comm, p->p_pid);
#endif
- KASSERT(amount > 0, ("hrl_free: invalid amount for resource %d: %ju",
+ KASSERT(amount > 0, ("rusage_sub: invalid amount for resource %d: %ju",
resource, amount));
mtx_lock(&container_lock);
KASSERT(amount <= p->p_container.c_resources[resource],
- ("hrl_free: freeing %ju of resource %d, which is more than allocated "
+ ("rusage_sub: freeing %ju of resource %d, which is more than allocated "
"%ld for %s (pid %d)", amount, resource,
p->p_container.c_resources[resource], p->p_comm, p->p_pid));
@@ -339,7 +339,7 @@
{
switch (resource) {
- case HRL_RESOURCE_MAXPROCESSES:
+ case RUSAGE_MAXPROCESSES:
return (0);
default:
return (1);
@@ -352,9 +352,9 @@
/*
* XXX: Free these three some other way.
*/
- hrl_allocated(p, HRL_RESOURCE_FILESIZE, 0);
- hrl_allocated(p, HRL_RESOURCE_COREDUMPSIZE, 0);
- hrl_allocated(p, HRL_RESOURCE_PTY, 0);
+ rusage_set(p, RUSAGE_FILESIZE, 0);
+ rusage_set(p, RUSAGE_COREDUMPSIZE, 0);
+ rusage_set(p, RUSAGE_PTY, 0);
mtx_lock(&container_lock);
container_destroy(&p->p_container);
@@ -387,10 +387,10 @@
container_join(&child->p_container, container);
}
- for (i = 0; i <= HRL_RESOURCE_MAX; i++) {
+ for (i = 0; i <= RUSAGE_MAX; i++) {
if (parent->p_container.c_resources[i] != 0 &&
container_resource_inheritable(i))
- hrl_allocated(child, i,
+ rusage_set(child, i,
parent->p_container.c_resources[i]);
}
==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_exit.c#21 (text+ko) ====
@@ -767,7 +767,7 @@
* Decrement the count of procs running with this uid.
*/
(void)chgproccnt(p->p_ucred->cr_ruidinfo, -1, 0);
- hrl_free(p->p_pptr, HRL_RESOURCE_MAXPROCESSES, 1);
+ rusage_sub(p->p_pptr, RUSAGE_MAXPROCESSES, 1);
/*
* Destroy resource container associated with the process.
@@ -933,9 +933,9 @@
if (child->p_pptr == parent)
return;
- hrl_free(child->p_pptr, HRL_RESOURCE_MAXPROCESSES, 1);
+ rusage_sub(child->p_pptr, RUSAGE_MAXPROCESSES, 1);
/* XXX: What about return value? */
- hrl_alloc(parent, HRL_RESOURCE_MAXPROCESSES, 1);
+ rusage_add(parent, RUSAGE_MAXPROCESSES, 1);
PROC_LOCK(child->p_pptr);
sigqueue_take(child->p_ksi);
==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_fork.c#16 (text+ko) ====
@@ -224,7 +224,7 @@
p1 = td->td_proc;
- error = hrl_alloc(p1, HRL_RESOURCE_MAXPROCESSES, 1);
+ error = rusage_add(p1, RUSAGE_MAXPROCESSES, 1);
if (error)
return (error);
@@ -238,7 +238,7 @@
PROC_LOCK(p1);
if (thread_single(SINGLE_BOUNDARY)) {
PROC_UNLOCK(p1);
- hrl_free(p1, HRL_RESOURCE_MAXPROCESSES, 1);
+ rusage_sub(p1, RUSAGE_MAXPROCESSES, 1);
return (ERESTART);
}
PROC_UNLOCK(p1);
@@ -273,7 +273,7 @@
}
*procp = NULL;
if (error)
- hrl_free(p1, HRL_RESOURCE_MAXPROCESSES, 1);
+ rusage_sub(p1, RUSAGE_MAXPROCESSES, 1);
return (error);
}
@@ -811,7 +811,7 @@
vmspace_free(vm2);
uma_zfree(proc_zone, newproc);
pause("fork", hz / 2);
- hrl_free(p1, HRL_RESOURCE_MAXPROCESSES, 1);
+ rusage_sub(p1, RUSAGE_MAXPROCESSES, 1);
return (error);
}
==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_hrl.c#78 (text+ko) ====
@@ -88,19 +88,19 @@
{ NULL, -1 }};
static struct dict resourcenames[] = {
- { "cputime", HRL_RESOURCE_CPUTIME },
- { "filesize", HRL_RESOURCE_FILESIZE },
- { "datasize", HRL_RESOURCE_DATASIZE },
- { "stacksize", HRL_RESOURCE_STACKSIZE },
- { "coredumpsize", HRL_RESOURCE_COREDUMPSIZE },
- { "memoryuse", HRL_RESOURCE_MEMORYUSE },
- { "memorylocked", HRL_RESOURCE_MEMORYLOCKED },
- { "maxprocesses", HRL_RESOURCE_MAXPROCESSES },
- { "filedescriptors", HRL_RESOURCE_FILEDESCRIPTORS },
- { "sbsize", HRL_RESOURCE_SBSIZE },
- { "vmemoryuse", HRL_RESOURCE_VMEMORYUSE },
- { "pty", HRL_RESOURCE_PTY },
- { "swap", HRL_RESOURCE_SWAP },
+ { "cputime", RUSAGE_CPUTIME },
+ { "filesize", RUSAGE_FILESIZE },
+ { "datasize", RUSAGE_DATASIZE },
+ { "stacksize", RUSAGE_STACKSIZE },
+ { "coredumpsize", RUSAGE_COREDUMPSIZE },
+ { "memoryuse", RUSAGE_MEMORYUSE },
+ { "memorylocked", RUSAGE_MEMORYLOCKED },
+ { "maxprocesses", RUSAGE_MAXPROCESSES },
+ { "filedescriptors", RUSAGE_FILEDESCRIPTORS },
+ { "sbsize", RUSAGE_SBSIZE },
+ { "vmemoryuse", RUSAGE_VMEMORYUSE },
+ { "pty", RUSAGE_PTY },
+ { "swap", RUSAGE_SWAP },
{ NULL, -1 }};
static struct dict actionnames[] = {
@@ -263,7 +263,7 @@
int
hrl_enforce_proc(struct proc *p, int resource, uint64_t amount)
{
- int64_t available[HRL_RESOURCE_MAX];
+ int64_t available[RUSAGE_MAX];
struct hrl_rule *rule;
struct hrl_rule_link *link;
struct sbuf sb;
@@ -369,7 +369,7 @@
mtx_assert(&container_lock, MA_OWNED);
- for (i = 0; i <= HRL_RESOURCE_MAX; i++)
+ for (i = 0; i <= RUSAGE_MAX; i++)
(*availablep)[i] = INT64_MAX;
LIST_FOREACH(link, &p->p_container.c_rule_links, hrl_next) {
@@ -428,7 +428,7 @@
}
}
- if (filter->hr_resource != HRL_RESOURCE_UNDEFINED) {
+ if (filter->hr_resource != RUSAGE_UNDEFINED) {
if (rule->hr_resource != filter->hr_resource)
return (0);
}
@@ -640,7 +640,7 @@
rule->hr_subject.hs_loginclass = NULL;
rule->hr_subject.hs_prison = NULL;
rule->hr_per = HRL_SUBJECT_TYPE_UNDEFINED;
- rule->hr_resource = HRL_RESOURCE_UNDEFINED;
+ rule->hr_resource = RUSAGE_UNDEFINED;
rule->hr_action = HRL_ACTION_UNDEFINED;
rule->hr_amount = HRL_AMOUNT_UNDEFINED;
refcount_init(&rule->hr_refcount, 1);
@@ -724,7 +724,7 @@
panic("hrl_rule_fully_specified: unknown subject type %d",
rule->hr_subject_type);
}
- if (rule->hr_resource == HRL_RESOURCE_UNDEFINED)
+ if (rule->hr_resource == RUSAGE_UNDEFINED)
return (0);
if (rule->hr_action == HRL_ACTION_UNDEFINED)
return (0);
@@ -816,7 +816,7 @@
}
if (resourcestr == NULL || resourcestr[0] == '\0')
- rule->hr_resource = HRL_RESOURCE_UNDEFINED;
+ rule->hr_resource = RUSAGE_UNDEFINED;
else {
error = str2value(resourcestr, &rule->hr_resource,
resourcenames);
@@ -1119,7 +1119,7 @@
struct sbuf *sb;
sb = sbuf_new_auto();
- for (i = 0; i <= HRL_RESOURCE_MAX; i++) {
+ for (i = 0; i <= RUSAGE_MAX; i++) {
sbuf_printf(sb, "%s=%jd,", hrl_resource_name(i),
container->c_resources[i]);
}
==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_resource.c#35 (text+ko) ====
@@ -671,49 +671,49 @@
switch (which) {
case RLIMIT_CPU:
- rule->hr_resource = HRL_RESOURCE_CPUTIME;
+ rule->hr_resource = RUSAGE_CPUTIME;
rule->hr_action = HRL_ACTION_SIGXCPU;
break;
case RLIMIT_FSIZE:
- rule->hr_resource = HRL_RESOURCE_FILESIZE;
+ rule->hr_resource = RUSAGE_FILESIZE;
break;
case RLIMIT_DATA:
- rule->hr_resource = HRL_RESOURCE_DATASIZE;
+ rule->hr_resource = RUSAGE_DATASIZE;
break;
case RLIMIT_STACK:
- rule->hr_resource = HRL_RESOURCE_STACKSIZE;
+ rule->hr_resource = RUSAGE_STACKSIZE;
rule->hr_action = HRL_ACTION_SIGSEGV;
break;
case RLIMIT_CORE:
- rule->hr_resource = HRL_RESOURCE_COREDUMPSIZE;
+ rule->hr_resource = RUSAGE_COREDUMPSIZE;
break;
case RLIMIT_RSS:
- rule->hr_resource = HRL_RESOURCE_MEMORYUSE;
+ rule->hr_resource = RUSAGE_MEMORYUSE;
break;
case RLIMIT_MEMLOCK:
- rule->hr_resource = HRL_RESOURCE_MEMORYLOCKED;
+ rule->hr_resource = RUSAGE_MEMORYLOCKED;
break;
case RLIMIT_NPROC:
- rule->hr_resource = HRL_RESOURCE_MAXPROCESSES;
+ rule->hr_resource = RUSAGE_MAXPROCESSES;
rule->hr_per = HRL_SUBJECT_TYPE_USER;
break;
case RLIMIT_NOFILE:
- rule->hr_resource = HRL_RESOURCE_FILEDESCRIPTORS;
+ rule->hr_resource = RUSAGE_FILEDESCRIPTORS;
rule->hr_action = HRL_ACTION_SIGXFSZ;
break;
case RLIMIT_SBSIZE:
- rule->hr_resource = HRL_RESOURCE_SBSIZE;
+ rule->hr_resource = RUSAGE_SBSIZE;
rule->hr_per = HRL_SUBJECT_TYPE_USER;
break;
case RLIMIT_VMEM:
- rule->hr_resource = HRL_RESOURCE_VMEMORYUSE;
+ rule->hr_resource = RUSAGE_VMEMORYUSE;
break;
case RLIMIT_NPTS:
- rule->hr_resource = HRL_RESOURCE_PTY;
+ rule->hr_resource = RUSAGE_PTY;
rule->hr_per = HRL_SUBJECT_TYPE_USER;
break;
case RLIMIT_SWAP:
- rule->hr_resource = HRL_RESOURCE_SWAP;
+ rule->hr_resource = RUSAGE_SWAP;
rule->hr_per = HRL_SUBJECT_TYPE_USER;
break;
default:
==== //depot/projects/soc2009/trasz_limits/sys/kern/tty_pts.c#16 (text+ko) ====
@@ -722,7 +722,7 @@
/* Resource limiting. */
PROC_LOCK(p);
ok = chgptscnt(uid, 1, lim_cur(p, RLIMIT_NPTS));
- error = hrl_alloc(p, HRL_RESOURCE_PTY, 1);
+ error = rusage_add(p, RUSAGE_PTY, 1);
PROC_UNLOCK(p);
if (ok != !error)
printf("pts_alloc: ok = %d, error = %d\n", ok, error);
@@ -733,7 +733,7 @@
unit = alloc_unr(pts_pool);
if (unit < 0) {
chgptscnt(uid, -1, 0);
- hrl_free(p, HRL_RESOURCE_PTY, 1);
+ rusage_sub(p, RUSAGE_PTY, 1);
return (EAGAIN);
}
@@ -772,7 +772,7 @@
/* Resource limiting. */
PROC_LOCK(p);
ok = chgptscnt(uid, 1, lim_cur(p, RLIMIT_NPTS));
- error = hrl_alloc(p, HRL_RESOURCE_PTY, 1);
+ error = rusage_add(p, RUSAGE_PTY, 1);
PROC_UNLOCK(p);
if (ok != !error)
printf("pts_alloc: ok = %d, error = %d\n", ok, error);
==== //depot/projects/soc2009/trasz_limits/sys/kern/vfs_vnops.c#16 (text+ko) ====
@@ -1347,6 +1347,6 @@
if (vp->v_type != VREG || td == NULL)
return (0);
- return (hrl_allocated(td->td_proc, HRL_RESOURCE_FILESIZE,
+ return (rusage_set(td->td_proc, RUSAGE_FILESIZE,
(uoff_t)uio->uio_offset + uio->uio_resid));
}
==== //depot/projects/soc2009/trasz_limits/sys/sys/container.h#4 (text+ko) ====
@@ -46,23 +46,23 @@
* one parent container, loginclass and uidinfo structures have none.
* This may change when - and if - we add per-group resource limits.
*/
-#define CONTAINER_PARENTS_MAX 3
+#define CONTAINER_PARENTS_MAX 3
-#define HRL_RESOURCE_UNDEFINED -1
-#define HRL_RESOURCE_CPUTIME 0x0000
-#define HRL_RESOURCE_FILESIZE 0x0001
-#define HRL_RESOURCE_DATASIZE 0x0002
-#define HRL_RESOURCE_STACKSIZE 0x0003
-#define HRL_RESOURCE_COREDUMPSIZE 0x0004
-#define HRL_RESOURCE_MEMORYUSE 0x0005
-#define HRL_RESOURCE_MEMORYLOCKED 0x0006
-#define HRL_RESOURCE_MAXPROCESSES 0x0007
-#define HRL_RESOURCE_FILEDESCRIPTORS 0x0008
-#define HRL_RESOURCE_SBSIZE 0x0009
-#define HRL_RESOURCE_VMEMORYUSE 0x000a
-#define HRL_RESOURCE_PTY 0x000b
-#define HRL_RESOURCE_SWAP 0x000c
-#define HRL_RESOURCE_MAX HRL_RESOURCE_SWAP
+#define RUSAGE_UNDEFINED -1
+#define RUSAGE_CPUTIME 0x0000
+#define RUSAGE_FILESIZE 0x0001
+#define RUSAGE_DATASIZE 0x0002
+#define RUSAGE_STACKSIZE 0x0003
+#define RUSAGE_COREDUMPSIZE 0x0004
+#define RUSAGE_MEMORYUSE 0x0005
+#define RUSAGE_MEMORYLOCKED 0x0006
+#define RUSAGE_MAXPROCESSES 0x0007
+#define RUSAGE_FILEDESCRIPTORS 0x0008
+#define RUSAGE_SBSIZE 0x0009
+#define RUSAGE_VMEMORYUSE 0x000a
+#define RUSAGE_PTY 0x000b
+#define RUSAGE_SWAP 0x000c
+#define RUSAGE_MAX RUSAGE_SWAP
/*
* 'container' defines resource consumption for a particular
@@ -84,14 +84,14 @@
* This structure must be filled with zeroes initially.
*/
struct container {
- int64_t c_resources[HRL_RESOURCE_MAX + 1];
+ int64_t c_resources[RUSAGE_MAX + 1];
struct container *c_parents[CONTAINER_PARENTS_MAX + 1];
LIST_HEAD(, hrl_rule_link) c_rule_links;
};
-int hrl_alloc(struct proc *p, int object, uint64_t amount);
-int hrl_allocated(struct proc *p, int object, uint64_t amount);
-void hrl_free(struct proc *p, int object, uint64_t amount);
+int rusage_add(struct proc *p, int object, uint64_t amount);
+int rusage_set(struct proc *p, int object, uint64_t amount);
+void rusage_sub(struct proc *p, int object, uint64_t amount);
void container_create(struct container *container);
void container_destroy(struct container *container);
==== //depot/projects/soc2009/trasz_limits/sys/vm/vm_map.c#15 (text+ko) ====
@@ -412,11 +412,11 @@
pmap_activate(td);
vmspace_dofree(vm);
}
- hrl_allocated(p, HRL_RESOURCE_DATASIZE, 0);
- hrl_allocated(p, HRL_RESOURCE_STACKSIZE, 0);
- hrl_allocated(p, HRL_RESOURCE_MEMORYUSE, 0);
- hrl_allocated(p, HRL_RESOURCE_MEMORYLOCKED, 0);
- hrl_allocated(p, HRL_RESOURCE_VMEMORYUSE, 0);
+ rusage_set(p, RUSAGE_DATASIZE, 0);
+ rusage_set(p, RUSAGE_STACKSIZE, 0);
+ rusage_set(p, RUSAGE_MEMORYUSE, 0);
+ rusage_set(p, RUSAGE_MEMORYLOCKED, 0);
+ rusage_set(p, RUSAGE_VMEMORYUSE, 0);
}
/* Acquire reference to vmspace owned by another process. */
==== //depot/projects/soc2009/trasz_limits/sys/vm/vm_unix.c#6 (text+ko) ====
@@ -85,7 +85,7 @@
base = round_page((vm_offset_t) vm->vm_daddr);
old = base + ctob(vm->vm_dsize);
if (new > base) {
- error = hrl_allocated(td->td_proc, HRL_RESOURCE_DATASIZE,
+ error = rusage_set(td->td_proc, RUSAGE_DATASIZE,
new - base);
if (error) {
error = ENOMEM;
@@ -105,7 +105,7 @@
goto done;
}
if (new > old) {
- error = hrl_allocated(td->td_proc, HRL_RESOURCE_VMEMORYUSE,
+ error = rusage_set(td->td_proc, RUSAGE_VMEMORYUSE,
vm->vm_map.size + (new - old));
if (error) {
error = ENOMEM;
More information about the p4-projects
mailing list