cgroupv2: change newCgroupHook interface

This commit is contained in:
Miao Wang 2021-07-23 15:29:28 +08:00
parent 27c33f86b3
commit 2949b9c58c
3 changed files with 11 additions and 5 deletions

View File

@ -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"
}

View File

@ -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()
@ -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()

View File

@ -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,
),
)
}