Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite the mount resource to fix at least one existing issue #744

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ffrank
Copy link
Contributor

@ffrank ffrank commented Mar 6, 2024

Let's go. It's still not perfect, but simpler and more correct.

The mount approach was flawed. It relied on editing fstab, then restarting the
systemd service that is responsible for mounting all defined filesystems. Among
other issues, this approach made it impossible for mgmt to unmount managed
filesystems, because after removing them from fstab, they would just be ignored
by systemd.

The new approach is based on creating a systemd unit for each managed mount,
through a unit file in /etc/systemd/system. These files are managed by wrapped
File resources now. Then a wrapped Svc resource manages the lifecycle of the
mount. This works even after removing the unit definition from systemd, because
as long as the filesystem is still mounted, systemd will be able to derive a
transient unit that can be managed.

This also simplifies the logic of the MountRes a lot, because we don't have to
be so careful anymore about matching existing fstab entries to what is expected
by a given Mount resource. We just overwrite the unit definition with whatever
is specified, and rely on systemd to handle the details. Systemd will even
create mount points if they don't yet exist.

Currently this approach is not yet equipped to handle the case that a mount
could be defined via fstab already, or through a unit file that is in a
different location than /etc/systemd/system. As such, this second iteration
should be considered as a partial (if more rounded than the first one)
solution.

Fixes purpleidea#525
As the --converged-timeout does not work anymore, we cannot use this current
approach to test the mount resource. Simple resources like file can sync in
time before the main loop terminates, but MountRes cannot. Therefor this test
script is skipping itself for now. We should replace all of these tests with
a more sophisticated approach.

Still, while we have them, we can reduce some copy/paste work by adding another
util function for checking sudo.
@ffrank
Copy link
Contributor Author

ffrank commented Mar 6, 2024

Fixes #525

@ffrank
Copy link
Contributor Author

ffrank commented Mar 6, 2024

The wrapping of resources is based on how NspawnRes does it.

But I wonder: It would feel much better to just run Watch of both the wrapped file and svc, and in the mount Watch, only wait for the svc to finish, and then also finish.

@purpleidea
Copy link
Owner

Hey great to see this! I had a quick look first. Lots of nice work there. Here are the open issues to discuss:

  1. This removes fstab support-- I actually think that is still valuable to have, at least for now-- so how do we handle that? Do we have a separate resource? Do we have it be an optional for this resource? Do we have mount:systemd and mount:fstab ? Also see 2...

  2. Is the systemd variant of this resource (as shown here) similar enough to the svc resource that they should just be combined there? I think architecturally they're quite similar. I would need to investigate more.

  3. I'm not convinced I want shell tests to stay around. So we should consider a better approach if possible. This won't block your patch, but I want to mention it in case you have ideas.

Thanks Felix!

@ffrank
Copy link
Contributor Author

ffrank commented Mar 6, 2024

  1. It's a big hassle in terms of required code. I will say, what was there seemed to do a good enough job. The unit tests were nicely elaborate, BUT most of them never ran (they were written as methods of MountRes...). Then again, this feature opens us up to many additional edge cases I believe.
  2. The whole point here is to generate the systemd unit first, which svc does not (and should not?) do. I was considering to move the systemd stuff to some common utility code, so that mount and svc could both rely on that. But with a very small patch to svc, it was embeddable as you had proposed originally. This seems like the right approach to me atm.
  3. That shell test is basically a placeholder. It does not run. I might go ahead and propose and prototype a better approach some time, and when I do, this test should not be forgotten. So having the placeholder is valuable from my point of view.

obj.init.Running() // when started, notify engine that we're running

// // watch the unit file
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should probably be uncommented, but I want better end-to-end testing facilities first. These wrapped resources make life a little bit complicated.

// restarting `local-fs.target` and `remote-fs.target` units.
if err := mountReload(ctx); err != nil {
return false, errwrap.Wrapf(err, "error reloading /etc/fstab")
if !checkOK {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah shoot this needs an && apply

@purpleidea
Copy link
Owner

FYI as per Felix good idea we're in #745 for now until we agree on how to proceed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants