forked from opencontainers/runc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs2 cgroup driver was not working because it did not enable controllers while creating cgroup directory; instead it was merely doing MkdirAll() and gathered the list of available controllers in NewManager(). Also, cgroup should be created in Apply(), not while creating a new manager instance. To fix: 1. Move the createCgroupsv2Path function from systemd driver to fs2 driver, renaming it to CreateCgroupPath. Use in Apply() from both fs2 and systemd drivers. 2. Delay available controllers map initialization to until it is needed. With this patch: - NewManager() only performs minimal initialization (initializin m.dirPath, if not provided); - Apply() properly creates cgroup path, enabling the controllers; - m.controllers is initialized lazily on demand. Signed-off-by: Kir Kolyshkin <[email protected]>
- Loading branch information
Showing
3 changed files
with
77 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package fs2 | ||
|
||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
// CreateCgroupPath creates cgroupv2 path, enabling all the | ||
// available controllers in the process. | ||
func CreateCgroupPath(path string) (Err error) { | ||
const file = UnifiedMountpoint + "/cgroup.controllers" | ||
content, err := ioutil.ReadFile(file) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ctrs := bytes.Fields(content) | ||
res := append([]byte("+"), bytes.Join(ctrs, []byte(" +"))...) | ||
|
||
current := "/sys/fs" | ||
elements := strings.Split(path, "/") | ||
for i, e := range elements[3:] { | ||
current = filepath.Join(current, e) | ||
if i > 0 { | ||
if err := os.Mkdir(current, 0755); err != nil { | ||
if !os.IsExist(err) { | ||
return err | ||
} | ||
} else { | ||
// If the directory was created, be sure it is not left around on errors. | ||
current := current | ||
defer func() { | ||
if Err != nil { | ||
os.Remove(current) | ||
} | ||
}() | ||
} | ||
} | ||
if i < len(elements[3:])-1 { | ||
if err := ioutil.WriteFile(filepath.Join(current, "cgroup.subtree_control"), res, 0755); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters