Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 0 additions & 123 deletions src/lxc/cgroups/cgfsng.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,129 +580,6 @@ __cgfsng_ops static void cgfsng_payload_destroy(struct cgroup_ops *ops,
SYSWARN("Failed to destroy cgroups");
}

#define __ISOL_CPUS "/sys/devices/system/cpu/isolated"
#define __OFFLINE_CPUS "/sys/devices/system/cpu/offline"
static bool cpuset1_cpus_initialize(int dfd_parent, int dfd_child,
bool am_initialized)
{
__do_free char *cpulist = NULL, *isolcpus = NULL,
*offlinecpus = NULL, *posscpus = NULL;
__do_free __u32 *possmask = NULL;
int ret;
__u32 poss_last_set_bit = 0;

#if !IS_BIONIC
posscpus = read_file_at(dfd_parent, "cpuset.cpus", PROTECT_OPEN, 0);
#else
posscpus = read_file_at(dfd_parent, "cpus", PROTECT_OPEN, 0);
#endif
if (!posscpus)
return log_error_errno(false, errno, "Failed to read file %d/cpuset.cpus", dfd_parent);

if (file_exists(__ISOL_CPUS)) {
isolcpus = read_file_at(-EBADF, __ISOL_CPUS, PROTECT_OPEN, 0);
if (!isolcpus)
return log_error_errno(false, errno, "Failed to read file \"%s\"", __ISOL_CPUS);

if (!isdigit(isolcpus[0]))
free_disarm(isolcpus);
} else {
TRACE("The path \""__ISOL_CPUS"\" to read isolated cpus from does not exist");
}

if (file_exists(__OFFLINE_CPUS)) {
offlinecpus = read_file_at(-EBADF, __OFFLINE_CPUS, PROTECT_OPEN, 0);
if (!offlinecpus)
return log_error_errno(false, errno, "Failed to read file \"%s\"", __OFFLINE_CPUS);

if (!isdigit(offlinecpus[0]))
free_disarm(offlinecpus);
} else {
TRACE("The path \""__OFFLINE_CPUS"\" to read offline cpus from does not exist");
}

if (!isolcpus && !offlinecpus) {
cpulist = move_ptr(posscpus);
goto copy_parent;
}

ret = lxc_cpumask(posscpus, &possmask, &poss_last_set_bit);
if (ret)
return log_error_errno(false, errno, "Failed to create cpumask for possible cpus");

if (isolcpus)
ret = lxc_cpumask_update(isolcpus, possmask, poss_last_set_bit, true);

if (offlinecpus)
ret |= lxc_cpumask_update(offlinecpus, possmask, poss_last_set_bit, true);

if (!ret) {
cpulist = lxc_cpumask_to_cpulist(possmask, poss_last_set_bit);
TRACE("No isolated or offline cpus present in cpuset");
} else {
cpulist = move_ptr(posscpus);
TRACE("Removed isolated or offline cpus from cpuset");
}
if (!cpulist)
return log_error_errno(false, errno, "Failed to create cpu list");

copy_parent:
if (!am_initialized) {
#if !IS_BIONIC
ret = lxc_writeat(dfd_child, "cpuset.cpus", cpulist, strlen(cpulist));
#else
ret = lxc_writeat(dfd_child, "cpus", cpulist, strlen(cpulist));
#endif
if (ret < 0)
return log_error_errno(false, errno, "Failed to write cpu list to \"%d/cpuset.cpus\"", dfd_child);

TRACE("Copied cpu settings of parent cgroup");
}

return true;
}

static bool cpuset1_initialize(int dfd_base, int dfd_next)
{
char mems[PATH_MAX];
ssize_t bytes;
char v;

/* Determine whether the base cgroup has cpuset inheritance turned on. */
bytes = lxc_readat(dfd_base, "cgroup.clone_children", &v, 1);
if (bytes < 0)
return syserror_ret(false, "Failed to read file %d(cgroup.clone_children)", dfd_base);

/* Initialize cpuset.cpus removing any isolated and offline cpus. */
if (!cpuset1_cpus_initialize(dfd_base, dfd_next, v == '1'))
return syserror_ret(false, "Failed to initialize cpuset.cpus");

/* Read cpuset.mems from parent... */
#if !IS_BIONIC
bytes = lxc_readat(dfd_base, "cpuset.mems", mems, sizeof(mems));
#else
bytes = lxc_readat(dfd_base, "mems", mems, sizeof(mems));
#endif
if (bytes < 0)
return syserror_ret(false, "Failed to read file %d(cpuset.mems)", dfd_base);

/* and copy to first cgroup in the tree... */
#if !IS_BIONIC
bytes = lxc_writeat(dfd_next, "cpuset.mems", mems, bytes);
#else
bytes = lxc_writeat(dfd_next, "mems", mems, bytes);
#endif
if (bytes < 0)
return syserror_ret(false, "Failed to write %d(cpuset.mems)", dfd_next);

/* and finally turn on cpuset inheritance. */
bytes = lxc_writeat(dfd_next, "cgroup.clone_children", "1", 1);
if (bytes < 0)
return syserror_ret(false, "Failed to write %d(cgroup.clone_children)", dfd_next);

return log_trace(true, "Initialized cpuset in the legacy hierarchy");
}

static int __cgroup_tree_create(int dfd_base, const char *path, mode_t mode,
bool cpuset_v1, bool eexist_ignore)
{
Expand Down
Loading