Skip to content

fstab-generator: handle nofail mounts with timer-based trigger - #6102

Closed
neilbrown wants to merge 2 commits into
systemd:mainfrom
neilbrown:nofail
Closed

neilbrown wants to merge 2 commits into
systemd:mainfrom
neilbrown:nofail

Conversation

@neilbrown

Copy link
Copy Markdown
Contributor

fstab-generator omits the Before=fs-XXX.target dependency
on automount and nofail mounts.
This causes a problem at shutdown. As the mounts are not "Before"
anything, they are initiated immediately, and might run while
services that use the mounts are still running.
This cause the mount to fail and never get unmounted.

This is particularly problematic for NFS the network can get shutdown
after these unmounts failed, and while services are still running.
If that happens, then any services (such as login sessions) using
the NFS mounts can block indefinitely - particularly if they had
written something to the NFS filesystem recently. They cannot exit
until the data is written, and that cannot happen with the network down.

So we need that "Before=" dependency, but we don't want fs-XXX.target
to have to wait for the mount to complete.

For automounts, there is no difficulty. The mount unit isn't activated
in the same transaction as the fs-XXX.target, so the ordering is not
effective. We can re-instate the Before= dependency for automounts
without causing any problems.

For nofail mounts we need a little more work. automounts set a good
example to follow. If the mount unit is activated in a separate
transaction, the Before= dependency can be restored without causing
and delays are startup. This is easily done with a timer unit.

So this patch:

  • restores the "Before=" dependency, so all mount units get it.
  • changes "nofail" handling to work much like "automount" except that
    a timer unit is created instead of an automount unit. This timer
    unit has OnActiveSec=0 and triggers the mount unit.

Fixes #5991

@arvidjaar

Copy link
Copy Markdown
Contributor

changes "nofail" handling to work much like "automount" except that a timer unit is created instead of an automount unit. This timer unit has OnActiveSec=0 and triggers the mount unit.

Somehow I miss this part of patch.

@neilbrown

Copy link
Copy Markdown
Contributor Author

Somehow I miss this part of patch.

Yeah, sorry - it isn't there any more. Someone pointed that that approach couldn't work because I was misunderstanding the independence of transaction. So I came up with a new approach.
Maybe I'm not using github properly, but is seems hard to keep conversations in one place and each pull request created a new conversation, which i would rather be part of the original issue..

@fbuihuu

fbuihuu commented Jun 12, 2017

Copy link
Copy Markdown
Contributor

Maybe I'm not using github properly, but is seems hard to keep conversations in one place and each pull request created a new conversation, which i would rather be part of the original issue..

I agree github makes it hard to follow.

I answered in the initial issue and I think this approach is the simplest one, we might want to document the new behavior though.

@fbuihuu

fbuihuu commented Jun 26, 2017

Copy link
Copy Markdown
Contributor

@poettering could you have a look at Neil's changes ?

I think they make sense and remove the need of the asymmetric deps.

@poettering

Copy link
Copy Markdown
Member

Hmm, this doesn't look right, sorry. The thing is that deps never go away after they are created. That means if you have a mount unit that is started once, then stopped it will have gained the dep, and that dep won't go away, hence a subsequent second start will be run with it in effect...

There are plans to track properly how each dep came to be, so that we can flush them out piecemeal, but that's not done yet, and not entirely trivial, but until that point I am not sure this can work...

Comment thread src/core/mount.c Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just found that the !u->default_dependencies should be inverted, i.e. the ordering dep should only be added if the mount unit has DefaultDependencies=true

@fbuihuu

fbuihuu commented Jul 3, 2017

Copy link
Copy Markdown
Contributor

Hmm, this doesn't look right, sorry. The thing is that deps never go away after they are created. That means if you have a mount unit that is started once, then stopped it will have gained the dep, and that dep won't go away, hence a subsequent second start will be run with it in effect...

Hmm I'm not sure to understand the problem here. The ordering dep patching is supposed to help during the boot process only but will have basically no effects after since at that point local-fs.target is always active.

NeilBrown added 2 commits July 4, 2017 10:14
If a mount is allowed to fail (e.g. marked "nofail" in /etc/fstab)
then it is likely that Before=local-fs.target would not be wanted,
as that could cause an unhelpful delay (and fstab-generator excludes
local-fs.target for that reason).

However, once the filesystem is mounted, it is important that it doesn't
get unmounted at shutdown until any services using it have completed,
otherwise the unmount might fail.

So at mount time, we add a Before dependency on local-fs.target.

Note that, since
 Commit: a6d305f ("mount: add remote-fs dependencies if needed
 after change")
we already auto-add a Before dependency on remote-fs.target for remote
filesystems.  This change just makes local mounts behave in the same
way.

Fixes systemd#5991
When a mount unit is mounted, one of
  Before=local-fs.target
or
  Before=network-fs.target

is added, as appropriate.  This ensures they are not unmounted before
services and session that are using them have completed.

This needs to be documented.
@neilbrown

Copy link
Copy Markdown
Contributor Author

I revised the commit to fixed the inversion of the test on ->default_dependencies.
I agree with @fbuihuu that after local-fs.target has been reached, future attempts to mount a unit with "Before=local-fs.target" will not be impacted, so adding the dependency which cannot be removed will not cause problems.

@poettering

Copy link
Copy Markdown
Member

THe initial transaction should be repeatable, i.e. you should be able to "systemctl isolate emergency.target" and back to "systemctl isolate multi-user.target" and things should work. But if the the initial transaction modified tht dep tree, than it will be different from any repetition...

@neilbrown

Copy link
Copy Markdown
Contributor Author

Thanks for the pointer to repeatability of the initial transaction. I'll take your word for it that that is useful, but I have trouble seeing it as more important than the orderly normal startup and shutdown of the system - which might be seen as systemd's core responsibility. It is the orderly shutdown that isn't working correctly here. Until the removal of individual dependencies is implemented, you might need to just trigger a "daemon-reload" once emergency.target is reached.
The initial transaction already cannot be repeated if there are nofail network filesystems.
Commit a6d305f adds Before=remote-fs.target to remote mounts when they are mounted. Given the presence of that commit, there seems little justification for rejecting this pull request.

@gonzoleeman

Copy link
Copy Markdown

Until this is fixed, mounting and unmounting of remote filesystems, particularly at shutdown, is broken.

@keszybz keszybz added the please-review PR is ready for (re-)review by a maintainer label Dec 8, 2022
@daandemeyer daandemeyer added needs-rebase and removed please-review PR is ready for (re-)review by a maintainer labels Jan 10, 2023
@brauner

brauner commented May 13, 2026

Copy link
Copy Markdown
Member

@neilbrown hey there. Didn't expect to see you here. I'm closing this since this has been unresolved for quite a few years. If this is still an issue that needs to be addressed please open a new pr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

User sessions not reliably stopped before filesystem unmounted on shutdown

8 participants