mirror of
https://github.com/versity/scoutfs.git
synced 2026-02-10 12:40:09 +00:00
We were trying to tear down our mounted file system resources in the ->kill_sb() callback. This happens relatively early in the unmount process. We call kill_block_super() in our teardown which syncs the mount and tears down the vfs structures. By tearing down in ->kill_sb() we were forced to juggle tearing down before and after the call to kill_block_super(). When we got that wrong we'd tear down too many resources and crash in kill_block_super() or we wouldn't tear down enough and leave work still pending that'd explode as we tried to shut down after kill_block_super(). It turns out the vfs has a callback specifcally to solve this ordering problem. The put_super callback is called after having synced the mount but before its totally torn down. By putting all our shutdown in there we no longer have to worry about racing with active use. Auditing the shutdown dependencies also found some bad cases where we were tearding down subsystems that were still in use. The biggest problem was shutting down locking and networking before shutting down the transaction processing which relies on both. Now we first shut down all the client processing, then all the server processing, then the lowest level common infrastructure. The trickiest part in understanding this is knowing that kill_block_super() only calls put_super during mount failure if mount got far enough to assign the root dentry to s_root. We call put_super manually ourselves in mount failure if it didn't get far enough so that all teardown goes through put_super. (You'll see this s_root test in other upstream file system error paths.) Finally while auding the setup and shutdown paths I noticed a few, trans and counters, that needed simple fixes to properly cleanup errors and only shutdown if they've been setup. This all was stressed with an xfstests that races mount and unmount across the cluster. Before this change it'd crash/hang almost instantly and with this change it runs to completion. Signed-off-by: Zach Brown <zab@versity.com>