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] 6a9dcb6886

Change-Id: I5d2d9c074aa0390a6f8b7c8c0ba1c839fe26f6c5
This commit is contained in:
Damian Dabrowski 2022-12-24 01:09:29 +01:00 committed by Dmitriy Rabotyagov
parent 526293ad5b
commit 480bb0c871
1 changed files with 3 additions and 1 deletions

View File

@ -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 %}