Skip to content

Commit 2dc3ea4

Browse files
committed
libct: simplify setIOPriority/setupScheduler calls
Move the nil check inside, simplifying the callers. Fixes: bfbd030 ("Add I/O priority") Fixes: 770728e ("Support `process.scheduler`") Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 2e906e2 commit 2dc3ea4

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

libcontainer/init_linux.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,9 @@ func setupRlimits(limits []configs.Rlimit, pid int) error {
662662
}
663663

664664
func setupScheduler(config *configs.Config) error {
665+
if config.Scheduler == nil {
666+
return nil
667+
}
665668
attr, err := configs.ToSchedAttr(config.Scheduler)
666669
if err != nil {
667670
return err

libcontainer/process_linux.go

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

169-
if p.process.IOPriority != nil {
170-
if err := setIOPriority(p.process.IOPriority); err != nil {
171-
return err
172-
}
169+
if err := setIOPriority(p.process.IOPriority); err != nil {
170+
return err
173171
}
174172

175173
// get the "before" value of oom kill count
@@ -912,6 +910,9 @@ func (p *Process) InitializeIO(rootuid, rootgid int) (i *IO, err error) {
912910
func setIOPriority(ioprio *configs.IOPriority) error {
913911
const ioprioWhoPgrp = 1
914912

913+
if ioprio == nil {
914+
return nil
915+
}
915916
class, ok := configs.IOPrioClassMapping[ioprio.Class]
916917
if !ok {
917918
return fmt.Errorf("invalid io priority class: %s", ioprio.Class)

libcontainer/setns_init_linux.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,8 @@ func (l *linuxSetnsInit) Init() error {
7171
unix.Umask(int(*l.config.Config.Umask))
7272
}
7373

74-
if l.config.Config.Scheduler != nil {
75-
if err := setupScheduler(l.config.Config); err != nil {
76-
return err
77-
}
74+
if err := setupScheduler(l.config.Config); err != nil {
75+
return err
7876
}
7977

8078
// Tell our parent that we're ready to exec. This must be done before the

libcontainer/standard_init_linux.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,12 @@ func (l *linuxStandardInit) Init() error {
155155
}
156156
}
157157

158-
if l.config.Config.Scheduler != nil {
159-
if err := setupScheduler(l.config.Config); err != nil {
160-
return err
161-
}
158+
if err := setupScheduler(l.config.Config); err != nil {
159+
return err
162160
}
163-
if l.config.Config.IOPriority != nil {
164-
if err := setIOPriority(l.config.Config.IOPriority); err != nil {
165-
return err
166-
}
161+
162+
if err := setIOPriority(l.config.Config.IOPriority); err != nil {
163+
return err
167164
}
168165

169166
// Tell our parent that we're ready to exec. This must be done before the

0 commit comments

Comments
 (0)