diff options
author | umohnani8 <umohnani@redhat.com> | 2018-04-03 13:37:25 -0400 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-04-06 00:09:46 +0000 |
commit | 998fd2ece0480e581e013124d0969a1af6305110 (patch) | |
tree | 84f3ae049fb1246a2f31c5eb5f55b40e6a17fc81 /cmd/podman/spec.go | |
parent | c3e2b00333d42dc87a3385939715813006cc8af1 (diff) | |
download | podman-998fd2ece0480e581e013124d0969a1af6305110.tar.gz podman-998fd2ece0480e581e013124d0969a1af6305110.tar.bz2 podman-998fd2ece0480e581e013124d0969a1af6305110.zip |
Functionality changes to the following flags
--group-add
--blkio-weight-device
--device-read-bps
--device-write-bps
--device-read-iops
--device-write-iops
--group-add now supports group names as well as the gid associated with them.
All the --device flags work now with moderate changes to the code to support both
bps and iops.
Added tests for all the flags.
Signed-off-by: umohnani8 <umohnani@redhat.com>
Closes: #590
Approved by: mheon
Diffstat (limited to 'cmd/podman/spec.go')
-rw-r--r-- | cmd/podman/spec.go | 78 |
1 files changed, 48 insertions, 30 deletions
diff --git a/cmd/podman/spec.go b/cmd/podman/spec.go index 5e98d5b50..14fe3a38a 100644 --- a/cmd/podman/spec.go +++ b/cmd/podman/spec.go @@ -181,9 +181,7 @@ func createConfigToOCISpec(config *createConfig) (*spec.Spec, error) { g.SetProcessCwd(config.WorkDir) g.SetProcessArgs(config.Command) g.SetProcessTerminal(config.Tty) - for _, gid := range config.GroupAdd { - g.AddProcessAdditionalGid(gid) - } + for key, val := range config.GetAnnotations() { g.AddAnnotation(key, val) } @@ -369,7 +367,7 @@ func createConfigToOCISpec(config *createConfig) (*spec.Spec, error) { } // BLOCK IO - blkio, err := config.CreateBlockIO() + blkio, err := config.createBlockIO() if err != nil { return nil, errors.Wrapf(err, "error creating block io") } @@ -403,7 +401,12 @@ func createConfigToOCISpec(config *createConfig) (*spec.Spec, error) { return configSpec, nil } -func (c *createConfig) CreateBlockIO() (*spec.LinuxBlockIO, error) { +const ( + bps = iota + iops +) + +func (c *createConfig) createBlockIO() (*spec.LinuxBlockIO, error) { bio := &spec.LinuxBlockIO{} bio.Weight = &c.Resources.BlkioWeight if len(c.Resources.BlkioWeightDevice) > 0 { @@ -413,7 +416,10 @@ func (c *createConfig) CreateBlockIO() (*spec.LinuxBlockIO, error) { if err != nil { return bio, errors.Wrapf(err, "invalid values for blkio-weight-device") } - wdStat := getStatFromPath(wd.path) + wdStat, err := getStatFromPath(wd.path) + if err != nil { + return bio, errors.Wrapf(err, "error getting stat from path %q", wd.path) + } lwd := spec.LinuxWeightDevice{ Weight: &wd.weight, } @@ -424,28 +430,28 @@ func (c *createConfig) CreateBlockIO() (*spec.LinuxBlockIO, error) { bio.WeightDevice = lwds } if len(c.Resources.DeviceReadBps) > 0 { - readBps, err := makeThrottleArray(c.Resources.DeviceReadBps) + readBps, err := makeThrottleArray(c.Resources.DeviceReadBps, bps) if err != nil { return bio, err } bio.ThrottleReadBpsDevice = readBps } if len(c.Resources.DeviceWriteBps) > 0 { - writeBpds, err := makeThrottleArray(c.Resources.DeviceWriteBps) + writeBpds, err := makeThrottleArray(c.Resources.DeviceWriteBps, bps) if err != nil { return bio, err } bio.ThrottleWriteBpsDevice = writeBpds } if len(c.Resources.DeviceReadIOps) > 0 { - readIOps, err := makeThrottleArray(c.Resources.DeviceReadIOps) + readIOps, err := makeThrottleArray(c.Resources.DeviceReadIOps, iops) if err != nil { return bio, err } bio.ThrottleReadIOPSDevice = readIOps } if len(c.Resources.DeviceWriteIOps) > 0 { - writeIOps, err := makeThrottleArray(c.Resources.DeviceWriteIOps) + writeIOps, err := makeThrottleArray(c.Resources.DeviceWriteIOps, iops) if err != nil { return bio, err } @@ -454,6 +460,35 @@ func (c *createConfig) CreateBlockIO() (*spec.LinuxBlockIO, error) { return bio, nil } +func makeThrottleArray(throttleInput []string, rateType int) ([]spec.LinuxThrottleDevice, error) { + var ( + ltds []spec.LinuxThrottleDevice + t *throttleDevice + err error + ) + for _, i := range throttleInput { + if rateType == bps { + t, err = validateBpsDevice(i) + } else { + t, err = validateIOpsDevice(i) + } + if err != nil { + return []spec.LinuxThrottleDevice{}, err + } + ltdStat, err := getStatFromPath(t.path) + if err != nil { + return ltds, errors.Wrapf(err, "error getting stat from path %q", t.path) + } + ltd := spec.LinuxThrottleDevice{ + Rate: t.rate, + } + ltd.Major = int64(unix.Major(ltdStat.Rdev)) + ltd.Minor = int64(unix.Minor(ltdStat.Rdev)) + ltds = append(ltds, ltd) + } + return ltds, nil +} + // GetAnnotations returns the all the annotations for the container func (c *createConfig) GetAnnotations() map[string]string { a := getDefaultAnnotations() @@ -668,27 +703,10 @@ func (c *createConfig) GetContainerCreateOptions() ([]libpod.CtrCreateOption, er return options, nil } -func getStatFromPath(path string) unix.Stat_t { +func getStatFromPath(path string) (unix.Stat_t, error) { s := unix.Stat_t{} - _ = unix.Stat(path, &s) - return s -} - -func makeThrottleArray(throttleInput []string) ([]spec.LinuxThrottleDevice, error) { - var ltds []spec.LinuxThrottleDevice - for _, i := range throttleInput { - t, err := validateBpsDevice(i) - if err != nil { - return []spec.LinuxThrottleDevice{}, err - } - ltd := spec.LinuxThrottleDevice{} - ltd.Rate = t.rate - ltdStat := getStatFromPath(t.path) - ltd.Major = int64(unix.Major(ltdStat.Rdev)) - ltd.Minor = int64(unix.Major(ltdStat.Rdev)) - ltds = append(ltds, ltd) - } - return ltds, nil + err := unix.Stat(path, &s) + return s, err } // CreatePortBindings iterates ports mappings and exposed ports into a format CNI understands |