Skip to content

Commit 7e39a96

Browse files
nixprimegvisor-bot
authored andcommitted
Internal change.
PiperOrigin-RevId: 827749523
1 parent 589c763 commit 7e39a96

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

runsc/cgroup/cgroup.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,3 +960,17 @@ func (*hugeTLB) set(spec *specs.LinuxResources, path string) error {
960960
}
961961
return nil
962962
}
963+
964+
// RunInCgroup executes fn inside the specified cgroup. If cg is nil, execute
965+
// it in the current context.
966+
func RunInCgroup(cg Cgroup, fn func() error) error {
967+
if cg == nil {
968+
return fn()
969+
}
970+
restore, err := cg.Join()
971+
if err != nil {
972+
return err
973+
}
974+
defer restore()
975+
return fn()
976+
}

runsc/container/container.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ func New(conf *config.Config, args Args) (*Container, error) {
297297
if err := nvProxyPreGoferHostSetup(args.Spec, conf); err != nil {
298298
return nil, err
299299
}
300-
if err := runInCgroup(containerCgroup, func() error {
300+
if err := cgroup.RunInCgroup(containerCgroup, func() error {
301301
ioFiles, goferFilestores, devIOFile, specFile, err := c.createGoferProcess(conf, mountHints, args.Attached)
302302
if err != nil {
303303
return fmt.Errorf("cannot create gofer process: %w", err)
@@ -451,7 +451,7 @@ func (c *Container) startImpl(conf *config.Config, action string, startRoot func
451451
} else {
452452
// Join cgroup to start gofer process to ensure it's part of the cgroup from
453453
// the start (and all their children processes).
454-
if err := runInCgroup(c.Sandbox.CgroupJSON.Cgroup, func() error {
454+
if err := cgroup.RunInCgroup(c.Sandbox.CgroupJSON.Cgroup, func() error {
455455
// Create the gofer process.
456456
goferFiles, goferFilestores, devIOFile, mountsFile, err := c.createGoferProcess(conf, c.Sandbox.MountHints, false /* attached */)
457457
if err != nil {
@@ -1589,20 +1589,6 @@ func isRoot(spec *specs.Spec) bool {
15891589
return specutils.SpecContainerType(spec) != specutils.ContainerTypeContainer
15901590
}
15911591

1592-
// runInCgroup executes fn inside the specified cgroup. If cg is nil, execute
1593-
// it in the current context.
1594-
func runInCgroup(cg cgroup.Cgroup, fn func() error) error {
1595-
if cg == nil {
1596-
return fn()
1597-
}
1598-
restore, err := cg.Join()
1599-
if err != nil {
1600-
return err
1601-
}
1602-
defer restore()
1603-
return fn()
1604-
}
1605-
16061592
// adjustGoferOOMScoreAdj sets the oom_store_adj for the container's gofer.
16071593
func (c *Container) adjustGoferOOMScoreAdj() error {
16081594
goferPid := c.GoferPid.Load()

runsc/sandbox/sandbox.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ func (s *Sandbox) createSandboxProcess(conf *config.Config, args *Args, startSyn
986986
donations.DonateAndClose("save-fds", files...)
987987
}
988988

989-
if err := createSandboxProcessExtra(conf, args, cmd, &donations); err != nil {
989+
if err := s.createSandboxProcessExtra(conf, args, cmd, &donations); err != nil {
990990
return err
991991
}
992992

@@ -1540,7 +1540,7 @@ func (s *Sandbox) Checkpoint(conf *config.Config, cid string, imagePath string,
15401540
_ = f.Close()
15411541
}
15421542
}()
1543-
if err := setCheckpointOptsImpl(conf, imagePath, opts, &opt); err != nil {
1543+
if err := s.setCheckpointOptsImpl(conf, imagePath, opts, &opt); err != nil {
15441544
return err
15451545
}
15461546

runsc/sandbox/sandbox_impl.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ import (
2626
"gvisor.dev/gvisor/runsc/donation"
2727
)
2828

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

3333
type checkpointOptsExtra struct{}
3434

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

0 commit comments

Comments
 (0)