1
0
mirror of https://github.com/systemd/systemd synced 2025-11-09 20:04:46 +01:00

Compare commits

...

8 Commits

Author SHA1 Message Date
Jeremy Cline
efdbf5fe9c shared: treat generator units as vendor units
Units created with "systemctl edit --full" from generator units aren't
removed with "systemctl revert" because units in the generator,
generator_early, and generator_late paths aren't considered vendor
units.

Alter path_is_vendor() to return true if the given path is a
generator unit, which in turn causes "systemctl revert" to remove units
created with "systemctl edit --full" as they now have vendor versions.

Fixes #10053
2020-05-21 10:03:40 +02:00
Lidong Zhong
9b3278d907 udev: rename the persistent link for ATA devices
ATA devices should use the ATA ids like port number and (possibly)
master/slave or multiplier id, not the generic SCSI ID.
Currently only port number is included in the link. With this patch
the link would be able to support more cases, which are a) when the
device is behind a port multiplexer b) the distinction between master
and slave (distinguished by target id).

I tried to verify scenario a) with this patch, but I failed to find a
machine with PMP SATA devices attached. But the link below
https://github.com/systemd/systemd/issues/3943
could show what's the difference. Here is my test for scenario b)

Current version:
linux-ql21:~ # ll /sys/class/block/sd[ab]
lrwxrwxrwx 1 root root 0 May  8 20:46 /sys/class/block/sda ->
../../devices/pci0000:00/0000:00:01.1/ata4/host3/target3:0:0/3:0:0:0/block/sda
lrwxrwxrwx 1 root root 0 May  8 20:46 /sys/class/block/sdb ->
../../devices/pci0000:00/0000:00:01.1/ata4/host3/target3:0:1/3:0:1:0/block/sdb
linux-ql21:~ # ll /dev/disk/by-path/pci-0000\:00\:01.1-ata-1
lrwxrwxrwx 1 root root 9 May  8 20:44
/dev/disk/by-path/pci-0000:00:01.1-ata-1 -> ../../sdb
linux-ql21:~ # udevadm info /sys/class/block/sda |grep by-path
S: disk/by-path/pci-0000:00:01.1-ata-1
E: DEVLINKS=/dev/disk/by-id/ata-VBOX_HARDDISK_VB3649e885-3e0cdd64
/dev/disk/by-id/scsi-0ATA_VBOX_HARDDISK_VB3649e885-3e0cdd64
/dev/disk/by-id/scsi-1ATA_VBOX_HARDDISK_VB3649e885-3e0cdd64
/dev/disk/by-path/pci-0000:00:01.1-ata-1
/dev/disk/by-id/scsi-SATA_VBOX_HARDDISK_VB3649e885-3e0cdd64
linux-ql21:~ # udevadm info /sys/class/block/sdb |grep by-path
S: disk/by-path/pci-0000:00:01.1-ata-1
E: DEVLINKS=/dev/disk/by-id/ata-VBOX_HARDDISK_VBc53b2498-d84ae8de
/dev/disk/by-id/scsi-SATA_VBOX_HARDDISK_VBc53b2498-d84ae8de
/dev/disk/by-id/scsi-1ATA_VBOX_HARDDISK_VBc53b2498-d84ae8de
/dev/disk/by-id/scsi-0ATA_VBOX_HARDDISK_VBc53b2498-d84ae8de
/dev/disk/by-path/pci-0000:00:01.1-ata-1

After patch applied:
linux-ql21:~ # ll /sys/class/block/sd[ab]
lrwxrwxrwx 1 root root 0 May  8 21:07 /sys/class/block/sda ->
../../devices/pci0000:00/0000:00:01.1/ata4/host3/target3:0:0/3:0:0:0/block/sda
lrwxrwxrwx 1 root root 0 May  8 21:07 /sys/class/block/sdb ->
../../devices/pci0000:00/0000:00:01.1/ata4/host3/target3:0:1/3:0:1:0/block/sdb
linux-ql21:~ # ll /dev/disk/by-path/pci-0000\:00\:01.1-ata-*
lrwxrwxrwx 1 root root  9 May  8 21:07
/dev/disk/by-path/pci-0000:00:01.1-ata-1.0 -> ../../sda
lrwxrwxrwx 1 root root  9 May  8 21:07
/dev/disk/by-path/pci-0000:00:01.1-ata-1.1 -> ../../sdb
linux-ql21:~ # udevadm info /sys/class/block/sda |grep by-path
S: disk/by-path/pci-0000:00:01.1-ata-1.0
E: DEVLINKS=/dev/disk/by-id/scsi-1ATA_VBOX_HARDDISK_VB3649e885-3e0cdd64
/dev/disk/by-id/scsi-0ATA_VBOX_HARDDISK_VB3649e885-3e0cdd64
/dev/disk/by-id/ata-VBOX_HARDDISK_VB3649e885-3e0cdd64
/dev/disk/by-path/pci-0000:00:01.1-ata-1.0
/dev/disk/by-id/scsi-SATA_VBOX_HARDDISK_VB3649e885-3e0cdd64
linux-ql21:~ # udevadm info /sys/class/block/sdb |grep by-path
S: disk/by-path/pci-0000:00:01.1-ata-1.1
E: DEVLINKS=/dev/disk/by-id/scsi-0ATA_VBOX_HARDDISK_VBc53b2498-d84ae8de
/dev/disk/by-id/ata-VBOX_HARDDISK_VBc53b2498-d84ae8de
/dev/disk/by-id/scsi-1ATA_VBOX_HARDDISK_VBc53b2498-d84ae8de
/dev/disk/by-id/scsi-SATA_VBOX_HARDDISK_VBc53b2498-d84ae8de
/dev/disk/by-path/pci-0000:00:01.1-ata-1.1

Changelog:
v5: add another parameter compat_link in handle_scsi()
v4: comment for ID_PATH_ATA_COMPAT
    get string length with pointer difference
    (suggested by Franck Bui<fbui@suse.com>)
v3: creating compatible link from env
    variables type change
v2: remove udev rules modification for compatible link
    setup a test scenario of master/slave ATA devices
v1: initial patch
2020-05-21 09:58:06 +02:00
Lennart Poettering
1b1b7b44cc rules: automatically pull in smartcard.target from all CCID devices
We apparently never matched the USB interface class. Let's fix that.

Prompted by: #15676
2020-05-21 09:23:06 +02:00
Zbigniew Jędrzejewski-Szmek
7c15a55f8b
Merge pull request #15870 from poettering/proc-cmdline-efi-fix
udev /proc/cmdline handling fixes
2020-05-21 09:07:27 +02:00
Lennart Poettering
a60416f319 homed: fix return value mix-up
We generally return > 1 if any of the actions we are doing is instantly
complete and == 0 when we started doing it asynchronously (by forking
off homework), in our functions that execute operations on homes.

Fix a mix-up where the test for this was reversed in
home_dispatch_release() and home_dispatch_lock_all().

Fixes: #15684
2020-05-21 08:10:13 +02:00
Lennart Poettering
09835de3cc proc-cmdline: make checking of EFI options variable optional
And do not use it in the IMPORT{cmdline} udev code. Wherever we expose
direct interfaces to check the kernel cmdline, let's not consult our
systemd-specific EFI variable, but strictly use the actual kernel
variable, because that's what we claim we do. i.e. it's fine to use the
EFI variable for our own settings, but for the generic APIs to the
kernel cmdline we should not use it.

Specifically, this applies to IMPORT{cmdline} and
ConditionKernelCommandLine=. In the latter case we weren#t checking the
EFI variable anyway, hence let's do the same for the udev case, too.

Fixes: #15739
2020-05-20 19:22:09 +02:00
Lennart Poettering
05a7827e87 proc-cmdline: add checking of EFI options variable in proc_cmdline_get_key_many() too 2020-05-20 19:18:45 +02:00
Lennart Poettering
4b5ee5901c proc-cmdline: fix return value clobbering in proc_cmdline_get_key()
Let's make sure proc_cmdline_get_key() follows our coding style: never
clobber return values on failure, and always initialize on success.
2020-05-20 19:17:44 +02:00
8 changed files with 115 additions and 31 deletions

View File

@ -93,6 +93,9 @@ ENV{DEVTYPE}=="disk", DEVPATH!="*/virtual/*", IMPORT{builtin}="path_id"
KERNEL=="mmcblk[0-9]boot[0-9]", ENV{DEVTYPE}=="disk", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}-boot%n"
KERNEL!="mmcblk[0-9]boot[0-9]", ENV{DEVTYPE}=="disk", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}"
ENV{DEVTYPE}=="partition", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}-part%n"
# compatible links for ATA devices
KERNEL!="mmcblk[0-9]boot[0-9]", ENV{DEVTYPE}=="disk", ENV{ID_PATH_ATA_COMPAT}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH_ATA_COMPAT}"
ENV{DEVTYPE}=="partition", ENV{ID_PATH_ATA_COMPAT}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH_ATA_COMPAT}-part%n"
# legacy virtio-pci by-path links (deprecated)
KERNEL=="vd*[!0-9]", ENV{ID_PATH}=="pci-*", SYMLINK+="disk/by-path/virtio-$env{ID_PATH}"

View File

@ -49,6 +49,7 @@ SUBSYSTEM=="net", KERNEL!="lo", TAG+="systemd", ENV{SYSTEMD_ALIAS}+="/sys/subsys
SUBSYSTEM=="bluetooth", TAG+="systemd", ENV{SYSTEMD_ALIAS}+="/sys/subsystem/bluetooth/devices/%k"
SUBSYSTEM=="bluetooth", TAG+="systemd", ENV{SYSTEMD_WANTS}+="bluetooth.target", ENV{SYSTEMD_USER_WANTS}+="bluetooth.target"
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ENV{ID_USB_INTERFACES}=="*:0b????:*", ENV{ID_SMARTCARD_READER}="1"
ENV{ID_SMARTCARD_READER}=="?*", TAG+="systemd", ENV{SYSTEMD_WANTS}+="smartcard.target", ENV{SYSTEMD_USER_WANTS}+="smartcard.target"
SUBSYSTEM=="sound", KERNEL=="card*", TAG+="systemd", ENV{SYSTEMD_WANTS}+="sound.target", ENV{SYSTEMD_USER_WANTS}+="sound.target"

View File

@ -119,15 +119,18 @@ int proc_cmdline_parse(proc_cmdline_parse_t parse_item, void *data, ProcCmdlineF
/* We parse the EFI variable first, because later settings have higher priority. */
r = systemd_efi_options_variable(&line);
if (r < 0 && r != -ENODATA)
log_debug_errno(r, "Failed to get SystemdOptions EFI variable, ignoring: %m");
if (!FLAGS_SET(flags, PROC_CMDLINE_IGNORE_EFI_OPTIONS)) {
r = systemd_efi_options_variable(&line);
if (r < 0 && r != -ENODATA)
log_debug_errno(r, "Failed to get SystemdOptions EFI variable, ignoring: %m");
r = proc_cmdline_parse_given(line, parse_item, data, flags);
if (r < 0)
return r;
r = proc_cmdline_parse_given(line, parse_item, data, flags);
if (r < 0)
return r;
line = mfree(line);
}
line = mfree(line);
r = proc_cmdline(&line);
if (r < 0)
return r;
@ -218,7 +221,7 @@ static int cmdline_get_key(const char *line, const char *key, ProcCmdlineFlags f
}
int proc_cmdline_get_key(const char *key, ProcCmdlineFlags flags, char **ret_value) {
_cleanup_free_ char *line = NULL;
_cleanup_free_ char *line = NULL, *v = NULL;
int r;
/* Looks for a specific key on the kernel command line and (with lower priority) the EFI variable.
@ -245,14 +248,27 @@ int proc_cmdline_get_key(const char *key, ProcCmdlineFlags flags, char **ret_val
if (r < 0)
return r;
r = cmdline_get_key(line, key, flags, ret_value);
if (r != 0) /* Either error or true if found. */
if (FLAGS_SET(flags, PROC_CMDLINE_IGNORE_EFI_OPTIONS)) /* Shortcut */
return cmdline_get_key(line, key, flags, ret_value);
r = cmdline_get_key(line, key, flags, ret_value ? &v : NULL);
if (r < 0)
return r;
if (r > 0) {
if (ret_value)
*ret_value = TAKE_PTR(v);
return r;
}
line = mfree(line);
r = systemd_efi_options_variable(&line);
if (r == -ENODATA)
if (r == -ENODATA) {
if (ret_value)
*ret_value = NULL;
return false; /* Not found */
}
if (r < 0)
return r;
@ -286,6 +302,7 @@ int proc_cmdline_get_bool(const char *key, bool *ret) {
int proc_cmdline_get_key_many_internal(ProcCmdlineFlags flags, ...) {
_cleanup_free_ char *line = NULL;
bool processing_efi = true;
const char *p;
va_list ap;
int r, ret = 0;
@ -296,9 +313,11 @@ int proc_cmdline_get_key_many_internal(ProcCmdlineFlags flags, ...) {
/* This call may clobber arguments on failure! */
r = proc_cmdline(&line);
if (r < 0)
return r;
if (!FLAGS_SET(flags, PROC_CMDLINE_IGNORE_EFI_OPTIONS)) {
r = systemd_efi_options_variable(&line);
if (r < 0 && r != -ENODATA)
log_debug_errno(r, "Failed to get SystemdOptions EFI variable, ignoring: %m");
}
p = line;
for (;;) {
@ -307,8 +326,22 @@ int proc_cmdline_get_key_many_internal(ProcCmdlineFlags flags, ...) {
r = proc_cmdline_extract_first(&p, &word, flags);
if (r < 0)
return r;
if (r == 0)
if (r == 0) {
/* We finished with this command line. If this was the EFI one, then let's proceed with the regular one */
if (processing_efi) {
processing_efi = false;
line = mfree(line);
r = proc_cmdline(&line);
if (r < 0)
return r;
p = line;
continue;
}
break;
}
va_start(ap, flags);

View File

@ -6,9 +6,10 @@
#include "log.h"
typedef enum ProcCmdlineFlags {
PROC_CMDLINE_STRIP_RD_PREFIX = 1 << 0, /* automatically strip "rd." prefix if it is set (and we are in the initrd, since otherwise we'd not consider it anyway) */
PROC_CMDLINE_VALUE_OPTIONAL = 1 << 1, /* the value is optional (for boolean switches that can omit the value) */
PROC_CMDLINE_RD_STRICT = 1 << 2, /* ignore this in the initrd */
PROC_CMDLINE_STRIP_RD_PREFIX = 1 << 0, /* automatically strip "rd." prefix if it is set (and we are in the initrd, since otherwise we'd not consider it anyway) */
PROC_CMDLINE_VALUE_OPTIONAL = 1 << 1, /* the value is optional (for boolean switches that can omit the value) */
PROC_CMDLINE_RD_STRICT = 1 << 2, /* ignore this in the initrd */
PROC_CMDLINE_IGNORE_EFI_OPTIONS = 1 << 3, /* don't check systemd's private EFI variable */
} ProcCmdlineFlags;
typedef int (*proc_cmdline_parse_t)(const char *key, const char *value, void *data);

View File

@ -2364,7 +2364,7 @@ static int home_dispatch_release(Home *h, Operation *o) {
case HOME_UNFIXATED:
case HOME_ABSENT:
case HOME_INACTIVE:
r = 0; /* done */
r = 1; /* done */
break;
case HOME_LOCKED:
@ -2384,7 +2384,7 @@ static int home_dispatch_release(Home *h, Operation *o) {
assert(!h->current_operation);
if (r <= 0) /* failure or completed */
if (r != 0) /* failure or completed */
operation_result(o, r, &error);
else /* ongoing */
h->current_operation = operation_ref(o);
@ -2406,12 +2406,12 @@ static int home_dispatch_lock_all(Home *h, Operation *o) {
case HOME_ABSENT:
case HOME_INACTIVE:
log_info("Home %s is not active, no locking necessary.", h->user_name);
r = 0; /* done */
r = 1; /* done */
break;
case HOME_LOCKED:
log_info("Home %s is already locked.", h->user_name);
r = 0; /* done */
r = 1; /* done */
break;
case HOME_ACTIVE:

View File

@ -227,7 +227,7 @@ static int path_is_runtime(const LookupPaths *p, const char *path, bool check_pa
path_equal_ptr(path, p->runtime_control);
}
static int path_is_vendor(const LookupPaths *p, const char *path) {
static int path_is_vendor_or_generator(const LookupPaths *p, const char *path) {
const char *rpath;
assert(p);
@ -245,6 +245,9 @@ static int path_is_vendor(const LookupPaths *p, const char *path) {
return true;
#endif
if (path_is_generator(p, rpath))
return true;
return path_equal(rpath, SYSTEM_DATA_UNIT_PATH);
}
@ -2374,7 +2377,7 @@ int unit_file_revert(
return -errno;
} else if (S_ISREG(st.st_mode)) {
/* Check if there's a vendor version */
r = path_is_vendor(&paths, path);
r = path_is_vendor_or_generator(&paths, path);
if (r < 0)
return r;
if (r > 0)

View File

@ -253,14 +253,20 @@ static sd_device *handle_scsi_iscsi(sd_device *parent, char **path) {
return parent;
}
static sd_device *handle_scsi_ata(sd_device *parent, char **path) {
static sd_device *handle_scsi_ata(sd_device *parent, char **path, char **compat_path) {
sd_device *targetdev, *target_parent;
_cleanup_(sd_device_unrefp) sd_device *atadev = NULL;
const char *port_no, *sysname;
const char *port_no, *sysname, *name;
unsigned host, bus, target, lun;
assert(parent);
assert(path);
if (sd_device_get_sysname(parent, &name) < 0)
return NULL;
if (sscanf(name, "%u:%u:%u:%u", &host, &bus, &target, &lun) != 4)
return NULL;
if (sd_device_get_parent_with_subsystem_devtype(parent, "scsi", "scsi_host", &targetdev) < 0)
return NULL;
@ -275,7 +281,17 @@ static sd_device *handle_scsi_ata(sd_device *parent, char **path) {
if (sd_device_get_sysattr_value(atadev, "port_no", &port_no) < 0)
return NULL;
path_prepend(path, "ata-%s", port_no);
if (bus != 0)
/* Devices behind port multiplier have a bus != 0*/
path_prepend(path, "ata-%s.%u.0", port_no, bus);
else
/* Master/slave are distinguished by target id */
path_prepend(path, "ata-%s.%u", port_no, target);
/* old compatible persistent link for ATA devices */
if (compat_path)
path_prepend(compat_path, "ata-%s", port_no);
return parent;
}
@ -392,7 +408,7 @@ static sd_device *handle_scsi_hyperv(sd_device *parent, char **path, size_t guid
return parent;
}
static sd_device *handle_scsi(sd_device *parent, char **path, bool *supported_parent) {
static sd_device *handle_scsi(sd_device *parent, char **path, char **compat_path, bool *supported_parent) {
const char *devtype, *id, *name;
if (sd_device_get_devtype(parent, &devtype) < 0 ||
@ -426,7 +442,7 @@ static sd_device *handle_scsi(sd_device *parent, char **path, bool *supported_pa
}
if (strstr(name, "/ata"))
return handle_scsi_ata(parent, path);
return handle_scsi_ata(parent, path, compat_path);
if (strstr(name, "/vmbus_"))
return handle_scsi_hyperv(parent, path, 37);
@ -520,6 +536,7 @@ static sd_device *handle_ap(sd_device *parent, char **path) {
static int builtin_path_id(sd_device *dev, int argc, char *argv[], bool test) {
sd_device *parent;
_cleanup_free_ char *path = NULL;
_cleanup_free_ char *compat_path = NULL;
bool supported_transport = false;
bool supported_parent = false;
const char *subsystem;
@ -537,7 +554,7 @@ static int builtin_path_id(sd_device *dev, int argc, char *argv[], bool test) {
} else if (streq(subsys, "scsi_tape")) {
handle_scsi_tape(parent, &path);
} else if (streq(subsys, "scsi")) {
parent = handle_scsi(parent, &path, &supported_parent);
parent = handle_scsi(parent, &path, &compat_path, &supported_parent);
supported_transport = true;
} else if (streq(subsys, "cciss")) {
parent = handle_cciss(parent, &path);
@ -557,19 +574,27 @@ static int builtin_path_id(sd_device *dev, int argc, char *argv[], bool test) {
}
} else if (streq(subsys, "pci")) {
path_prepend(&path, "pci-%s", sysname);
if (compat_path)
path_prepend(&compat_path, "pci-%s", sysname);
parent = skip_subsystem(parent, "pci");
supported_parent = true;
} else if (streq(subsys, "platform")) {
path_prepend(&path, "platform-%s", sysname);
if (compat_path)
path_prepend(&compat_path, "platform-%s", sysname);
parent = skip_subsystem(parent, "platform");
supported_transport = true;
supported_parent = true;
} else if (streq(subsys, "acpi")) {
path_prepend(&path, "acpi-%s", sysname);
if (compat_path)
path_prepend(&compat_path, "acpi-%s", sysname);
parent = skip_subsystem(parent, "acpi");
supported_parent = true;
} else if (streq(subsys, "xen")) {
path_prepend(&path, "xen-%s", sysname);
if (compat_path)
path_prepend(&compat_path, "xen-%s", sysname);
parent = skip_subsystem(parent, "xen");
supported_parent = true;
} else if (streq(subsys, "virtio")) {
@ -577,16 +602,22 @@ static int builtin_path_id(sd_device *dev, int argc, char *argv[], bool test) {
supported_transport = true;
} else if (streq(subsys, "scm")) {
path_prepend(&path, "scm-%s", sysname);
if (compat_path)
path_prepend(&compat_path, "scm-%s", sysname);
parent = skip_subsystem(parent, "scm");
supported_transport = true;
supported_parent = true;
} else if (streq(subsys, "ccw")) {
path_prepend(&path, "ccw-%s", sysname);
if (compat_path)
path_prepend(&compat_path, "ccw-%s", sysname);
parent = skip_subsystem(parent, "ccw");
supported_transport = true;
supported_parent = true;
} else if (streq(subsys, "ccwgroup")) {
path_prepend(&path, "ccwgroup-%s", sysname);
if (compat_path)
path_prepend(&compat_path, "ccwgroup-%s", sysname);
parent = skip_subsystem(parent, "ccwgroup");
supported_transport = true;
supported_parent = true;
@ -596,6 +627,8 @@ static int builtin_path_id(sd_device *dev, int argc, char *argv[], bool test) {
supported_parent = true;
} else if (streq(subsys, "iucv")) {
path_prepend(&path, "iucv-%s", sysname);
if (compat_path)
path_prepend(&compat_path, "iucv-%s", sysname);
parent = skip_subsystem(parent, "iucv");
supported_transport = true;
supported_parent = true;
@ -604,6 +637,8 @@ static int builtin_path_id(sd_device *dev, int argc, char *argv[], bool test) {
if (sd_device_get_sysattr_value(dev, "nsid", &nsid) >= 0) {
path_prepend(&path, "nvme-%s", nsid);
if (compat_path)
path_prepend(&compat_path, "nvme-%s", nsid);
parent = skip_subsystem(parent, "nvme");
supported_parent = true;
supported_transport = true;
@ -671,6 +706,14 @@ static int builtin_path_id(sd_device *dev, int argc, char *argv[], bool test) {
udev_builtin_add_property(dev, test, "ID_PATH_TAG", tag);
}
/*
* Compatible link generation for ATA devices
* we assign compat_link to the env variable
* ID_PATH_ATA_COMPAT
*/
if (compat_path)
udev_builtin_add_property(dev, test, "ID_PATH_ATA_COMPAT", compat_path);
return 0;
}

View File

@ -1814,7 +1814,7 @@ static int udev_rule_apply_token_to_event(
case TK_M_IMPORT_CMDLINE: {
_cleanup_free_ char *value = NULL;
r = proc_cmdline_get_key(token->value, PROC_CMDLINE_VALUE_OPTIONAL, &value);
r = proc_cmdline_get_key(token->value, PROC_CMDLINE_VALUE_OPTIONAL|PROC_CMDLINE_IGNORE_EFI_OPTIONS, &value);
if (r < 0)
return log_rule_error_errno(dev, rules, r,
"Failed to read '%s' option from /proc/cmdline: %m",