@@ -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 ),
@@ -500,7 +508,7 @@ func (c *linuxContainer) Pause() error {
500508 }
501509 switch status {
502510 case Running , Created :
503- if err := c .cgroupManager .Freeze (configs .Frozen ); err != nil {
511+ if err := c .resourceManagers [ "cgroups" ] .Freeze (configs .Frozen ); err != nil {
504512 return err
505513 }
506514 return c .state .transition (& pausedState {
@@ -520,7 +528,7 @@ func (c *linuxContainer) Resume() error {
520528 if status != Paused {
521529 return newGenericError (fmt .Errorf ("container not paused" ), ContainerNotPaused )
522530 }
523- if err := c .cgroupManager .Freeze (configs .Thawed ); err != nil {
531+ if err := c .resourceManagers [ "cgroups" ] .Freeze (configs .Thawed ); err != nil {
524532 return err
525533 }
526534 return c .state .transition (& runningState {
@@ -529,11 +537,11 @@ func (c *linuxContainer) Resume() error {
529537}
530538
531539func (c * linuxContainer ) NotifyOOM () (<- chan struct {}, error ) {
532- return notifyOnOOM (c .cgroupManager .GetPaths ())
540+ return notifyOnOOM (c .resourceManagers [ "cgroups" ] .GetPaths ())
533541}
534542
535543func (c * linuxContainer ) NotifyMemoryPressure (level PressureLevel ) (<- chan struct {}, error ) {
536- return notifyMemoryPressure (c .cgroupManager .GetPaths (), level )
544+ return notifyMemoryPressure (c .resourceManagers [ "cgroups" ] .GetPaths (), level )
537545}
538546
539547// checkCriuVersion checks Criu version greater than or equal to minVersion
@@ -931,7 +939,7 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error {
931939}
932940
933941func (c * linuxContainer ) criuApplyCgroups (pid int , req * criurpc.CriuReq ) error {
934- if err := c .cgroupManager .Apply (pid ); err != nil {
942+ if err := c .resourceManagers [ "cgroups" ] .Apply (pid ); err != nil {
935943 return err
936944 }
937945
@@ -1297,7 +1305,7 @@ func (c *linuxContainer) runType() (Status, error) {
12971305}
12981306
12991307func (c * linuxContainer ) isPaused () (bool , error ) {
1300- data , err := ioutil .ReadFile (filepath .Join (c .cgroupManager .GetPaths ()["freezer" ], "freezer.state" ))
1308+ data , err := ioutil .ReadFile (filepath .Join (c .resourceManagers [ "cgroups" ] .GetPaths ()["freezer" ], "freezer.state" ))
13011309 if err != nil {
13021310 // If freezer cgroup is not mounted, the container would just be not paused.
13031311 if os .IsNotExist (err ) {
@@ -1327,7 +1335,7 @@ func (c *linuxContainer) currentState() (*State, error) {
13271335 InitProcessStartTime : startTime ,
13281336 Created : c .created ,
13291337 },
1330- CgroupPaths : c .cgroupManager .GetPaths (),
1338+ CgroupPaths : c .resourceManagers [ "cgroups" ] .GetPaths (),
13311339 NamespacePaths : make (map [configs.NamespaceType ]string ),
13321340 ExternalDescriptors : externalDescriptors ,
13331341 }
0 commit comments