Skip to content

Commit 7296dc1

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 8772c4d commit 7296dc1

File tree

2 files changed

+16
-36
lines changed

2 files changed

+16
-36
lines changed

libcontainer/container_linux.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,9 +1902,10 @@ func (c *linuxContainer) currentState() (*State, error) {
19021902
startTime, _ = c.initProcess.startTime()
19031903
externalDescriptors = c.initProcess.externalDescriptors()
19041904
}
1905-
intelRdtPath, err := intelrdt.GetIntelRdtPath(c.ID())
1906-
if err != nil {
1907-
intelRdtPath = ""
1905+
1906+
intelRdtPath := ""
1907+
if c.intelRdtManager != nil {
1908+
intelRdtPath = c.intelRdtManager.GetPath()
19081909
}
19091910
state := &State{
19101911
BaseState: BaseState{

libcontainer/intelrdt/intelrdt.go

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ var (
207207
type intelRdtData struct {
208208
root string
209209
config *configs.Config
210-
pid int
211210
}
212211

213212
// Check if Intel RDT sub-features are enabled in featuresInit()
@@ -405,18 +404,6 @@ func writeFile(dir, file, data string) error {
405404
return nil
406405
}
407406

408-
func getIntelRdtData(c *configs.Config, pid int) (*intelRdtData, error) {
409-
rootPath, err := getIntelRdtRoot()
410-
if err != nil {
411-
return nil, err
412-
}
413-
return &intelRdtData{
414-
root: rootPath,
415-
config: c,
416-
pid: pid,
417-
}, nil
418-
}
419-
420407
// Get the read-only L3 cache information
421408
func getL3CacheInfo() (*L3CacheInfo, error) {
422409
l3CacheInfo := &L3CacheInfo{}
@@ -532,14 +519,13 @@ func IsMBAScEnabled() bool {
532519
}
533520

534521
// Get the 'container_id' path in Intel RDT "resource control" filesystem
535-
func GetIntelRdtPath(id string) (string, error) {
522+
func (m *intelRdtManager) getIntelRdtPath() (string, error) {
536523
rootPath, err := getIntelRdtRoot()
537524
if err != nil {
538525
return "", err
539526
}
540527

541-
path := filepath.Join(rootPath, id)
542-
return path, nil
528+
return filepath.Join(rootPath, m.id), nil
543529
}
544530

545531
// Applies Intel RDT configuration to the process with the specified pid
@@ -548,16 +534,21 @@ func (m *intelRdtManager) Apply(pid int) (err error) {
548534
if m.config.IntelRdt == nil {
549535
return nil
550536
}
551-
d, err := getIntelRdtData(m.config, pid)
537+
538+
path, err := m.getIntelRdtPath()
552539
if err != nil {
553540
return err
554541
}
555542

556543
m.mu.Lock()
557544
defer m.mu.Unlock()
558-
path, err := d.join(m.id)
559-
if err != nil {
560-
return err
545+
546+
if err := os.MkdirAll(path, 0o755); err != nil {
547+
return newLastCmdError(err)
548+
}
549+
550+
if err := WriteIntelRdtTasks(path, pid); err != nil {
551+
return newLastCmdError(err)
561552
}
562553

563554
m.path = path
@@ -579,7 +570,7 @@ func (m *intelRdtManager) Destroy() error {
579570
// restore the object later
580571
func (m *intelRdtManager) GetPath() string {
581572
if m.path == "" {
582-
m.path, _ = GetIntelRdtPath(m.id)
573+
m.path, _ = m.getIntelRdtPath()
583574
}
584575
return m.path
585576
}
@@ -747,18 +738,6 @@ func (m *intelRdtManager) Set(container *configs.Config) error {
747738
return nil
748739
}
749740

750-
func (raw *intelRdtData) join(id string) (string, error) {
751-
path := filepath.Join(raw.root, id)
752-
if err := os.MkdirAll(path, 0o755); err != nil {
753-
return "", newLastCmdError(err)
754-
}
755-
756-
if err := WriteIntelRdtTasks(path, raw.pid); err != nil {
757-
return "", err
758-
}
759-
return path, nil
760-
}
761-
762741
func newLastCmdError(err error) error {
763742
status, err1 := getLastCmdStatus()
764743
if err1 == nil {

0 commit comments

Comments
 (0)