1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-02 10:51:20 +03:00
Commit Graph

36921 Commits

Author SHA1 Message Date
Lennart Poettering
b8b6f32104 cgroup: when we unload a unit, also update all its parent's members mask
This way we can corectly ensure that when a unit that requires some
controller goes away, we propagate the removal of it all the way up, so
that the controller is turned off in all the parents too.
2018-11-23 13:41:37 +01:00
Lennart Poettering
5af8805872 cgroup: drastically simplify caching of cgroups members mask
Previously we tried to be smart: when a new unit appeared and it only
added controllers to the cgroup mask we'd update the cached members mask
in all parents by ORing in the controller flags in their cached values.
Unfortunately this was quite broken, as we missed some conditions when
this cache had to be reset (for example, when a unit got unloaded),
moreover the optimization doesn't work when a controller is removed
anyway (as in that case there's no other way for the parent to iterate
though all children if any other, remaining child unit still needs it).
Hence, let's simplify the logic substantially: instead of updating the
cache on the right events (which we didn't get right), let's simply
invalidate the cache, and generate it lazily when we encounter it later.
This should actually result in better behaviour as we don't have to
calculate the new members mask for a whole subtree whever we have the
suspicion something changed, but can delay it to the point where we
actually need the members mask.

This allows us to simplify things quite a bit, which is good, since
validating this cache for correctness is hard enough.

Fixes: #9512
2018-11-23 13:41:37 +01:00
Lennart Poettering
8a0d538815 cgroup: extend comment on what unit_release_cgroup() is for 2018-11-23 13:41:37 +01:00
Lennart Poettering
1fd3a10c38 cgroup: extend reasons when we realize the enable mask
After creating a cgroup we need to initialize its
"cgroup.subtree_control" file with the controllers its children want to
use. Currently we do so whenever the mkdir() on the cgroup succeeded,
i.e. when we know the cgroup is "fresh". Let's update the condition
slightly that we also do so when internally we assume a cgroup doesn't
exist yet, even if it already does (maybe left-over from a previous
run).

This shouldn't change anything IRL but make things a bit more robust.
2018-11-23 13:41:37 +01:00
Lennart Poettering
d5095dcd30 cgroup: tighten call that detects whether we need to realize a unit's cgroup a bit, and comment why 2018-11-23 13:41:37 +01:00
Lennart Poettering
5a62e5e2ac cgroup: document what the various masks variables are used for 2018-11-23 13:41:37 +01:00
Lennart Poettering
67558d15ec cgroup: extend cg_mask_supported() comment a bit 2018-11-23 13:41:37 +01:00
Lennart Poettering
27c4ed790a cgroup: simplify check whether it makes sense to realize a cgroup 2018-11-23 13:41:37 +01:00
Lennart Poettering
e00068e71f cgroup: in unit_invalidate_cgroup() actually modify invalidation mask
Previously this would manipulate the realization mask for invalidating
the realization. This is a bit ugly though as the realization mask's
primary purpose to is to reflect in which hierarchies a cgroup currently
exists, and it's probably a good idea to keep that in sync with
realities.

We nowadays have the an explicit fields for invalidating cgroup
controller information, the "cgroup_invalidated_mask", let's use this
one instead.

The effect is pretty much the same, as the main consumer of these masks
(unit_has_mask_realize()) checks both anyway.
2018-11-23 13:41:37 +01:00
Lennart Poettering
27adcc9737 cgroup: be more careful with which controllers we can enable/disable on a cgroup
This changes cg_enable_everywhere() to return which controllers are
enabled for the specified cgroup. This information is then used to
correctly track the enablement mask currently in effect for a unit.
Moreover, when we try to turn off a controller, and this works, then
this is indicates that the parent unit might succesfully turn it off
now, too as our unit might have kept it busy.

So far, when realizing cgroups, i.e. when syncing up the kernel
representation of relevant cgroups with our own idea we would strictly
work from the root to the leaves. This is generally a good approach, as
when controllers are enabled this has to happen in root-to-leaves order.
However, when controllers are disabled this has to happen in the
opposite order: in leaves-to-root order (this is because controllers can
only be enabled in a child if it is already enabled in the parent, and
if it shall be disabled in the parent then it has to be disabled in the
child first, otherwise it is considered busy when it is attempted to
remove it in the parent).

To make things complicated when invalidating a unit's cgroup membershup
systemd can actually turn off some controllers previously turned on at
the very same time as it turns on other controllers previously turned
off. In such a case we have to work up leaves-to-root *and*
root-to-leaves right after each other. With this patch this is
implemented: we still generally operate root-to-leaves, but as soon as
we noticed we successfully turned off a controller previously turned on
for a cgroup we'll re-enqueue the cgroup realization for all parents of
a unit, thus implementing leaves-to-root where necessary.
2018-11-23 13:41:37 +01:00
Zbigniew Jędrzejewski-Szmek
e5e0a79623 pid1,sd-device: use PATH_STARTSWITH_SET more 2018-11-23 13:37:47 +01:00
Zbigniew Jędrzejewski-Szmek
f5a9bd21b9 basic/path-util: add missing header
PATH_STARTSWITH_SET uses STRV_FOREACH...
2018-11-23 13:37:40 +01:00
Lennart Poettering
00f8eea8fc run: set $INVOCATION_ID for scope units
Services invoked by PID1 have $INVOCATION_ID initialized, hence let's do
that for scope units (where the payload process is invoked by us on the
client side) too, to minimize needless differences.

Fixes: #8082
2018-11-23 12:49:00 +01:00
Lennart Poettering
0565120f00 run: port to static destructors 2018-11-23 12:49:00 +01:00
Lennart Poettering
ef08ad7aa8 run: port to DEFINE_MAIN_FUNCTION() 2018-11-23 12:49:00 +01:00
Lennart Poettering
badd28e158 run: add new --shell switch for spawning a shell as service
I keep running "systemd-run -t /bin/bash" to quickly get a shell running
in service context. I suspect I am not the only one, hence let's add a
shortcut for it. While we are at it, let's make it smarter, and
automatically inherit the $SHELL of the invoking user as well as the
working directory, and let's imply --pty. --shell (or -S) is hence
equivalent to "-t -d $SHELL".
2018-11-23 12:49:00 +01:00
Lennart Poettering
2d21165a4e run: add a switch for specifiying the working directory of a service
I find myself testing service management quite often with "systemd-run
-t /bin/bash". For that it is handy if the invoked shell would use the
working directory I am currently in. Hence introduce a shorthand for
that:

        $ systemd-run -dt /bin/bash

This will automatically insert a WorkingDirectory= property into the
transient service, pointing to the working directory of the caller.
2018-11-23 12:49:00 +01:00
Lennart Poettering
94f344fb03 cgroup: tweak log message, so that it doesn't claim we always enable controllers when we actually disable them 2018-11-23 12:24:37 +01:00
Lennart Poettering
54b5ba1d1f cgroup: propagate errors when we cannot open cgroup.subtree_control 2018-11-23 12:24:37 +01:00
Lennart Poettering
26a17ca280 cgroup: add explanatory comment 2018-11-23 12:24:37 +01:00
Lennart Poettering
442ce7759c cgroup: units that aren't loaded properly should not result in cgroup controllers being pulled in
This shouldn't make much difference in real life, but is a bit cleaner.
2018-11-23 12:24:37 +01:00
Lennart Poettering
0adf88b68c cgroup: dump delegation mask too 2018-11-23 12:24:37 +01:00
Lennart Poettering
1649244588 cgroup: make unit_get_needs_bpf_firewall() static too 2018-11-23 12:24:37 +01:00
Lennart Poettering
53aea74a60 cgroup: make some functions static 2018-11-23 12:24:37 +01:00
Lennart Poettering
52fecf20b9 cgroup: fine tune when to apply cgroup attributes to the root cgroup
Let's tweak when precisely to apply cgroup attributes on the root
cgroup.

With this we now follow the following rules:

1. On cgroupsv2 we never apply any regular cgroups to the host root,
   since the attributes generally do not exist there.

2. On cgroupsv1 we do not apply any "weight" or "shares" style
   attributes to the host root cgroup, since they don't make much sense
   on the top level where there's only one group, hence no need to
   compare weights against each other. The other attributes are applied
   to the host root cgroup however.

3. In any case we don't apply attributes to the root of container
   environments (and --user roots), under the assumption that this is
   managed by the manager further up. (Note that on cgroupsv2 this is
   even enforced by the kernel)

4. BPF pseudo-attributes are applied in all cases (since we can have as
   many of them as we want)
2018-11-23 12:24:37 +01:00
Lennart Poettering
589a5f7a38 cgroup: append \n to static strings we write to cgroup attributes
This is a bit cleaner since we when we format numeric limits we append
it. And this way write_string_file() doesn't have to append it.
2018-11-23 12:24:37 +01:00
Lennart Poettering
28cfdc5aeb cgroup: tighten manager_owns_host_root_cgroup() a bit
This tightening is not strictly necessary (as the m->cgroup_root check
further down does the same), but let's make this explicit.
2018-11-23 12:24:37 +01:00
Lennart Poettering
611c4f8afb cgroup: rename {manager_owns|unit_has}_root_cgroup() → .._host_root_cgroup()
Let's emphasize that this function checks for the host root cgroup, i.e.
returns false for the root cgroup when we run in a container where
CLONE_NEWCGROUP is used. There has been some confusion around this
already, for example cgroup_context_apply() uses the function
incorrectly (which we'll fix in a later commit).

Just some refactoring, not change in behaviour.
2018-11-23 12:24:37 +01:00
Lennart Poettering
293d32df39 cgroup: add a common routine for writing to attributes, and logging about it
We can use this at quite a few places, and this allows us to shorten our
code quite a bit.
2018-11-23 12:24:37 +01:00
Lennart Poettering
39b9fefb2e cgroup: add a new macro for determining log level for cgroup attr write failures
For now, let's use it only at one place, but a follow-up commit will
make more use of it.
2018-11-23 12:24:37 +01:00
Lennart Poettering
2c74e12bb3 cgroup: ignore EPERM for a couple of more attribute writes 2018-11-23 12:24:37 +01:00
Lennart Poettering
8c83840772 cgroup: add comment explaining why we ignore EINVAL at two places
These are just copies from further down.
2018-11-23 12:24:37 +01:00
Lennart Poettering
73fe5314bf cgroup: suffix settings with "=" in log messages where appropriate 2018-11-23 12:24:37 +01:00
Lennart Poettering
a0c339ed4b cgroup: only install cgroup release agent when we own the root cgroup
If we run in a container we shouldn't patch around this, and most likely
we can't anyway, and there's not much point in complaining about this.
Hence let's strictly say: the agent is private property of the host's
system instance, nothing else.
2018-11-23 12:24:37 +01:00
Lennart Poettering
de8a711a58 cgroup: use structured initialization 2018-11-23 12:24:37 +01:00
Zbigniew Jędrzejewski-Szmek
527ead383d libudev: drop unnecessary check
sd_device_get_subsystem returns -ENOENT if subsystem is not set.
2018-11-23 09:16:11 +01:00
Zbigniew Jędrzejewski-Szmek
91540eaa5c
Merge pull request #10861 from yuwata/udev-list-cleanups
libudev: several cleanups for udev-list
2018-11-23 09:12:56 +01:00
Zbigniew Jędrzejewski-Szmek
7f22ad1083
Merge pull request #10886 from yuwata/sd-device-monitor-fix-filter
sd-device: fix subsystem filter
2018-11-23 08:53:33 +01:00
Lennart Poettering
00e7b3c8e5 unit: minor optimization, use stack over heap, when we can 2018-11-23 00:46:56 +01:00
Daniel van Vugt
26d7cf3daf 70-mouse.hwdb: Set DPI for MS Classic IntelliMouse
It defaults to 3200 DPI and 1000 Hz. Note the ?? is required to
match the multibyte UTF-8 character '®'.
2018-11-23 00:46:35 +01:00
Lennart Poettering
50111496dd
Merge pull request #10891 from yuwata/use-main-macro-2
tree-wide: use recently introduced macros
2018-11-23 00:46:02 +01:00
Lennart Poettering
27da878e7e unit: drop an unused fields from Unit struct 2018-11-23 00:37:00 +01:00
Yu Watanabe
a5a59a2447 test: add more tests for subsystem filter 2018-11-23 06:46:29 +09:00
Lennart Poettering
66fa4bdd70 core: add two minor comments (#10890) 2018-11-23 06:25:27 +09:00
Yu Watanabe
c6f09e6a2d locale: define main through macro 2018-11-23 06:22:30 +09:00
Yu Watanabe
af7865c1b7 locale: store polkit_registry in Context 2018-11-23 06:22:30 +09:00
Yu Watanabe
6804d7a849 locale: rename context_free() to context_clear() 2018-11-23 06:22:30 +09:00
Yu Watanabe
f6aa61909e resolvectl: use static destructor and define main through macro 2018-11-23 06:22:30 +09:00
Yu Watanabe
7a83c3aee0 rfkill: define main through macro 2018-11-23 06:22:30 +09:00
Yu Watanabe
5f5f0afc8b rfkill: store write queue and rfkill fd in struct Context 2018-11-23 06:22:30 +09:00