Skip to content

Commit bdfa0af

Browse files
committed
implement trim operation
1 parent 57668cc commit bdfa0af

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,8 @@ extension FilesystemOperation {
614614
return .freeze(.init())
615615
case .thaw:
616616
return .thaw(.init())
617+
case .trim:
618+
return .trim(.init())
617619
}
618620
}
619621
}

vminitd/Sources/VminitdCore/Server+GRPC.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -753,13 +753,16 @@ extension Initd: Com_Apple_Containerization_Sandbox_V3_SandboxContext.SimpleServ
753753
}
754754
}
755755

756-
private static let FITRIM: UInt = 0xC004_5879
756+
private struct fitrim_range {
757+
var start: UInt64
758+
var len: UInt64
759+
var minimumLen: UInt64
760+
}
757761

758762
private func trimFilesystem(fd: Int32, params: Com_Apple_Containerization_Sandbox_V3_FiTrimParams) throws {
759-
760-
// TODO logic for trim filesystem
761-
762-
let rc: CInt = ioctl(fd, FITRIM, 0)
763+
let FITRIM: UInt = 0xC004_5879
764+
var trange = fitrim_range(start: UInt64(params.start), len: UInt64(params.len), minimumLen: UInt64(params.minimumLen))
765+
let rc: CInt = ioctl(fd, FITRIM, &trange)
763766
if rc != 0 {
764767
let error = swiftErrno("ioctl(FITRIM)")
765768
throw RPCError(code: .internalError, message: "trim failed", cause: error)

0 commit comments

Comments
 (0)