Skip to content

Commit 60a9851

Browse files
authored
Merge pull request #155 from klihub/devel/linux-io-priority
api,adaptation,generate: allow setting container I/O priority.
2 parents 5c6533b + 3ad35fa commit 60a9851

File tree

12 files changed

+1318
-638
lines changed

12 files changed

+1318
-638
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ The following pieces of container metadata are available to plugins in NRI:
181181
- mounts
182182
- OCI hooks
183183
- rlimits
184+
- I/O priority
184185
- linux
185186
- namespace IDs
186187
- devices
@@ -227,6 +228,7 @@ container parameters:
227228
- environment variables
228229
- OCI hooks
229230
- rlimits
231+
- I/O priority
230232
- linux
231233
- devices
232234
- resources

pkg/adaptation/adaptation_suite_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,17 @@ var _ = Describe("Plugin container creation adjustments", func() {
514514
},
515515
)
516516

517+
case "I/O priority":
518+
a.SetLinuxIOPriority(&nri.LinuxIOPriority{
519+
Class: api.IOPrioClass_IOPRIO_CLASS_RT,
520+
Priority: 5,
521+
})
522+
523+
case "clear I/O priority":
524+
a.SetLinuxIOPriority(&nri.LinuxIOPriority{
525+
Class: api.IOPrioClass_IOPRIO_CLASS_NONE,
526+
})
527+
517528
case "resources/cpu":
518529
a.SetLinuxCPUShares(123)
519530
a.SetLinuxCPUQuota(456)
@@ -700,6 +711,25 @@ var _ = Describe("Plugin container creation adjustments", func() {
700711
},
701712
},
702713
),
714+
715+
Entry("adjust I/O priority", "I/O priority",
716+
&api.ContainerAdjustment{
717+
Linux: &api.LinuxContainerAdjustment{
718+
IoPriority: &api.LinuxIOPriority{
719+
Class: api.IOPrioClass_IOPRIO_CLASS_RT,
720+
Priority: 5,
721+
},
722+
},
723+
},
724+
),
725+
Entry("clear I/O priority", "clear I/O priority",
726+
&api.ContainerAdjustment{
727+
Linux: &api.LinuxContainerAdjustment{
728+
IoPriority: &api.LinuxIOPriority{},
729+
},
730+
},
731+
),
732+
703733
Entry("adjust CPU resources", "resources/cpu",
704734
&api.ContainerAdjustment{
705735
Linux: &api.LinuxContainerAdjustment{
@@ -921,6 +951,7 @@ var _ = Describe("Plugin container creation adjustments", func() {
921951
},
922952
),
923953
Entry("adjust resources", "resources/classes", false, true, nil),
954+
Entry("adjust I/O priority (conflicts)", "I/O priority", false, true, nil),
924955
)
925956
})
926957

pkg/adaptation/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ type (
8989
LinuxMemory = api.LinuxMemory
9090
LinuxDevice = api.LinuxDevice
9191
LinuxDeviceCgroup = api.LinuxDeviceCgroup
92+
LinuxIOPriority = api.LinuxIOPriority
9293
CDIDevice = api.CDIDevice
9394
HugepageLimit = api.HugepageLimit
9495
Hooks = api.Hooks
@@ -160,6 +161,7 @@ var (
160161
FromOCILinuxNamespaces = api.FromOCILinuxNamespaces
161162
FromOCILinuxDevices = api.FromOCILinuxDevices
162163
FromOCILinuxResources = api.FromOCILinuxResources
164+
FromOCILinuxIOPriority = api.FromOCILinuxIOPriority
163165
DupStringSlice = api.DupStringSlice
164166
DupStringMap = api.DupStringMap
165167
IsMarkedForRemoval = api.IsMarkedForRemoval

pkg/adaptation/result.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ func (r *result) adjust(rpl *ContainerAdjustment, plugin string) error {
221221
if err := r.adjustOomScoreAdj(rpl.Linux.OomScoreAdj, plugin); err != nil {
222222
return err
223223
}
224+
if err := r.adjustIOPriority(rpl.Linux.IoPriority, plugin); err != nil {
225+
return err
226+
}
224227
}
225228
if err := r.adjustRlimits(rpl.Rlimits, plugin); err != nil {
226229
return err
@@ -773,6 +776,23 @@ func (r *result) adjustOomScoreAdj(OomScoreAdj *OptionalInt, plugin string) erro
773776
return nil
774777
}
775778

779+
func (r *result) adjustIOPriority(priority *LinuxIOPriority, plugin string) error {
780+
if priority == nil {
781+
return nil
782+
}
783+
784+
create, id := r.request.create, r.request.create.Container.Id
785+
786+
if err := r.owners.ClaimIOPriority(id, plugin); err != nil {
787+
return err
788+
}
789+
790+
create.Container.Linux.IoPriority = priority
791+
r.reply.adjust.Linux.IoPriority = priority
792+
793+
return nil
794+
}
795+
776796
func (r *result) adjustRlimits(rlimits []*POSIXRlimit, plugin string) error {
777797
create, id, adjust := r.request.create, r.request.create.Container.Id, r.reply.adjust
778798
for _, l := range rlimits {

pkg/api/adjustment.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ func (a *ContainerAdjustment) SetLinuxOomScoreAdj(value *int) {
283283
a.Linux.OomScoreAdj = Int(value) // using Int(value) from ./options.go to optionally allocate a pointer to normalized copy of value
284284
}
285285

286+
// SetLinuxIOPriority records setting the I/O priority for a container.
287+
func (a *ContainerAdjustment) SetLinuxIOPriority(ioprio *LinuxIOPriority) {
288+
a.initLinux()
289+
a.Linux.IoPriority = ioprio
290+
}
291+
286292
//
287293
// Initializing a container adjustment and container update.
288294
//

0 commit comments

Comments
 (0)