From 90bdbaaa084e55c089cbe1679310c9515f27ff85 Mon Sep 17 00:00:00 2001 From: DreamConnected <1487442471@qq.com> Date: Tue, 5 May 2026 18:50:16 +0800 Subject: [PATCH] lxc/cgfsng: drop cgroup1 cpus support Signed-off-by: DreamConnected <1487442471@qq.com> --- src/lxc/cgroups/cgfsng.c | 123 --------------------------------------- 1 file changed, 123 deletions(-) diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c index fcaea291fc..ce618c86c1 100644 --- a/src/lxc/cgroups/cgfsng.c +++ b/src/lxc/cgroups/cgfsng.c @@ -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) {