@@ -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" )
@@ -357,7 +365,7 @@ func (c *linuxContainer) newInitProcess(p *Process, cmd *exec.Cmd, parentPipe, c
357365 cmd : cmd ,
358366 childPipe : childPipe ,
359367 parentPipe : parentPipe ,
360- manager : c . cgroupManager ,
368+ managers : c . resourceManagers ,
361369 config : c .newInitConfig (p ),
362370 container : c ,
363371 process : p ,
@@ -383,7 +391,7 @@ func (c *linuxContainer) newSetnsProcess(p *Process, cmd *exec.Cmd, parentPipe,
383391 p .consoleChan = make (chan * os.File , 1 )
384392 return & setnsProcess {
385393 cmd : cmd ,
386- cgroupPaths : c .cgroupManager .GetPaths (),
394+ cgroupPaths : c .resourceManagers [ "cgroups" ] .GetPaths (),
387395 childPipe : childPipe ,
388396 parentPipe : parentPipe ,
389397 config : c .newInitConfig (p ),
@@ -458,7 +466,7 @@ func (c *linuxContainer) Pause() error {
458466 }
459467 switch status {
460468 case Running , Created :
461- if err := c .cgroupManager .Freeze (configs .Frozen ); err != nil {
469+ if err := c .resourceManagers [ "cgroups" ] .Freeze (configs .Frozen ); err != nil {
462470 return err
463471 }
464472 return c .state .transition (& pausedState {
@@ -478,7 +486,7 @@ func (c *linuxContainer) Resume() error {
478486 if status != Paused {
479487 return newGenericError (fmt .Errorf ("container not paused" ), ContainerNotPaused )
480488 }
481- if err := c .cgroupManager .Freeze (configs .Thawed ); err != nil {
489+ if err := c .resourceManagers [ "cgroups" ] .Freeze (configs .Thawed ); err != nil {
482490 return err
483491 }
484492 return c .state .transition (& runningState {
@@ -487,11 +495,11 @@ func (c *linuxContainer) Resume() error {
487495}
488496
489497func (c * linuxContainer ) NotifyOOM () (<- chan struct {}, error ) {
490- return notifyOnOOM (c .cgroupManager .GetPaths ())
498+ return notifyOnOOM (c .resourceManagers [ "cgroups" ] .GetPaths ())
491499}
492500
493501func (c * linuxContainer ) NotifyMemoryPressure (level PressureLevel ) (<- chan struct {}, error ) {
494- return notifyMemoryPressure (c .cgroupManager .GetPaths (), level )
502+ return notifyMemoryPressure (c .resourceManagers [ "cgroups" ] .GetPaths (), level )
495503}
496504
497505// checkCriuVersion checks Criu version greater than or equal to minVersion
@@ -876,7 +884,7 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error {
876884}
877885
878886func (c * linuxContainer ) criuApplyCgroups (pid int , req * criurpc.CriuReq ) error {
879- if err := c .cgroupManager .Apply (pid ); err != nil {
887+ if err := c .resourceManagers [ "cgroups" ] .Apply (pid ); err != nil {
880888 return err
881889 }
882890
@@ -1230,7 +1238,7 @@ func (c *linuxContainer) runType() (Status, error) {
12301238}
12311239
12321240func (c * linuxContainer ) isPaused () (bool , error ) {
1233- data , err := ioutil .ReadFile (filepath .Join (c .cgroupManager .GetPaths ()["freezer" ], "freezer.state" ))
1241+ data , err := ioutil .ReadFile (filepath .Join (c .resourceManagers [ "cgroups" ] .GetPaths ()["freezer" ], "freezer.state" ))
12341242 if err != nil {
12351243 // If freezer cgroup is not mounted, the container would just be not paused.
12361244 if os .IsNotExist (err ) {
@@ -1260,7 +1268,7 @@ func (c *linuxContainer) currentState() (*State, error) {
12601268 InitProcessStartTime : startTime ,
12611269 Created : c .created ,
12621270 },
1263- CgroupPaths : c .cgroupManager .GetPaths (),
1271+ CgroupPaths : c .resourceManagers [ "cgroups" ] .GetPaths (),
12641272 NamespacePaths : make (map [configs.NamespaceType ]string ),
12651273 ExternalDescriptors : externalDescriptors ,
12661274 }
0 commit comments