!279 remove old device on move event
From: @yangmingtaip Reviewed-by: @overweight Signed-off-by: @overweight
This commit is contained in:
commit
fb3e5a67fe
@ -0,0 +1,56 @@
|
||||
From 51d9aec0ff333ff554079da4babf6dbfa9837096 Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Mon, 14 Sep 2020 15:20:04 +0900
|
||||
Subject: [PATCH] Revert "udev: import the full db on MOVE events for devices
|
||||
without dev_t"
|
||||
|
||||
This reverts commit b081b27e1433cdc7ac72b25ae8b4db887d79187f.
|
||||
|
||||
If a network interface get a 'move' event, then previously SYSTEMD_ALIAS=
|
||||
property still contains an old alias, and the old alias .device unit
|
||||
will not be removed.
|
||||
|
||||
This makes all properties cleared on 'move' event, and then old alias
|
||||
.device unit will be removed by pid1.
|
||||
|
||||
Fixes #16967.
|
||||
|
||||
Reference:https://github.com/systemd/systemd/commit/51d9aec0ff333ff554079da4babf6dbfa9837096
|
||||
Conflict:context adaptation
|
||||
---
|
||||
src/udev/udev-event.c | 11 ++---------
|
||||
1 file changed, 2 insertions(+), 9 deletions(-)
|
||||
|
||||
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
|
||||
index 7c78b4c680..ede8e3aef7 100644
|
||||
--- a/src/udev/udev-event.c
|
||||
+++ b/src/udev/udev-event.c
|
||||
@@ -940,16 +940,9 @@ static void event_execute_rules_on_remove(
|
||||
(void) udev_node_remove(dev);
|
||||
}
|
||||
|
||||
-static int udev_event_on_move(UdevEvent *event) {
|
||||
- sd_device *dev = event->dev;
|
||||
+static int udev_event_on_move(sd_device *dev) {
|
||||
int r;
|
||||
|
||||
- if (sd_device_get_devnum(dev, NULL) < 0) {
|
||||
- r = device_copy_properties(dev, event->dev_db_clone);
|
||||
- if (r < 0)
|
||||
- log_device_debug_errno(dev, r, "Failed to copy properties from cloned sd_device object, ignoring: %m");
|
||||
- }
|
||||
-
|
||||
/* Drop previously added property */
|
||||
r = device_add_property(dev, "ID_RENAMING", NULL);
|
||||
if (r < 0)
|
||||
@@ -1017,7 +1010,7 @@ int udev_event_execute_rules(UdevEvent *event,
|
||||
(void) udev_watch_end(event->dev_db_clone);
|
||||
|
||||
if (action == DEVICE_ACTION_MOVE) {
|
||||
- r = udev_event_on_move(event);
|
||||
+ r = udev_event_on_move(event->dev);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
--
|
||||
2.27.0
|
||||
@ -0,0 +1,59 @@
|
||||
From 87bc687a8cbadbc9eb3c77fba41a6caf3219cf7c Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Mon, 7 Sep 2020 13:43:56 +0900
|
||||
Subject: [PATCH] core/device: remove .device unit corresponding to DEVPATH_OLD
|
||||
|
||||
Partially fixes #16967.
|
||||
|
||||
Reference:https://github.com/systemd/systemd/commit/87bc687a8cbadbc9eb3c77fba41a6caf3219cf7c
|
||||
Conflict:context adaptation
|
||||
---
|
||||
src/core/device.c | 26 ++++++++++++++++++++++++++
|
||||
1 file changed, 26 insertions(+)
|
||||
|
||||
diff --git a/src/core/device.c b/src/core/device.c
|
||||
index 31aa3341c2..d242d15e36 100644
|
||||
--- a/src/core/device.c
|
||||
+++ b/src/core/device.c
|
||||
@@ -897,6 +897,29 @@ static void device_propagate_reload_by_sysfs(Manager *m, const char *sysfs) {
|
||||
}
|
||||
}
|
||||
|
||||
+static int device_remove_old(Manager *m, sd_device *dev) {
|
||||
+ _cleanup_free_ char *syspath_old = NULL, *e = NULL;
|
||||
+ const char *devpath_old;
|
||||
+ int r;
|
||||
+
|
||||
+ r = sd_device_get_property_value(dev, "DEVPATH_OLD", &devpath_old);
|
||||
+ if (r < 0) {
|
||||
+ log_device_debug_errno(dev, r, "Failed to get DEVPATH_OLD= property on 'move' uevent, ignoring: %m");
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ syspath_old = path_join("/sys", devpath_old);
|
||||
+ if (!syspath_old)
|
||||
+ return log_oom();
|
||||
+
|
||||
+ r = unit_name_from_path(syspath_old, ".device", &e);
|
||||
+ if (r < 0)
|
||||
+ return log_device_error_errno(dev, r, "Failed to generate unit name from old device path: %m");
|
||||
+
|
||||
+ device_update_found_by_sysfs(m, syspath_old, 0, DEVICE_FOUND_UDEV|DEVICE_FOUND_MOUNT|DEVICE_FOUND_SWAP);
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
static int device_dispatch_io(sd_device_monitor *monitor, sd_device *dev, void *userdata) {
|
||||
Manager *m = userdata;
|
||||
DeviceAction action;
|
||||
@@ -921,6 +944,9 @@ static int device_dispatch_io(sd_device_monitor *monitor, sd_device *dev, void *
|
||||
if (!IN_SET(action, DEVICE_ACTION_ADD, DEVICE_ACTION_REMOVE, DEVICE_ACTION_MOVE))
|
||||
device_propagate_reload_by_sysfs(m, sysfs);
|
||||
|
||||
+ if (action == DEVICE_ACTION_MOVE)
|
||||
+ (void) device_remove_old(m, dev);
|
||||
+
|
||||
/* A change event can signal that a device is becoming ready, in particular if the device is using
|
||||
* the SYSTEMD_READY logic in udev so we need to reach the else block of the following if, even for
|
||||
* change events */
|
||||
--
|
||||
2.27.0
|
||||
@ -0,0 +1,68 @@
|
||||
From ae6ad21e0b9a179e3408c12297783870cf13a00a Mon Sep 17 00:00:00 2001
|
||||
From: Lennart Poettering <lennart@poettering.net>
|
||||
Date: Wed, 12 Dec 2018 21:31:12 +0100
|
||||
Subject: [PATCH] device: propagate reload events from devices on everything
|
||||
but "add", and "remove"
|
||||
|
||||
Any uevent other then the initial and the last uevent we see for a
|
||||
device (which is "add" and "remove") should result in a reload being
|
||||
triggered, including "bind" and "unbind". Hence, let's fix up the check.
|
||||
|
||||
("move" is kinda a combined "remove" + "add", hence cover that too)
|
||||
|
||||
Reference:https://github.com/systemd/systemd/commit/ae6ad21e0b9a179e3408c12297783870cf13a00a
|
||||
Conflict: NA
|
||||
---
|
||||
src/core/device.c | 22 +++++++++-------------
|
||||
1 file changed, 9 insertions(+), 13 deletions(-)
|
||||
|
||||
diff --git a/src/core/device.c b/src/core/device.c
|
||||
index 50d55289fa..5b8134159a 100644
|
||||
--- a/src/core/device.c
|
||||
+++ b/src/core/device.c
|
||||
@@ -915,20 +915,19 @@ static int device_dispatch_io(sd_device_monitor *monitor, sd_device *dev, void *
|
||||
return 0;
|
||||
}
|
||||
|
||||
- if (action == DEVICE_ACTION_CHANGE)
|
||||
+ if (!IN_SET(action, DEVICE_ACTION_ADD, DEVICE_ACTION_REMOVE, DEVICE_ACTION_MOVE))
|
||||
device_propagate_reload_by_sysfs(m, sysfs);
|
||||
|
||||
- /* A change event can signal that a device is becoming ready, in particular if
|
||||
- * the device is using the SYSTEMD_READY logic in udev
|
||||
- * so we need to reach the else block of the following if, even for change events */
|
||||
+ /* A change event can signal that a device is becoming ready, in particular if the device is using
|
||||
+ * the SYSTEMD_READY logic in udev so we need to reach the else block of the following if, even for
|
||||
+ * change events */
|
||||
if (action == DEVICE_ACTION_REMOVE) {
|
||||
r = swap_process_device_remove(m, dev);
|
||||
if (r < 0)
|
||||
log_device_warning_errno(dev, r, "Failed to process swap device remove event, ignoring: %m");
|
||||
|
||||
- /* If we get notified that a device was removed by
|
||||
- * udev, then it's completely gone, hence unset all
|
||||
- * found bits */
|
||||
+ /* If we get notified that a device was removed by udev, then it's completely gone, hence
|
||||
+ * unset all found bits */
|
||||
device_update_found_by_sysfs(m, sysfs, 0, DEVICE_FOUND_UDEV|DEVICE_FOUND_MOUNT|DEVICE_FOUND_SWAP);
|
||||
|
||||
} else if (device_is_ready(dev)) {
|
||||
@@ -944,13 +943,10 @@ static int device_dispatch_io(sd_device_monitor *monitor, sd_device *dev, void *
|
||||
/* The device is found now, set the udev found bit */
|
||||
device_update_found_by_sysfs(m, sysfs, DEVICE_FOUND_UDEV, DEVICE_FOUND_UDEV);
|
||||
|
||||
- } else {
|
||||
- /* The device is nominally around, but not ready for
|
||||
- * us. Hence unset the udev bit, but leave the rest
|
||||
- * around. */
|
||||
-
|
||||
+ } else
|
||||
+ /* The device is nominally around, but not ready for us. Hence unset the udev bit, but leave
|
||||
+ * the rest around. */
|
||||
device_update_found_by_sysfs(m, sysfs, 0, DEVICE_FOUND_UDEV);
|
||||
- }
|
||||
|
||||
return 0;
|
||||
}
|
||||
--
|
||||
2.27.0
|
||||
72
backport-test-add-test-for-device-renaming-issue-16967.patch
Normal file
72
backport-test-add-test-for-device-renaming-issue-16967.patch
Normal file
@ -0,0 +1,72 @@
|
||||
From efdaeb88f02aeb406068d45ae7687abf1bd4a8a3 Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Mon, 14 Sep 2020 15:44:30 +0900
|
||||
Subject: [PATCH] test: add test for device renaming issue #16967
|
||||
|
||||
Reference:https://github.com/systemd/systemd/commit/efdaeb88f02aeb406068d45ae7687abf1bd4a8a3
|
||||
Conflict:context adaptation
|
||||
---
|
||||
test/TEST-29-UDEV-ID_RENAMING/test.sh | 15 +++++++++++++++
|
||||
test/units/testsuite-29.sh | 16 ++++++++++++++++
|
||||
2 files changed, 31 insertions(+)
|
||||
|
||||
diff --git a/test/TEST-29-UDEV-ID_RENAMING/test.sh b/test/TEST-29-UDEV-ID_RENAMING/test.sh
|
||||
index 4feafc04d7..ddf6db9735 100755
|
||||
--- a/test/TEST-29-UDEV-ID_RENAMING/test.sh
|
||||
+++ b/test/TEST-29-UDEV-ID_RENAMING/test.sh
|
||||
@@ -1,11 +1,26 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
TEST_DESCRIPTION="UDEV ID_RENAMING property"
|
||||
+IMAGE_NAME="udev-id-renaming"
|
||||
TEST_NO_NSPAWN=1
|
||||
|
||||
. $TEST_BASE_DIR/test-functions
|
||||
QEMU_TIMEOUT=300
|
||||
|
||||
+test_create_image() {
|
||||
+ create_empty_image_rootdir
|
||||
+
|
||||
+ # Create what will eventually be our root filesystem onto an overlay
|
||||
+ (
|
||||
+ LOG_LEVEL=5
|
||||
+ setup_basic_environment
|
||||
+ mask_supporting_services
|
||||
+
|
||||
+ instmods dummy
|
||||
+ generate_module_dependencies
|
||||
+ )
|
||||
+}
|
||||
+
|
||||
test_setup() {
|
||||
create_empty_image_rootdir
|
||||
|
||||
diff --git a/test/TEST-29-UDEV-ID_RENAMING/testsuite.sh b/test/TEST-29-UDEV-ID_RENAMING/testsuite.sh
|
||||
index eb9b2ff..b477d16 100755
|
||||
--- a/test/TEST-29-UDEV-ID_RENAMING/testsuite.sh
|
||||
+++ b/test/TEST-29-UDEV-ID_RENAMING/testsuite.sh
|
||||
@@ -38,6 +38,22 @@ STATE=$(systemctl show --property=ActiveState --value sys-devices-virtual-net-lo
|
||||
rm -f /run/udev/rules.d/50-testsuite.rules
|
||||
udevadm control --reload --timeout=600
|
||||
|
||||
+# test for issue #16967
|
||||
+
|
||||
+ip link add hoge type dummy
|
||||
+udevadm info --wait-for-initialization=10s /sys/devices/virtual/net/hoge
|
||||
+sleep 1
|
||||
+if ! systemctl status sys-devices-virtual-net-hoge.device; then exit 1; fi
|
||||
+if ! systemctl status sys-subsystem-net-devices-hoge.device; then exit 1; fi
|
||||
+
|
||||
+ip link set hoge name foobar
|
||||
+udevadm info --wait-for-initialization=10s /sys/devices/virtual/net/foobar
|
||||
+sleep 1
|
||||
+if systemctl status sys-devices-virtual-net-hoge.device; then exit 1; fi
|
||||
+if systemctl status sys-subsystem-net-devices-hoge.device; then exit 1; fi
|
||||
+if ! systemctl status sys-devices-virtual-net-foobar.device; then exit 1; fi
|
||||
+if ! systemctl status sys-subsystem-net-devices-foobar.device; then exit 1; fi
|
||||
+
|
||||
echo OK > /testok
|
||||
|
||||
exit 0
|
||||
--
|
||||
2.23.0
|
||||
@ -0,0 +1,64 @@
|
||||
From f57673025680fdca0c200e7ca7a37fed943d2b49 Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Mon, 14 Sep 2020 18:28:29 +0900
|
||||
Subject: [PATCH] udev: allow to match OriginalName= with renamed interface
|
||||
name
|
||||
|
||||
Reference:https://github.com/systemd/systemd/commit/f57673025680fdca0c200e7ca7a37fed943d2b49
|
||||
Conflict:context adaptation
|
||||
---
|
||||
src/udev/net/link-config.c | 27 ++++++++-------------------
|
||||
1 file changed, 8 insertions(+), 19 deletions(-)
|
||||
|
||||
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
|
||||
index 5c871b6717..cb1db3b52b 100644
|
||||
--- a/src/udev/net/link-config.c
|
||||
+++ b/src/udev/net/link-config.c
|
||||
@@ -232,6 +232,7 @@ bool link_config_should_reload(link_config_ctx *ctx) {
|
||||
}
|
||||
|
||||
int link_config_get(link_config_ctx *ctx, sd_device *device, link_config **ret) {
|
||||
+ unsigned name_assign_type = NET_NAME_UNKNOWN;
|
||||
link_config *link;
|
||||
|
||||
assert(ctx);
|
||||
@@ -238,30 +238,17 @@ int link_config_get(link_config_ctx *ctx, sd_device *device, link_config **ret)
|
||||
assert(device);
|
||||
assert(ret);
|
||||
|
||||
+ (void) link_unsigned_attribute(device, "name_assign_type", &name_assign_type);
|
||||
+
|
||||
LIST_FOREACH(links, link, ctx->links) {
|
||||
if (net_match_config(link->match_mac, link->match_path, link->match_driver,
|
||||
link->match_type, link->match_name, link->match_property,
|
||||
device, NULL, NULL)) {
|
||||
- if (link->match_name && !strv_contains(link->match_name, "*")) {
|
||||
- unsigned name_assign_type = NET_NAME_UNKNOWN;
|
||||
-
|
||||
- (void) link_unsigned_attribute(device, "name_assign_type", &name_assign_type);
|
||||
-
|
||||
- if (name_assign_type == NET_NAME_ENUM) {
|
||||
- log_device_warning(device, "Config file %s applies to device based on potentially unpredictable interface name",
|
||||
- link->filename);
|
||||
- *ret = link;
|
||||
-
|
||||
- return 0;
|
||||
- } else if (name_assign_type == NET_NAME_RENAMED) {
|
||||
- log_device_warning(device, "Config file %s matches device based on renamed interface name, ignoring",
|
||||
- link->filename);
|
||||
-
|
||||
- continue;
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- log_device_debug(device, "Config file %s is applied", link->filename);
|
||||
+ if (link->match_name && !strv_contains(link->match_name, "*") && name_assign_type == NET_NAME_ENUM)
|
||||
+ log_device_warning(device, "Config file %s is applied to device based on potentially unpredictable interface name.",
|
||||
+ link->filename);
|
||||
+ else
|
||||
+ log_device_debug(device, "Config file %s is applied", link->filename);
|
||||
|
||||
*ret = link;
|
||||
return 0;
|
||||
--
|
||||
2.23.0
|
||||
25
backport-udev-do-not-update-return-value-on-failure.patch
Normal file
25
backport-udev-do-not-update-return-value-on-failure.patch
Normal file
@ -0,0 +1,25 @@
|
||||
From 7f67b01e3f81029a64c2bb46e2fb57fae6c9d505 Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Mon, 14 Sep 2020 18:30:58 +0900
|
||||
Subject: [PATCH] udev: do not update return value on failure
|
||||
|
||||
Reference:https://github.com/systemd/systemd/pull/16968/commits/7f67b01e3f81029a64c2bb46e2fb57fae6c9d505
|
||||
Conflict:NA
|
||||
---
|
||||
src/udev/net/link-config.c | 1 -
|
||||
1 file changed, 1 deletion(-)
|
||||
|
||||
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
|
||||
index cb1db3b52b..c23c2bdd20 100644
|
||||
--- a/src/udev/net/link-config.c
|
||||
+++ b/src/udev/net/link-config.c
|
||||
@@ -287,7 +287,6 @@ int link_config_get(link_config_ctx *ctx, sd_device *device, link_config **ret)
|
||||
}
|
||||
}
|
||||
|
||||
- *ret = NULL;
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
--
|
||||
2.27.0
|
||||
53
backport-udev-drop-unnecessary-checks.patch
Normal file
53
backport-udev-drop-unnecessary-checks.patch
Normal file
@ -0,0 +1,53 @@
|
||||
From 28266c446a64597c55f68e33c086da7465541a21 Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Tue, 21 Jul 2020 11:39:44 +0900
|
||||
Subject: [PATCH] udev: drop unnecessary checks
|
||||
|
||||
Also, drop one unnecessary sd_device_unref(), as dev_db_clone will be
|
||||
unref()ed in udev_event_free().
|
||||
---
|
||||
src/udev/udev-event.c | 10 +++-------
|
||||
1 file changed, 3 insertions(+), 7 deletions(-)
|
||||
|
||||
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
|
||||
index 2ae76eb51a43..e1c2baf7f212 100644
|
||||
--- a/src/udev/udev-event.c
|
||||
+++ b/src/udev/udev-event.c
|
||||
@@ -881,8 +881,7 @@ static int update_devnode(UdevEvent *event) {
|
||||
return log_device_error_errno(dev, r, "Failed to get devnum: %m");
|
||||
|
||||
/* remove/update possible left-over symlinks from old database entry */
|
||||
- if (event->dev_db_clone)
|
||||
- (void) udev_node_update_old_links(dev, event->dev_db_clone);
|
||||
+ (void) udev_node_update_old_links(dev, event->dev_db_clone);
|
||||
|
||||
if (!uid_is_valid(event->uid)) {
|
||||
r = device_get_devnode_uid(dev, &event->uid);
|
||||
@@ -945,8 +944,7 @@ static int udev_event_on_move(UdevEvent *event) {
|
||||
sd_device *dev = event->dev;
|
||||
int r;
|
||||
|
||||
- if (event->dev_db_clone &&
|
||||
- sd_device_get_devnum(dev, NULL) < 0) {
|
||||
+ if (sd_device_get_devnum(dev, NULL) < 0) {
|
||||
r = device_copy_properties(dev, event->dev_db_clone);
|
||||
if (r < 0)
|
||||
log_device_debug_errno(dev, r, "Failed to copy properties from cloned sd_device object, ignoring: %m");
|
||||
@@ -992,7 +990,7 @@ int udev_event_execute_rules(UdevEvent *event,
|
||||
if (r < 0)
|
||||
return log_device_debug_errno(dev, r, "Failed to clone sd_device object: %m");
|
||||
|
||||
- if (event->dev_db_clone && sd_device_get_devnum(dev, NULL) >= 0)
|
||||
+ if (sd_device_get_devnum(dev, NULL) >= 0)
|
||||
/* Disable watch during event processing. */
|
||||
(void) udev_watch_end(event->dev_db_clone);
|
||||
|
||||
@@ -1030,8 +1028,6 @@ int udev_event_execute_rules(UdevEvent *event,
|
||||
|
||||
device_set_is_initialized(dev);
|
||||
|
||||
- event->dev_db_clone = sd_device_unref(event->dev_db_clone);
|
||||
-
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -0,0 +1,93 @@
|
||||
From e0e789c1e97e2cdf1cafe0c6b7d7e43fa054f151 Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Mon, 14 Sep 2020 15:21:04 +0900
|
||||
Subject: [PATCH] udev: re-assign ID_NET_DRIVER=, ID_NET_LINK_FILE=,
|
||||
ID_NET_NAME= properties on non-'add' uevent
|
||||
|
||||
Previous commit makes drop ID_NET_DRIVER=, ID_NET_LINK_FILE=, and
|
||||
ID_NET_NAME= properties for network interfaces on 'move' uevent.
|
||||
ID_NET_DRIVER= and ID_NET_LINK_FILE= properties are used by networkctl.
|
||||
ID_NET_NAME= may be used by end-user rules or programs. So, let's
|
||||
re-assign them on 'move' uevent. (Note that strictly speaking, this
|
||||
makes them re-assigned on all but 'remove' uevent.)
|
||||
|
||||
Reference:https://github.com/systemd/systemd/commit/e0e789c1e97e2cdf1cafe0c6b7d7e43fa054f151
|
||||
Conflict:context adaptation
|
||||
---
|
||||
diff --git a/rules/80-net-setup-link.rules b/rules/80-net-setup-link.rules
|
||||
index 6e411a9..bafc3fb 100644
|
||||
--- a/rules/80-net-setup-link.rules
|
||||
+++ b/rules/80-net-setup-link.rules
|
||||
@@ -4,7 +4,7 @@ SUBSYSTEM!="net", GOTO="net_setup_link_end"
|
||||
|
||||
IMPORT{builtin}="path_id"
|
||||
|
||||
-ACTION!="add", GOTO="net_setup_link_end"
|
||||
+ACTION=="remove", GOTO="net_setup_link_end"
|
||||
|
||||
IMPORT{builtin}="net_setup_link"
|
||||
|
||||
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
|
||||
index 5fa439b..9c13906 100644
|
||||
--- a/src/udev/net/link-config.c
|
||||
+++ b/src/udev/net/link-config.c
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "conf-files.h"
|
||||
#include "conf-parser.h"
|
||||
#include "def.h"
|
||||
+#include "device-private.h"
|
||||
#include "device-util.h"
|
||||
#include "ethtool-util.h"
|
||||
#include "fd-util.h"
|
||||
@@ -480,6 +481,7 @@ no_rename:
|
||||
|
||||
int link_config_apply(link_config_ctx *ctx, const link_config *config, sd_device *device, const char **ret_name) {
|
||||
const char *new_name;
|
||||
+ DeviceAction a;
|
||||
int r;
|
||||
|
||||
assert(ctx);
|
||||
@@ -487,6 +489,20 @@ int link_config_apply(link_config_ctx *ctx, const link_config *config, sd_device
|
||||
assert(device);
|
||||
assert(ret_name);
|
||||
|
||||
+ r = device_get_action(device, &a);
|
||||
+ if (r < 0)
|
||||
+ return log_device_error_errno(device, r, "Failed to get ACTION= property: %m");
|
||||
+
|
||||
+ if (!IN_SET(a, DEVICE_ACTION_ADD, DEVICE_ACTION_BIND, DEVICE_ACTION_MOVE)) {
|
||||
+ log_device_debug(device, "Skipping to apply .link settings on '%s' uevent.", device_action_to_string(a));
|
||||
+
|
||||
+ r = sd_device_get_sysname(device, ret_name);
|
||||
+ if (r < 0)
|
||||
+ return log_device_error_errno(device, r, "Failed to get sysname: %m");
|
||||
+
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
r = link_config_apply_ethtool_settings(&ctx->ethtool_fd, config, device);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -495,9 +511,17 @@ int link_config_apply(link_config_ctx *ctx, const link_config *config, sd_device
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
- r = link_config_generate_new_name(ctx, config, device, &new_name);
|
||||
- if (r < 0)
|
||||
- return r;
|
||||
+ if (a == DEVICE_ACTION_MOVE) {
|
||||
+ log_device_debug(device, "Skipping to apply Name= and NamePolicy= on '%s' uevent.", device_action_to_string(a));
|
||||
+
|
||||
+ r = sd_device_get_sysname(device, &new_name);
|
||||
+ if (r < 0)
|
||||
+ return log_device_error_errno(device, r, "Failed to get sysname: %m");
|
||||
+ } else {
|
||||
+ r = link_config_generate_new_name(ctx, config, device, &new_name);
|
||||
+ if (r < 0)
|
||||
+ return r;
|
||||
+ }
|
||||
|
||||
*ret_name = new_name;
|
||||
|
||||
--
|
||||
2.27.0
|
||||
256
backport-udev-split-link_config_apply-into-small-pieces.patch
Normal file
256
backport-udev-split-link_config_apply-into-small-pieces.patch
Normal file
@ -0,0 +1,256 @@
|
||||
From 2e17fed5f3000175f3ea67ece47fb7fd6ca41efa Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Tue, 15 Sep 2020 10:41:38 +0900
|
||||
Subject: [PATCH] udev: split link_config_apply() into small pieces
|
||||
|
||||
Reference:https://github.com/systemd/systemd/commit/2e17fed5f3000175f3ea67ece47fb7fd6ca41efa
|
||||
Conflict:context adaptation
|
||||
---
|
||||
src/udev/net/link-config.c | 154 ++++++++++++++++++++++++-------------
|
||||
src/udev/net/link-config.h | 4 +-
|
||||
2 files changed, 104 insertions(+), 54 deletions(-)
|
||||
|
||||
diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c
|
||||
index 6a414db..8453785 100644
|
||||
--- a/src/udev/net/link-config.c
|
||||
+++ b/src/udev/net/link-config.c
|
||||
@@ -320,67 +320,94 @@ static int get_mac(sd_device *device, MACAddressPolicy policy, struct ether_addr
|
||||
return 1;
|
||||
}
|
||||
|
||||
-int link_config_apply(link_config_ctx *ctx, link_config *config,
|
||||
- sd_device *device, const char **name) {
|
||||
- struct ether_addr generated_mac;
|
||||
- struct ether_addr *mac = NULL;
|
||||
- const char *new_name = NULL;
|
||||
- const char *old_name;
|
||||
- unsigned speed, name_type = NET_NAME_UNKNOWN;
|
||||
- NamePolicy policy;
|
||||
- int r, ifindex;
|
||||
-
|
||||
- assert(ctx);
|
||||
+static int link_config_apply_ethtool_settings(int *ethtool_fd, const link_config *config, sd_device *device) {
|
||||
+ const char *name;
|
||||
+ int r;
|
||||
+
|
||||
+ assert(ethtool_fd);
|
||||
assert(config);
|
||||
assert(device);
|
||||
- assert(name);
|
||||
|
||||
- r = sd_device_get_sysname(device, &old_name);
|
||||
+ r = sd_device_get_sysname(device, &name);
|
||||
if (r < 0)
|
||||
- return r;
|
||||
+ return log_device_error_errno(device, r, "Failed to get sysname: %m");
|
||||
|
||||
- r = ethtool_set_glinksettings(&ctx->ethtool_fd, old_name,
|
||||
+ r = ethtool_set_glinksettings(ethtool_fd, name,
|
||||
config->autonegotiation, config->advertise,
|
||||
config->speed, config->duplex, config->port);
|
||||
- if (r < 0) {
|
||||
|
||||
+ if (r < 0) {
|
||||
if (config->port != _NET_DEV_PORT_INVALID)
|
||||
- log_warning_errno(r, "Could not set port (%s) of %s: %m", port_to_string(config->port), old_name);
|
||||
+ log_device_warning_errno(device, r, "Could not set port '%s', ignoring: %m", port_to_string(config->port));
|
||||
|
||||
if (!eqzero(config->advertise))
|
||||
- log_warning_errno(r, "Could not set advertise mode: %m"); /* TODO: include modes in the log message. */
|
||||
+ log_device_warning_errno(device, r, "Could not set advertise mode, ignoring: %m"); /* TODO: include modes in the log message. */
|
||||
|
||||
if (config->speed) {
|
||||
- speed = DIV_ROUND_UP(config->speed, 1000000);
|
||||
+ unsigned speed = DIV_ROUND_UP(config->speed, 1000000);
|
||||
if (r == -EOPNOTSUPP) {
|
||||
- r = ethtool_set_speed(&ctx->ethtool_fd, old_name, speed, config->duplex);
|
||||
+ r = ethtool_set_speed(ethtool_fd, name, speed, config->duplex);
|
||||
if (r < 0)
|
||||
- log_warning_errno(r, "Could not set speed of %s to %u Mbps: %m", old_name, speed);
|
||||
+ log_device_warning_errno(device, r, "Could not set speed to %uMbps, ignoring: %m", speed);
|
||||
}
|
||||
}
|
||||
|
||||
- if (config->duplex !=_DUP_INVALID)
|
||||
- log_warning_errno(r, "Could not set duplex of %s to (%s): %m", old_name, duplex_to_string(config->duplex));
|
||||
+ if (config->duplex != _DUP_INVALID)
|
||||
+ log_device_warning_errno(device, r, "Could not set duplex to %s, ignoring: %m", duplex_to_string(config->duplex));
|
||||
}
|
||||
|
||||
- r = ethtool_set_wol(&ctx->ethtool_fd, old_name, config->wol);
|
||||
+ r = ethtool_set_wol(ethtool_fd, name, config->wol);
|
||||
if (r < 0)
|
||||
- log_warning_errno(r, "Could not set WakeOnLan of %s to %s: %m",
|
||||
- old_name, wol_to_string(config->wol));
|
||||
+ log_device_warning_errno(device, r, "Could not set WakeOnLan to %s, ignoring: %m", wol_to_string(config->wol));
|
||||
|
||||
- r = ethtool_set_features(&ctx->ethtool_fd, old_name, config->features);
|
||||
+ r = ethtool_set_features(ethtool_fd, name, config->features);
|
||||
if (r < 0)
|
||||
- log_warning_errno(r, "Could not set offload features of %s: %m", old_name);
|
||||
+ log_device_warning_errno(device, r, "Could not set offload features, ignoring: %m");
|
||||
|
||||
if (config->channels.rx_count_set || config->channels.tx_count_set || config->channels.other_count_set || config->channels.combined_count_set) {
|
||||
- r = ethtool_set_channels(&ctx->ethtool_fd, old_name, &config->channels);
|
||||
+ r = ethtool_set_channels(ethtool_fd, name, &config->channels);
|
||||
if (r < 0)
|
||||
- log_warning_errno(r, "Could not set channels of %s: %m", old_name);
|
||||
+ log_device_warning_errno(device, r, "Could not set channels, ignoring: %m");
|
||||
}
|
||||
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static int link_config_apply_rtnl_settings(sd_netlink **rtnl, const link_config *config, sd_device *device) {
|
||||
+ struct ether_addr generated_mac, *mac = NULL;
|
||||
+ int ifindex, r;
|
||||
+
|
||||
+ assert(rtnl);
|
||||
+ assert(config);
|
||||
+ assert(device);
|
||||
+
|
||||
r = sd_device_get_ifindex(device, &ifindex);
|
||||
if (r < 0)
|
||||
- return log_device_warning_errno(device, r, "Could not find ifindex: %m");
|
||||
+ return log_device_error_errno(device, r, "Could not find ifindex: %m");
|
||||
+
|
||||
+ if (IN_SET(config->mac_address_policy, MAC_ADDRESS_POLICY_PERSISTENT, MAC_ADDRESS_POLICY_RANDOM)) {
|
||||
+ if (get_mac(device, config->mac_address_policy, &generated_mac) > 0)
|
||||
+ mac = &generated_mac;
|
||||
+ } else
|
||||
+ mac = config->mac;
|
||||
+
|
||||
+ r = rtnl_set_link_properties(rtnl, ifindex, config->alias, mac, config->mtu);
|
||||
+ if (r < 0)
|
||||
+ log_device_warning_errno(device, r, "Could not set Alias=, MACAddress= or MTU=, ignoring: %m");
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static int link_config_generate_new_name(const link_config_ctx *ctx, const link_config *config, sd_device *device, const char **ret_name) {
|
||||
+ unsigned name_type = NET_NAME_UNKNOWN;
|
||||
+ const char *new_name = NULL;
|
||||
+ NamePolicy policy;
|
||||
+ int r;
|
||||
+
|
||||
+ assert(ctx);
|
||||
+ assert(config);
|
||||
+ assert(device);
|
||||
+ assert(ret_name);
|
||||
|
||||
(void) link_unsigned_attribute(device, "name_assign_type", &name_type);
|
||||
|
||||
@@ -390,15 +417,13 @@ int link_config_apply(link_config_ctx *ctx, link_config *config,
|
||||
goto no_rename;
|
||||
}
|
||||
|
||||
- if (ctx->enable_name_policy && config->name_policy)
|
||||
- for (NamePolicy *p = config->name_policy; !new_name && *p != _NAMEPOLICY_INVALID; p++) {
|
||||
+ if (ctx->enable_name_policy && config->name_policy)
|
||||
+ for (NamePolicy *p = config->name_policy; *p != _NAMEPOLICY_INVALID; p++) {
|
||||
policy = *p;
|
||||
-
|
||||
switch (policy) {
|
||||
case NAMEPOLICY_KERNEL:
|
||||
if (name_type != NET_NAME_PREDICTABLE)
|
||||
continue;
|
||||
-
|
||||
/* The kernel claims to have given a predictable name, keep it. */
|
||||
log_device_debug(device, "Policy *%s*: keeping predictable kernel name",
|
||||
name_policy_to_string(policy));
|
||||
@@ -406,7 +431,6 @@ int link_config_apply(link_config_ctx *ctx, link_config *config,
|
||||
case NAMEPOLICY_KEEP:
|
||||
if (!IN_SET(name_type, NET_NAME_USER, NET_NAME_RENAMED))
|
||||
continue;
|
||||
-
|
||||
log_device_debug(device, "Policy *%s*: keeping existing userspace name",
|
||||
name_policy_to_string(policy));
|
||||
goto no_rename;
|
||||
@@ -428,28 +452,54 @@ int link_config_apply(link_config_ctx *ctx, link_config *config,
|
||||
default:
|
||||
assert_not_reached("invalid policy");
|
||||
}
|
||||
- }
|
||||
+ if (ifname_valid(new_name))
|
||||
+ break;
|
||||
+ }
|
||||
|
||||
- if (new_name)
|
||||
+ if (new_name) {
|
||||
log_device_debug(device, "Policy *%s* yields \"%s\".", name_policy_to_string(policy), new_name);
|
||||
- else if (config->name) {
|
||||
- new_name = config->name;
|
||||
- log_device_debug(device, "Policies didn't yield a name, using specified Name=%s.", new_name);
|
||||
- } else
|
||||
- log_device_debug(device, "Policies didn't yield a name and Name= is not given, not renaming.");
|
||||
- no_rename:
|
||||
+ *ret_name = new_name;
|
||||
+ return 0;
|
||||
+ }
|
||||
|
||||
- if (IN_SET(config->mac_address_policy, MAC_ADDRESS_POLICY_PERSISTENT, MAC_ADDRESS_POLICY_RANDOM)) {
|
||||
- if (get_mac(device, config->mac_address_policy, &generated_mac) > 0)
|
||||
- mac = &generated_mac;
|
||||
- } else
|
||||
- mac = config->mac;
|
||||
+ if (config->name) {
|
||||
+ log_device_debug(device, "Policies didn't yield a name, using specified Name=%s.", config->name);
|
||||
+ *ret_name = config->name;
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ log_device_debug(device, "Policies didn't yield a name and Name= is not given, not renaming.");
|
||||
|
||||
- r = rtnl_set_link_properties(&ctx->rtnl, ifindex, config->alias, mac, config->mtu);
|
||||
+no_rename:
|
||||
+ r = sd_device_get_sysname(device, ret_name);
|
||||
+ if (r < 0)
|
||||
+ return log_device_error_errno(device, r, "Failed to get sysname: %m");
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+int link_config_apply(link_config_ctx *ctx, const link_config *config, sd_device *device, const char **ret_name) {
|
||||
+ const char *new_name;
|
||||
+ int r;
|
||||
+
|
||||
+ assert(ctx);
|
||||
+ assert(config);
|
||||
+ assert(device);
|
||||
+ assert(ret_name);
|
||||
+
|
||||
+ r = link_config_apply_ethtool_settings(&ctx->ethtool_fd, config, device);
|
||||
+ if (r < 0)
|
||||
+ return r;
|
||||
+
|
||||
+ r = link_config_apply_rtnl_settings(&ctx->rtnl, config, device);
|
||||
if (r < 0)
|
||||
- return log_warning_errno(r, "Could not set Alias=, MACAddress= or MTU= on %s: %m", old_name);
|
||||
+ return r;
|
||||
+
|
||||
+ r = link_config_generate_new_name(ctx, config, device, &new_name);
|
||||
+ if (r < 0)
|
||||
+ return r;
|
||||
|
||||
- *name = new_name;
|
||||
+ *ret_name = new_name;
|
||||
|
||||
return 0;
|
||||
}
|
||||
diff --git a/src/udev/net/link-config.h b/src/udev/net/link-config.h
|
||||
index 26666ad..4922be6 100644
|
||||
--- a/src/udev/net/link-config.h
|
||||
+++ b/src/udev/net/link-config.h
|
||||
@@ -70,8 +70,8 @@ int link_load_one(link_config_ctx *ctx, const char *filename);
|
||||
int link_config_load(link_config_ctx *ctx);
|
||||
bool link_config_should_reload(link_config_ctx *ctx);
|
||||
|
||||
-int link_config_get(link_config_ctx *ctx, sd_device *device, struct link_config **ret);
|
||||
-int link_config_apply(link_config_ctx *ctx, struct link_config *config, sd_device *device, const char **name);
|
||||
+int link_config_get(link_config_ctx *ctx, sd_device *device, link_config **ret);
|
||||
+int link_config_apply(link_config_ctx *ctx, const link_config *config, sd_device *device, const char **ret_name);
|
||||
int link_get_driver(link_config_ctx *ctx, sd_device *device, char **ret);
|
||||
|
||||
const char *name_policy_to_string(NamePolicy p) _const_;
|
||||
--
|
||||
2.27.0
|
||||
16
systemd.spec
16
systemd.spec
@ -16,7 +16,7 @@
|
||||
Name: systemd
|
||||
Url: https://www.freedesktop.org/wiki/Software/systemd
|
||||
Version: 243
|
||||
Release: 55
|
||||
Release: 56
|
||||
License: MIT and LGPLv2+ and GPLv2+
|
||||
Summary: System and Service Manager
|
||||
|
||||
@ -172,6 +172,15 @@ Patch0124: backport-0013-CVE-2020-13776-parse-util-rewrite-parse_mode-on-to
|
||||
Patch0125: backport-0014-CVE-2020-13776-user-util-be-stricter-in-parse_uid.patch
|
||||
Patch0126: backport-0015-CVE-2020-13776-parse-util-also-parse-integers-prefixed-with-0b-and-.patch
|
||||
Patch0127: backport-udev-rename-the-persistent-link-for-ATA-devices.patch
|
||||
Patch0128: backport-udev-drop-unnecessary-checks.patch
|
||||
Patch0129: backport-device-propagate-reload-events-from-devices-on-every.patch
|
||||
Patch0130: backport-core-device-remove-.device-unit-corresponding-to-DEV.patch
|
||||
Patch0131: backport-udev-split-link_config_apply-into-small-pieces.patch
|
||||
Patch0132: backport-Revert-udev-import-the-full-db-on-MOVE-events-for-de.patch
|
||||
Patch0133: backport-udev-re-assign-ID_NET_DRIVER-ID_NET_LINK_FILE-ID_NET.patch
|
||||
Patch0134: backport-udev-allow-to-match-OriginalName-with-renamed-interf.patch
|
||||
Patch0135: backport-udev-do-not-update-return-value-on-failure.patch
|
||||
Patch0136: backport-test-add-test-for-device-renaming-issue-16967.patch
|
||||
|
||||
|
||||
#openEuler
|
||||
@ -1561,7 +1570,10 @@ fi
|
||||
%exclude /usr/share/man/man3/*
|
||||
|
||||
%changelog
|
||||
* Mon Feb 28 2022 yangmingtai <yangmingtai@huawei.com> - 243-54
|
||||
* Wed May 18 2022 yangmingtai <yangmingtai@huawei.com> - 243-56
|
||||
- remove old device on move event
|
||||
|
||||
* Mon Feb 28 2022 yangmingtai <yangmingtai@huawei.com> - 243-55
|
||||
- add backport-udev-rename-the-persistent-link-for-ATA-devices.patch
|
||||
for the link of ATA devices
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user