...

Source file src/github.com/containerd/cgroups/net_cls.go

Documentation: github.com/containerd/cgroups

     1  /*
     2     Copyright The containerd Authors.
     3  
     4     Licensed under the Apache License, Version 2.0 (the "License");
     5     you may not use this file except in compliance with the License.
     6     You may obtain a copy of the License at
     7  
     8         http://www.apache.org/licenses/LICENSE-2.0
     9  
    10     Unless required by applicable law or agreed to in writing, software
    11     distributed under the License is distributed on an "AS IS" BASIS,
    12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13     See the License for the specific language governing permissions and
    14     limitations under the License.
    15  */
    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