Repository navigation
Description
Submission type
- [ XX ] Bug report
- Request for enhancement (RFE)
NOTE: Do not submit anything other than bug reports or RFEs via the issue tracker!
systemd version the issue has been seen with
…systemd-210, but still present upstream.
NOTE: Do not submit bug reports about anything but the two most recently released systemd versions upstream!
Used distribution
…SLES12-SP1
In case of bug report: Expected behaviour you didn't see
…On shutdown, filesystems should not be unmounted until
all user session have been stopped.
In case of bug report: Unexpected behaviour you saw
…On shutdown, unmount of filesystems failed because some
user sessions were still running and were keeping the filesystem busy.
The network was then shutdown, still before the user session had completed.
The filesystems were NFS filesystem, and the user processes were
blocked writing to the NFS filesystem. Now that the network was gone,
they blocked indefinitely.
In case of bug report: Steps to reproduce the problem
List an NFS filesystem in /etc/fstab as "noauto", then reboot, then mount
the filesysytem manually.
Then write a large file (e.g. use dd to create a few gigabytes) to the NFS filesystem.
This needs to be something that will take a while to complete.
The system needs enough memory to buffer enough data that flushing it
out will take tens of seconds. This isn't an enormous requirement, but means
that it might be harder to duplicating on a tiny VM..
Once the write has started, "shutdown -r now".
This will
- signal the 'dd' process, but it takes a while to die as it has to flush out the data
- try to unmount the NFS filesystem, and fail
- shut down the network
- try to sys_sync, and hang.
The root of the problem seems to be that fstab-generator doesn't create a Before=
dependency for noauto (and nofail) mounts. (in SLES, we also avoid the Before=
for "bg" nfs mounts, and that is what actually lead to us seeing the problem).
The "Before" dependency usually ensures that the mountpoints are unmounted after
some other stuff, which includes stopping the user processes.
"noauto" mounts don't get that ordering, so they are unmounted immediately.
I think that we need a new fs.target, possibly optional-fs.target.
fstab-generator would always create a Before= ordering, either against
an existing XX-fs.target, or against optional-fs.target.
The tricky bit, then, is getting optional-fs.target to start up, ever though some things
that are "Before" it might not have done so.
I think that this can be done be Want-ing optional-fs.target is a separate transaction from the transaction that mounts filesystem. I suspect you understand the details of that better than me.
In any case, *.mounts that are not Before=XX-fs.target already need to be Before=optional-fs.target, and user sessions need to be After=optional-fs.target, without Wanting that target or mount points.
This idea seems to work in some simple testing, but I haven't pushed it very hard.
Activity
marcosfrm commentedon May 19, 2017
#5547 ?
fbuihuu commentedon May 19, 2017
I believe this PR only addressed the "noauto" case.
However the same issue stands and remains for mountpoint entries using the "nofail" option: in this case you don't want to delay the boot process with such mount entries but you still want them to be ordered correctly when shutting down.
I hacked a fix a while ago #2036, but it's hack.
@keszybz suggested however:
neilbrown commentedon May 19, 2017
Asymmetrical Before/After would be a great solution. In general I'm in favor of being able to make precise requests, rather than having some related behavior assumed.
Another option might be a way to say that a mount unit should be treated as ready (for the purpose of before/after) immediately, rather than only after the mount command succeed. e.g. a bit like "Type=simple" for service units.
[mount]
NoWait = True
Werkov commentedon May 24, 2017
(
nofailimplying noBefore={local,remote}-fs.targetordering is a bit counter-intuitive to me but that's perhaps misunderstood vocabulary on my side.)Anyway, another use case justifying asymmetric dependencies might be socket activated services. Typically, clients don't need explicit ordering upon startup but on shutdown client should be gracefully terminated before their servers (services).
Another possibility (with unclear implementation at the moment) would be behavior analogous to
network.targetandnetwork-online.target.remote-fs-base.targetandremote-fs-ready.target,remote-fs-base.targetwould be active immediately aftermount -o bgexit andremote-fs-ready.targetonly later (this just a specific idea), all potential users would haveAfter=remote-fs-base.targetwhich would mainly ensure proper ordering during shutdown.neilbrown commentedon May 26, 2017
I've been exploring this issue some more, and experimenting a bit, and I now think the solution is easy.
The ref to #5547 is appropriate - we need to the same thing for other mount types.
i.e. we should always add a Before= dependency on either local-fs.target or remote-fs.target.
Doing this fixes the problem at shutdown, and doesn't introduce any problem.
The correct way to handle nofail is by using Wants, which is done already.
Automounts don't need any handling as they aren't started in the same transaction.
I've prepare a patch which does this and explains in even more detail.
I'll submit a pull request.
Thank everyone for providing thoughts and context.
fbuihuu commentedon May 29, 2017
The problem by adding
Before=dependency whennofailis used is that the whole boot sequence will wait for such mount points to be setup. It won't make the transaction fails (sinceWants=is used in this case) but it will delay the boot process if the device is missing.For example, the user might have a "nofail" entry in fstab used to mount a USB stick and expect the system to mount it automatically if it's plugged but don't expect the system to fail nor wait for the device until a timeout expires if it's missing.
neilbrown commentedon May 29, 2017
If it is a timeout issue, then it should be addressed by setting a timeout.
I suspect (though I haven't tested) that we could set a JobTimeout on the .mount unit, and boot would then continue after the timeout.
If we set it to "0.01", then local-fs.target should quickly timeout waiting for the .mount, but the .mount will still be stopped after all the users are stopped.... I wonder if that would cause other problems at shutdown... Maybe something like "5" would be safer.
Given that device discovery is async, assuming zero timeout is naive, I think.
fbuihuu commentedon May 29, 2017
If I'm following you, the timeout idea you're proposing is the same fix I submitted some time ago:
4e90ab1 through #2036.
But as I said earlier it was (and is probably still) considered as a hack and shouldn't be considered as a long term solution.
poettering commentedon May 29, 2017
yeah, this issue doesn't fit into the current model nicely. Because ordering is symmetric regarding start/stop ordering things for shutdown would also imply ordering things at startup, and that's problematic as this means delaying user sessions if a unit happens to be requested in some way.
I don't really see a nice way out here... We'd have to add asymmteric ordering, but I am not enthusiastic about the idea I must say...
neilbrown commentedon May 29, 2017
Clearly we think alike! I was considering that option, but I meant to suggest putting the JobTimeout on the mount unit, not the device unit. That is more focused, as it is the "mount" that is "nofail", not the device. It would mean that if the device did turn up in the first 90 seconds, it would still get mounted, even though the rest of boot didn't wait for it ... a bit like "bg" NFS mounts. But if other's don't like the idea....
neilbrown commentedon May 29, 2017
Understandable. I'm not enthusiastic about shutdown hanging because things are stopped in the wrong order. I'm also not enthusiastic about designs which conflate conceptually distinct concepts such as start-up order and shutdown order :-(
There is another approach. It would only solve the ordering problem with mounts, but that would do for now.
The handling for "stop" on mount units could be changed so that the unmount is retried (exponential timeout? Add MNT_FORCE?) until it succeeds (or maybe until a long timeout fires).
That way, jobs that are ordered after the mount is stopped, will not actually run until the filesystem is unmounted. Currently they can run while the filesystem is still mounted.
fstab-generator: add Before= dependency to mount units using automount
neilbrown commentedon May 29, 2017
In the interests of forward-progress, I've revised pull request 6037 to only change the behaviour in the automount case, and leave the "nofail" case unchanged.
Are there any arguments against having the Before= ordering for automount mounts?
5 remaining items
neilbrown commentedon Jun 8, 2017
I had a brainwave....
In order for nofail mount units to function correctly, we need the Before= ordering to be honoured at shutdown, but not at startup. This can be done by starting the mount unit in a separate transaction. This is easily done using a timer unit.
The pull request mentioned above changes "nofail" mounts to be handled just like "automount" mounts except that a timer unit is used instead of an automount unit. The timeout is zero, so the mount is attempted immediately, but in a different transaction.
I think this should solve the issue to everyone's satisfaction.
neilbrown commentedon Jun 9, 2017
Ok, that brainwave wasn't so good. Transactions aren't as independent as I thought.
So I dug deeper, following the patch from @fbuihuu above and I found that since a6d305f remote filesystems get a Before=remote-fs.target when they are mounted. Local filesystems don't get a matching fix though.
So I've revise my patch to throw away the timer-based-automount idea, and just add Before=local-fs.target when non-remote filesystems are mounted.
I think this should completely resolve the issue (but hey, I 've thought that before...)
fbuihuu commentedon Jun 12, 2017
Yeah your version looks better than mine. IOW adding dynamically
Before=local-fs.targetinmount_setup_existing_unit()seems the right approach if we want to keep this simple without adding the asymmetrical deps.Actually I'm wondering if this couldn't be factorized in
mount_setup_unit()instead sincemount_setup_new_unit()is doing quite a similar initialization and this seems quite Independent of how the mount unit got generated.Also we might want to document the fact that by default (
DefaultDependencies=yes) mount units will be always ordered after {local-fs/remote-fs.target} during shutdown even if the don't have the asymmetric Before= one during the boot process.neilbrown commentedon Jun 13, 2017
I've pushed a new commit which updated the systemd.mount documentation as suggested: b975e8692b356f9646fb4c12ed3a4f3ef323bdd7
Suggestions for improvements most welcome.
Refactoring might be a good idea, but that requires someone who understands the code, and I'm still making too many mistakes..
core/mount: ensure filesystems are unmounted at the correct time
LionNatsu commentedon Jul 10, 2017
This always appears during the shutdown process recently... Is it relevant to the issue?
Log:
Unit status:
neilbrown commentedon Jul 11, 2017
It could be related. What version of systemd are you running? Does it have this patch included?
var-lib-nfs-rpc_pipefs.mount need to be "After" systemd-tmpfiles-setup.service because in some contexts, /var/lib/nfs doesn't exist until tmpfile has run. But tmpfiles shouldn't run until the local filesystems have been been mounted... so var-lib-nfs-rpc_pipefs mustn't be treated as a local mount...
None of this is relevant at shutdown. Any ordering with systemd-tmpfiles-setup.service is pointless at shutdown because shutdown down that service does nothing.
I cannot think of any straight forward way to fix this. It is another case where ordering that makes perfect sense at start-up, makes no sense at all at shutdown.
You could possibly remove the "Conflicts=shutdown.target" line from /usr/lib/systemd/system/systemd-tmpfiles-setup.service
I'm not sure that is the "right" thing to do, but it would be interesting to see if it helps.
LionNatsu commentedon Jul 11, 2017
@neilbrown
systemd-233, with some patches. You may check the list here:
https://github.com/AOSC-Dev/aosc-os-abbs/tree/cc3e584/extra-admin/systemd/autobuild/patches
It does help, now there is only
systemd[1]: Unmounting /home....But wait, does it only "ignore" the chain of shutting down "systemd-tmpfiles-setup.service"? Because I can still see the cycle on
var-lib-nfs-rpc_pipefs.mount: Before=local-fs.targetbysystemctl show. Are there any side-effects?neilbrown commentedon Jul 11, 2017
Not this patch though. So something else is adding the Before=local-fs.target.
Does the /var/lib/nfs/rpc_pipefs filesystem get mounted by some script? If it gets mounted before systemd tries to mount it, that could cause this. If so, can you retry removing the mount from that script?
Yes, the cycle is still there, but as systemd doesn't try to shut systemd-tmpfiles-setup.service down, it doesn't see the cycle.
Possibly. I don't really know what they are. If you used systemd to stop everything, and then restart, without actually doing a reboot, it might not quite work correctly... I don't know how important that is.
LionNatsu commentedon Jul 11, 2017
The unit file is in source code repository, in the package
nfs-utilsv2.1.1.You may check out the repository here:
Unit files: http://git.linux-nfs.org/?p=steved/nfs-utils.git;a=tree;f=systemd
Shortlog: http://git.linux-nfs.org/?p=steved/nfs-utils.git;a=shortlog
Note that, the commit "nfs-server-generator: handle 'noauto' mounts correctly" mentioned systemd #5249 (Issue "Documentation for RequiresMountsFor= with
noautomount points is incorrect").I'll rebuild the nfs-utils using the newest source code in that repository , and see what will happen.
Babber commentedon Dec 28, 2021
Dear All,
I assume I bumped into the same bug in systemd 245 (245.4-4ubuntu3.13). I have a service that executes some jobs before shutdown and it looks like this:
But when my script runs, I find that the volume that I'd like to access is already gone, sometimes with an error message in the logs saying
Could you confirm if this is the same bug indeed? It looks similar to the one posted by @LionNatsu. Is there since some workaround (eg. some fix to the service file?..) that would allow access to mounted (local) file systems at shutdown/reboot?
Cheers
Werkov commentedon Jan 3, 2022
This (not tested myself):
Babber commentedon Jan 5, 2022
Thank you, @Werkov for your suggestion! It works! Actually, my original solution turns out to be working as well. :) I had an issue at hand much more convoluted than I thought first with a loop device refusing to detach, etc, and I was looking in the wrong direction at the beginning of the debugging process. But thank you anyway, it's nice to have this different approach to run my shutdown jobs!
core: introduce asymmetrical Before=/After= ordering constraints effe…