Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions runsc/cgroup/cgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -960,3 +960,17 @@ func (*hugeTLB) set(spec *specs.LinuxResources, path string) error {
}
return nil
}

// RunInCgroup executes fn inside the specified cgroup. If cg is nil, execute
// it in the current context.
func RunInCgroup(cg Cgroup, fn func() error) error {
if cg == nil {
return fn()
}
restore, err := cg.Join()
if err != nil {
return err
}
defer restore()
return fn()
}
18 changes: 2 additions & 16 deletions runsc/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func New(conf *config.Config, args Args) (*Container, error) {
if err := nvProxyPreGoferHostSetup(args.Spec, conf); err != nil {
return nil, err
}
if err := runInCgroup(containerCgroup, func() error {
if err := cgroup.RunInCgroup(containerCgroup, func() error {
ioFiles, goferFilestores, devIOFile, specFile, err := c.createGoferProcess(conf, mountHints, args.Attached)
if err != nil {
return fmt.Errorf("cannot create gofer process: %w", err)
Expand Down Expand Up @@ -451,7 +451,7 @@ func (c *Container) startImpl(conf *config.Config, action string, startRoot func
} else {
// Join cgroup to start gofer process to ensure it's part of the cgroup from
// the start (and all their children processes).
if err := runInCgroup(c.Sandbox.CgroupJSON.Cgroup, func() error {
if err := cgroup.RunInCgroup(c.Sandbox.CgroupJSON.Cgroup, func() error {
// Create the gofer process.
goferFiles, goferFilestores, devIOFile, mountsFile, err := c.createGoferProcess(conf, c.Sandbox.MountHints, false /* attached */)
if err != nil {
Expand Down Expand Up @@ -1589,20 +1589,6 @@ func isRoot(spec *specs.Spec) bool {
return specutils.SpecContainerType(spec) != specutils.ContainerTypeContainer
}

// runInCgroup executes fn inside the specified cgroup. If cg is nil, execute
// it in the current context.
func runInCgroup(cg cgroup.Cgroup, fn func() error) error {
if cg == nil {
return fn()
}
restore, err := cg.Join()
if err != nil {
return err
}
defer restore()
return fn()
}

// adjustGoferOOMScoreAdj sets the oom_store_adj for the container's gofer.
func (c *Container) adjustGoferOOMScoreAdj() error {
goferPid := c.GoferPid.Load()
Expand Down
4 changes: 2 additions & 2 deletions runsc/sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ func (s *Sandbox) createSandboxProcess(conf *config.Config, args *Args, startSyn
donations.DonateAndClose("save-fds", files...)
}

if err := createSandboxProcessExtra(conf, args, cmd, &donations); err != nil {
if err := s.createSandboxProcessExtra(conf, args, cmd, &donations); err != nil {
return err
}

Expand Down Expand Up @@ -1540,7 +1540,7 @@ func (s *Sandbox) Checkpoint(conf *config.Config, cid string, imagePath string,
_ = f.Close()
}
}()
if err := setCheckpointOptsImpl(conf, imagePath, opts, &opt); err != nil {
if err := s.setCheckpointOptsImpl(conf, imagePath, opts, &opt); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions runsc/sandbox/sandbox_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import (
"gvisor.dev/gvisor/runsc/donation"
)

func createSandboxProcessExtra(conf *config.Config, args *Args, cmd *exec.Cmd, donations *donation.Agency) error {
func (s *Sandbox) createSandboxProcessExtra(conf *config.Config, args *Args, cmd *exec.Cmd, donations *donation.Agency) error {
return nil
}

type checkpointOptsExtra struct{}

func setCheckpointOptsImpl(conf *config.Config, imagePath string, opts CheckpointOpts, opt *control.SaveOpts) error {
func (s *Sandbox) setCheckpointOptsImpl(conf *config.Config, imagePath string, opts CheckpointOpts, opt *control.SaveOpts) error {
return setCheckpointOptsForLocalCheckpointFiles(conf, imagePath, opts, opt)
}

Expand Down
Loading