Commit 831d155c authored by Dmitry Safonov's avatar Dmitry Safonov Committed by Andrei Vagin

cgroup: Separate devices.list cgroup restoring

Now restore_special_property() only deals which special property
restore and restore_devices_list() deals with devices.list.

BTW, let's have two variables dev_allow and dev_deny on stack
to simplify it - all this fuss with old_val and old_name
kills the fun.
Signed-off-by: 's avatarDmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent f14cdada
......@@ -1371,78 +1371,75 @@ int prepare_cgroup_properties(void)
return 0;
}
static int restore_special_property(char *paux, size_t off, CgroupPropEntry *pr)
{
/*
* 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.
*/
if (!strcmp(pr->name, "memory.swappiness") && !strcmp(pr->value, "60"))
return 0;
if (!strcmp(pr->name, "memory.oom_control") && !strcmp(pr->value, "0"))
return 0;
if (!strcmp(pr->name, "devices.list")) {
/*
/*
* The devices cgroup must be restored in a special way:
* only the contents of devices.list can be read, and it
* is a whitelist of all the devices the cgroup is allowed
* to create. To re-create this whitelist, we firstly deny
* everything via devices.deny, and then write the list back
* into devices.allow.
* only the contents of devices.list can be read, and it is a whitelist
* of all the devices the cgroup is allowed to create. To re-create
* this whitelist, we firstly deny everything via devices.deny,
* and then write the list back into devices.allow.
*
* Further, we must have a write() call for each line,
* because the kernel only parses the first line of
* any write().
* Further, we must have a write() call for each line, because the kernel
* only parses the first line of any write().
*/
CgroupPropEntry *pe = pr;
char *old_val = pe->value, *old_name = pe->name;
int ret;
static int restore_devices_list(char *paux, size_t off, CgroupPropEntry *pr)
{
CgroupPropEntry dev_allow = *pr;
CgroupPropEntry dev_deny = *pr;
char *pos;
int ret;
/*
* A bit of a fudge here. These are write only by owner
* by default, but the container engine could have changed
* the perms. We should come up with a better way to
* restore all of this stuff.
*/
pe->perms->mode = 0200;
dev_allow.name = "devices.allow";
dev_deny.name = "devices.deny";
dev_deny.value = "a";
pe->name = "devices.deny";
pe->value = "a";
ret = restore_cgroup_prop(pr, paux, off);
pe->name = old_name;
pe->value = old_val;
ret = restore_cgroup_prop(&dev_deny, paux, off);
/*
* An emptry string here means nothing is allowed,
* and the kernel disallows writing an "" to devices.allow,
* so let's just keep going.
*/
if (!strcmp(pe->value, ""))
if (!strcmp(dev_allow.value, ""))
return 0;
if (ret < 0)
return -1;
pe->name = "devices.allow";
pos = pe->value;
pos = dev_allow.value;
while (*pos) {
int offset = next_device_entry(pos);
pe->value = pos;
ret = restore_cgroup_prop(pe, paux, off);
if (ret < 0) {
pe->name = old_name;
pe->value = old_val;
dev_allow.value = pos;
ret = restore_cgroup_prop(&dev_allow, paux, off);
if (ret < 0)
return -1;
}
pos += offset;
}
pe->value = old_val;
pe->name = old_name;
return 0;
}
static int restore_special_property(char *paux, size_t off, CgroupPropEntry *pr)
{
/*
* 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.
*/
if (!strcmp(pr->name, "memory.swappiness") && !strcmp(pr->value, "60"))
return 0;
if (!strcmp(pr->name, "memory.oom_control") && !strcmp(pr->value, "0"))
return 0;
if (!strcmp(pr->name, "devices.list")) {
/*
* A bit of a fudge here. These are write only by owner
* by default, but the container engine could have changed
* the perms. We should come up with a better way to
* restore all of this stuff.
*/
pr->perms->mode = 0200;
return restore_devices_list(paux, off, pr);
}
return restore_cgroup_prop(pr, paux, off);
......
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