File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package fs
22
33import (
4+ "fmt"
5+ "io"
46 "io/ioutil"
57 "os"
8+ "path"
69 "path/filepath"
710 "strconv"
811 "sync"
@@ -75,10 +78,13 @@ type data struct {
7578}
7679
7780func (m * Manager ) Apply (pid int ) error {
81+
7882 if m .Cgroups == nil {
7983 return nil
8084 }
8185
86+ var c = m .Cgroups
87+
8288 d , err := getCgroupData (m .Cgroups , pid )
8389 if err != nil {
8490 return err
@@ -108,6 +114,28 @@ func (m *Manager) Apply(pid int) error {
108114 }
109115 m .Paths = paths
110116
117+ var cpuShares int64
118+
119+ fd , err := os .Open (path .Join (m .Paths ["cpu" ], "cpu.shares" ))
120+ if err != nil {
121+ return err
122+ }
123+
124+ _ , err = fmt .Fscanf (fd , "%d" , & cpuShares )
125+ if err != nil && err != io .EOF {
126+ return err
127+ }
128+
129+ fd .Close ()
130+
131+ if c .CpuShares != 0 {
132+ if c .CpuShares > cpuShares {
133+ return fmt .Errorf ("The maximum allowed cpu-shares is %d" , cpuShares )
134+ } else if c .CpuShares < cpuShares {
135+ return fmt .Errorf ("The minimum allowed cpu-shares is %d" , cpuShares )
136+ }
137+ }
138+
111139 return nil
112140}
113141
Original file line number Diff line number Diff line change @@ -5,8 +5,10 @@ package systemd
55import (
66 "bytes"
77 "fmt"
8+ "io"
89 "io/ioutil"
910 "os"
11+ "path"
1012 "path/filepath"
1113 "strconv"
1214 "strings"
@@ -241,6 +243,28 @@ func (m *Manager) Apply(pid int) error {
241243
242244 m .Paths = paths
243245
246+ var cpuShares int64
247+
248+ fd , err := os .Open (path .Join (m .Paths ["cpu" ], "cpu.shares" ))
249+ if err != nil {
250+ return err
251+ }
252+
253+ _ , err = fmt .Fscanf (fd , "%d" , & cpuShares )
254+ if err != nil && err != io .EOF {
255+ return err
256+ }
257+
258+ fd .Close ()
259+
260+ if c .CpuShares != 0 {
261+ if c .CpuShares > cpuShares {
262+ return fmt .Errorf ("The maximum allowed cpu-shares is %d" , cpuShares )
263+ } else if c .CpuShares < cpuShares {
264+ return fmt .Errorf ("The minimum allowed cpu-shares is %d" , cpuShares )
265+ }
266+ }
267+
244268 return nil
245269}
246270
You can’t perform that action at this time.
0 commit comments