You've already forked runc
mirror of
https://github.com/opencontainers/runc.git
synced 2025-08-09 23:42:44 +03:00
Throw an error if cgroup tries to set cpu-shares more/less than the maximum/minimum permissible value.
Signed-off-by: Shishir Mahajan <shishir.mahajan@redhat.com>
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
package fs
|
package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -75,10 +78,13 @@ type data struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) Apply(pid int) error {
|
func (m *Manager) Apply(pid int) error {
|
||||||
|
|
||||||
if m.Cgroups == nil {
|
if m.Cgroups == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var c = m.Cgroups
|
||||||
|
|
||||||
d, err := getCgroupData(m.Cgroups, pid)
|
d, err := getCgroupData(m.Cgroups, pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -108,6 +114,28 @@ func (m *Manager) Apply(pid int) error {
|
|||||||
}
|
}
|
||||||
m.Paths = paths
|
m.Paths = paths
|
||||||
|
|
||||||
|
var cpuShares int64
|
||||||
|
|
||||||
|
fd, err := os.Open(path.Join(m.Paths["cpu"], "cpu.shares"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = fmt.Fscanf(fd, "%d", &cpuShares)
|
||||||
|
if err != nil && err != io.EOF {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fd.Close()
|
||||||
|
|
||||||
|
if c.CpuShares != 0 {
|
||||||
|
if c.CpuShares > cpuShares {
|
||||||
|
return fmt.Errorf("The maximum allowed cpu-shares is %d", cpuShares)
|
||||||
|
} else if c.CpuShares < cpuShares {
|
||||||
|
return fmt.Errorf("The minimum allowed cpu-shares is %d", cpuShares)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,8 +5,10 @@ package systemd
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -241,6 +243,28 @@ func (m *Manager) Apply(pid int) error {
|
|||||||
|
|
||||||
m.Paths = paths
|
m.Paths = paths
|
||||||
|
|
||||||
|
var cpuShares int64
|
||||||
|
|
||||||
|
fd, err := os.Open(path.Join(m.Paths["cpu"], "cpu.shares"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = fmt.Fscanf(fd, "%d", &cpuShares)
|
||||||
|
if err != nil && err != io.EOF {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fd.Close()
|
||||||
|
|
||||||
|
if c.CpuShares != 0 {
|
||||||
|
if c.CpuShares > cpuShares {
|
||||||
|
return fmt.Errorf("The maximum allowed cpu-shares is %d", cpuShares)
|
||||||
|
} else if c.CpuShares < cpuShares {
|
||||||
|
return fmt.Errorf("The minimum allowed cpu-shares is %d", cpuShares)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user