From 31d4f35c631dde53412d344bd5721aed68a31d57 Mon Sep 17 00:00:00 2001 From: hongjinghao Date: Sat, 6 Dec 2025 17:21:38 +0800 Subject: [PATCH] umount do not move busy network mounts (cherry picked from commit d9de9187c3f10ba10745f2fa8fd69fa9fff8f558) --- ...ount-do-not-move-busy-network-mounts.patch | 88 +++++++++++++++++++ systemd.spec | 6 +- 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 backport-umount-do-not-move-busy-network-mounts.patch diff --git a/backport-umount-do-not-move-busy-network-mounts.patch b/backport-umount-do-not-move-busy-network-mounts.patch new file mode 100644 index 0000000..05d623f --- /dev/null +++ b/backport-umount-do-not-move-busy-network-mounts.patch @@ -0,0 +1,88 @@ +From cef2181cda87cbecd6e92f6d7a3bb8556067a88e Mon Sep 17 00:00:00 2001 +From: Antonio Alvarez Feijoo +Date: Mon, 10 Mar 2025 12:21:26 +0100 +Subject: [PATCH] umount: do not move busy network mounts + +If a network mount returns EBUSY on umount, the logic introduced in +6dc68a00cfc816678fd713b12ae2a4cf2ae6da85 causes shutdown to hang indefinitely on +`fstatat()` (i.e., within `is_dir(m->path, true)`). Hence, skip this logic for +network mounts (following the same motivation we use to skip read-only mounts in +this kind of file systems). + +Fixes 6dc68a00cfc816678fd713b12ae2a4cf2ae6da85 +--- + src/shutdown/umount.c | 14 +++++++++----- + src/shutdown/umount.h | 2 +- + 2 files changed, 10 insertions(+), 6 deletions(-) + +diff --git a/src/shutdown/umount.c b/src/shutdown/umount.c +index 220ae2e..068d18a 100644 +--- a/src/shutdown/umount.c ++++ b/src/shutdown/umount.c +@@ -64,7 +64,7 @@ int mount_points_list_get(const char *mountinfo, MountPoint **head) { + struct libmnt_fs *fs; + const char *path, *fstype; + unsigned long remount_flags = 0u; +- bool try_remount_ro, is_api_vfs; ++ bool try_remount_ro, is_api_vfs, is_network; + _cleanup_free_ MountPoint *m = NULL; + + r = mnt_table_next_fs(table, iter, &fs); +@@ -99,6 +99,7 @@ int mount_points_list_get(const char *mountinfo, MountPoint **head) { + PATH_STARTSWITH_SET(path, "/dev", "/sys", "/proc")) + continue; + ++ is_network = fstype_is_network(fstype); + is_api_vfs = fstype_is_api_vfs(fstype); + + /* If we are in a container, don't attempt to read-only mount anything as that brings no real +@@ -109,7 +110,7 @@ int mount_points_list_get(const char *mountinfo, MountPoint **head) { + * leave a "dirty fs") and could hang if the network is down. Note that umount2() is more + * careful and will not hang because of the network being down. */ + try_remount_ro = detect_container() <= 0 && +- !fstype_is_network(fstype) && ++ !is_network && + !is_api_vfs && + !fstype_is_ro(fstype) && + !fstab_test_yes_no_option(options, "ro\0rw\0"); +@@ -153,7 +154,11 @@ int mount_points_list_get(const char *mountinfo, MountPoint **head) { + /* Unmount sysfs/procfs/… lazily, since syncing doesn't matter there, and it's OK if + * something keeps an fd open to it. */ + .umount_lazily = is_api_vfs, +- .leaf = leaf, ++ ++ /* If a mount point is not a leaf, moving it would invalidate our mount table. ++ * If a mount point is on the network and the network is down, it can hang and block ++ * the shutdown. */ ++ .umount_move_if_busy = leaf && !is_network, + }; + + m->path = strdup(path); +@@ -410,10 +415,9 @@ static int mount_points_list_umount(MountPoint **head, bool *changed, bool last_ + *changed = true; + + /* If a mount is busy, we move it to not keep parent mount points busy. +- * If a mount point is not a leaf, moving it would invalidate our mount table. + * More moving will occur in next iteration with a fresh mount table. + */ +- if (r != -EBUSY || !m->leaf) ++ if (r != -EBUSY || !m->umount_move_if_busy) + continue; + + _cleanup_free_ char *dirname = NULL; +diff --git a/src/shutdown/umount.h b/src/shutdown/umount.h +index f8f9ae8..e76106c 100644 +--- a/src/shutdown/umount.h ++++ b/src/shutdown/umount.h +@@ -18,7 +18,7 @@ typedef struct MountPoint { + unsigned long remount_flags; + bool try_remount_ro; + bool umount_lazily; +- bool leaf; ++ bool umount_move_if_busy; + LIST_FIELDS(struct MountPoint, mount_point); + } MountPoint; + +-- +2.33.0 + diff --git a/systemd.spec b/systemd.spec index ea5d273..9117c8d 100644 --- a/systemd.spec +++ b/systemd.spec @@ -25,7 +25,7 @@ Name: systemd Url: https://systemd.io/ Version: 255 -Release: 50 +Release: 51 License: MIT and LGPLv2+ and GPLv2+ Summary: System and Service Manager @@ -928,6 +928,7 @@ Patch6873: backport-core-introduce-Unit.dependency_generation-counter-an.pa Patch6874: backport-test-add-test-case-for-issue-36031.patch Patch6875: backport-core-escape-UTF-8-in-mount-unit-Where-field-before-s.patch Patch6876: backport-fd-util-fix-path_is_root_at-when-dealing-wi.patch +Patch6877: backport-umount-do-not-move-busy-network-mounts.patch Patch9008: update-rtc-with-system-clock-when-shutdown.patch Patch9009: udev-add-actions-while-rename-netif-failed.patch @@ -2518,6 +2519,9 @@ fi %{_unitdir}/veritysetup.target %changelog +* Sat Dec 6 2025 hongjinghao - 255-51 +- umount do not move busy network mounts + * Thu Oct 30 2025 wangjiang - 255-50 - fix udevadm trigger coredump after execute mount / -- Gitee