-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,18 +72,7 @@ func GenerateSystemDFilesForVirtiofsMounts(mounts []machine.VirtIoFs) ([]ignitio | |
|
||
unitFiles := make([]ignition.Unit, 0, len(mounts)) | ||
for _, mnt := range mounts { | ||
// Here we are looping the mounts and for each mount, we are adding two unit files | ||
// for virtiofs. One unit file is the mount itself and the second is to automount it | ||
// on boot. | ||
autoMountUnit := parser.NewUnitFile() | ||
autoMountUnit.Add("Automount", "Where", "%s") | ||
autoMountUnit.Add("Install", "WantedBy", "multi-user.target") | ||
autoMountUnit.Add("Unit", "Description", "Mount virtiofs volume %s") | ||
autoMountUnitFile, err := autoMountUnit.ToString() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Create mount unit for each mount | ||
mountUnit := parser.NewUnitFile() | ||
mountUnit.Add("Mount", "What", "%s") | ||
mountUnit.Add("Mount", "Where", "%s") | ||
|
@@ -95,49 +84,57 @@ func GenerateSystemDFilesForVirtiofsMounts(mounts []machine.VirtIoFs) ([]ignitio | |
return nil, err | ||
} | ||
|
||
virtiofsAutomount := ignition.Unit{ | ||
Enabled: ignition.BoolToPtr(true), | ||
Name: fmt.Sprintf("%s.automount", parser.PathEscape(mnt.Target)), | ||
Contents: ignition.StrToPtr(fmt.Sprintf(autoMountUnitFile, mnt.Tag, mnt.Target)), | ||
} | ||
virtiofsMount := ignition.Unit{ | ||
Enabled: ignition.BoolToPtr(true), | ||
Name: fmt.Sprintf("%s.mount", parser.PathEscape(mnt.Target)), | ||
Contents: ignition.StrToPtr(fmt.Sprintf(mountUnitFile, mnt.Tag, mnt.Target)), | ||
} | ||
|
||
// This "unit" simulates something like systemctl enable virtiofs-mount-prepare@ | ||
enablePrep := ignition.Unit{ | ||
Enabled: ignition.BoolToPtr(true), | ||
Name: fmt.Sprintf("virtiofs-mount-prepare@%s.service", parser.PathEscape(mnt.Target)), | ||
} | ||
|
||
unitFiles = append(unitFiles, virtiofsAutomount, virtiofsMount, enablePrep) | ||
unitFiles = append(unitFiles, virtiofsMount) | ||
} | ||
|
||
// mount prep is a way to workaround the FCOS limitation of creating directories | ||
// This is a way to workaround the FCOS limitation of creating directories | ||
// at the rootfs / and then mounting to them. | ||
mountPrep := parser.NewUnitFile() | ||
mountPrep.Add("Unit", "Description", "Allow virtios to mount to /") | ||
mountPrep.Add("Unit", "DefaultDependencies", "no") | ||
mountPrep.Add("Unit", "ConditionPathExists", "!%f") | ||
|
||
mountPrep.Add("Service", "Type", "oneshot") | ||
mountPrep.Add("Service", "ExecStartPre", "chattr -i /") | ||
mountPrep.Add("Service", "ExecStart", "mkdir -p '%f'") | ||
mountPrep.Add("Service", "ExecStopPost", "chattr +i /") | ||
|
||
mountPrep.Add("Install", "WantedBy", "remote-fs.target") | ||
mountPrepFile, err := mountPrep.ToString() | ||
immutableRootOff := parser.NewUnitFile() | ||
immutableRootOff.Add("Unit", "Description", "Allow systemd to create mount points on /") | ||
immutableRootOff.Add("Unit", "DefaultDependencies", "no") | ||
|
||
immutableRootOff.Add("Service", "Type", "oneshot") | ||
immutableRootOff.Add("Service", "ExecStart", "chattr -i /") | ||
|
||
immutableRootOff.Add("Install", "WantedBy", "remote-fs-pre.target") | ||
immutableRootOffFile, err := immutableRootOff.ToString() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
immutableRootOffUnit := ignition.Unit{ | ||
Contents: ignition.StrToPtr(immutableRootOffFile), | ||
Name: "immutable-root-off.service", | ||
Enabled: ignition.BoolToPtr(true), | ||
} | ||
unitFiles = append(unitFiles, immutableRootOffUnit) | ||
|
||
immutableRootOn := parser.NewUnitFile() | ||
immutableRootOn.Add("Unit", "Description", "Set / back to immutable after mounts are done") | ||
immutableRootOn.Add("Unit", "DefaultDependencies", "no") | ||
immutableRootOn.Add("Unit", "After", "remote-fs.target") | ||
|
||
immutableRootOn.Add("Service", "Type", "oneshot") | ||
immutableRootOn.Add("Service", "ExecStart", "chattr +i /") | ||
|
||
immutableRootOn.Add("Install", "WantedBy", "remote-fs.target") | ||
immutableRootOnFile, err := immutableRootOn.ToString() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
virtioFSChattr := ignition.Unit{ | ||
Contents: ignition.StrToPtr(mountPrepFile), | ||
Name: "[email protected]", | ||
immutableRootOnUnit := ignition.Unit{ | ||
Contents: ignition.StrToPtr(immutableRootOnFile), | ||
Name: "immutable-root-on.service", | ||
Enabled: ignition.BoolToPtr(true), | ||
} | ||
unitFiles = append(unitFiles, virtioFSChattr) | ||
unitFiles = append(unitFiles, immutableRootOnUnit) | ||
|
||
return unitFiles, nil | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 isWantedBy remote-fs.target
, isn't that a circular dependency loop?There was a problem hiding this comment.
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=
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this shows it nicely enough to understand.