@@ -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 {
@@ -295,7 +303,7 @@ func (c *linuxContainer) start(process *Process, isInit bool) error {
295303
296304func (c * linuxContainer ) Signal (s os.Signal , all bool ) error {
297305 if all {
298- return signalAllProcesses (c .cgroupManager , s )
306+ return signalAllProcesses (c .resourceManagers [ "cgroups" ] , s )
299307 }
300308 if err := c .initProcess .signal (s ); err != nil {
301309 return newSystemErrorWithCause (err , "signaling init process" )
@@ -400,7 +408,7 @@ func (c *linuxContainer) newInitProcess(p *Process, cmd *exec.Cmd, parentPipe, c
400408 cmd : cmd ,
401409 childPipe : childPipe ,
402410 parentPipe : parentPipe ,
403- manager : c . cgroupManager ,
411+ managers : c . resourceManagers ,
404412 config : c .newInitConfig (p ),
405413 container : c ,
406414 process : p ,
@@ -426,7 +434,7 @@ func (c *linuxContainer) newSetnsProcess(p *Process, cmd *exec.Cmd, parentPipe,
426434 p .consoleChan = make (chan * os.File , 1 )
427435 return & setnsProcess {
428436 cmd : cmd ,
429- cgroupPaths : c .cgroupManager .GetPaths (),
437+ cgroupPaths : c .resourceManagers [ "cgroups" ] .GetPaths (),
430438 childPipe : childPipe ,
431439 parentPipe : parentPipe ,
432440 config : c .newInitConfig (p ),
@@ -501,7 +509,7 @@ func (c *linuxContainer) Pause() error {
501509 }
502510 switch status {
503511 case Running , Created :
504- if err := c .cgroupManager .Freeze (configs .Frozen ); err != nil {
512+ if err := c .resourceManagers [ "cgroups" ] .Freeze (configs .Frozen ); err != nil {
505513 return err
506514 }
507515 return c .state .transition (& pausedState {
@@ -521,7 +529,7 @@ func (c *linuxContainer) Resume() error {
521529 if status != Paused {
522530 return newGenericError (fmt .Errorf ("container not paused" ), ContainerNotPaused )
523531 }
524- if err := c .cgroupManager .Freeze (configs .Thawed ); err != nil {
532+ if err := c .resourceManagers [ "cgroups" ] .Freeze (configs .Thawed ); err != nil {
525533 return err
526534 }
527535 return c .state .transition (& runningState {
@@ -530,11 +538,11 @@ func (c *linuxContainer) Resume() error {
530538}
531539
532540func (c * linuxContainer ) NotifyOOM () (<- chan struct {}, error ) {
533- return notifyOnOOM (c .cgroupManager .GetPaths ())
541+ return notifyOnOOM (c .resourceManagers [ "cgroups" ] .GetPaths ())
534542}
535543
536544func (c * linuxContainer ) NotifyMemoryPressure (level PressureLevel ) (<- chan struct {}, error ) {
537- return notifyMemoryPressure (c .cgroupManager .GetPaths (), level )
545+ return notifyMemoryPressure (c .resourceManagers [ "cgroups" ] .GetPaths (), level )
538546}
539547
540548// checkCriuVersion checks Criu version greater than or equal to minVersion
@@ -932,7 +940,7 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error {
932940}
933941
934942func (c * linuxContainer ) criuApplyCgroups (pid int , req * criurpc.CriuReq ) error {
935- if err := c .cgroupManager .Apply (pid ); err != nil {
943+ if err := c .resourceManagers [ "cgroups" ] .Apply (pid ); err != nil {
936944 return err
937945 }
938946
@@ -1298,7 +1306,7 @@ func (c *linuxContainer) runType() (Status, error) {
12981306}
12991307
13001308func (c * linuxContainer ) isPaused () (bool , error ) {
1301- data , err := ioutil .ReadFile (filepath .Join (c .cgroupManager .GetPaths ()["freezer" ], "freezer.state" ))
1309+ data , err := ioutil .ReadFile (filepath .Join (c .resourceManagers [ "cgroups" ] .GetPaths ()["freezer" ], "freezer.state" ))
13021310 if err != nil {
13031311 // If freezer cgroup is not mounted, the container would just be not paused.
13041312 if os .IsNotExist (err ) {
@@ -1328,7 +1336,7 @@ func (c *linuxContainer) currentState() (*State, error) {
13281336 InitProcessStartTime : startTime ,
13291337 Created : c .created ,
13301338 },
1331- CgroupPaths : c .cgroupManager .GetPaths (),
1339+ CgroupPaths : c .resourceManagers [ "cgroups" ] .GetPaths (),
13321340 NamespacePaths : make (map [configs.NamespaceType ]string ),
13331341 ExternalDescriptors : externalDescriptors ,
13341342 }
0 commit comments