Skip to content

Commit 161e8ab

Browse files
nixprimegvisor-bot
authored andcommitted
Internal change.
PiperOrigin-RevId: 827191756
1 parent feddee9 commit 161e8ab

File tree

7 files changed

+26
-21
lines changed

7 files changed

+26
-21
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/containerd/go-runc v1.0.0
1616
github.com/containerd/log v0.1.0
1717
github.com/containerd/typeurl v1.0.2
18-
github.com/coreos/go-systemd/v22 v22.5.0
18+
github.com/coreos/go-systemd/v22 v22.6.0
1919
github.com/godbus/dbus/v5 v5.1.0
2020
github.com/gofrs/flock v0.8.0
2121
github.com/gogo/protobuf v1.3.2

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+
234234
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
235235
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
236236
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
237+
github.com/coreos/go-systemd/v22 v22.6.0 h1:aGVa/v8B7hpb0TKl0MWoAavPDmHvobFe5R5zn0bCJWo=
238+
github.com/coreos/go-systemd/v22 v22.6.0/go.mod h1:iG+pp635Fo7ZmV/j14KUcmEyWF+0X7Lua8rrTWzYgWU=
237239
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
238240
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
239241
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=

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/cgroup/systemd.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ func (c *cgroupSystemd) Join() (func(), error) {
182182
return nil, fmt.Errorf("unknown job completion status %q", s)
183183
}
184184
} else if unitAlreadyExists(err) {
185+
if err := c.dbusConn.AttachProcessesToUnit(timedCtx, unitName, "" /* subcgroup */, []uint32{uint32(os.Getpid())}); err != nil {
186+
return nil, fmt.Errorf("error joining systemd unit `%s`: %w", unitName, err)
187+
}
185188
return clean.Release(), nil
186189
} else {
187190
return nil, fmt.Errorf("systemd error: %v", err)

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)