Skip to content

Commit

Permalink
cgroups: rename cgroupfs mount fd
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 26, 2021
1 parent 540b8ae commit 02ca9e8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions src/lxc/cgroups/cgfsng.c
Expand Up @@ -3082,19 +3082,19 @@ static int __initialize_cgroups(struct cgroup_ops *ops, bool relative,
if (IS_ERR(current_cgroup))
return PTR_ERR(current_cgroup);

if (unified_cgroup_fd(ops->dfd_mnt_cgroupfs_host)) {
dfd_mnt = dup_cloexec(ops->dfd_mnt_cgroupfs_host);
if (unified_cgroup_fd(ops->dfd_mnt)) {
dfd_mnt = dup_cloexec(ops->dfd_mnt);
unified_mnt = "";
} else {
dfd_mnt = open_at(ops->dfd_mnt_cgroupfs_host,
dfd_mnt = open_at(ops->dfd_mnt,
"unified",
PROTECT_OPATH_DIRECTORY,
PROTECT_LOOKUP_ABSOLUTE_XDEV, 0);
unified_mnt = "unified";
}
if (dfd_mnt < 0) {
if (errno != ENOENT)
return syserrno(-errno, "Failed to open %d/unified", ops->dfd_mnt_cgroupfs_host);
return syserrno(-errno, "Failed to open %d/unified", ops->dfd_mnt);

SYSTRACE("Unified cgroup not mounted");
continue;
Expand Down Expand Up @@ -3144,13 +3144,13 @@ static int __initialize_cgroups(struct cgroup_ops *ops, bool relative,
if (!controllers)
return ret_errno(ENOMEM);

dfd_mnt = open_at(ops->dfd_mnt_cgroupfs_host,
dfd_mnt = open_at(ops->dfd_mnt,
controllers, PROTECT_OPATH_DIRECTORY,
PROTECT_LOOKUP_ABSOLUTE_XDEV, 0);
if (dfd_mnt < 0) {
if (errno != ENOENT)
return syserrno(-errno, "Failed to open %d/%s",
ops->dfd_mnt_cgroupfs_host, controllers);
ops->dfd_mnt, controllers);

SYSTRACE("%s not mounted", controllers);
continue;
Expand Down Expand Up @@ -3234,7 +3234,7 @@ static int initialize_cgroups(struct cgroup_ops *ops, struct lxc_conf *conf)
int ret;
const char *controllers_use;

if (ops->dfd_mnt_cgroupfs_host >= 0)
if (ops->dfd_mnt >= 0)
return ret_errno(EBUSY);

/*
Expand Down Expand Up @@ -3268,7 +3268,7 @@ static int initialize_cgroups(struct cgroup_ops *ops, struct lxc_conf *conf)
* once we know the initialization succeeded. So if we fail we clean up
* the dfd.
*/
ops->dfd_mnt_cgroupfs_host = dfd;
ops->dfd_mnt = dfd;

ret = __initialize_cgroups(ops, conf->cgroup_meta.relative, !lxc_list_empty(&conf->id_map));
if (ret < 0)
Expand Down Expand Up @@ -3306,7 +3306,7 @@ struct cgroup_ops *cgroup_ops_init(struct lxc_conf *conf)
return ret_set_errno(NULL, ENOMEM);

cgfsng_ops->cgroup_layout = CGROUP_LAYOUT_UNKNOWN;
cgfsng_ops->dfd_mnt_cgroupfs_host = -EBADF;
cgfsng_ops->dfd_mnt = -EBADF;

if (initialize_cgroups(cgfsng_ops, conf))
return NULL;
Expand Down
4 changes: 2 additions & 2 deletions src/lxc/cgroups/cgroup.c
Expand Up @@ -73,8 +73,8 @@ void cgroup_exit(struct cgroup_ops *ops)

bpf_device_program_free(ops);

if (ops->dfd_mnt_cgroupfs_host >= 0)
close(ops->dfd_mnt_cgroupfs_host);
if (ops->dfd_mnt >= 0)
close(ops->dfd_mnt);

for (struct hierarchy **it = ops->hierarchies; it && *it; it++) {
for (char **p = (*it)->controllers; p && *p; p++)
Expand Down
2 changes: 1 addition & 1 deletion src/lxc/cgroups/cgroup.h
Expand Up @@ -130,7 +130,7 @@ struct cgroup_ops {
* So for CGROUP_LAYOUT_LEGACY or CGROUP_LAYOUT_HYBRID we allow
* mountpoint crossing iff we cross from a tmpfs into a cgroupfs mount.
* */
int dfd_mnt_cgroupfs_host;
int dfd_mnt;

/* What controllers is the container supposed to use. */
char **cgroup_use;
Expand Down

0 comments on commit 02ca9e8

Please sign in to comment.