mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
@@ -222,6 +222,9 @@ type Config struct {
|
||||
|
||||
// Personality contains configuration for the Linux personality syscall.
|
||||
Personality *LinuxPersonality `json:"personality,omitempty"`
|
||||
|
||||
// IOPriority is the container's I/O priority.
|
||||
IOPriority *IOPriority `json:"io_priority,omitempty"`
|
||||
}
|
||||
|
||||
// Scheduler is based on the Linux sched_setattr(2) syscall.
|
||||
@@ -283,6 +286,14 @@ func ToSchedAttr(scheduler *Scheduler) (*unix.SchedAttr, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
var IOPrioClassMapping = map[specs.IOPriorityClass]int{
|
||||
specs.IOPRIO_CLASS_RT: 1,
|
||||
specs.IOPRIO_CLASS_BE: 2,
|
||||
specs.IOPRIO_CLASS_IDLE: 3,
|
||||
}
|
||||
|
||||
type IOPriority = specs.LinuxIOPriority
|
||||
|
||||
type (
|
||||
HookName string
|
||||
HookList []Hook
|
||||
|
||||
@@ -32,6 +32,7 @@ func Validate(config *configs.Config) error {
|
||||
rootlessEUIDCheck,
|
||||
mountsStrict,
|
||||
scheduler,
|
||||
ioPriority,
|
||||
}
|
||||
for _, c := range checks {
|
||||
if err := c(config); err != nil {
|
||||
@@ -396,3 +397,14 @@ func scheduler(config *configs.Config) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ioPriority(config *configs.Config) error {
|
||||
if config.IOPriority == nil {
|
||||
return nil
|
||||
}
|
||||
priority := config.IOPriority.Priority
|
||||
if priority < 0 || priority > 7 {
|
||||
return fmt.Errorf("invalid ioPriority.Priority: %d", priority)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -842,3 +842,32 @@ func TestValidateScheduler(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateIOPriority(t *testing.T) {
|
||||
testCases := []struct {
|
||||
isErr bool
|
||||
priority int
|
||||
}{
|
||||
{isErr: false, priority: 0},
|
||||
{isErr: false, priority: 7},
|
||||
{isErr: true, priority: -1},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
ioPriroty := configs.IOPriority{
|
||||
Priority: tc.priority,
|
||||
}
|
||||
config := &configs.Config{
|
||||
Rootfs: "/var",
|
||||
IOPriority: &ioPriroty,
|
||||
}
|
||||
|
||||
err := Validate(config)
|
||||
if tc.isErr && err == nil {
|
||||
t.Errorf("iopriority: %d, expected error, got nil", tc.priority)
|
||||
}
|
||||
if !tc.isErr && err != nil {
|
||||
t.Errorf("iopriority: %d, expected nil, got error %v", tc.priority, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user