Date: Sun, 11 Jul 2010 13:00:10 GMT From: Edward Tomasz Napierala <trasz@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 180757 for review Message-ID: <201007111300.o6BD0ASd042506@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@180757?ac=10 Change 180757 by trasz@trasz_victim on 2010/07/11 13:00:03 Properly handle joining and leaving containers that have parents. Affected files ... .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#14 edit Differences ... ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#14 (text+ko) ==== @@ -62,40 +62,57 @@ static struct mtx container_lock; MTX_SYSINIT(container_lock, &container_lock, "container lock", MTX_DEF); +static void container_sub(struct container *dest, const struct container *src); + static int container_add(struct container *dest, const struct container *src) { - int i; + int i, error; mtx_assert(&container_lock, MA_OWNED); + /* + * Update resource usage in dest's parents. + */ + for (i = 0; i <= CONTAINER_PARENTS_MAX; i++) { + if (dest->c_parents[i] == NULL) + continue; + error = container_add(dest->c_parents[i], src); + if (error) { + for (i--; i >= 0; i--) + container_sub(dest->c_parents[i], src); + return (error); + } + } + + /* + * Update resource usage in dest. + */ 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, ("resource usage propagation meltdown: src < 0")); /* - * XXX: Container hierarchy! - */ - /* * XXX: Enforce limit here; if exceeded, undo everything * and return error. */ dest->c_resources[i] += src->c_resources[i]; - KASSERT(dest->c_resources[i] >= 0, - ("resource usage propagation meltdown: dest < 0 after addition")); } return (0); } static void -container_subtract(struct container *dest, const struct container *src) +container_sub(struct container *dest, const struct container *src) { int i; mtx_assert(&container_lock, MA_OWNED); + /* + * Update resource usage in dest. + */ for (i = 0; i <= RUSAGE_MAX; i++) { KASSERT(dest->c_resources[i] >= 0, ("resource usage propagation meltdown: dest < 0")); @@ -104,11 +121,15 @@ KASSERT(src->c_resources[i] <= dest->c_resources[i], ("resource usage propagation meltdown: src > dest")); dest->c_resources[i] -= src->c_resources[i]; - /* - * XXX: Container hierarchy! - */ - KASSERT(dest->c_resources[i] >= 0, - ("resource usage propagation meltdown: dest < 0 after subtraction")); + } + + /* + * Update resource usage in dest's parents. + */ + for (i = 0; i <= CONTAINER_PARENTS_MAX; i++) { + if (dest->c_parents[i] == NULL) + continue; + container_sub(dest->c_parents[i], src); } } @@ -159,7 +180,7 @@ for (i = 0; i <= CONTAINER_PARENTS_MAX; i++) { if (child->c_parents[i] == parent) { - container_subtract(parent, child); + container_sub(parent, child); child->c_parents[i] = NULL; return; } @@ -187,7 +208,7 @@ for (i = 0; i <= CONTAINER_PARENTS_MAX; i++) { if (child->c_parents[i] == NULL) continue; - container_subtract(child->c_parents[i], child); + container_sub(child->c_parents[i], child); child->c_parents[i] = NULL; } }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201007111300.o6BD0ASd042506>