1
0
mirror of https://github.com/systemd/systemd synced 2026-04-13 10:35:08 +02:00

Compare commits

...

10 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek
b09869eaf7
Merge pull request #22172 from yuwata/udev-sd-device-more-debugging-logs
udev, sd-device: more debugging logs
2022-01-19 15:11:48 +01:00
Yu Watanabe
5ab9addd68 test: replace multiple echo with cat
Suggested by shell check SC2129.
2022-01-19 20:48:36 +09:00
Yu Watanabe
e916276016 udev-util: add event UUID to debugging logs 2022-01-19 20:48:36 +09:00
Yu Watanabe
d7cb60daf6 sd-device: add more debugging logs in device_set_syspath()
On failure, the function previously sometimes logs in debug level, but
sometimes does not. Let's always log the error cause.
2022-01-19 20:48:36 +09:00
Yu Watanabe
30b6f7d714 meson: skip to search clang, llvm-string, and bpftool, if libbpf not found
Prompted by https://github.com/systemd/systemd/pull/22093#issuecomment-1016254914.
2022-01-19 14:23:41 +03:00
Yu Watanabe
39f83dd760 test: wait for newly created btrfs triggered
Fixes the second issue in #21819.
2022-01-19 09:32:23 +00:00
Zbigniew Jędrzejewski-Szmek
01f5177ffd
Merge pull request #22163 from bluca/extension_images_validation
Improve ExtensionImages validation
2022-01-19 08:57:15 +01:00
Luca Boccassi
70a5c6dce0 sysext: use LO_FLAGS_PARTSCAN when opening image
Jan 17 12:34:59 myguest1 (sd-sysext)[486]: Device '/var/lib/extensions/myext.raw' is loopback block device with partition scanning turned off, please turn it on.

Fixes https://github.com/systemd/systemd/issues/22146
2022-01-19 08:54:50 +01:00
Luca Boccassi
78ab2b5064 core: refuse to mount ExtensionImages if the base layer doesn't at least have ID in os-release
We can't match an extension if we don't at least have an ID,
so refuse to continue
2022-01-19 00:08:57 +00:00
Luca Boccassi
37361f46d5 dissect-image: validate extension-release even if the host has only ID in os-release
A rolling distro won't set VERSION_ID or SYSEXT_LEVEL in os-release,
which means we skip validation of ExtensionImages.
Validate even with just an ID, the lower level helper already
recognizes and accepts this use case.

Fixes https://github.com/systemd/systemd/issues/22146
2022-01-19 00:01:48 +00:00
8 changed files with 47 additions and 18 deletions

View File

@ -984,7 +984,7 @@ bpf_framework_required = want_bpf_framework == 'true'
libbpf = dependency('libbpf', required : bpf_framework_required, version : '>= 0.2') libbpf = dependency('libbpf', required : bpf_framework_required, version : '>= 0.2')
conf.set10('HAVE_LIBBPF', libbpf.found()) conf.set10('HAVE_LIBBPF', libbpf.found())
if want_bpf_framework == 'false' if want_bpf_framework == 'false' or not libbpf.found()
conf.set10('BPF_FRAMEWORK', 0) conf.set10('BPF_FRAMEWORK', 0)
else else
# Support 'versioned' clang/llvm-strip binaries, as seen on Debian/Ubuntu # Support 'versioned' clang/llvm-strip binaries, as seen on Debian/Ubuntu
@ -1030,7 +1030,7 @@ else
required : bpf_framework_required, required : bpf_framework_required,
version : '>= 5.6') version : '>= 5.6')
deps_found = libbpf.found() and clang_found and clang_supports_bpf and clang_supports_flags and llvm_strip.found() and bpftool.found() deps_found = clang_found and clang_supports_bpf and clang_supports_flags and llvm_strip.found() and bpftool.found()
# Can build BPF program from source code in restricted C # Can build BPF program from source code in restricted C
conf.set10('BPF_FRAMEWORK', deps_found) conf.set10('BPF_FRAMEWORK', deps_found)

View File

@ -1151,6 +1151,8 @@ static int mount_image(const MountEntry *m, const char *root_directory) {
NULL); NULL);
if (r < 0) if (r < 0)
return log_debug_errno(r, "Failed to acquire 'os-release' data of OS tree '%s': %m", empty_to_root(root_directory)); return log_debug_errno(r, "Failed to acquire 'os-release' data of OS tree '%s': %m", empty_to_root(root_directory));
if (isempty(host_os_release_id))
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "'ID' field not found or empty in 'os-release' data of OS tree '%s': %m", empty_to_root(root_directory));
} }
r = verity_dissect_and_mount( r = verity_dissect_and_mount(

View File

@ -152,7 +152,9 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) {
if (verify) { if (verify) {
r = chase_symlinks(_syspath, NULL, 0, &syspath, NULL); r = chase_symlinks(_syspath, NULL, 0, &syspath, NULL);
if (r == -ENOENT) if (r == -ENOENT)
return -ENODEV; /* the device does not exist (any more?) */ /* the device does not exist (any more?) */
return log_debug_errno(SYNTHETIC_ERRNO(ENODEV),
"sd-device: Failed to chase symlinks in \"%s\".", _syspath);
if (r < 0) if (r < 0)
return log_debug_errno(r, "sd-device: Failed to get target of '%s': %m", _syspath); return log_debug_errno(r, "sd-device: Failed to get target of '%s': %m", _syspath);
@ -173,7 +175,7 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) {
new_syspath = path_join("/sys", p); new_syspath = path_join("/sys", p);
if (!new_syspath) if (!new_syspath)
return -ENOMEM; return log_oom_debug();
free_and_replace(syspath, new_syspath); free_and_replace(syspath, new_syspath);
path_simplify(syspath); path_simplify(syspath);
@ -187,30 +189,31 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) {
if (access(path, F_OK) < 0) { if (access(path, F_OK) < 0) {
if (errno == ENOENT) if (errno == ENOENT)
/* this is not a valid device */ /* this is not a valid device */
return -ENODEV; return log_debug_errno(SYNTHETIC_ERRNO(ENODEV),
"sd-device: the uevent file \"%s\" does not exist.", path);
return log_debug_errno(errno, "sd-device: cannot access uevent file for %s: %m", syspath); return log_debug_errno(errno, "sd-device: cannot access uevent file for %s: %m", syspath);
} }
} else { } else {
/* everything else just needs to be a directory */ /* everything else just needs to be a directory */
if (!is_dir(syspath, false)) if (!is_dir(syspath, false))
return -ENODEV; return log_debug_errno(SYNTHETIC_ERRNO(ENODEV),
"sd-device: the syspath \"%s\" is not a directory.", syspath);
} }
} else { } else {
syspath = strdup(_syspath); syspath = strdup(_syspath);
if (!syspath) if (!syspath)
return -ENOMEM; return log_oom_debug();
} }
devpath = syspath + STRLEN("/sys"); devpath = syspath + STRLEN("/sys");
if (devpath[0] != '/') if (devpath[0] != '/')
/* '/sys' alone is not a valid device path */ return log_debug_errno(SYNTHETIC_ERRNO(ENODEV), "sd-device: \"/sys\" alone is not a valid device path.");
return -ENODEV;
r = device_add_property_internal(device, "DEVPATH", devpath); r = device_add_property_internal(device, "DEVPATH", devpath);
if (r < 0) if (r < 0)
return r; return log_debug_errno(r, "sd-device: Failed to add \"DEVPATH\" property for device \"%s\": %m", syspath);
free_and_replace(device->syspath, syspath); free_and_replace(device->syspath, syspath);
device->devpath = devpath; device->devpath = devpath;

View File

@ -3534,9 +3534,9 @@ int verity_dissect_and_mount(
/* If we got os-release values from the caller, then we need to match them with the image's /* If we got os-release values from the caller, then we need to match them with the image's
* extension-release.d/ content. Return -EINVAL if there's any mismatch. * extension-release.d/ content. Return -EINVAL if there's any mismatch.
* First, check the distro ID. If that matches, then check the new SYSEXT_LEVEL value if * First, check the distro ID. If that matches, then check the new SYSEXT_LEVEL value if
* available, or else fallback to VERSION_ID. */ * available, or else fallback to VERSION_ID. If neither is present (eg: rolling release),
if (required_host_os_release_id && * then a simple match on the ID will be performed. */
(required_host_os_release_version_id || required_host_os_release_sysext_level)) { if (required_host_os_release_id) {
_cleanup_strv_free_ char **extension_release = NULL; _cleanup_strv_free_ char **extension_release = NULL;
r = load_extension_release_pairs(dest, dissected_image->image_name, &extension_release); r = load_extension_release_pairs(dest, dissected_image->image_name, &extension_release);

View File

@ -13,6 +13,7 @@
#include "errno-util.h" #include "errno-util.h"
#include "escape.h" #include "escape.h"
#include "fd-util.h" #include "fd-util.h"
#include "id128-util.h"
#include "log.h" #include "log.h"
#include "macro.h" #include "macro.h"
#include "parse-util.h" #include "parse-util.h"
@ -337,6 +338,7 @@ bool device_for_action(sd_device *dev, sd_device_action_t a) {
void log_device_uevent(sd_device *device, const char *str) { void log_device_uevent(sd_device *device, const char *str) {
sd_device_action_t action = _SD_DEVICE_ACTION_INVALID; sd_device_action_t action = _SD_DEVICE_ACTION_INVALID;
sd_id128_t event_id = SD_ID128_NULL;
uint64_t seqnum = 0; uint64_t seqnum = 0;
if (!DEBUG_LOGGING) if (!DEBUG_LOGGING)
@ -344,9 +346,12 @@ void log_device_uevent(sd_device *device, const char *str) {
(void) sd_device_get_seqnum(device, &seqnum); (void) sd_device_get_seqnum(device, &seqnum);
(void) sd_device_get_action(device, &action); (void) sd_device_get_action(device, &action);
log_device_debug(device, "%s%s(SEQNUM=%"PRIu64", ACTION=%s)", (void) sd_device_get_trigger_uuid(device, &event_id);
log_device_debug(device, "%s%s(SEQNUM=%"PRIu64", ACTION=%s%s%s)",
strempty(str), isempty(str) ? "" : " ", strempty(str), isempty(str) ? "" : " ",
seqnum, strna(device_action_to_string(action))); seqnum, strna(device_action_to_string(action)),
sd_id128_is_null(event_id) ? "" : ", UUID=",
sd_id128_is_null(event_id) ? "" : id128_to_uuid_string(event_id, (char[ID128_UUID_STRING_MAX]){}));
} }
int udev_rule_parse_value(char *str, char **ret_value, char **ret_endpos) { int udev_rule_parse_value(char *str, char **ret_value, char **ret_endpos) {

View File

@ -2,6 +2,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <getopt.h> #include <getopt.h>
#include <linux/loop.h>
#include <sys/mount.h> #include <sys/mount.h>
#include <unistd.h> #include <unistd.h>
@ -529,7 +530,11 @@ static int merge_subprocess(Hashmap *images, const char *workspace) {
if (verity_settings.data_path) if (verity_settings.data_path)
flags |= DISSECT_IMAGE_NO_PARTITION_TABLE; flags |= DISSECT_IMAGE_NO_PARTITION_TABLE;
r = loop_device_make_by_path(img->path, O_RDONLY, 0, &d); r = loop_device_make_by_path(
img->path,
O_RDONLY,
FLAGS_SET(flags, DISSECT_IMAGE_NO_PARTITION_TABLE) ? 0 : LO_FLAGS_PARTSCAN,
&d);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to set up loopback device for %s: %m", img->path); return log_error_errno(r, "Failed to set up loopback device for %s: %m", img->path);

View File

@ -11,8 +11,10 @@ setup() {
ACTION=="add", SUBSYSTEM=="mem", KERNEL=="null", OPTIONS="log_level=debug" ACTION=="add", SUBSYSTEM=="mem", KERNEL=="null", OPTIONS="log_level=debug"
ACTION=="add", SUBSYSTEM=="mem", KERNEL=="null", PROGRAM=="/bin/sleep 60" ACTION=="add", SUBSYSTEM=="mem", KERNEL=="null", PROGRAM=="/bin/sleep 60"
EOF EOF
echo "event_timeout=10" >>/etc/udev/udev.conf cat >>/etc/udev/udev.conf <<EOF
echo "timeout_signal=SIGABRT" >>/etc/udev/udev.conf event_timeout=10
timeout_signal=SIGABRT
EOF
systemctl restart systemd-udevd.service systemctl restart systemd-udevd.service
} }

View File

@ -390,6 +390,10 @@ testcase_btrfs_basic() {
uuid="deadbeef-dead-dead-beef-000000000000" uuid="deadbeef-dead-dead-beef-000000000000"
label="btrfs_root" label="btrfs_root"
mkfs.btrfs -L "$label" -U "$uuid" "${devices[0]}" mkfs.btrfs -L "$label" -U "$uuid" "${devices[0]}"
# We need to do some active waiting anyway, as it may take kernel a bit
# to trigger the newly created btrfs
helper_wait_for_dev "/dev/disk/by-uuid/$uuid"
helper_wait_for_dev "/dev/disk/by-label/$label"
udevadm settle udevadm settle
btrfs filesystem show btrfs filesystem show
test -e "/dev/disk/by-uuid/$uuid" test -e "/dev/disk/by-uuid/$uuid"
@ -409,6 +413,8 @@ name="diskpart4", size=85M
EOF EOF
udevadm settle udevadm settle
mkfs.btrfs -d single -m raid1 -L "$label" -U "$uuid" /dev/disk/by-partlabel/diskpart{1..4} mkfs.btrfs -d single -m raid1 -L "$label" -U "$uuid" /dev/disk/by-partlabel/diskpart{1..4}
helper_wait_for_dev "/dev/disk/by-uuid/$uuid"
helper_wait_for_dev "/dev/disk/by-label/$label"
udevadm settle udevadm settle
btrfs filesystem show btrfs filesystem show
test -e "/dev/disk/by-uuid/$uuid" test -e "/dev/disk/by-uuid/$uuid"
@ -420,6 +426,8 @@ EOF
uuid="deadbeef-dead-dead-beef-000000000002" uuid="deadbeef-dead-dead-beef-000000000002"
label="btrfs_mdisk" label="btrfs_mdisk"
mkfs.btrfs -M -d raid10 -m raid10 -L "$label" -U "$uuid" "${devices[@]}" mkfs.btrfs -M -d raid10 -m raid10 -L "$label" -U "$uuid" "${devices[@]}"
helper_wait_for_dev "/dev/disk/by-uuid/$uuid"
helper_wait_for_dev "/dev/disk/by-label/$label"
udevadm settle udevadm settle
btrfs filesystem show btrfs filesystem show
test -e "/dev/disk/by-uuid/$uuid" test -e "/dev/disk/by-uuid/$uuid"
@ -457,6 +465,8 @@ EOF
ls -l /dev/mapper/encbtrfs{0..3} ls -l /dev/mapper/encbtrfs{0..3}
# Create a multi-device btrfs filesystem on the LUKS devices # Create a multi-device btrfs filesystem on the LUKS devices
mkfs.btrfs -M -d raid1 -m raid1 -L "$label" -U "$uuid" /dev/mapper/encbtrfs{0..3} mkfs.btrfs -M -d raid1 -m raid1 -L "$label" -U "$uuid" /dev/mapper/encbtrfs{0..3}
helper_wait_for_dev "/dev/disk/by-uuid/$uuid"
helper_wait_for_dev "/dev/disk/by-label/$label"
udevadm settle udevadm settle
btrfs filesystem show btrfs filesystem show
test -e "/dev/disk/by-uuid/$uuid" test -e "/dev/disk/by-uuid/$uuid"
@ -483,6 +493,8 @@ EOF
# Start the corresponding mount unit and check if the btrfs device was reconstructed # Start the corresponding mount unit and check if the btrfs device was reconstructed
# correctly # correctly
systemctl start "${mpoint##*/}.mount" systemctl start "${mpoint##*/}.mount"
helper_wait_for_dev "/dev/disk/by-uuid/$uuid"
helper_wait_for_dev "/dev/disk/by-label/$label"
btrfs filesystem show btrfs filesystem show
test -e "/dev/disk/by-uuid/$uuid" test -e "/dev/disk/by-uuid/$uuid"
test -e "/dev/disk/by-label/$label" test -e "/dev/disk/by-label/$label"