Skip to content

Commit

Permalink
Add runc-facade
Browse files Browse the repository at this point in the history
  • Loading branch information
Furisto committed Feb 28, 2022
1 parent f3d2c4a commit 5ba438d
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
75 changes: 75 additions & 0 deletions components/ws-daemon/gp-runc/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package main

import (
"encoding/json"
"os"
"os/exec"
"syscall"

"github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
"golang.org/x/xerrors"
)

var (
fuseDeviceMajor int64 = 10
fuseDeviceMinor int64 = 229
)

func main() {
log := logrus.New()
log.SetLevel(logrus.DebugLevel)

var err error
runcPath, err := exec.LookPath("runc.orig")
if err != nil {
log.WithError(err).Fatal("runc not found")
}

var useFacade bool
for _, arg := range os.Args {
if arg == "create" {
useFacade = true
break
}
}

if useFacade {
err = createAndRunc(runcPath, log)
} else {
err = syscall.Exec(runcPath, os.Args, os.Environ())
}
if err != nil {
log.WithError(err).Fatal("failed")
}
}

func createAndRunc(runcPath string, log *logrus.Logger) error {
fc, err := os.ReadFile("config.json")
if err != nil {
return xerrors.Errorf("cannot read config.json: %w", err)
}

var cfg specs.Spec
err = json.Unmarshal(fc, &cfg)
if err != nil {
return xerrors.Errorf("cannot decode config.json: %w", err)
}

fuseDevice := specs.LinuxDeviceCgroup{
Type: "c",
Minor: &fuseDeviceMinor,
Major: &fuseDeviceMajor,
Access: "rwm",
Allow: true,
}

cfg.Linux.Resources.Devices = append(cfg.Linux.Resources.Devices, fuseDevice)

err = syscall.Exec(runcPath, os.Args, os.Environ())
if err != nil {
return xerrors.Errorf("exec %s: %w", runcPath, err)
}

return nil
}
20 changes: 20 additions & 0 deletions components/ws-daemon/pkg/cpulimit/cfs_cg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cpulimit

import (
"github.com/containerd/cgroups"
)

type CFSControllerCgroup struct {
cgroup cgroups.Cgroup
}

func Load(base string) (CFSControllerCgroup, error) {
cgroup, err := cgroups.Load(cgroups.V1, cgroups.StaticPath(base))
if err != nil {
return CFSControllerCgroup{}, err
}

return CFSControllerCgroup{
cgroup: cgroup,
}, nil
}
1 change: 1 addition & 0 deletions components/ws-daemon/pkg/cpulimit/cfs_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
type CgroupV2CFSController string

func (basePath CgroupV2CFSController) Usage() (CPUTime, error) {

usage, err := basePath.getFlatKeyedValue("usage_usec")
if err != nil {
return 0, err
Expand Down

0 comments on commit 5ba438d

Please sign in to comment.