From 54adfc9a3525fec10e1bfd0105d188f7a366f05e Mon Sep 17 00:00:00 2001 From: Damian Dabrowski Date: Sat, 24 Dec 2022 01:09:29 +0100 Subject: [PATCH] Fix mount's systemd unit dependency logic Improve logic for making systemd mount dependent on network-online.target when network filesystem is being used. This change improves feature implemented in commit [1]. Currently when device is specified by UUID or LABEL, dependency for network-online.target is added even it's not a network filesystem. We should be careful with this as it may create circular dependency. In my case, circular dependency looked like this: network.target -> network-pre.target -> netfilter-persistent.service -> local-fs.target -> var-lib-nova.mount -> network-online.target -> network.target Additionally, this commit was originally supposed to add dependency also for CIFS mounts(these ones starting from '//') but it never worked in my opinion. It was also fixed by this change. [1] https://opendev.org/openstack/ansible-role-systemd_mount/commit/6a9dcb688628a1a3900f25f72effce4f62f6900e Change-Id: I5d2d9c074aa0390a6f8b7c8c0ba1c839fe26f6c5 (cherry picked from commit 480bb0c871848f2c65f6c7312eab77c33b88ee7a) --- templates/systemd-mount.j2 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/templates/systemd-mount.j2 b/templates/systemd-mount.j2 index 2999e87..0835e5c 100644 --- a/templates/systemd-mount.j2 +++ b/templates/systemd-mount.j2 @@ -2,7 +2,9 @@ [Unit] Description=Auto mount for {{ systemd_mount_item }} -{% if not (item.what is search("^/.*")) or not (item.what is search("^//.*")) %} +{# make unit dependent on network-online.target if network filesystem is being mounted #} +{# dependency is also added for strings starting with '//' because it may indicate that CIFS/Samba is being used. #} +{% if not (item.what is search("^(/[^/]|UUID=|LABEL=).*")) %} Requires=network-online.target After=network-online.target {% endif %}