Skip to content

Commit

Permalink
cgfsng: mount_cgroup_full()
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Feb 21, 2018
1 parent f73fcbf commit 643b967
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions src/lxc/cgroups/cgfsng.c
Expand Up @@ -1971,42 +1971,51 @@ static bool cgfsng_chown(void *hdata, struct lxc_conf *conf)
return true;
}

/*
* We've safe-mounted a tmpfs as parent, so we don't need to protect against
* symlinks any more - just use mount
/* We've safe-mounted a tmpfs as parent, so we don't need to protect against
* symlinks any more - just use mount.
*
* mount cgroup-full if requested
*/

/* mount cgroup-full if requested */
static int mount_cgroup_full(int type, struct hierarchy *h, char *dest,
char *container_cgroup)
{
int ret;
char *rwpath, *source;

if (type < LXC_AUTO_CGROUP_FULL_RO || type > LXC_AUTO_CGROUP_FULL_MIXED)
return 0;
if (mount(h->mountpoint, dest, "cgroup", MS_BIND, NULL) < 0) {
SYSERROR("Error bind-mounting %s cgroup onto %s", h->mountpoint,
dest);

ret = mount(h->mountpoint, dest, "cgroup", MS_BIND, NULL);
if (ret < 0) {
SYSERROR("Failed to bind mount cgroup \"%s\" onto \"%s\"",
h->mountpoint, dest);
return -1;
}

if (type != LXC_AUTO_CGROUP_FULL_RW) {
unsigned long flags = MS_BIND | MS_NOSUID | MS_NOEXEC | MS_NODEV |
MS_REMOUNT | MS_RDONLY;
if (mount(NULL, dest, "cgroup", flags, NULL) < 0) {
SYSERROR("Error remounting %s readonly", dest);

ret = mount(NULL, dest, "cgroup", flags, NULL);
if (ret < 0) {
SYSERROR("Failed to remount cgroup \"%s\" read-only", dest);
return -1;
}
}

INFO("Bind mounted %s onto %s", h->mountpoint, dest);
INFO("Bind mounted \"%s\" onto \"%s\"", h->mountpoint, dest);
if (type != LXC_AUTO_CGROUP_FULL_MIXED)
return 0;

/* mount just the container path rw */
char *source = must_make_path(h->mountpoint, h->base_cgroup, container_cgroup, NULL);
char *rwpath = must_make_path(dest, h->base_cgroup, container_cgroup, NULL);
if (mount(source, rwpath, "cgroup", MS_BIND, NULL) < 0)
WARN("Failed to mount %s read-write: %s", rwpath,
strerror(errno));
INFO("Made %s read-write", rwpath);
source = must_make_path(h->mountpoint, h->base_cgroup, container_cgroup, NULL);
rwpath = must_make_path(dest, h->base_cgroup, container_cgroup, NULL);
ret = mount(source, rwpath, "cgroup", MS_BIND, NULL);
if (ret < 0)
WARN("%s - Failed to mount cgroup \"%s\" read-write",
strerror(errno), rwpath);

TRACE("Mounted cgroup \"%s\" read-write", rwpath);
free(rwpath);
free(source);
return 0;
Expand Down

0 comments on commit 643b967

Please sign in to comment.