-
Notifications
You must be signed in to change notification settings - Fork 330
Expand file tree
/
Copy pathLinuxBlockIO.swift
More file actions
125 lines (115 loc) · 4.73 KB
/
Copy pathLinuxBlockIO.swift
File metadata and controls
125 lines (115 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//===----------------------------------------------------------------------===//
// Copyright © 2026 Apple Inc. and the Containerization project authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//===----------------------------------------------------------------------===//
import ContainerizationOCI
/// Block I/O resource limits applied to the container cgroup.
public struct LinuxBlockIO: Sendable {
/// The relative weight of the cgroup for block I/O. Valid range is 10 to 1000.
public var weight: UInt16?
/// The relative weight applied to tasks of the cgroup but not their descendant cgroups.
public var leafWeight: UInt16?
/// Per-device weight overrides.
public var weightDevice: [LinuxWeightDevice]
/// Per-device read rate limits in bytes per second.
public var throttleReadBpsDevice: [LinuxThrottleDevice]
/// Per-device write rate limits in bytes per second.
public var throttleWriteBpsDevice: [LinuxThrottleDevice]
/// Per-device read rate limits in IO operations per second.
public var throttleReadIOPSDevice: [LinuxThrottleDevice]
/// Per-device write rate limits in IO operations per second.
public var throttleWriteIOPSDevice: [LinuxThrottleDevice]
public init(
weight: UInt16? = nil,
leafWeight: UInt16? = nil,
weightDevice: [LinuxWeightDevice] = [],
throttleReadBpsDevice: [LinuxThrottleDevice] = [],
throttleWriteBpsDevice: [LinuxThrottleDevice] = [],
throttleReadIOPSDevice: [LinuxThrottleDevice] = [],
throttleWriteIOPSDevice: [LinuxThrottleDevice] = []
) {
self.weight = weight
self.leafWeight = leafWeight
self.weightDevice = weightDevice
self.throttleReadBpsDevice = throttleReadBpsDevice
self.throttleWriteBpsDevice = throttleWriteBpsDevice
self.throttleReadIOPSDevice = throttleReadIOPSDevice
self.throttleWriteIOPSDevice = throttleWriteIOPSDevice
}
/// Convert to OCI format for transport.
public func toOCI() -> ContainerizationOCI.LinuxBlockIO {
ContainerizationOCI.LinuxBlockIO(
weight: self.weight,
leafWeight: self.leafWeight,
weightDevice: self.weightDevice.map { $0.toOCI() },
throttleReadBpsDevice: self.throttleReadBpsDevice.map { $0.toOCI() },
throttleWriteBpsDevice: self.throttleWriteBpsDevice.map { $0.toOCI() },
throttleReadIOPSDevice: self.throttleReadIOPSDevice.map { $0.toOCI() },
throttleWriteIOPSDevice: self.throttleWriteIOPSDevice.map { $0.toOCI() }
)
}
}
/// A per-device block I/O weight override.
public struct LinuxWeightDevice: Sendable {
/// The major device number.
public var major: Int64
/// The minor device number.
public var minor: Int64
/// The relative weight applied to the device. Valid range is 10 to 1000.
public var weight: UInt16?
/// The relative weight applied to tasks of the cgroup but not their descendant cgroups.
public var leafWeight: UInt16?
public init(
major: Int64,
minor: Int64,
weight: UInt16? = nil,
leafWeight: UInt16? = nil
) {
self.major = major
self.minor = minor
self.weight = weight
self.leafWeight = leafWeight
}
/// Convert to OCI format for transport.
public func toOCI() -> ContainerizationOCI.LinuxWeightDevice {
ContainerizationOCI.LinuxWeightDevice(
major: self.major,
minor: self.minor,
weight: self.weight,
leafWeight: self.leafWeight
)
}
}
/// A per-device block I/O throughput limit.
public struct LinuxThrottleDevice: Sendable {
/// The major device number.
public var major: Int64
/// The minor device number.
public var minor: Int64
/// The rate limit applied to the device.
public var rate: UInt64
public init(major: Int64, minor: Int64, rate: UInt64) {
self.major = major
self.minor = minor
self.rate = rate
}
/// Convert to OCI format for transport.
public func toOCI() -> ContainerizationOCI.LinuxThrottleDevice {
ContainerizationOCI.LinuxThrottleDevice(
major: self.major,
minor: self.minor,
rate: self.rate
)
}
}