Skip to content

Commit 5d3942e

Browse files
committed
libct: unify IOPriority setting
For some reason, io priority is set in different places between runc start/run and runc exec: - for runc start/run, it is done in the middle of (*linuxStandardInit).Init, close to the place where we exec runc init. - for runc exec, it is done much earlier, in (*setnsProcess) start(). Let's move setIOPriority call for runc exec to (*linuxSetnsInit).Init, so it is in the same logical place as for runc start/run. Also, move the function itself to init_linux.go as it's part of init. Should not have any visible effect, except part of runc init is run with a different I/O priority. While at it, rename setIOPriority to setupIOPriority, and make it accept the whole *configs.Config, for uniformity with other similar functions. Fixes: bfbd030 ("Add I/O priority") Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent ec465d3 commit 5d3942e

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

libcontainer/init_linux.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,28 @@ func setupScheduler(config *configs.Config) error {
678678
return nil
679679
}
680680

681+
func setupIOPriority(config *configs.Config) error {
682+
const ioprioWhoPgrp = 1
683+
684+
ioprio := config.IOPriority
685+
if ioprio == nil {
686+
return nil
687+
}
688+
class, ok := configs.IOPrioClassMapping[ioprio.Class]
689+
if !ok {
690+
return fmt.Errorf("invalid io priority class: %s", ioprio.Class)
691+
}
692+
693+
// Combine class and priority into a single value
694+
// https://github.com/torvalds/linux/blob/v5.18/include/uapi/linux/ioprio.h#L5-L17
695+
iop := (class << 13) | ioprio.Priority
696+
_, _, errno := unix.RawSyscall(unix.SYS_IOPRIO_SET, ioprioWhoPgrp, 0, uintptr(iop))
697+
if errno != 0 {
698+
return fmt.Errorf("failed to set io priority: %w", errno)
699+
}
700+
return nil
701+
}
702+
681703
func setupPersonality(config *configs.Config) error {
682704
return system.SetLinuxPersonality(config.Personality.Domain)
683705
}

libcontainer/process_linux.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,6 @@ type setnsProcess struct {
166166
func (p *setnsProcess) start() (retErr error) {
167167
defer p.comm.closeParent()
168168

169-
if err := setIOPriority(p.process.IOPriority); err != nil {
170-
return err
171-
}
172-
173169
// get the "before" value of oom kill count
174170
oom, _ := p.manager.OOMKillCount()
175171
err := p.cmd.Start()
@@ -906,24 +902,3 @@ func (p *Process) InitializeIO(rootuid, rootgid int) (i *IO, err error) {
906902
}
907903
return i, nil
908904
}
909-
910-
func setIOPriority(ioprio *configs.IOPriority) error {
911-
const ioprioWhoPgrp = 1
912-
913-
if ioprio == nil {
914-
return nil
915-
}
916-
class, ok := configs.IOPrioClassMapping[ioprio.Class]
917-
if !ok {
918-
return fmt.Errorf("invalid io priority class: %s", ioprio.Class)
919-
}
920-
921-
// Combine class and priority into a single value
922-
// https://github.com/torvalds/linux/blob/v5.18/include/uapi/linux/ioprio.h#L5-L17
923-
iop := (class << 13) | ioprio.Priority
924-
_, _, errno := unix.RawSyscall(unix.SYS_IOPRIO_SET, ioprioWhoPgrp, 0, uintptr(iop))
925-
if errno != 0 {
926-
return fmt.Errorf("failed to set io priority: %w", errno)
927-
}
928-
return nil
929-
}

libcontainer/setns_init_linux.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ func (l *linuxSetnsInit) Init() error {
7575
return err
7676
}
7777

78+
if err := setupIOPriority(l.config.Config); err != nil {
79+
return err
80+
}
7881
// Tell our parent that we're ready to exec. This must be done before the
7982
// Seccomp rules have been applied, because we need to be able to read and
8083
// write to a socket.

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 := setIOPriority(l.config.Config.IOPriority); err != nil {
162+
if err := setupIOPriority(l.config.Config); err != nil {
163163
return err
164164
}
165165

0 commit comments

Comments
 (0)