Skip to content

Commit

Permalink
[lxd-import] lxd/instance/drivers: Check running status with `InitPID…
Browse files Browse the repository at this point in the history
…` for cgroups

Cgroup storage limits are not applied when the container starts up. That
is because `IsRunning` returns `false` during the container startup.

This commits fixes this issue by relying on `InitPID` instead of
`IsRunning`. The former will return a positive integer if the container
is running even if the container is not fully set up yet.

Fixes #12343

Signed-off-by: Thomas Hipp <[email protected]>
  • Loading branch information
monstermunchkin authored and stgraber committed Oct 24, 2023
1 parent 6bec695 commit 9119691
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions internal/server/instance/drivers/driver_lxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1752,7 +1752,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 @@ -3967,8 +3970,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

0 comments on commit 9119691

Please sign in to comment.