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

lxd/instance/drivers: Check running status with InitPID for cgroups #12441

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions lxd/instance/drivers/driver_lxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,7 @@ func (d *lxc) deviceAddCgroupRules(cgroups []deviceConfig.RunConfigItem) error {
// Add the new device cgroup rule.
err := d.CGroupSet(rule.Key, rule.Value)
if err != nil {
return fmt.Errorf("Failed to add cgroup rule for device")
return fmt.Errorf("Failed to add cgroup rule for device: %w", err)
}
}

Expand Down Expand Up @@ -1746,7 +1746,10 @@ func (d *lxc) deviceHandleMounts(mounts []deviceConfig.MountEntryItem) error {
// DeviceEventHandler actions the results of a RunConfig after an event has occurred on a device.
func (d *lxc) DeviceEventHandler(runConf *deviceConfig.RunConfig) error {
// Device events can only be processed when the container is running.
if !d.IsRunning() {
// We use InitPID here rather than IsRunning because this task can be triggered during the
// container startup process, which is during the time that the start lock is held, which causes
// IsRunning to return false (because the container hasn't fully started yet).
if d.InitPID() <= 0 {
return nil
}

Expand Down Expand Up @@ -4012,8 +4015,12 @@ func (d *lxc) CGroupSet(key string, value string) error {
return err
}

// Make sure the container is running
if !d.IsRunning() {
// Make sure the container is running.
// We use InitPID here rather than IsRunning because this task can be triggered during the container's
// startup process, which is during the time that the start lock is held, which causes IsRunning to
// return false (because the container hasn't fully started yet) but it is sufficiently started to
// have its cgroup disk limits set.
if d.InitPID() <= 0 {
return fmt.Errorf("Can't set cgroups on a stopped container")
}

Expand Down
Loading