From 7e39a96f22c7cb6b0f02f0f6c9c16bcd08fb4ac6 Mon Sep 17 00:00:00 2001 From: Jamie Liu Date: Mon, 3 Nov 2025 19:50:00 -0800 Subject: [PATCH] Internal change. PiperOrigin-RevId: 827749523 --- runsc/cgroup/cgroup.go | 14 ++++++++++++++ runsc/container/container.go | 18 ++---------------- runsc/sandbox/sandbox.go | 4 ++-- runsc/sandbox/sandbox_impl.go | 4 ++-- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/runsc/cgroup/cgroup.go b/runsc/cgroup/cgroup.go index 91a650a281..a5aa4c8e68 100644 --- a/runsc/cgroup/cgroup.go +++ b/runsc/cgroup/cgroup.go @@ -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() +} diff --git a/runsc/container/container.go b/runsc/container/container.go index 44da90ce28..86c07b9300 100644 --- a/runsc/container/container.go +++ b/runsc/container/container.go @@ -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) @@ -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 { @@ -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() diff --git a/runsc/sandbox/sandbox.go b/runsc/sandbox/sandbox.go index 7cbcd04de6..cb4011e951 100644 --- a/runsc/sandbox/sandbox.go +++ b/runsc/sandbox/sandbox.go @@ -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 } @@ -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 } diff --git a/runsc/sandbox/sandbox_impl.go b/runsc/sandbox/sandbox_impl.go index cd5bf81f8b..31f7e8665c 100644 --- a/runsc/sandbox/sandbox_impl.go +++ b/runsc/sandbox/sandbox_impl.go @@ -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) }