Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions libcontainer/intelrdt/intelrdt.go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,11 @@ import (
*/

type Manager struct {
mu sync.Mutex
config *configs.Config
id string
path string
mu sync.Mutex
config *configs.Config
id string
path string
directoryCreated bool
}

// NewManager returns a new instance of Manager, or nil if the Intel RDT
Expand Down Expand Up @@ -186,9 +187,10 @@ func NewManager(config *configs.Config, id string, path string) *Manager {
// is actually available. Used by unit tests that mock intelrdt paths.
func newManager(config *configs.Config, id string, path string) *Manager {
return &Manager{
config: config,
id: id,
path: path,
config: config,
id: id,
path: path,
directoryCreated: false,
}
}

Expand Down Expand Up @@ -460,6 +462,14 @@ func (m *Manager) Apply(pid int) (err error) {
}
}

// If the directory doesn't exist we need to create it -> it means we also need
// to clean it up afterwards. Make a note to the manager.
if _, err := os.Stat(path); err != nil {
if os.IsNotExist(err) {
m.directoryCreated = true
}
}

if err := os.Mkdir(path, 0o755); err != nil && !os.IsExist(err) {
return newLastCmdError(err)
}
Expand Down Expand Up @@ -489,8 +499,9 @@ func (m *Manager) Destroy() error {
}
// Don't remove resctrl group if closid has been explicitly specified. The
// group is likely externally managed, i.e. by some other entity than us.
// There are probably other containers/tasks sharing the same group.
if m.config.IntelRdt.ClosID == "" {
// There are probably other containers/tasks sharing the same group. Also
// only remove the directory if it was created by us.
if m.config.IntelRdt.ClosID == "" && m.directoryCreated {
m.mu.Lock()
defer m.mu.Unlock()
if err := os.Remove(m.GetPath()); err != nil && !os.IsNotExist(err) {
Expand Down