gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

net_prio.go (1611B)


      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 cgroup1
     18 
     19 import (
     20 	"fmt"
     21 	"os"
     22 	"path/filepath"
     23 
     24 	specs "github.com/opencontainers/runtime-spec/specs-go"
     25 )
     26 
     27 func NewNetPrio(root string) *netprioController {
     28 	return &netprioController{
     29 		root: filepath.Join(root, string(NetPrio)),
     30 	}
     31 }
     32 
     33 type netprioController struct {
     34 	root string
     35 }
     36 
     37 func (n *netprioController) Name() Name {
     38 	return NetPrio
     39 }
     40 
     41 func (n *netprioController) Path(path string) string {
     42 	return filepath.Join(n.root, path)
     43 }
     44 
     45 func (n *netprioController) 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 {
     50 		for _, prio := range resources.Network.Priorities {
     51 			if err := os.WriteFile(
     52 				filepath.Join(n.Path(path), "net_prio.ifpriomap"),
     53 				formatPrio(prio.Name, prio.Priority),
     54 				defaultFilePerm,
     55 			); err != nil {
     56 				return err
     57 			}
     58 		}
     59 	}
     60 	return nil
     61 }
     62 
     63 func formatPrio(name string, prio uint32) []byte {
     64 	return []byte(fmt.Sprintf("%s %d", name, prio))
     65 }