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

apple virtiofs: fix racy mount setup #23118

Merged
merged 2 commits into from
Jun 27, 2024

Conversation

Luap99
Copy link
Member

@Luap99 Luap99 commented Jun 27, 2024

One problem on FCOS is that the root directory is immutable, as such in
order to mount arbitrary paths from the host we must make it mutable
again and create these dir on boot in order to be able to mount there.

The current logic was racy as it used one unit for each path and they
all did chattr -i /; mkdir -p $path; chattr -i / and systemd can run
these units in parallel. That means it was possible for another unit to
make / immutable before the unit could do the mkdir. I pointed this out
on the original PR[1] but we never followed up on it...

Now this here changes several things. First have one unit that does the
chattr -i / (immutable-root-off.service), it is hooked into
remote-fs-pre.target which means it is executed before the network
mounts (virtiofs) are done.

Then we have another unit that does chattr +i /
(immutable-root-on.service) which turn the immutable root back on after
remote-fs.target which means all mount are done at this point.

Additionally the automount unit is removed because it does not add any
value for us and it was borken anyway as it used the virtiofs tag as
path so systemd just ignored it.

[1] #20612 (comment)

Fixes #22569

Does this PR introduce a user-facing change?

Fixed a race condition which could prevent the mount of some podman machine volumes inside the VM.

Copy link
Contributor

openshift-ci bot commented Jun 27, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Luap99

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 27, 2024
Copy link

Ephemeral COPR build failed. @containers/packit-build please check.

Luap99 added 2 commits June 27, 2024 14:24
The task got renamed but didn't fix the URL for the machine test task
only the artifacts task url was fixed.

Fixes 439fe90 ("Minor: Rename the OSX Cross task")

Signed-off-by: Paul Holzinger <[email protected]>
One problem on FCOS is that the root directory is immutable, as such in
order to mount arbitrary paths from the host we must make it mutable
again and create these dir on boot in order to be able to mount there.

The current logic was racy as it used one unit for each path and they
all did chattr -i /; mkdir -p $path; chattr -i / and systemd can run
these units in parallel. That means it was possible for another unit to
make / immutable before the unit could do the mkdir. I pointed this out
on the original PR[1] but we never followed up on it...

Now this here changes several things. First have one unit that does the
chattr -i / (immutable-root-off.service), it is hooked into
remote-fs-pre.target which means it is executed before the network
mounts (virtiofs) are done.

Then we have another unit that does chattr +i /
(immutable-root-on.service) which turn the immutable root back on after
remote-fs.target which means all mount are done at this point.

Additionally the automount unit is removed because it does not add any
value for us and it was borken anyway as it used the virtiofs tag as
path so systemd just ignored it.

[1] containers#20612 (comment)

Fixes containers#22569

Signed-off-by: Paul Holzinger <[email protected]>
@Luap99 Luap99 changed the title machine test: debug apple volume flake apple virtiofs: fix racy mount setup Jun 27, 2024
@Luap99
Copy link
Member Author

Luap99 commented Jun 27, 2024

@ashley-cui @baude PTAL

@Luap99
Copy link
Member Author

Luap99 commented Jun 27, 2024

@edsantiago edsantiago added the No New Tests Allow PR to proceed without adding regression tests label Jun 27, 2024
@ashley-cui
Copy link
Member

Not an expert here but LGTM

immutableRootOn.Add("Service", "Type", "oneshot")
immutableRootOn.Add("Service", "ExecStart", "chattr +i /")

immutableRootOn.Add("Install", "WantedBy", "remote-fs.target")
Copy link
Member

Choose a reason for hiding this comment

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

systemd makes my head hurt, so this is probably a stupid question, but: line 121 is After remote-fs.target, and this one is WantedBy remote-fs.target, isn't that a circular dependency loop?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, https://www.freedesktop.org/software/systemd/man/latest/systemd.unit.html#Wants=

Note that requirement dependencies do not influence the order in which services are started or stopped. This has to be configured independently with the After= or Before= options. If unit foo.service pulls in unit bar.service as configured with Wants= and no ordering is configured with After= or Before=, then both units will be started simultaneously and without any delay between them if foo.service is activated.

The WantedBy is used by systemctl enable to active the unit when that given target is reached. We can still say we want to run this unit of this one. But I can double check the logs

Copy link
Member Author

Choose a reason for hiding this comment

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

core@localhost:~$ systemctl list-dependencies --reverse  immutable-root-off.service
immutable-root-off.service
● └─remote-fs-pre.target
○   ├─dracut-initqueue.service
○   ├─iscsi-shutdown.service
○   ├─iscsid.service
○   ├─iscsiuio.service
●   └─nfs-client.target
●     ├─multi-user.target
○     │ └─graphical.target
●     └─remote-fs.target
○       ├─dracut-pre-pivot.service
●       └─multi-user.target
○         └─graphical.target
core@localhost:~$ systemctl list-dependencies --reverse  immutable-root-on.service 
immutable-root-on.service
● └─remote-fs.target
○   ├─dracut-pre-pivot.service
●   └─multi-user.target
○     └─graphical.target

I think this shows it nicely enough to understand.

@rhatdan
Copy link
Member

rhatdan commented Jun 27, 2024

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jun 27, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit d367d55 into containers:main Jun 27, 2024
88 checks passed
@Luap99 Luap99 deleted the machine-flake branch June 27, 2024 15:43
@cfergeau
Copy link
Contributor

I believe this comment

// mounting in fcos with virtiofs is a bit of a dance. we need a unit file for the mount, a unit file
// for automatic mounting on boot, and a "preparatory" service file that disables FCOS security, performs
// the mkdir of the mount point, and then re-enables security. This must be done for each mount.
is out of date after this PR.

@stale-locking-app stale-locking-app bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 27, 2024
@stale-locking-app stale-locking-app bot locked as resolved and limited conversation to collaborators Sep 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. machine No New Tests Allow PR to proceed without adding regression tests release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

machine: Volume ops test: statfs /private/tmp/ci/ginkgoNNN: no such file or directory
5 participants