Skip to content

Commit

Permalink
libct: simplify setIOPriority/setupScheduler calls
Browse files Browse the repository at this point in the history
Move the nil check to inside those functions, simplifying the callers.

Signed-off-by: Kir Kolyshkin <[email protected]>
  • Loading branch information
kolyshkin committed Jun 26, 2024
1 parent ab010ae commit 593fcf9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
3 changes: 3 additions & 0 deletions libcontainer/init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,9 @@ func setupRlimits(limits []configs.Rlimit, pid int) error {
}

func setupScheduler(config *configs.Config) error {
if config.Scheduler == nil {
return nil
}
attr, err := configs.ToSchedAttr(config.Scheduler)
if err != nil {
return err
Expand Down
9 changes: 5 additions & 4 deletions libcontainer/process_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,8 @@ func (p *setnsProcess) signal(sig os.Signal) error {
func (p *setnsProcess) start() (retErr error) {
defer p.comm.closeParent()

if p.process.IOPriority != nil {
if err := setIOPriority(p.process.IOPriority); err != nil {
return err
}
if err := setIOPriority(p.process.IOPriority); err != nil {
return err
}

// get the "before" value of oom kill count
Expand Down Expand Up @@ -992,6 +990,9 @@ func initWaiter(r io.Reader) chan error {
func setIOPriority(ioprio *configs.IOPriority) error {
const ioprioWhoPgrp = 1

if ioprio == nil {
return nil
}
class, ok := configs.IOPrioClassMapping[ioprio.Class]
if !ok {
return fmt.Errorf("invalid io priority class: %s", ioprio.Class)
Expand Down
6 changes: 2 additions & 4 deletions libcontainer/setns_init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ func (l *linuxSetnsInit) Init() error {
unix.Umask(int(*l.config.Config.Umask))
}

if l.config.Config.Scheduler != nil {
if err := setupScheduler(l.config.Config); err != nil {
return err
}
if err := setupScheduler(l.config.Config); err != nil {
return err
}

// Tell our parent that we're ready to exec. This must be done before the
Expand Down
13 changes: 5 additions & 8 deletions libcontainer/standard_init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,12 @@ func (l *linuxStandardInit) Init() error {
}
}

if l.config.Config.Scheduler != nil {
if err := setupScheduler(l.config.Config); err != nil {
return err
}
if err := setupScheduler(l.config.Config); err != nil {
return err
}
if l.config.Config.IOPriority != nil {
if err := setIOPriority(l.config.Config.IOPriority); err != nil {
return err
}

if err := setIOPriority(l.config.Config.IOPriority); err != nil {
return err
}

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

0 comments on commit 593fcf9

Please sign in to comment.