-
Notifications
You must be signed in to change notification settings - Fork 2.2k
libcontainer/intelrdt: add support for EnableMonitoring field #4832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
520aadd
to
d141fb0
Compare
libcontainer/intelrdt/intelrdt.go
Outdated
@@ -474,6 +474,16 @@ func (m *Manager) Apply(pid int) (err error) { | |||
return newLastCmdError(err) | |||
} | |||
|
|||
// Create MON group | |||
if monPath := m.GetMonPath(); monPath != "" { | |||
if err := os.MkdirAll(monPath, 0o755); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this path? Inside the container? On the host?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is on the host (now changed to Mkdir)
169609d
to
4024488
Compare
86329fe
to
2380794
Compare
Rebased |
e31d98c
to
4af20b5
Compare
Updated:
|
fd132e2
to
4e43d65
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the fmt.Println()
lines
4e43d65
to
2fbcde5
Compare
@@ -478,6 +478,16 @@ func (m *Manager) Apply(pid int) (err error) { | |||
return newLastCmdError(err) | |||
} | |||
|
|||
// Create MON group | |||
if monPath := m.GetMonPath(); monPath != "" { | |||
if err := os.Mkdir(monPath, 0o755); err != nil && !os.IsExist(err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who has control of this path? In runc this is trusted, okay, but is it exposed in k8s or containerd or some other to the user?
Not sure with the https://github.com/intel/k8s-rdt-controller what is exposed to an end user
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's runc, it's in this very same file (and patch):
func (m *Manager) GetMonPath() string {
if closPath := m.GetPath(); closPath != "" && m.config.IntelRdt.EnableMonitoring {
path, err := securejoin.SecureJoin(filepath.Join(closPath, "mon_groups"), m.id)
So it's basically <clos-dir>/mon_groups/<container-id>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, and that comes from intelRdtRoot. But where does that come from? Is there any way an unprivileged user (or just anyone that is not the sysadmin or so) can control any path component (or the intelRDT root)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That, in turn, comes from parsing the output of statfs syscall (unix.Statfs()
). Note that in the case of runc update the closPath is taken from the config.json
of the container.
In any case I cannot see any way that an unprivileged user can control the path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So statfs will have some string value and we will mkdir it on the host, outside of the container rootfs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This conversation was broken out of this thread, it continued in the main PR discussion. The final answer I found for this is posted here: #4832 (comment)
Basically, the fs will be mounted somewhere on the host by the admin and we might create/delete some dirs inside that. None of that is accessible to the container process.
@marquiz correct me if I'm getting something wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kolyshkin PTAL, I'd like someone else to look at this part too, just in case I'm missing something :)
2fbcde5
to
abafdf8
Compare
Rebased (see if the unrelated linter errors go away...) |
@@ -478,6 +478,16 @@ func (m *Manager) Apply(pid int) (err error) { | |||
return newLastCmdError(err) | |||
} | |||
|
|||
// Create MON group | |||
if monPath := m.GetMonPath(); monPath != "" { | |||
if err := os.Mkdir(monPath, 0o755); err != nil && !os.IsExist(err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So statfs will have some string value and we will mkdir it on the host, outside of the container rootfs?
Yes the data comes from the Linux kernel. See statfs syscall, e.g. https://man7.org/linux/man-pages/man2/statfs.2.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mostly LGTM. But let's use the well-known table tests (or are you avoiding them for a reason?)
abafdf8
to
dac3655
Compare
Updated, review comments addressed |
ce987d5
to
88604c3
Compare
Updated @rata |
Signed-off-by: Markus Lehtonen <[email protected]>
88604c3
to
c0415e2
Compare
Rebased to resolve conflicts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I didn't check the tests before. Let's improve and reduce the c&p. Let's make it more standard golang table-tests.
libcontainer/intelrdt/intelrdt.go
Outdated
defer m.mu.Unlock() | ||
if err := os.Remove(m.GetPath()); err != nil && !os.IsNotExist(err) { | ||
return err | ||
if m.config.IntelRdt != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Let's do a quick return if intelRdt is nil and remove the indentation for the rest of the function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed as suggested
closPath := filepath.Join(intelRdtRoot, closID) | ||
intelrdt := newManager(helper.config, "", closPath) | ||
if err := intelrdt.Apply(1234); err == nil { | ||
t.Fatal("unexpected success when applying pid") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this can be part of the for ... range tests
loop,a s it's c&p in every testFunc()
. Yes, one needs a slightly different param, but that can be part of the test struct, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests refactored
helper.config.IntelRdt = &configs.IntelRdt{ | ||
ClosID: closID, | ||
} | ||
|
||
closPath := filepath.Join(intelRdtRoot, closID) | ||
if err := os.MkdirAll(closPath, 0o755); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
intelrdt := newManager(helper.config, "container-1", closPath) | ||
if err := intelrdt.Apply(1234); err != nil { | ||
t.Fatalf("Apply() failed: %v", err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored
c0415e2
to
d7032f0
Compare
The linux.intelRdt.enableMonitoring field enables the creation of a per-container monitoring group. The monitoring group is removed when the container is destroyed. Signed-off-by: Markus Lehtonen <[email protected]>
d7032f0
to
19e2d0a
Compare
Updated: test refactored |
The linux.intelRdt.enableMonitoring field enables the creation of a per-container monitoring group. The monitoring group is removed when the container is destroyed.
Refs: opencontainers/runtime-spec#1287