@@ -22,6 +22,7 @@ import (
2222 "github.com/opencontainers/runc/libcontainer/cgroups"
2323 "github.com/opencontainers/runc/libcontainer/configs"
2424 "github.com/opencontainers/runc/libcontainer/criurpc"
25+ "github.com/opencontainers/runc/libcontainer/resourcemanager"
2526 "github.com/opencontainers/runc/libcontainer/system"
2627 "github.com/opencontainers/runc/libcontainer/utils"
2728 "github.com/syndtr/gocapability/capability"
@@ -34,7 +35,7 @@ type linuxContainer struct {
3435 id string
3536 root string
3637 config * configs.Config
37- cgroupManager cgroups. Manager
38+ resourceManagers map [ string ]resourcemanager. ResourceManager
3839 initArgs []string
3940 initProcess parentProcess
4041 initProcessStartTime string
@@ -142,7 +143,7 @@ func (c *linuxContainer) State() (*State, error) {
142143}
143144
144145func (c * linuxContainer ) Processes () ([]int , error ) {
145- pids , err := c .cgroupManager .GetAllPids ()
146+ pids , err := c .resourceManagers [ "cgroups" ] .GetAllPids ()
146147 if err != nil {
147148 return nil , newSystemErrorWithCause (err , "getting all container pids from cgroups" )
148149 }
@@ -154,7 +155,9 @@ func (c *linuxContainer) Stats() (*Stats, error) {
154155 err error
155156 stats = & Stats {}
156157 )
157- if stats .CgroupStats , err = c .cgroupManager .GetStats (); err != nil {
158+ cgroupStats , err := c .resourceManagers ["cgroups" ].GetStats ()
159+ stats .CgroupStats = cgroupStats .(* cgroups.Stats )
160+ if err != nil {
158161 return stats , newSystemErrorWithCause (err , "getting container stats from cgroups" )
159162 }
160163 for _ , iface := range c .config .Networks {
@@ -181,7 +184,12 @@ func (c *linuxContainer) Set(config configs.Config) error {
181184 return newGenericError (fmt .Errorf ("container not running" ), ContainerNotRunning )
182185 }
183186 c .config = & config
184- return c .cgroupManager .Set (c .config )
187+ for _ , resourceManager := range c .resourceManagers {
188+ if err := resourceManager .Set (c .config ); err != nil {
189+ return err
190+ }
191+ }
192+ return nil
185193}
186194
187195func (c * linuxContainer ) Start (process * Process ) error {
@@ -283,7 +291,7 @@ func (c *linuxContainer) start(process *Process, isInit bool) error {
283291
284292func (c * linuxContainer ) Signal (s os.Signal , all bool ) error {
285293 if all {
286- return signalAllProcesses (c .cgroupManager , s )
294+ return signalAllProcesses (c .resourceManagers [ "cgroups" ] , s )
287295 }
288296 if err := c .initProcess .signal (s ); err != nil {
289297 return newSystemErrorWithCause (err , "signaling init process" )
@@ -350,7 +358,7 @@ func (c *linuxContainer) newInitProcess(p *Process, cmd *exec.Cmd, parentPipe, c
350358 cmd : cmd ,
351359 childPipe : childPipe ,
352360 parentPipe : parentPipe ,
353- manager : c . cgroupManager ,
361+ managers : c . resourceManagers ,
354362 config : c .newInitConfig (p ),
355363 container : c ,
356364 process : p ,
@@ -376,7 +384,7 @@ func (c *linuxContainer) newSetnsProcess(p *Process, cmd *exec.Cmd, parentPipe,
376384 p .consoleChan = make (chan * os.File , 1 )
377385 return & setnsProcess {
378386 cmd : cmd ,
379- cgroupPaths : c .cgroupManager .GetPaths (),
387+ cgroupPaths : c .resourceManagers [ "cgroups" ] .GetPaths (),
380388 childPipe : childPipe ,
381389 parentPipe : parentPipe ,
382390 config : c .newInitConfig (p ),
@@ -452,7 +460,7 @@ func (c *linuxContainer) Pause() error {
452460 }
453461 switch status {
454462 case Running , Created :
455- if err := c .cgroupManager .Freeze (configs .Frozen ); err != nil {
463+ if err := c .resourceManagers [ "cgroups" ] .Freeze (configs .Frozen ); err != nil {
456464 return err
457465 }
458466 return c .state .transition (& pausedState {
@@ -472,7 +480,7 @@ func (c *linuxContainer) Resume() error {
472480 if status != Paused {
473481 return newGenericError (fmt .Errorf ("container not paused" ), ContainerNotPaused )
474482 }
475- if err := c .cgroupManager .Freeze (configs .Thawed ); err != nil {
483+ if err := c .resourceManagers [ "cgroups" ] .Freeze (configs .Thawed ); err != nil {
476484 return err
477485 }
478486 return c .state .transition (& runningState {
@@ -481,11 +489,11 @@ func (c *linuxContainer) Resume() error {
481489}
482490
483491func (c * linuxContainer ) NotifyOOM () (<- chan struct {}, error ) {
484- return notifyOnOOM (c .cgroupManager .GetPaths ())
492+ return notifyOnOOM (c .resourceManagers [ "cgroups" ] .GetPaths ())
485493}
486494
487495func (c * linuxContainer ) NotifyMemoryPressure (level PressureLevel ) (<- chan struct {}, error ) {
488- return notifyMemoryPressure (c .cgroupManager .GetPaths (), level )
496+ return notifyMemoryPressure (c .resourceManagers [ "cgroups" ] .GetPaths (), level )
489497}
490498
491499// checkCriuVersion checks Criu version greater than or equal to minVersion
@@ -870,7 +878,7 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error {
870878}
871879
872880func (c * linuxContainer ) criuApplyCgroups (pid int , req * criurpc.CriuReq ) error {
873- if err := c .cgroupManager .Apply (pid ); err != nil {
881+ if err := c .resourceManagers [ "cgroups" ] .Apply (pid ); err != nil {
874882 return err
875883 }
876884
@@ -1224,7 +1232,7 @@ func (c *linuxContainer) runType() (Status, error) {
12241232}
12251233
12261234func (c * linuxContainer ) isPaused () (bool , error ) {
1227- data , err := ioutil .ReadFile (filepath .Join (c .cgroupManager .GetPaths ()["freezer" ], "freezer.state" ))
1235+ data , err := ioutil .ReadFile (filepath .Join (c .resourceManagers [ "cgroups" ] .GetPaths ()["freezer" ], "freezer.state" ))
12281236 if err != nil {
12291237 // If freezer cgroup is not mounted, the container would just be not paused.
12301238 if os .IsNotExist (err ) {
@@ -1254,7 +1262,7 @@ func (c *linuxContainer) currentState() (*State, error) {
12541262 InitProcessStartTime : startTime ,
12551263 Created : c .created ,
12561264 },
1257- CgroupPaths : c .cgroupManager .GetPaths (),
1265+ CgroupPaths : c .resourceManagers [ "cgroups" ] .GetPaths (),
12581266 NamespacePaths : make (map [configs.NamespaceType ]string ),
12591267 ExternalDescriptors : externalDescriptors ,
12601268 }
0 commit comments