Skip to content

Commit 4e0f2f8

Browse files
committed
libcontainer/intelrdt: refactor clos path handling
Simplify the code and make path a property of the container (via intelRdtManager). Signed-off-by: Markus Lehtonen <[email protected]>
1 parent 42a18e7 commit 4e0f2f8

File tree

2 files changed

+17
-36
lines changed

2 files changed

+17
-36
lines changed

libcontainer/container_linux.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,9 +1914,10 @@ func (c *linuxContainer) currentState() (*State, error) {
19141914
startTime, _ = c.initProcess.startTime()
19151915
externalDescriptors = c.initProcess.externalDescriptors()
19161916
}
1917-
intelRdtPath, err := intelrdt.GetIntelRdtPath(c.ID())
1918-
if err != nil {
1919-
intelRdtPath = ""
1917+
1918+
intelRdtPath := ""
1919+
if c.intelRdtManager != nil {
1920+
intelRdtPath = c.intelRdtManager.GetPath()
19201921
}
19211922
state := &State{
19221923
BaseState: BaseState{

libcontainer/intelrdt/intelrdt.go

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -419,18 +419,6 @@ func writeFile(dir, file, data string) error {
419419
return nil
420420
}
421421

422-
func getIntelRdtData(c *configs.Config, pid int) (*intelRdtData, error) {
423-
rootPath, err := getIntelRdtRoot()
424-
if err != nil {
425-
return nil, err
426-
}
427-
return &intelRdtData{
428-
root: rootPath,
429-
config: c,
430-
pid: pid,
431-
}, nil
432-
}
433-
434422
// Get the read-only L3 cache information
435423
func getL3CacheInfo() (*L3CacheInfo, error) {
436424
l3CacheInfo := &L3CacheInfo{}
@@ -546,14 +534,13 @@ func IsMBAScEnabled() bool {
546534
}
547535

548536
// Get the 'container_id' path in Intel RDT "resource control" filesystem
549-
func GetIntelRdtPath(id string) (string, error) {
537+
func (m *intelRdtManager) getIntelRdtPath() (string, error) {
550538
rootPath, err := getIntelRdtRoot()
551539
if err != nil {
552540
return "", err
553541
}
554542

555-
path := filepath.Join(rootPath, id)
556-
return path, nil
543+
return filepath.Join(rootPath, m.id), nil
557544
}
558545

559546
// Applies Intel RDT configuration to the process with the specified pid
@@ -562,16 +549,21 @@ func (m *intelRdtManager) Apply(pid int) (err error) {
562549
if m.config.IntelRdt == nil {
563550
return nil
564551
}
565-
d, err := getIntelRdtData(m.config, pid)
566-
if err != nil && !IsNotFound(err) {
552+
553+
path, err := m.getIntelRdtPath()
554+
if err != nil {
567555
return err
568556
}
569557

570558
m.mu.Lock()
571559
defer m.mu.Unlock()
572-
path, err := d.join(m.id)
573-
if err != nil {
574-
return err
560+
561+
if err := os.MkdirAll(path, 0o755); err != nil {
562+
return NewLastCmdError(err)
563+
}
564+
565+
if err := WriteIntelRdtTasks(path, pid); err != nil {
566+
return NewLastCmdError(err)
575567
}
576568

577569
m.path = path
@@ -593,7 +585,7 @@ func (m *intelRdtManager) Destroy() error {
593585
// restore the object later
594586
func (m *intelRdtManager) GetPath() string {
595587
if m.path == "" {
596-
m.path, _ = GetIntelRdtPath(m.id)
588+
m.path, _ = m.getIntelRdtPath()
597589
}
598590
return m.path
599591
}
@@ -761,18 +753,6 @@ func (m *intelRdtManager) Set(container *configs.Config) error {
761753
return nil
762754
}
763755

764-
func (raw *intelRdtData) join(id string) (string, error) {
765-
path := filepath.Join(raw.root, id)
766-
if err := os.MkdirAll(path, 0o755); err != nil {
767-
return "", NewLastCmdError(err)
768-
}
769-
770-
if err := WriteIntelRdtTasks(path, raw.pid); err != nil {
771-
return "", NewLastCmdError(err)
772-
}
773-
return path, nil
774-
}
775-
776756
type NotFoundError struct {
777757
ResourceControl string
778758
}

0 commit comments

Comments
 (0)