Commit f14cdada authored by Dmitry Safonov's avatar Dmitry Safonov Committed by Andrei Vagin

cgroup: Introduce restore_special_propery()

To reduce restore_special_props() size - let's factor a new
function for restoring one special property.

No functional change expected.
Signed-off-by: 's avatarDmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 16683565
...@@ -1371,72 +1371,57 @@ int prepare_cgroup_properties(void) ...@@ -1371,72 +1371,57 @@ int prepare_cgroup_properties(void)
return 0; return 0;
} }
static int restore_special_props(char *paux, size_t off, CgroupDirEntry *e) static int restore_special_property(char *paux, size_t off, CgroupPropEntry *pr)
{ {
int j; /*
* XXX: we can drop this hack and make memory.swappiness and
pr_info("Restore special props\n"); * memory.oom_control regular properties when we drop support for
{
for (j = 0; j < e->n_properties; j++) {
CgroupPropEntry *prop = e->properties[j];
if (is_special_property(prop->name)) {
/* XXX: we can drop this hack and make
* memory.swappiness and memory.oom_control
* regular properties when we drop support for
* kernels < 3.16. See 3dae7fec5. * kernels < 3.16. See 3dae7fec5.
*/ */
if (!strcmp(prop->name, "memory.swappiness") && if (!strcmp(pr->name, "memory.swappiness") && !strcmp(pr->value, "60"))
!strcmp(prop->value, "60")) { return 0;
continue; if (!strcmp(pr->name, "memory.oom_control") && !strcmp(pr->value, "0"))
} else if (!strcmp(prop->name, "memory.oom_control") && return 0;
!strcmp(prop->value, "0")) {
continue;
}
if (!strcmp(prop->name, "devices.list")) { if (!strcmp(pr->name, "devices.list")) {
/* The devices cgroup must be restored in a /*
* special way: only the contents of * The devices cgroup must be restored in a special way:
* devices.list can be read, and it is a * only the contents of devices.list can be read, and it
* whitelist of all the devices the cgroup is * is a whitelist of all the devices the cgroup is allowed
* allowed to create. To re-creat this * to create. To re-create this whitelist, we firstly deny
* whitelist, we first deny everything via * everything via devices.deny, and then write the list back
* devices.deny, and then write the list back
* into devices.allow. * into devices.allow.
* *
* Further, we must have a write() call for * Further, we must have a write() call for each line,
* each line, because the kernel only parses * because the kernel only parses the first line of
* the first line of any write(). * any write().
*/ */
CgroupPropEntry *pe = prop; CgroupPropEntry *pe = pr;
char *old_val = pe->value, *old_name = pe->name; char *old_val = pe->value, *old_name = pe->name;
int ret; int ret;
char *pos; char *pos;
/* A bit of a fudge here. These are /*
* write only by owner by default, but * A bit of a fudge here. These are write only by owner
* the container engine could have * by default, but the container engine could have changed
* changed the perms. We should come up * the perms. We should come up with a better way to
* with a better way to restore all of * restore all of this stuff.
* this stuff.
*/ */
pe->perms->mode = 0200; pe->perms->mode = 0200;
pe->name = "devices.deny"; pe->name = "devices.deny";
pe->value = "a"; pe->value = "a";
ret = restore_cgroup_prop(prop, paux, off); ret = restore_cgroup_prop(pr, paux, off);
pe->name = old_name; pe->name = old_name;
pe->value = old_val; pe->value = old_val;
/* an emptry string here means nothing /*
* is allowed, and the kernel disallows * An emptry string here means nothing is allowed,
* writing an "" to devices.allow, so * and the kernel disallows writing an "" to devices.allow,
* let's just keep going. * so let's just keep going.
*/ */
if (!strcmp(pe->value, "")) if (!strcmp(pe->value, ""))
continue; return 0;
if (ret < 0) if (ret < 0)
return -1; return -1;
...@@ -1457,16 +1442,29 @@ static int restore_special_props(char *paux, size_t off, CgroupDirEntry *e) ...@@ -1457,16 +1442,29 @@ static int restore_special_props(char *paux, size_t off, CgroupDirEntry *e)
} }
pe->value = old_val; pe->value = old_val;
pe->name = old_name; pe->name = old_name;
continue; return 0;
} }
if (restore_cgroup_prop(prop, paux, off) < 0) { return restore_cgroup_prop(pr, paux, off);
}
static int restore_special_props(char *paux, size_t off, CgroupDirEntry *e)
{
unsigned int j;
pr_info("Restore special props\n");
for (j = 0; j < e->n_properties; j++) {
CgroupPropEntry *prop = e->properties[j];
if (!is_special_property(prop->name))
continue;
if (restore_special_property(paux, off, prop) < 0) {
pr_err("Restoring %s special property failed\n", prop->name);
return -1; return -1;
} }
} }
}
}
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment