Skip to content

Commit

Permalink
Fix setting IOPriority on exec
Browse files Browse the repository at this point in the history
Commit bfbd030 added IOPriority for both Config and Process, but
forgot to add a mechanism to overwrite the per-process IOPriority.
As a result, runc exec does not take Process.IOPriority into account.

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

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Jan 8, 2025
1 parent 181bd4b commit a12d2da
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,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 @@ -722,6 +723,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 @@ -82,6 +82,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"`

// Properties that only exist in container config.
// FIXME: they are also passed in Config above.
Expand Down Expand Up @@ -700,7 +701,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 @@ -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
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 @@ -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
}

Expand Down
16 changes: 15 additions & 1 deletion tests/integration/ioprio.bats
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ function teardown() {
# Check the process made from the exec command.
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_RT",
"priority": 7
},
"args": [ "/usr/bin/ionice" ],
"cwd": "/"
}'
runc exec --process <(echo "$proc") test_ioprio
[ "$status" -eq 0 ]
[[ "$output" = *'realtime: prio 7'* ]]
}

0 comments on commit a12d2da

Please sign in to comment.