Skip to content

Commit b9114d9

Browse files
committed
runc exec: fix setting process.ioPriority
Commit bfbd030 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 <[email protected]>
1 parent 73849e7 commit b9114d9

File tree

7 files changed

+34
-7
lines changed

7 files changed

+34
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
IDs before calling libcontainer; it is recommended to use Go package
1818
github.com/moby/sys/user for that. (#3999)
1919

20+
### Fixed
21+
* `runc exec -p` no longer ignores specified `ioPriority` setting.
22+
Similarly, libcontainer's `Container.Start` and `Container.Run`
23+
methods no longer ignore `Process.IOPriority` setting. (#4585)
24+
2025
## [1.2.0] - 2024-10-22
2126

2227
> できるときにできることをやるんだ。それが今だ。

libcontainer/container_linux.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,7 @@ func (c *Container) newInitConfig(process *Process) *initConfig {
707707
AppArmorProfile: c.config.AppArmorProfile,
708708
ProcessLabel: c.config.ProcessLabel,
709709
Rlimits: c.config.Rlimits,
710+
IOPriority: c.config.IOPriority,
710711
CreateConsole: process.ConsoleSocket != nil,
711712
ConsoleWidth: process.ConsoleWidth,
712713
ConsoleHeight: process.ConsoleHeight,
@@ -729,6 +730,9 @@ func (c *Container) newInitConfig(process *Process) *initConfig {
729730
if len(process.Rlimits) > 0 {
730731
cfg.Rlimits = process.Rlimits
731732
}
733+
if process.IOPriority != nil {
734+
cfg.IOPriority = process.IOPriority
735+
}
732736

733737
// Set misc properties.
734738

libcontainer/init_linux.go

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

8586
// Miscellaneous properties, filled in by [Container.newInitConfig]
8687
// unless documented otherwise.
@@ -623,7 +624,7 @@ func setupScheduler(config *configs.Config) error {
623624
return nil
624625
}
625626

626-
func setupIOPriority(config *configs.Config) error {
627+
func setupIOPriority(config *initConfig) error {
627628
const ioprioWhoPgrp = 1
628629

629630
ioprio := config.IOPriority

libcontainer/process.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ type Process struct {
114114

115115
Scheduler *configs.Scheduler
116116

117+
// IOPriority is a process I/O priority.
118+
//
119+
// If not empty, takes precedence over container's [configs.Config.IOPriority].
117120
IOPriority *configs.IOPriority
118121
}
119122

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: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,25 @@ function teardown() {
2020
# Check the init process.
2121
runc exec test_ioprio ionice -p 1
2222
[ "$status" -eq 0 ]
23-
[[ "$output" = *'best-effort: prio 4'* ]]
23+
[ "${lines[0]}" = 'best-effort: prio 4' ]
2424

25-
# Check the process made from the exec command.
25+
# Check an exec process, which should derive ioprio from config.json.
2626
runc exec test_ioprio ionice
2727
[ "$status" -eq 0 ]
28-
29-
[[ "$output" = *'best-effort: prio 4'* ]]
28+
[ "${lines[0]}" = 'best-effort: prio 4' ]
29+
30+
# Check an exec with a priority taken from process.json,
31+
# which should override the ioprio in config.json.
32+
proc='
33+
{
34+
"terminal": false,
35+
"ioPriority": {
36+
"class": "IOPRIO_CLASS_IDLE"
37+
},
38+
"args": [ "/usr/bin/ionice" ],
39+
"cwd": "/"
40+
}'
41+
runc exec --process <(echo "$proc") test_ioprio
42+
[ "$status" -eq 0 ]
43+
[ "${lines[0]}" = 'idle' ]
3044
}

0 commit comments

Comments
 (0)