This repository was archived by the owner on Feb 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 880
stage1/kvm: Avoid writing misleading subcgroup #3107
Merged
Merged
Changes from all commits
Commits
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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -215,8 +215,9 @@ func installAssets() error { | |
return proj2aci.PrepareAssets(assets, "./stage1/rootfs/", nil) | ||
} | ||
|
||
// getArgsEnv returns the nspawn or lkvm args and env according to the flavor used | ||
func getArgsEnv(p *stage1commontypes.Pod, flavor string, debug bool, n *networking.Networking, insecureOptions stage1initcommon.Stage1InsecureOptions) ([]string, []string, error) { | ||
// getArgsEnv returns the nspawn or lkvm args and env according to the flavor | ||
// as the first two return values respectively. | ||
func getArgsEnv(p *stage1commontypes.Pod, flavor string, canMachinedRegister bool, debug bool, n *networking.Networking, insecureOptions stage1initcommon.Stage1InsecureOptions) ([]string, []string, error) { | ||
var args []string | ||
env := os.Environ() | ||
|
||
|
@@ -298,7 +299,7 @@ func getArgsEnv(p *stage1commontypes.Pod, flavor string, debug bool, n *networki | |
args = append(args, fmt.Sprintf("-L%s", context)) | ||
} | ||
|
||
if machinedRegister() { | ||
if canMachinedRegister { | ||
args = append(args, fmt.Sprintf("--register=true")) | ||
} else { | ||
args = append(args, fmt.Sprintf("--register=false")) | ||
|
@@ -320,7 +321,7 @@ func getArgsEnv(p *stage1commontypes.Pod, flavor string, debug bool, n *networki | |
args = append(args, fmt.Sprintf("-L%s", context)) | ||
} | ||
|
||
if machinedRegister() { | ||
if canMachinedRegister { | ||
args = append(args, fmt.Sprintf("--register=true")) | ||
} else { | ||
args = append(args, fmt.Sprintf("--register=false")) | ||
|
@@ -581,7 +582,12 @@ func stage1() int { | |
return 1 | ||
} | ||
|
||
args, env, err := getArgsEnv(p, flavor, debug, n, insecureOptions) | ||
canMachinedRegister := false | ||
if flavor != "kvm" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does fly fit into this PR? Should it be taken into account here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fly neither writes a file nor does machined registration (this |
||
// kvm doesn't register with systemd right now, see #2664. | ||
canMachinedRegister = machinedRegister() | ||
} | ||
args, env, err := getArgsEnv(p, flavor, canMachinedRegister, debug, n, insecureOptions) | ||
if err != nil { | ||
log.Error(err) | ||
return 1 | ||
|
@@ -622,13 +628,14 @@ func stage1() int { | |
} | ||
s1Root := common.Stage1RootfsPath(p.Root) | ||
machineID := stage1initcommon.GetMachineID(p) | ||
subcgroup, err := getContainerSubCgroup(machineID) | ||
subcgroup, err := getContainerSubCgroup(machineID, canMachinedRegister) | ||
if err == nil { | ||
if err := ioutil.WriteFile(filepath.Join(p.Root, "subcgroup"), | ||
[]byte(fmt.Sprintf("%s", subcgroup)), 0644); err != nil { | ||
log.FatalE("cannot write subcgroup file", err) | ||
return 1 | ||
} | ||
|
||
if err := mountContainerCgroups(s1Root, enabledCgroups, subcgroup, serviceNames); err != nil { | ||
log.PrintE("couldn't mount the container cgroups", err) | ||
return 1 | ||
|
@@ -720,7 +727,7 @@ func mountContainerCgroups(s1Root string, enabledCgroups map[int][]string, subcg | |
return nil | ||
} | ||
|
||
func getContainerSubCgroup(machineID string) (string, error) { | ||
func getContainerSubCgroup(machineID string, canMachinedRegister bool) (string, error) { | ||
var subcgroup string | ||
fromUnit, err := util.RunningFromSystemService() | ||
if err != nil { | ||
|
@@ -743,7 +750,7 @@ func getContainerSubCgroup(machineID string) (string, error) { | |
} else { | ||
escapedmID := strings.Replace(machineID, "-", "\\x2d", -1) | ||
machineDir := "machine-" + escapedmID + ".scope" | ||
if machinedRegister() { | ||
if canMachinedRegister { | ||
// we are not in the final cgroup yet: systemd-nspawn will move us | ||
// to the correct cgroup later during registration so we can't | ||
// look it up in /proc/self/cgroup | ||
|
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.
If I remember correctly, this is also used for cgroup GC. Perhaps we should also mention that here.
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.
It is, I'll work that into this.
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.
Actually, on second thought, the fact that it's used for gc is an internal detail of the stage1 gc entrypoint is why I didn't include it. The
rkt stage0
has no knowledge nor use of this, so that detail isn't something to document here.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.
Fair enough.