Skip to content

Commit

Permalink
runc exec: fix setting process.ioPriority
Browse files Browse the repository at this point in the history
Commit bfbd030 added IOPriority property 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>
  • Loading branch information
kolyshkin committed Jan 16, 2025
1 parent 30bc73b commit 273da82
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
4 changes: 4 additions & 0 deletions libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,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,
Expand All @@ -720,6 +721,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.

Expand Down
3 changes: 2 additions & 1 deletion libcontainer/init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -672,7 +673,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
Expand Down
2 changes: 1 addition & 1 deletion libcontainer/setns_init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,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
Expand Down
2 changes: 1 addition & 1 deletion libcontainer/standard_init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,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
}

Expand Down
18 changes: 16 additions & 2 deletions tests/integration/ioprio.bats
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,23 @@ function teardown() {
[ "$status" -eq 0 ]
[[ "$output" = *'best-effort: prio 4'* ]]

# Check the process made from the exec command.
# Check the process made from the exec command,
# which should derive ioprio from config.json.
runc exec test_ioprio ionice
[ "$status" -eq 0 ]

[[ "$output" = *'best-effort: prio 4'* ]]

# Run exec with a different priority.
proc='
{
"terminal": false,
"ioPriority": {
"class": "IOPRIO_CLASS_IDLE"
},
"args": [ "/usr/bin/ionice" ],
"cwd": "/"
}'
runc exec --process <(echo "$proc") test_ioprio
[ "$status" -eq 0 ]
[[ "$output" = *'idle'* ]]
}

0 comments on commit 273da82

Please sign in to comment.