Skip to content

Commit 79d292b

Browse files
committed
libcontainer/intelrdt: verify ClosID existence
Check that the ClosID directory pre-exists if no L3 or MB schema has been specified. Conform with the following line from runtime-spec (config-linux): If closID is set, and neither of l3CacheSchema and memBwSchema are set, runtime MUST check if corresponding pre-configured directory closID is present in mounted resctrl. If such pre-configured directory closID exists, runtime MUST assign container to this closID and generate an error if directory does not exist. Add a TODO note for verifying existing schemata against L3/MB parameters. Signed-off-by: Markus Lehtonen <[email protected]>
1 parent 17e3b41 commit 79d292b

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

libcontainer/intelrdt/intelrdt.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ var (
205205
)
206206

207207
type intelRdtData struct {
208-
root string
209208
config *configs.Config
210209
}
211210

@@ -548,6 +547,14 @@ func (m *intelRdtManager) Apply(pid int) (err error) {
548547
m.mu.Lock()
549548
defer m.mu.Unlock()
550549

550+
if m.config.IntelRdt.ClosID != "" && m.config.IntelRdt.L3CacheSchema == "" && m.config.IntelRdt.MemBwSchema == "" {
551+
// Check that the CLOS exists, i.e. it has been pre-configured to
552+
// conform with the runtime spec
553+
if _, err := os.Stat(path); err != nil {
554+
return fmt.Errorf("clos dir not accessible (must be pre-created when l3CacheSchema and memBwSchema are empty): %w", err)
555+
}
556+
}
557+
551558
if err := os.MkdirAll(path, 0o755); err != nil {
552559
return newLastCmdError(err)
553560
}
@@ -723,6 +730,12 @@ func (m *intelRdtManager) Set(container *configs.Config) error {
723730
l3CacheSchema := container.IntelRdt.L3CacheSchema
724731
memBwSchema := container.IntelRdt.MemBwSchema
725732

733+
// TODO: verify that l3CacheSchema and/or memBwSchema match the
734+
// existing schemata if ClosID has been specified. This is a more
735+
// involved than reading the file and doing plain string comparison as
736+
// the value written in does not necessarily match what gets read out
737+
// (leading zeros, cache id ordering etc).
738+
726739
// Write a single joint schema string to schemata file
727740
if l3CacheSchema != "" && memBwSchema != "" {
728741
if err := writeFile(path, "schemata", l3CacheSchema+"\n"+memBwSchema); err != nil {

libcontainer/intelrdt/intelrdt_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package intelrdt
55
import (
66
"errors"
77
"io"
8+
"os"
9+
"path/filepath"
810
"strings"
911
"testing"
1012
)
@@ -111,6 +113,35 @@ func TestIntelRdtSetMemBwScSchema(t *testing.T) {
111113
}
112114
}
113115

116+
func TestApply(t *testing.T) {
117+
helper := NewIntelRdtTestUtil(t)
118+
119+
const closID = "test-clos"
120+
121+
helper.IntelRdtData.config.IntelRdt.ClosID = closID
122+
intelrdt := NewManager(helper.IntelRdtData.config, "", helper.IntelRdtPath)
123+
if err := intelrdt.Apply(1234); err == nil {
124+
t.Fatal("unexpected success when applying pid")
125+
}
126+
if _, err := os.Stat(filepath.Join(helper.IntelRdtPath, closID)); err == nil {
127+
t.Fatal("closid dir should not exist")
128+
}
129+
130+
// Dir should be created if some schema has been specified
131+
intelrdt.(*intelRdtManager).config.IntelRdt.L3CacheSchema = "L3:0=f"
132+
if err := intelrdt.Apply(1235); err != nil {
133+
t.Fatalf("Apply() failed: %v", err)
134+
}
135+
136+
pids, err := getIntelRdtParamString(intelrdt.GetPath(), "tasks")
137+
if err != nil {
138+
t.Fatalf("failed to read tasks file: %v", err)
139+
}
140+
if pids != "1235" {
141+
t.Fatalf("unexpected tasks file, expected '1235', got %q", pids)
142+
}
143+
}
144+
114145
const (
115146
mountinfoValid = `18 40 0:18 / /sys rw,nosuid,nodev,noexec,relatime shared:6 - sysfs sysfs rw
116147
19 40 0:3 / /proc rw,nosuid,nodev,noexec,relatime shared:5 - proc proc rw

libcontainer/intelrdt/util_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ func NewIntelRdtTestUtil(t *testing.T) *intelRdtTestUtil {
3030
config: &configs.Config{
3131
IntelRdt: &configs.IntelRdt{},
3232
},
33-
root: t.TempDir(),
3433
}
35-
testIntelRdtPath := filepath.Join(d.root, "resctrl")
34+
intelRdtRoot = t.TempDir()
35+
testIntelRdtPath := filepath.Join(intelRdtRoot, "resctrl")
3636

3737
// Ensure the full mock Intel RDT "resource control" filesystem path exists
3838
if err := os.MkdirAll(testIntelRdtPath, 0o755); err != nil {

0 commit comments

Comments
 (0)