Skip to content

Commit 6b7b42c

Browse files
authored
[vminitd]: api for trim filesystem operations (#700)
Addition of `vminitd` API for trim filesystem operations Closes #773 Depends on #685
1 parent 5887dc5 commit 6b7b42c

8 files changed

Lines changed: 382 additions & 13 deletions

File tree

Sources/Containerization/SandboxContext/SandboxContext.pb.swift

Lines changed: 217 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,41 @@ public struct Com_Apple_Containerization_Sandbox_V3_StatResponse: @unchecked Sen
10541054
fileprivate var _storage = _StorageClass.defaultInstance
10551055
}
10561056

1057+
public struct Com_Apple_Containerization_Sandbox_V3_FiTrimParams: Sendable {
1058+
// SwiftProtobuf.Message conformance is added in an extension below. See the
1059+
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
1060+
// methods supported on all messages.
1061+
1062+
public var schedule: Com_Apple_Containerization_Sandbox_V3_FiTrimParams.OneOf_Schedule? = nil
1063+
1064+
public var oneShot: Com_Apple_Containerization_Sandbox_V3_FiTrimParams.OneShot {
1065+
get {
1066+
if case .oneShot(let v)? = schedule {return v}
1067+
return Com_Apple_Containerization_Sandbox_V3_FiTrimParams.OneShot()
1068+
}
1069+
set {schedule = .oneShot(newValue)}
1070+
}
1071+
1072+
public var unknownFields = SwiftProtobuf.UnknownStorage()
1073+
1074+
public enum OneOf_Schedule: Equatable, Sendable {
1075+
case oneShot(Com_Apple_Containerization_Sandbox_V3_FiTrimParams.OneShot)
1076+
1077+
}
1078+
1079+
public struct OneShot: Sendable {
1080+
// SwiftProtobuf.Message conformance is added in an extension below. See the
1081+
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
1082+
// methods supported on all messages.
1083+
1084+
public var unknownFields = SwiftProtobuf.UnknownStorage()
1085+
1086+
public init() {}
1087+
}
1088+
1089+
public init() {}
1090+
}
1091+
10571092
public struct Com_Apple_Containerization_Sandbox_V3_FiFreezeParams: Sendable {
10581093
// SwiftProtobuf.Message conformance is added in an extension below. See the
10591094
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
@@ -1074,6 +1109,18 @@ public struct Com_Apple_Containerization_Sandbox_V3_FiThawParams: Sendable {
10741109
public init() {}
10751110
}
10761111

1112+
public struct Com_Apple_Containerization_Sandbox_V3_FiTrimResult: Sendable {
1113+
// SwiftProtobuf.Message conformance is added in an extension below. See the
1114+
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
1115+
// methods supported on all messages.
1116+
1117+
public var trimmedBytes: UInt64 = 0
1118+
1119+
public var unknownFields = SwiftProtobuf.UnknownStorage()
1120+
1121+
public init() {}
1122+
}
1123+
10771124
public struct Com_Apple_Containerization_Sandbox_V3_FilesystemOperationRequest: Sendable {
10781125
// SwiftProtobuf.Message conformance is added in an extension below. See the
10791126
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
@@ -1083,6 +1130,14 @@ public struct Com_Apple_Containerization_Sandbox_V3_FilesystemOperationRequest:
10831130

10841131
public var operation: Com_Apple_Containerization_Sandbox_V3_FilesystemOperationRequest.OneOf_Operation? = nil
10851132

1133+
public var trim: Com_Apple_Containerization_Sandbox_V3_FiTrimParams {
1134+
get {
1135+
if case .trim(let v)? = operation {return v}
1136+
return Com_Apple_Containerization_Sandbox_V3_FiTrimParams()
1137+
}
1138+
set {operation = .trim(newValue)}
1139+
}
1140+
10861141
public var freeze: Com_Apple_Containerization_Sandbox_V3_FiFreezeParams {
10871142
get {
10881143
if case .freeze(let v)? = operation {return v}
@@ -1102,6 +1157,7 @@ public struct Com_Apple_Containerization_Sandbox_V3_FilesystemOperationRequest:
11021157
public var unknownFields = SwiftProtobuf.UnknownStorage()
11031158

11041159
public enum OneOf_Operation: Equatable, Sendable {
1160+
case trim(Com_Apple_Containerization_Sandbox_V3_FiTrimParams)
11051161
case freeze(Com_Apple_Containerization_Sandbox_V3_FiFreezeParams)
11061162
case thaw(Com_Apple_Containerization_Sandbox_V3_FiThawParams)
11071163

@@ -1115,8 +1171,23 @@ public struct Com_Apple_Containerization_Sandbox_V3_FilesystemOperationResponse:
11151171
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
11161172
// methods supported on all messages.
11171173

1174+
public var result: Com_Apple_Containerization_Sandbox_V3_FilesystemOperationResponse.OneOf_Result? = nil
1175+
1176+
public var trim: Com_Apple_Containerization_Sandbox_V3_FiTrimResult {
1177+
get {
1178+
if case .trim(let v)? = result {return v}
1179+
return Com_Apple_Containerization_Sandbox_V3_FiTrimResult()
1180+
}
1181+
set {result = .trim(newValue)}
1182+
}
1183+
11181184
public var unknownFields = SwiftProtobuf.UnknownStorage()
11191185

1186+
public enum OneOf_Result: Equatable, Sendable {
1187+
case trim(Com_Apple_Containerization_Sandbox_V3_FiTrimResult)
1188+
1189+
}
1190+
11201191
public init() {}
11211192
}
11221193

@@ -3247,6 +3318,71 @@ extension Com_Apple_Containerization_Sandbox_V3_StatResponse: SwiftProtobuf.Mess
32473318
}
32483319
}
32493320

3321+
extension Com_Apple_Containerization_Sandbox_V3_FiTrimParams: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
3322+
public static let protoMessageName: String = _protobuf_package + ".FiTrimParams"
3323+
public static let _protobuf_nameMap = SwiftProtobuf._NameMap(bytecode: "\0\u{3}one_shot\0")
3324+
3325+
public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
3326+
while let fieldNumber = try decoder.nextFieldNumber() {
3327+
// The use of inline closures is to circumvent an issue where the compiler
3328+
// allocates stack space for every case branch when no optimizations are
3329+
// enabled. https://github.com/apple/swift-protobuf/issues/1034
3330+
switch fieldNumber {
3331+
case 1: try {
3332+
var v: Com_Apple_Containerization_Sandbox_V3_FiTrimParams.OneShot?
3333+
var hadOneofValue = false
3334+
if let current = self.schedule {
3335+
hadOneofValue = true
3336+
if case .oneShot(let m) = current {v = m}
3337+
}
3338+
try decoder.decodeSingularMessageField(value: &v)
3339+
if let v = v {
3340+
if hadOneofValue {try decoder.handleConflictingOneOf()}
3341+
self.schedule = .oneShot(v)
3342+
}
3343+
}()
3344+
default: break
3345+
}
3346+
}
3347+
}
3348+
3349+
public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
3350+
// The use of inline closures is to circumvent an issue where the compiler
3351+
// allocates stack space for every if/case branch local when no optimizations
3352+
// are enabled. https://github.com/apple/swift-protobuf/issues/1034 and
3353+
// https://github.com/apple/swift-protobuf/issues/1182
3354+
try { if case .oneShot(let v)? = self.schedule {
3355+
try visitor.visitSingularMessageField(value: v, fieldNumber: 1)
3356+
} }()
3357+
try unknownFields.traverse(visitor: &visitor)
3358+
}
3359+
3360+
public static func ==(lhs: Com_Apple_Containerization_Sandbox_V3_FiTrimParams, rhs: Com_Apple_Containerization_Sandbox_V3_FiTrimParams) -> Bool {
3361+
if lhs.schedule != rhs.schedule {return false}
3362+
if lhs.unknownFields != rhs.unknownFields {return false}
3363+
return true
3364+
}
3365+
}
3366+
3367+
extension Com_Apple_Containerization_Sandbox_V3_FiTrimParams.OneShot: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
3368+
public static let protoMessageName: String = Com_Apple_Containerization_Sandbox_V3_FiTrimParams.protoMessageName + ".OneShot"
3369+
public static let _protobuf_nameMap = SwiftProtobuf._NameMap()
3370+
3371+
public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
3372+
// Load everything into unknown fields
3373+
while try decoder.nextFieldNumber() != nil {}
3374+
}
3375+
3376+
public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
3377+
try unknownFields.traverse(visitor: &visitor)
3378+
}
3379+
3380+
public static func ==(lhs: Com_Apple_Containerization_Sandbox_V3_FiTrimParams.OneShot, rhs: Com_Apple_Containerization_Sandbox_V3_FiTrimParams.OneShot) -> Bool {
3381+
if lhs.unknownFields != rhs.unknownFields {return false}
3382+
return true
3383+
}
3384+
}
3385+
32503386
extension Com_Apple_Containerization_Sandbox_V3_FiFreezeParams: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
32513387
public static let protoMessageName: String = _protobuf_package + ".FiFreezeParams"
32523388
public static let _protobuf_nameMap = SwiftProtobuf._NameMap()
@@ -3285,9 +3421,39 @@ extension Com_Apple_Containerization_Sandbox_V3_FiThawParams: SwiftProtobuf.Mess
32853421
}
32863422
}
32873423

3424+
extension Com_Apple_Containerization_Sandbox_V3_FiTrimResult: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
3425+
public static let protoMessageName: String = _protobuf_package + ".FiTrimResult"
3426+
public static let _protobuf_nameMap = SwiftProtobuf._NameMap(bytecode: "\0\u{3}trimmed_bytes\0")
3427+
3428+
public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
3429+
while let fieldNumber = try decoder.nextFieldNumber() {
3430+
// The use of inline closures is to circumvent an issue where the compiler
3431+
// allocates stack space for every case branch when no optimizations are
3432+
// enabled. https://github.com/apple/swift-protobuf/issues/1034
3433+
switch fieldNumber {
3434+
case 1: try { try decoder.decodeSingularUInt64Field(value: &self.trimmedBytes) }()
3435+
default: break
3436+
}
3437+
}
3438+
}
3439+
3440+
public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
3441+
if self.trimmedBytes != 0 {
3442+
try visitor.visitSingularUInt64Field(value: self.trimmedBytes, fieldNumber: 1)
3443+
}
3444+
try unknownFields.traverse(visitor: &visitor)
3445+
}
3446+
3447+
public static func ==(lhs: Com_Apple_Containerization_Sandbox_V3_FiTrimResult, rhs: Com_Apple_Containerization_Sandbox_V3_FiTrimResult) -> Bool {
3448+
if lhs.trimmedBytes != rhs.trimmedBytes {return false}
3449+
if lhs.unknownFields != rhs.unknownFields {return false}
3450+
return true
3451+
}
3452+
}
3453+
32883454
extension Com_Apple_Containerization_Sandbox_V3_FilesystemOperationRequest: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
32893455
public static let protoMessageName: String = _protobuf_package + ".FilesystemOperationRequest"
3290-
public static let _protobuf_nameMap = SwiftProtobuf._NameMap(bytecode: "\0\u{1}path\0\u{1}freeze\0\u{1}thaw\0")
3456+
public static let _protobuf_nameMap = SwiftProtobuf._NameMap(bytecode: "\0\u{1}path\0\u{1}trim\0\u{1}freeze\0\u{1}thaw\0")
32913457

32923458
public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
32933459
while let fieldNumber = try decoder.nextFieldNumber() {
@@ -3297,6 +3463,19 @@ extension Com_Apple_Containerization_Sandbox_V3_FilesystemOperationRequest: Swif
32973463
switch fieldNumber {
32983464
case 1: try { try decoder.decodeSingularStringField(value: &self.path) }()
32993465
case 2: try {
3466+
var v: Com_Apple_Containerization_Sandbox_V3_FiTrimParams?
3467+
var hadOneofValue = false
3468+
if let current = self.operation {
3469+
hadOneofValue = true
3470+
if case .trim(let m) = current {v = m}
3471+
}
3472+
try decoder.decodeSingularMessageField(value: &v)
3473+
if let v = v {
3474+
if hadOneofValue {try decoder.handleConflictingOneOf()}
3475+
self.operation = .trim(v)
3476+
}
3477+
}()
3478+
case 3: try {
33003479
var v: Com_Apple_Containerization_Sandbox_V3_FiFreezeParams?
33013480
var hadOneofValue = false
33023481
if let current = self.operation {
@@ -3309,7 +3488,7 @@ extension Com_Apple_Containerization_Sandbox_V3_FilesystemOperationRequest: Swif
33093488
self.operation = .freeze(v)
33103489
}
33113490
}()
3312-
case 3: try {
3491+
case 4: try {
33133492
var v: Com_Apple_Containerization_Sandbox_V3_FiThawParams?
33143493
var hadOneofValue = false
33153494
if let current = self.operation {
@@ -3336,13 +3515,17 @@ extension Com_Apple_Containerization_Sandbox_V3_FilesystemOperationRequest: Swif
33363515
try visitor.visitSingularStringField(value: self.path, fieldNumber: 1)
33373516
}
33383517
switch self.operation {
3518+
case .trim?: try {
3519+
guard case .trim(let v)? = self.operation else { preconditionFailure() }
3520+
try visitor.visitSingularMessageField(value: v, fieldNumber: 2)
3521+
}()
33393522
case .freeze?: try {
33403523
guard case .freeze(let v)? = self.operation else { preconditionFailure() }
3341-
try visitor.visitSingularMessageField(value: v, fieldNumber: 2)
3524+
try visitor.visitSingularMessageField(value: v, fieldNumber: 3)
33423525
}()
33433526
case .thaw?: try {
33443527
guard case .thaw(let v)? = self.operation else { preconditionFailure() }
3345-
try visitor.visitSingularMessageField(value: v, fieldNumber: 3)
3528+
try visitor.visitSingularMessageField(value: v, fieldNumber: 4)
33463529
}()
33473530
case nil: break
33483531
}
@@ -3359,18 +3542,45 @@ extension Com_Apple_Containerization_Sandbox_V3_FilesystemOperationRequest: Swif
33593542

33603543
extension Com_Apple_Containerization_Sandbox_V3_FilesystemOperationResponse: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
33613544
public static let protoMessageName: String = _protobuf_package + ".FilesystemOperationResponse"
3362-
public static let _protobuf_nameMap = SwiftProtobuf._NameMap()
3545+
public static let _protobuf_nameMap = SwiftProtobuf._NameMap(bytecode: "\0\u{1}trim\0")
33633546

33643547
public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
3365-
// Load everything into unknown fields
3366-
while try decoder.nextFieldNumber() != nil {}
3548+
while let fieldNumber = try decoder.nextFieldNumber() {
3549+
// The use of inline closures is to circumvent an issue where the compiler
3550+
// allocates stack space for every case branch when no optimizations are
3551+
// enabled. https://github.com/apple/swift-protobuf/issues/1034
3552+
switch fieldNumber {
3553+
case 1: try {
3554+
var v: Com_Apple_Containerization_Sandbox_V3_FiTrimResult?
3555+
var hadOneofValue = false
3556+
if let current = self.result {
3557+
hadOneofValue = true
3558+
if case .trim(let m) = current {v = m}
3559+
}
3560+
try decoder.decodeSingularMessageField(value: &v)
3561+
if let v = v {
3562+
if hadOneofValue {try decoder.handleConflictingOneOf()}
3563+
self.result = .trim(v)
3564+
}
3565+
}()
3566+
default: break
3567+
}
3568+
}
33673569
}
33683570

33693571
public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
3572+
// The use of inline closures is to circumvent an issue where the compiler
3573+
// allocates stack space for every if/case branch local when no optimizations
3574+
// are enabled. https://github.com/apple/swift-protobuf/issues/1034 and
3575+
// https://github.com/apple/swift-protobuf/issues/1182
3576+
try { if case .trim(let v)? = self.result {
3577+
try visitor.visitSingularMessageField(value: v, fieldNumber: 1)
3578+
} }()
33703579
try unknownFields.traverse(visitor: &visitor)
33713580
}
33723581

33733582
public static func ==(lhs: Com_Apple_Containerization_Sandbox_V3_FilesystemOperationResponse, rhs: Com_Apple_Containerization_Sandbox_V3_FilesystemOperationResponse) -> Bool {
3583+
if lhs.result != rhs.result {return false}
33743584
if lhs.unknownFields != rhs.unknownFields {return false}
33753585
return true
33763586
}

Sources/Containerization/SandboxContext/SandboxContext.proto

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,18 +294,34 @@ message StatResponse {
294294
string error = 2; // Non-empty if stat failed.
295295
}
296296

297+
message FiTrimParams {
298+
oneof schedule {
299+
OneShot one_shot = 1;
300+
}
301+
302+
message OneShot {}
303+
}
297304
message FiFreezeParams {}
298305
message FiThawParams {}
299306

307+
message FiTrimResult {
308+
uint64 trimmed_bytes = 1;
309+
}
310+
300311
message FilesystemOperationRequest {
301312
string path = 1;
302313
oneof operation {
303-
FiFreezeParams freeze = 2;
304-
FiThawParams thaw = 3;
314+
FiTrimParams trim = 2;
315+
FiFreezeParams freeze = 3;
316+
FiThawParams thaw = 4;
305317
}
306318
}
307319

308-
message FilesystemOperationResponse {}
320+
message FilesystemOperationResponse {
321+
oneof result {
322+
FiTrimResult trim = 1;
323+
}
324+
}
309325

310326
message IpLinkSetRequest {
311327
string interface = 1;

Sources/Containerization/VirtualMachineAgent.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public struct WriteFileFlags {
2828
public enum FilesystemOperation: Sendable {
2929
case freeze
3030
case thaw
31+
case trim
3132
}
3233

3334
/// A protocol for the agent running inside a virtual machine. If an operation isn't

Sources/Containerization/Vminitd.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,11 @@ extension FilesystemOperation {
631631
return .freeze(.init())
632632
case .thaw:
633633
return .thaw(.init())
634+
case .trim:
635+
return .trim(
636+
.with {
637+
$0.oneShot = .init()
638+
})
634639
}
635640
}
636641
}

0 commit comments

Comments
 (0)