summaryrefslogtreecommitdiff
path: root/src/basic/cgroup-util.h
Commit message (Collapse)AuthorAge
* cgroup-util: add brief comments clarifying which controllers are v2-only and ↵Lennart Poettering2017-11-08
| | | | which v1-only
* Prep 235: Enabled sd_bus_creds_get_slice(), sd_bus_creds_get_user_slice(), ↵Sven Eden2018-01-09
| | | | sd_peer_get_user_slice() and sd_pid_get_user_slice() to try to work with eloginds session id to user mapping.
* Prep 235: Enabled sd_peer_get_slice() and sd_pid_get_slice() to at least try ↵Sven Eden2018-01-09
| | | | to work. This is considered experimental.
* Prep 235: Although systemd slices are unsupported, make cg_path_get_slice() ↵Sven Eden2018-01-09
| | | | available, but in 'elogind jargon'
* Prep 235: Implement an alternative approach for sd_pid_get_owner_uid(), ↵Sven Eden2017-12-13
| | | | making test-login to no longer fail.
* Apply updates from upstreamSven Eden2017-12-07
|
* Prep v235: Add missing includes and dependencies.Sven Eden2017-08-14
|
* Prep v234: Eventually fix the cgroup stuff. elogind is not init.Sven Eden2017-07-27
|
* core: introduce cg_mask_from_string()/cg_mask_to_string()Franck Bui2017-07-25
|
* Prep v233.3: Unmask various functions for future coverage tests.Sven Eden2017-07-19
| | | | | These functions, although not used by elogind itself, are mostly tiny and crucial for important tests to work.
* Prep v233: Unmask now needed functions in src/basicSven Eden2017-07-17
|
* cgroup: rename cg_unified() → cg_unified_controller()Lennart Poettering2017-07-17
| | | | | cg_unified() is a bit generic a name, let's make clear that it checks whether a specified controller is in unified mode.
* cgroup: change cg_unified() to possibly return errors againLennart Poettering2017-07-17
| | | | | | | | | We use our cgroup APIs in various contexts, including from our libraries sd-login, sd-bus. As we don#t control those environments we can't rely that the unified cgroup setup logic succeeds, and hence really shouldn't assert on it. This more or less reverts 415fc41ceaeada2e32639f24f134b1c248b9e43f.
* Rename cg_is_unified_elogind_controller_wanted to cg_is_hybrid_wantedZbigniew Jędrzejewski-Szmek2017-07-17
| | | | Less typing and doesn't make the table so incredibly wide.
* core: simplify cg_[all_]unified()Tejun Heo2017-07-17
| | | | | | | | | | | | | | | | | | | | | | | | | cg_[all_]unified() test whether a specific controller or all controllers are on the unified hierarchy. While what's being asked is a simple binary question, the callers must assume that the functions may fail any time, which unnecessarily complicates their usages. This complication is unnecessary. Internally, the test result is cached anyway and there are only a few places where the test actually needs to be performed. This patch simplifies cg_[all_]unified(). * cg_[all_]unified() are updated to return bool. If the result can't be decided, assertion failure is triggered. Error handlings from their callers are dropped. * cg_unified_flush() is updated to calculate the new result synchrnously and return whether it succeeded or not. Places which need to flush the test result are updated to test for failure. This ensures that all the following cg_[all_]unified() tests succeed. * Places which expected possible cg_[all_]unified() failures are updated to call and test cg_unified_flush() before calling cg_[all_]unified(). This includes functions used while setting up mounts during boot and manager_setup_cgroup().
* core: make hybrid cgroup unified mode keep compat /sys/fs/cgroup/elogind ↵Tejun Heo2017-07-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | hierarchy Currently the hybrid mode mounts cgroup v2 on /sys/fs/cgroup instead of the v1 name=elogind hierarchy. While this works fine for elogind itself, it breaks tools which expect cgroup v1 hierarchy on /sys/fs/cgroup/elogind. This patch updates the hybrid mode so that it mounts v2 hierarchy on /sys/fs/cgroup/unified and keeps v1 "name=elogind" hierarchy on /sys/fs/cgroup/elogind for compatibility. elogind itself doesn't depend on the "name=elogind" hierarchy at all. All operations take place on the v2 hierarchy as before but the v1 hierarchy is kept in sync so that any tools which expect it to be there can keep doing so. This allows elogind to take advantage of cgroup v2 process management without requiring other tools to be aware of the hybrid mode. The hybrid mode is implemented by mapping the special elogind controller to /sys/fs/cgroup/unified and making the basic cgroup utility operations - cg_attach(), cg_create(), cg_rmdir() and cg_trim() - also operate on the /sys/fs/cgroup/elogind hierarchy whenever the cgroup2 hierarchy is updated. While a bit messy, this will allow dropping complications from using cgroup v1 for process management a lot sooner than otherwise possible which should make it a net gain in terms of maintainability. v2: Fixed !cgns breakage reported by @evverx and renamed the unified mount point to /sys/fs/cgroup/unified as suggested by @brauner. v3: chown the compat hierarchy too on delegation. Suggested by @evverx. v4: [zj] - drop the change to default, full "legacy" is still the default.
* Prep v232.2: Mask more unneeded functionsSven Eden2017-07-07
|
* Prep v232: Do not listen to SYSTEMD_* environment variables to override things.Sven Eden2017-07-05
|
* Prep v232: Mask new functions that are unneeded by elogindSven Eden2017-07-05
|
* Prep v232: Apply missing updates from upstreamSven Eden2017-07-05
|
* nspawn: cleanup and chown the synced cgroup hierarchy (#4223)Evgeny Vereshchagin2017-07-05
| | | | Fixes: #4181
* logind: update empty and "infinity" handling for [User]TasksMax (#3835)Tejun Heo2017-07-05
| | | | | | | | | | | | | | | | | The parsing functions for [User]TasksMax were inconsistent. Empty string and "infinity" were interpreted as no limit for TasksMax but not accepted for UserTasksMax. Update them so that they're consistent with other knobs. * Empty string indicates the default value. * "infinity" indicates no limit. While at it, replace opencoded (uint64_t) -1 with CGROUP_LIMIT_MAX in TasksMax handling. v2: Update empty string to indicate the default value as suggested by Zbigniew Jędrzejewski-Szmek. v3: Fixed empty UserTasksMax handling.
* core: rename cg_unified() to cg_all_unified()Tejun Heo2017-07-05
| | | | | | | | | | | A following patch will update cgroup handling so that the elogind controller (/sys/fs/cgroup/elogind) can use the unified hierarchy even if the kernel resource controllers are on the legacy hierarchies. This would require distinguishing whether all controllers are on cgroup v2 or only the elogind controller is. In preparation, this patch renames cg_unified() to cg_all_unified(). This patch doesn't cause any functional changes.
* core: use the unified hierarchy for the elogind cgroup controller hierarchyTejun Heo2017-07-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, elogind uses either the legacy hierarchies or the unified hierarchy. When the legacy hierarchies are used, elogind uses a named legacy hierarchy mounted on /sys/fs/cgroup/elogind without any kernel controllers for process management. Due to the shortcomings in the legacy hierarchy, this involves a lot of workarounds and complexities. Because the unified hierarchy can be mounted and used in parallel to legacy hierarchies, there's no reason for elogind to use a legacy hierarchy for management even if the kernel resource controllers need to be mounted on legacy hierarchies. It can simply mount the unified hierarchy under /sys/fs/cgroup/elogind and use it without affecting other legacy hierarchies. This disables a significant amount of fragile workaround logics and would allow using features which depend on the unified hierarchy membership such bpf cgroup v2 membership test. In time, this would also allow deleting the said complexities. This patch updates elogind so that it prefers the unified hierarchy for the elogind cgroup controller hierarchy when legacy hierarchies are used for kernel resource controllers. * cg_unified(@controller) is introduced which tests whether the specific controller in on unified hierarchy and used to choose the unified hierarchy code path for process and service management when available. Kernel controller specific operations remain gated by cg_all_unified(). * "elogind.legacy_elogind_cgroup_controller" kernel argument can be used to force the use of legacy hierarchy for elogind cgroup controller. * nspawn: By default nspawn uses the same hierarchies as the host. If UNIFIED_CGROUP_HIERARCHY is set to 1, unified hierarchy is used for all. If 0, legacy for all. * nspawn: arg_unified_cgroup_hierarchy is made an enum and now encodes one of three options - legacy, only elogind controller on unified, and unified. The value is passed into mount setup functions and controls cgroup configuration. * nspawn: Interpretation of SYSTEMD_CGROUP_CONTROLLER to the actual mount option is moved to mount_legacy_cgroup_hierarchy() so that it can take an appropriate action depending on the configuration of the host. v2: - CGroupUnified enum replaces open coded integer values to indicate the cgroup operation mode. - Various style updates. v3: Fixed a bug in detect_unified_cgroup_hierarchy() introduced during v2. v4: Restored legacy container on unified host support and fixed another bug in detect_unified_cgroup_hierarchy().
* core: add cgroup CPU controller support on the unified hierarchyTejun Heo2017-07-05
| | | | | | | | | | | | | | | | | | | | | | | | | Unfortunately, due to the disagreements in the kernel development community, CPU controller cgroup v2 support has not been merged and enabling it requires applying two small out-of-tree kernel patches. The situation is explained in the following documentation. https://git.kernel.org/cgit/linux/kernel/git/tj/cgroup.git/tree/Documentation/cgroup-v2-cpu.txt?h=cgroup-v2-cpu While it isn't clear what will happen with CPU controller cgroup v2 support, there are critical features which are possible only on cgroup v2 such as buffered write control making cgroup v2 essential for a lot of workloads. This commit implements elogind CPU controller support on the unified hierarchy so that users who choose to deploy CPU controller cgroup v2 support can easily take advantage of it. On the unified hierarchy, "cpu.weight" knob replaces "cpu.shares" and "cpu.max" replaces "cpu.cfs_period_us" and "cpu.cfs_quota_us". [Startup]CPUWeight config options are added with the usual compat translation. CPU quota settings remain unchanged and apply to both legacy and unified hierarchies. v2: - Error in man page corrected. - CPU config application in cgroup_context_apply() refactored. - CPU accounting now works on unified hierarchy.
* cgroup: detect cgroup namespacesChristian Brauner2017-07-05
| | | | | - define CLONE_NEWCGROUP - add fun to detect whether cgroup namespaces are supported
* Prep v231: Apply missing fixes from upstream (1/6) src/basicSven Eden2017-06-16
|
* core: when forcibly killing/aborting left-over unit processes log about itLennart Poettering2017-06-16
| | | | | | | | | | | | | | | Let's lot at LOG_NOTICE about any processes that we are going to SIGKILL/SIGABRT because clean termination of them didn't work. This turns the various boolean flag parameters to cg_kill(), cg_migrate() and related calls into a single binary flags parameter, simply because the function now gained even more parameters and the parameter listed shouldn't get too long. Logging for killing processes is done either when the kill signal is SIGABRT or SIGKILL, or on explicit request if KILL_TERMINATE_AND_LOG instead of LOG_TERMINATE is passed. This isn't used yet in this patch, but is made use of in a later patch.
* Prep v230: Apply missing upstream fixes and updates (2/8) src/basic.Sven Eden2017-06-16
|
* core: update populated event handling in unified hierarchyTejun Heo2017-06-16
| | | | | | | Earlier during the development of unified hierarchy, the populated event was reported through by the dedicated "cgroup.populated" file; however, the interface was updated so that it's reported through the "populated" field of "cgroup.events" file. Update populated event handling logic accordingly.
* Prep v229: Add missing fixes from upstream [1/6] src/basicSven Eden2017-05-17
|
* cgroup: remove support for NetClass= directiveDaniel Mack2017-05-17
| | | | | | | | | | | | | | | | | | | Support for net_cls.class_id through the NetClass= configuration directive has been added in v227 in preparation for a per-unit packet filter mechanism. However, it turns out the kernel people have decided to deprecate the net_cls and net_prio controllers in v2. Tejun provides a comprehensive justification for this in his commit, which has landed during the merge window for kernel v4.5: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=bd1060a1d671 As we're aiming for full support for the v2 cgroup hierarchy, we can no longer support this feature. Userspace tool such as nftables are moving over to setting rules that are specific to the full cgroup path of a task, which obsoletes these controllers anyway. This commit removes support for tweaking details in the net_cls controller, but keeps the NetClass= directive around for legacy compatibility reasons.
* tree-wide: remove Emacs lines from all filesDaniel Mack2017-05-17
| | | | | This should be handled fine now by .dir-locals.el, so need to carry that stuff in every file.
* Prep v228: Full diff to master revealed more functions that are unused.Sven Eden2017-04-26
|
* Prep v228: Condense elogind source masks (1/5)Sven Eden2017-04-26
| | | | | | | | | | | | Although having a two line mask like /// UNNEEDED by elogind #if 0 it is much more easier to read (and patch!) if those two lines were condense into a one-line mask start like #if 0 /// UNNEEDED by elogind
* Prep v228: Substitute declaration masks (1/4)Sven Eden2017-04-26
| | | | | | | | | | | | | | | | | Although it looks very ugly, substitute all declaration masks of the form: // UNNEEDED type foo(...); with: /// UNNEEDED by elogind #if 0 type foo(...); #endif // 0 to make future merging of upstream pathes easier, as the relevant lines themselves are not changed any more.
* Prep v228: Clean up the new src/basic/*-util-[hc] files:Sven Eden2017-04-26
| | | | | | | | | | | | | - src/basic/capability-util.[hc] - src/basic/cgroup-util.[hc] - src/basic/fd-util.[hc] - src/basic/fs-util.[hc] - src/basic/memfd-util.[hc] - src/basic/path-util.[hc] - src/basic/socket-util.[hc] - src/basic/terminal-util.[hc] - src/basic/user-util.[hc] - src/basic/xattr-util.[hc]
* Prep v227: Clean up various *-util.[hc] filesSven Eden2017-04-09
| | | | | | | | - src/basic/cgroup-util.[hc] - src/basic/memfd-util.[hc] - src/basic/path-util.[hc] - src/basic/process-util.[hc] - src/basic/smack-util.[hc]
* [1/5] Apply missing fixes from upstreamSven Eden2017-03-29
|
* Add mounting of a name=elogind cgroup if no init controller is found.Sven Eden2017-03-14
| | | | | This is done for systems, which init systems are no cgroup controllers. One example is runit on Void Linux.
* Cleaned up more unneeded functions and types in:Sven Eden2017-03-14
| | | | | | | | | | | | | | | | | | | | - src/basic/ioprio.h - removed - src/basic/ring.h - removed - src/basic/capability.[hc] - cleaned - src/basic/cgroup-util.[hc] - cleaned - src/basic/hostname-util.[hc] - cleaned - src/basic/path-util.[hc] - cleaned - src/basic/socket-util.h - cleaned - src/basic/strv.[hc] - cleaned - src/basic/time-util.[hc] - cleaned - src/basic/unit-name.[hc] - cleaned - src/basic/util.[hc] - cleaned - src/libelogind/sd-bus/bus-introspect.c - cleaned - src/login/loginctl.c - cleaned - src/login/logind-dbus.c - cleaned - src/login/logind.h - cleaned - src/shared/conf-parser.[hc] - cleaned
* Classify processes from sessions into cgroupsSven Eden2017-03-14
| | | | | | | Create a private cgroup tree associated with no controllers, and use it to map PIDs to sessions. Since we use our own path structure, remove internal cgroup-related helpers that interpret the cgroup path structure to pull out users, slices, and scopes.
* [Patch 3/3] Add cgroups initialization and handlingSven Eden2017-03-14
| | | | | Let elogind setup cgroups support on its manager initialization and free the cgroups subsystem when the manager is destroyed.
* Prep v226: Mask all unneeded functionsSven Eden2017-03-14
|
* Prep v226: Apply missing fixes and changes to src/basicSven Eden2017-03-14
|
* Prep v225: Added needed udev support and re-enabled some masked cgroup ↵Sven Eden2017-03-14
| | | | functions.
* Prep v224: Major cleanup of unneeded functions and some source files.Sven Eden2017-03-14
|
* Prep v221: Update and clean up build system to sync with upstreamSven Eden2017-03-14
This commit replays the moving around of source files that have been done between systemd-219 and systemd-221. Further the Makefile.am is synchronized with the upstream version and then "re-cleaned". A lot of functions, that are not used anywhere in elogind have been coated into #if 0/#endif directives to further shorten the list of dependencies. All unneeded files have been removed.