Skip to content

Commit

Permalink
cgroupv2: change newCgroupHook interface
Browse files Browse the repository at this point in the history
  • Loading branch information
shankerwangmiao committed Jul 23, 2021
1 parent 27c33f8 commit 2949b9c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
7 changes: 6 additions & 1 deletion worker/cgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ func waitExec () {
panic("Exec failed.")
}

func newCgroupHook(p mirrorProvider, basePath, baseGroup, subsystem string, memLimit MemBytes) *cgroupHook {
func newCgroupHook(p mirrorProvider, cfg cgroupConfig, memLimit MemBytes) *cgroupHook {
var (
basePath = cfg.BasePath
baseGroup = cfg.Group
subsystem = cfg.Subsystem
)
if basePath == "" {
basePath = "/sys/fs/cgroup"
}
Expand Down
6 changes: 4 additions & 2 deletions worker/cgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ sleep 30
provider, err := newCmdProvider(c)
So(err, ShouldBeNil)

cg := newCgroupHook(provider, "/sys/fs/cgroup", "tunasync", "cpu", 0)
cgcf := cgroupConfig{BasePath: "/sys/fs/cgroup", Group: "tunasync", Subsystem: "cpu"}
cg := newCgroupHook(provider, cgcf, 0)
provider.AddHook(cg)

err = cg.preExec()
Expand Down Expand Up @@ -133,7 +134,8 @@ sleep 30
provider, err := newRsyncProvider(c)
So(err, ShouldBeNil)

cg := newCgroupHook(provider, "/sys/fs/cgroup", "tunasync", "cpu", 512 * units.MiB)
cgcf := cgroupConfig{BasePath: "/sys/fs/cgroup", Group: "tunasync", Subsystem: "cpu"}
cg := newCgroupHook(provider, cgcf, 512 * units.MiB)
provider.AddHook(cg)

err = cg.preExec()
Expand Down
3 changes: 1 addition & 2 deletions worker/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ func newMirrorProvider(mirror mirrorConfig, cfg *Config) mirrorProvider {
// Add Cgroup Hook
provider.AddHook(
newCgroupHook(
provider, cfg.Cgroup.BasePath, cfg.Cgroup.Group,
cfg.Cgroup.Subsystem, mirror.MemoryLimit,
provider, cfg.Cgroup, mirror.MemoryLimit,
),
)
}
Expand Down

0 comments on commit 2949b9c

Please sign in to comment.