runc exec: fix setting process.ioPriority

Commit bfbd0305b added IOPriority field into both Config and Process,
but forgot to add a mechanism to actually use Process.IOPriority.
As a result, runc exec does not set Process.IOPriority ever.

Fix it, and a test case (which fails before the fix).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2025-01-07 19:48:58 -08:00
parent 73849e797f
commit b9114d91e2
7 changed files with 33 additions and 6 deletions
+5
View File
@@ -17,6 +17,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
IDs before calling libcontainer; it is recommended to use Go package
github.com/moby/sys/user for that. (#3999)
### Fixed
* `runc exec -p` no longer ignores specified `ioPriority` setting.
Similarly, libcontainer's `Container.Start` and `Container.Run`
methods no longer ignore `Process.IOPriority` setting. (#4585)
## [1.2.0] - 2024-10-22
> できるときにできることをやるんだ。それが今だ。
+4
View File
@@ -707,6 +707,7 @@ func (c *Container) newInitConfig(process *Process) *initConfig {
AppArmorProfile: c.config.AppArmorProfile,
ProcessLabel: c.config.ProcessLabel,
Rlimits: c.config.Rlimits,
IOPriority: c.config.IOPriority,
CreateConsole: process.ConsoleSocket != nil,
ConsoleWidth: process.ConsoleWidth,
ConsoleHeight: process.ConsoleHeight,
@@ -729,6 +730,9 @@ func (c *Container) newInitConfig(process *Process) *initConfig {
if len(process.Rlimits) > 0 {
cfg.Rlimits = process.Rlimits
}
if process.IOPriority != nil {
cfg.IOPriority = process.IOPriority
}
// Set misc properties.
+2 -1
View File
@@ -81,6 +81,7 @@ type initConfig struct {
NoNewPrivileges bool `json:"no_new_privileges"`
ProcessLabel string `json:"process_label"`
Rlimits []configs.Rlimit `json:"rlimits"`
IOPriority *configs.IOPriority `json:"io_priority,omitempty"`
// Miscellaneous properties, filled in by [Container.newInitConfig]
// unless documented otherwise.
@@ -623,7 +624,7 @@ func setupScheduler(config *configs.Config) error {
return nil
}
func setupIOPriority(config *configs.Config) error {
func setupIOPriority(config *initConfig) error {
const ioprioWhoPgrp = 1
ioprio := config.IOPriority
+3
View File
@@ -114,6 +114,9 @@ type Process struct {
Scheduler *configs.Scheduler
// IOPriority is a process I/O priority.
//
// If not empty, takes precedence over container's [configs.Config.IOPriority].
IOPriority *configs.IOPriority
}
+1 -1
View File
@@ -75,7 +75,7 @@ func (l *linuxSetnsInit) Init() error {
return err
}
if err := setupIOPriority(l.config.Config); err != nil {
if err := setupIOPriority(l.config); err != nil {
return err
}
// Tell our parent that we're ready to exec. This must be done before the
+1 -1
View File
@@ -159,7 +159,7 @@ func (l *linuxStandardInit) Init() error {
return err
}
if err := setupIOPriority(l.config.Config); err != nil {
if err := setupIOPriority(l.config); err != nil {
return err
}
+17 -3
View File
@@ -20,11 +20,25 @@ function teardown() {
# Check the init process.
runc exec test_ioprio ionice -p 1
[ "$status" -eq 0 ]
[[ "$output" = *'best-effort: prio 4'* ]]
[ "${lines[0]}" = 'best-effort: prio 4' ]
# Check the process made from the exec command.
# Check an exec process, which should derive ioprio from config.json.
runc exec test_ioprio ionice
[ "$status" -eq 0 ]
[ "${lines[0]}" = 'best-effort: prio 4' ]
[[ "$output" = *'best-effort: prio 4'* ]]
# Check an exec with a priority taken from process.json,
# which should override the ioprio in config.json.
proc='
{
"terminal": false,
"ioPriority": {
"class": "IOPRIO_CLASS_IDLE"
},
"args": [ "/usr/bin/ionice" ],
"cwd": "/"
}'
runc exec --process <(echo "$proc") test_ioprio
[ "$status" -eq 0 ]
[ "${lines[0]}" = 'idle' ]
}