diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-02-13 02:34:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-13 02:34:42 +0100 |
commit | a65f6b888ac4df13efec70c0d86c61af9090e3b7 (patch) | |
tree | 81c6598455eddfb6c4861265e76596b1bf561b5d /pkg/spec/config_linux.go | |
parent | 2281cbdd6d5b1b7bca99a605ffc8625b6bee7eb3 (diff) | |
parent | d3260738d330b6141fec5f11f1a3a91f40365018 (diff) | |
download | podman-a65f6b888ac4df13efec70c0d86c61af9090e3b7.tar.gz podman-a65f6b888ac4df13efec70c0d86c61af9090e3b7.tar.bz2 podman-a65f6b888ac4df13efec70c0d86c61af9090e3b7.zip |
Merge pull request #5152 from QiWang19/device-cgroup-rule
support device-cgroup-rule
Diffstat (limited to 'pkg/spec/config_linux.go')
-rw-r--r-- | pkg/spec/config_linux.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/pkg/spec/config_linux.go b/pkg/spec/config_linux.go index 32d8cb4de..5f39b6d0d 100644 --- a/pkg/spec/config_linux.go +++ b/pkg/spec/config_linux.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "os" "path/filepath" + "strconv" "strings" "github.com/containers/libpod/pkg/rootless" @@ -90,6 +91,42 @@ func devicesFromPath(g *generate.Generator, devicePath string) error { return addDevice(g, strings.Join(append([]string{resolvedDevicePath}, devs[1:]...), ":")) } +func deviceCgroupRules(g *generate.Generator, deviceCgroupRules []string) error { + for _, deviceCgroupRule := range deviceCgroupRules { + if err := validateDeviceCgroupRule(deviceCgroupRule); err != nil { + return err + } + ss := parseDeviceCgroupRule(deviceCgroupRule) + if len(ss[0]) != 5 { + return errors.Errorf("invalid device cgroup rule format: '%s'", deviceCgroupRule) + } + matches := ss[0] + var major, minor *int64 + if matches[2] == "*" { + majorDev := int64(-1) + major = &majorDev + } else { + majorDev, err := strconv.ParseInt(matches[2], 10, 64) + if err != nil { + return errors.Errorf("invalid major value in device cgroup rule format: '%s'", deviceCgroupRule) + } + major = &majorDev + } + if matches[3] == "*" { + minorDev := int64(-1) + minor = &minorDev + } else { + minorDev, err := strconv.ParseInt(matches[2], 10, 64) + if err != nil { + return errors.Errorf("invalid major value in device cgroup rule format: '%s'", deviceCgroupRule) + } + minor = &minorDev + } + g.AddLinuxResourcesDevice(true, matches[1], major, minor, matches[4]) + } + return nil +} + func addDevice(g *generate.Generator, device string) error { src, dst, permissions, err := ParseDevice(device) if err != nil { |