summaryrefslogtreecommitdiffstats
path: root/src/core/device.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* tree-wide: use PATH_STARTSWITH_SET() at two more placesLennart Poettering2018-06-111-2/+1
|
* core: be a bit stricter when validating SYSTEMD_ALIAS udev propsLennart Poettering2018-06-071-3/+5
|
* core: tighten when we unset the sysfs path of device unitsLennart Poettering2018-06-071-3/+4
| | | | | Make sure that whenever we enter "dead" state we unset the sysfs path, not just when we are changing to it due to "found" mask changes.
* core: rework how device units get set upLennart Poettering2018-06-071-80/+92
| | | | | | | | | | | | | | | | | | | | | This reworks how device units are "powered on". This makes sure that any device changes that might have happened while we were restarting/reloading will be noticed properly. For that we'll now properly serialize/deserialize both the device unit state and the device "found" flags, and restore these initially in the "coldplug" phase of the manager deserialization. While enumerating the udev devices during startup we'll put together a new "found" flags mask, which we'll the switch to in the "catchup" phase of the manager deserialization, which follows the "coldplug" phase. Note that during the "coldplug" phase no unit state change events are generated, which is different for the "catchall" phase which will do that. Thus we correctly make sure that the deserialized state won't pull in new deps, but any device's change while we were reloading would. Fixes: #8832 Replaces: #8675
* device: simplify device_found_to_string_many() a tiny bitLennart Poettering2018-06-071-3/+2
| | | | | No need to maintain a NULL marker at the end of the table if we know the size of the array anyway.
* udev: add helper udev_device_new_from_stat_rdev()Lennart Poettering2018-06-071-11/+8
| | | | | | This is a simple wrapper around udev_device_new_from_devnum(), and uses the data from a struct stat's .st_rdev field to derive the udev_device object.
* core: split out device validation from device_found_node()Lennart Poettering2018-06-071-38/+58
| | | | | | | Let's separate the validate step out. Also, let's update some comments which have long ceased to be true. No change in behaviour.
* core: rework device_found_node() prototypeLennart Poettering2018-06-071-28/+28
| | | | | | | | | | | | | | let's drop the "now" argument, it's exactly what MANAGER_IS_RUNNING() returns, hence let's use that instead to simplify things. Moreover, let's change the add/found argument pair to become found/mask, which allows us to change multiple flags at the same time into opposing directions, which will be useful later on. Also, let's change the return type to void. It's a notifier call where callers will ignore the return value anyway as it is nothing actionable. Should not change behaviour.
* core: split out reload propagation into its own functionLennart Poettering2018-06-071-14/+20
|
* core: improve error logging a bitLennart Poettering2018-06-071-8/+18
|
* core: log when unit_add_dependency() fails for some reasonLennart Poettering2018-06-071-3/+2
| | | | Also, proceed, as there's little we can do in this case.
* core: modernize device_update_description() a bitLennart Poettering2018-06-071-7/+6
|
* core: use device_found_to_string_many() result only on successLennart Poettering2018-06-071-2/+2
|
* core: use FLAGS_SET() macro at one more placeLennart Poettering2018-06-071-1/+1
|
* core: modernize device_set_sysfs() a bitLennart Poettering2018-06-071-4/+2
|
* core: don't trigger OnFailure= deps when a unit is going to restartLennart Poettering2018-06-011-1/+1
| | | | | | | | | | | | This adds a flags parameter to unit_notify() which can be used to pass additional notification information to the function. We the make the old reload_failure boolean parameter one of these flags, and then add a new flag that let's unit_notify() if we are configured to restart the service. Note that this adjusts behaviour of systemd to match what the docs say. Fixes: #8398
* Merge pull request #8981 from keszybz/ratelimit-and-dbusLennart Poettering2018-05-181-1/+1
|\ | | | | Ratelimit renaming and dbus error message fix
| * Rename ratelimit_test to ratelimit_belowZbigniew Jędrzejewski-Szmek2018-05-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | When I see "test", I have to think three times what the return value means. With "below" this is immediately clear. ratelimit_below(&limit) sounds almost like English and is imho immediately obvious. (I also considered ratelimit_ok, but this strongly implies that being under the limit is somehow better. Most of the times this is true, but then we use the ratelimit to detect triple-c-a-d, and "ok" doesn't fit so well there.) C.f. a1bcaa07.
* | core: use _cleanup_set_free_ instread of _cleanup_(set_freep)Yu Watanabe2018-05-141-1/+1
|/
* core: use automatic cleanup moreDavid Tardon2018-05-121-8/+4
|
* core: include Found state in device dumpsZbigniew Jędrzejewski-Szmek2018-04-261-2/+7
| | | | | | | | | In particular, this confirms that the Found state needs to remain a bit-field: $ systemd-analyze dump |grep 'Found: '|sort |uniq -c 105 Found: found-udev 3 Found: found-udev,found-mount 1 Found: found-udev,found-swap
* device: fix serialization and deserialization of DeviceFoundYu Watanabe2018-04-251-18/+70
| | | | | | | DeviceFound is a bit flag. So, it is necessary to support the case that multiple bits are set. Follow-up for 918e6f1c0151429f5095355f4f3f74f16e79724a.
* tree-wide: drop redundant _cleanup_ macros (#8810)Lennart Poettering2018-04-251-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | This drops a good number of type-specific _cleanup_ macros, and patches all users to just use the generic ones. In most recent code we abstained from defining type-specific macros, and this basically removes all those added already, with the exception of the really low-level ones. Having explicit macros for this is not too useful, as the expression without the extra macro is generally just 2ch wider. We should generally emphesize generic code, unless there are really good reasons for specific code, hence let's follow this in this case too. Note that _cleanup_free_ and similar really low-level, libc'ish, Linux API'ish macros continue to be defined, only the really high-level OO ones are dropped. From now on this should really be the rule: for really low-level stuff, such as memory allocation, fd handling and so one, go ahead and define explicit per-type macros, but for high-level, specific program code, just use the generic _cleanup_() macro directly, in order to keep things simple and as readable as possible for the uninitiated. Note that before this patch some of the APIs (notable libudev ones) were already used with the high-level macros at some places and with the generic _cleanup_ macro at others. With this patch we hence unify on the latter.
* core/device: avoid bogus errno use and invert ratelimit_test()Zbigniew Jędrzejewski-Szmek2018-04-241-2/+2
| | | | | | | | | I'm not sure if I understand the original code. AFAICS, errno does not have to be set at all in this callback. ratelimit_test() returns positive if we are under limit. The code would only log if the condition happened very often, which I assume is not inteded, and this check was supposed to prevent too much logging.
* device: skip deserialization of device units when udevd is not runningFranck Bui2018-04-201-0/+12
| | | | | | | | | | | | | Do not try to party initialize a device during deserialization if it's not known by udev (anymore) and therefore hasn't been seen during device enumeration. The device unit in this case has not been initialized properly and setting it in the "plugged" state can be confusing. Actually this happens during every boots when PID switches to the new rootfs: PID is reexecuted and enumerates devices but since udev is not running, the list of enumerated devices is empty.
* device: make sure to always retroactively start device dependenciesFranck Bui2018-04-201-1/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | PID1 updates the state of device units upon 2 different events: - when it processes an event sent by udev and in this case the device deps are started if the device enters in the "plugged" state. - when it enumerates all devices during its startup or when it is asked to reload its configuration data but in this case the device deps (if any) are not retroactively started. When udev processes a new "add" kernel event, it first registers the new device in its databases then sends an event to systemd. If for any reason, systemd is asked to reload its configuration between the previous 2 steps, it might see for the first time the new device while scanning /sys for all devices. Only during a second step, udev will send the event for the new device. In this peculiar case the device deps wont be started (even though the device is first seen by PID1). Indeed when reloading its configurations, PID1 will put the device unit in the "plugged" state but without starting the device deps. Thereafter PID1 will get the event from udev for the new device but the device unit will be in "plugged" state already therefore it won't see any need to start the device dependencies. Rather than assuming that during the reloading of systemd manager configuration all devices listed in udev DBs have been already processed and should be put in the "plugged" state (done by device_coldplug()), this patch does that only for devices which have been processed via an udev event (device_dispatch_io()) previously. In this case we set "d->found" to "DEVICE_FOUND_UDEV" and we make also sure to no more initialize "d->found" while enumerating devices. Instead this field is now saved/restored while devices are serialized.
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-061-13/+0
| | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* core/device: remove unnecessary check (#8661)Yu Watanabe2018-04-061-4/+1
| | | Follow-up for 0dfb0a0abd98f8726a39f26e4d737f47ec0fd53b.
* core/device: trivial simplificationYu Watanabe2018-04-051-4/+2
|
* When mangling names, optionally emit a warning (#8400)Zbigniew Jędrzejewski-Szmek2018-03-211-1/+1
| | | | | | | | | | | | | | | | | | The warning is not emitted for absolute paths like /dev/sda or /home, which are converted to .device and .mount unit names without any fuss. Most of the time it's unlikely that users use invalid unit names on purpose, so let's warn them. Warnings are silenced when --quiet is used. $ build/systemctl show -p Id hello@foo-bar/baz Invalid unit name "hello@foo-bar/baz" was escaped as "hello@foo-bar-baz" (maybe you should use systemd-escape?) Id=hello@foo-bar-baz.service $ build/systemd-run --user --slice foo-bar/baz --unit foo-bar/foo true Invalid unit name "foo-bar/foo" was escaped as "foo-bar-foo" (maybe you should use systemd-escape?) Invalid unit name "foo-bar/baz" was escaped as "foo-bar-baz" (maybe you should use systemd-escape?) Running as unit: foo-bar-foo.service Fixes #8302.
* tree-wide: use path_hash_ops instead of string_hash_ops whenever we key by a ↵Lennart Poettering2018-02-121-1/+1
| | | | | | path Let's make use of our new hash_ops!
* core/device: remove unused variableYu Watanabe2018-01-241-1/+0
| | | | Follow-up for bf70ff2cff719905f9dc3f726eaba79780dcae55.
* fix reload propagation for device aliasJérémy Rosen2018-01-221-5/+4
| | | | | | | | | | udev-made .device aliases are not normal alias They are full-fledged units which are linked to the same sysfs path we need to explicitely propagate reload to all alias
* Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-191-0/+1
| | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
* core: when a unit template is specified in SYSTEMD_WANTS=, instantiate it ↵Lennart Poettering2017-11-101-4/+21
| | | | | | | with sysfs path This should make cases like the user's setup in #7109 a lot easier to handle, as in that case we'll do the right escaping automatically.
* core: remove SYSTEMD_WANTS udev property configured dependencies at the ↵Lennart Poettering2017-11-101-19/+20
| | | | | | | | right moment Previously dependencies configured with SYSTEMD_WANTS would be collected on a device unit as long as it was loaded. let's fix that, and remove dependencies again when SYTEMD_WANTS changes.
* device: Let's simplify device_add_udev_wants() a bitLennart Poettering2017-11-101-4/+8
| | | | Let's drop use of one variable and make the rest more explicit.
* device: rework device_is_bound_by_mounts() a bitLennart Poettering2017-11-101-7/+12
| | | | | Let's log when we can't parse the udev property, and always use the most precise, correct types.
* core: track why unit dependencies came to beLennart Poettering2017-11-101-8/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This replaces the dependencies Set* objects by Hashmap* objects, where the key is the depending Unit, and the value is a bitmask encoding why the specific dependency was created. The bitmask contains a number of different, defined bits, that indicate why dependencies exist, for example whether they are created due to explicitly configured deps in files, by udev rules or implicitly. Note that memory usage is not increased by this change, even though we store more information, as we manage to encode the bit mask inside the value pointer each Hashmap entry contains. Why this all? When we know how a dependency came to be, we can update dependencies correctly when a configuration source changes but others are left unaltered. Specifically: 1. We can fix UDEV_WANTS dependency generation: so far we kept adding dependencies configured that way, but if a device lost such a dependency we couldn't them again as there was no scheme for removing of dependencies in place. 2. We can implement "pin-pointed" reload of unit files. If we know what dependencies were created as result of configuration in a unit file, then we know what to flush out when we want to reload it. 3. It's useful for debugging: "systemd-analyze dump" now shows this information, helping substantially with understanding how systemd's dependency tree came to be the way it came to be.
* device : reload when udev generates a "changed" event (#6850)Boucman2017-11-101-0/+20
|
* Revert "device : reload when udev generates a "changed" event" (#6836)Martin Pitt2017-09-151-21/+1
| | | | | | | This reverts commit 0ffddc6e2c6e19e5dc81812aee9fbe964059f3aa. That causes a rather severe disruption of D-Bus and other services when e. g. restarting local-fs.target (as spotted by the "storage" test regression). Fixes #6834
* device : reload when udev generates a "changed" eventJérémy Rosen2017-09-101-1/+21
|
* device: make sure to remove all device units sharing the same sysfs path (#6679)Franck Bui2017-08-301-2/+2
| | | | | | | | | When a device is unplugged all device units sharing the same sysfs path pointing to that device are supposed to be removed. However it didn't work since while iterating the device unit list containing all the relevant units, each unit was removed during each iteration of LIST_FOREACH. However LIST_FOREACH doesn't support this use case and LIST_FOREACH_SAFE must be use instead.
* core: unset sysfs path after transition to dead state (#6174)Michal Sekletar2017-06-231-1/+5
| | | | | | | | | | | | | | | | Device is gone and most likely it will get garbage collected. However in cases when it doesn't get gc'ed (because it is referenced by some other unit, e.g. mount from fstab) we need to unset sysfs. This is because when device appears next time, possibly, with different sysfs path we need to update the sysfs path. Current code could end up caching stale sysfs path forever. In reality this is not a problem for normal disks (unless you swap them during system runtime). However this issue causes failures to mount filesystems on LVM where sysfs path depends on activation order (i.e. logical volumes from volume group that is activated first get assigned lower dm-X numbers and corresponding syspaths). Fixes #6126.
* core/device: Use JobRunningTimeoutSec= for device unitsMichal Koutný2017-04-251-1/+1
| | | | | Device job timeouts should respect possible device job dependencies so we set JobRunningTimeoutSec= by default.
* core: make sure to not call device_is_bound_by_mounts() when dev is null (#5033)Franck Bui2017-01-101-1/+1
| | | | | | | | | | | device_setup_unit() might be called (when an event happened in /proc/self/mountinfo for example) with a null 'dev' parameter. This indicates that the device has been unplugged but the corresponding mountpoint is still visible in /proc/self/mountinfo. This patch makes sure we don't call device_is_bound_by_mounts() in this case. Fixes: #5025
* core: make mount units from /proc/self/mountinfo possibly bind to a device ↵Franck Bui2016-12-161-0/+46
| | | | | | | | | | | | | | | | | | | | | | | | | (#4515) Since commit 9d06297, mount units from mountinfo are not bound to their devices anymore (they use the "Requires" dependency instead). This has the following drawback: if a media is mounted and the eject button is pressed then the media is unconditionally ejected leaving some inconsistent states. Since udev is the component that is reacting (no matter if the device is used or not) to the eject button, users expect that udev at least try to unmount the media properly. This patch introduces a new property "SYSTEMD_MOUNT_DEVICE_BOUND". When set on a block device, all units that requires this device will see their "Requires" dependency upgraded to a "BindTo" one. This is currently only used by cdrom devices. This patch also gives the possibility to the user to restore the previous behavior that is bind a mount unit to a device. This is achieved by passing the "x-systemd.device-bound" option to mount(8). Please note that currently this is not working because libmount treats the x-* options has comments therefore they're not available in utab for later application retrievals.
* core: remove unused variableThomas Hindoe Paaboel Andersen2016-12-061-1/+1
|
* core: make unit_free() accept NULL pointersLennart Poettering2016-12-011-1/+1
| | | | | | | We generally try to make our destructors robust regarding NULL pointers, much in the same way as glibc's free(). Do this also for unit_free(). Follow-up for #4748.
* device: Avoid calling unit_free(NULL) in device setup logic (#4748)Dave Reisner2016-11-271-1/+1
| | | | | | | | | | | Since a581e45ae8f9bb5c, there's a few function calls to unit_new_for_name which will unit_free on failure. Prior to this commit, a failure would result in calling unit_free with a NULL unit, and hit an assertion failure, seen at least via device_setup_unit: Assertion 'u' failed at src/core/unit.c:519, function unit_free(). Aborting. Fixes #4747 https://bugs.archlinux.org/task/51950