...
1
16
17 package cgroups
18
19 import (
20 "os"
21 "path/filepath"
22 "strconv"
23
24 specs "github.com/opencontainers/runtime-spec/specs-go"
25 )
26
27 func NewNetCls(root string) *netclsController {
28 return &netclsController{
29 root: filepath.Join(root, string(NetCLS)),
30 }
31 }
32
33 type netclsController struct {
34 root string
35 }
36
37 func (n *netclsController) Name() Name {
38 return NetCLS
39 }
40
41 func (n *netclsController) Path(path string) string {
42 return filepath.Join(n.root, path)
43 }
44
45 func (n *netclsController) Create(path string, resources *specs.LinuxResources) error {
46 if err := os.MkdirAll(n.Path(path), defaultDirPerm); err != nil {
47 return err
48 }
49 if resources.Network != nil && resources.Network.ClassID != nil && *resources.Network.ClassID > 0 {
50 return retryingWriteFile(
51 filepath.Join(n.Path(path), "net_cls.classid"),
52 []byte(strconv.FormatUint(uint64(*resources.Network.ClassID), 10)),
53 defaultFilePerm,
54 )
55 }
56 return nil
57 }
58
59 func (n *netclsController) Update(path string, resources *specs.LinuxResources) error {
60 return n.Create(path, resources)
61 }
62
View as plain text