Skip to content

Commit a12d2da

Browse files
committed
Fix setting IOPriority on exec
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 <[email protected]>
1 parent 181bd4b commit a12d2da

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

libcontainer/container_linux.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ func (c *Container) newInitConfig(process *Process) *initConfig {
700700
AppArmorProfile: c.config.AppArmorProfile,
701701
ProcessLabel: c.config.ProcessLabel,
702702
Rlimits: c.config.Rlimits,
703+
IOPriority: c.config.IOPriority,
703704
CreateConsole: process.ConsoleSocket != nil,
704705
ConsoleWidth: process.ConsoleWidth,
705706
ConsoleHeight: process.ConsoleHeight,
@@ -722,6 +723,9 @@ func (c *Container) newInitConfig(process *Process) *initConfig {
722723
if len(process.Rlimits) > 0 {
723724
cfg.Rlimits = process.Rlimits
724725
}
726+
if process.IOPriority != nil {
727+
cfg.IOPriority = process.IOPriority
728+
}
725729

726730
// Set misc properties.
727731

libcontainer/init_linux.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ type initConfig struct {
8282
NoNewPrivileges bool `json:"no_new_privileges"`
8383
ProcessLabel string `json:"process_label"`
8484
Rlimits []configs.Rlimit `json:"rlimits"`
85+
IOPriority *configs.IOPriority `json:"io_priority"`
8586

8687
// Properties that only exist in container config.
8788
// FIXME: they are also passed in Config above.
@@ -700,7 +701,7 @@ func setupScheduler(config *configs.Config) error {
700701
return nil
701702
}
702703

703-
func setupIOPriority(config *configs.Config) error {
704+
func setupIOPriority(config *initConfig) error {
704705
const ioprioWhoPgrp = 1
705706

706707
ioprio := config.IOPriority

libcontainer/setns_init_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (l *linuxSetnsInit) Init() error {
7575
return err
7676
}
7777

78-
if err := setupIOPriority(l.config.Config); err != nil {
78+
if err := setupIOPriority(l.config); err != nil {
7979
return err
8080
}
8181
// Tell our parent that we're ready to exec. This must be done before the

libcontainer/standard_init_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (l *linuxStandardInit) Init() error {
159159
return err
160160
}
161161

162-
if err := setupIOPriority(l.config.Config); err != nil {
162+
if err := setupIOPriority(l.config); err != nil {
163163
return err
164164
}
165165

tests/integration/ioprio.bats

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ function teardown() {
2525
# Check the process made from the exec command.
2626
runc exec test_ioprio ionice
2727
[ "$status" -eq 0 ]
28-
2928
[[ "$output" = *'best-effort: prio 4'* ]]
29+
30+
# Run exec with a different priority.
31+
proc='
32+
{
33+
"terminal": false,
34+
"ioPriority": {
35+
"class": "IOPRIO_CLASS_RT",
36+
"priority": 7
37+
},
38+
"args": [ "/usr/bin/ionice" ],
39+
"cwd": "/"
40+
}'
41+
runc exec --process <(echo "$proc") test_ioprio
42+
[ "$status" -eq 0 ]
43+
[[ "$output" = *'realtime: prio 7'* ]]
3044
}

0 commit comments

Comments
 (0)