Skip to content

Commit 7285ef1

Browse files
committed
implement trim operation
1 parent 3824bae commit 7285ef1

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
@@ -604,6 +604,8 @@ extension FilesystemOperation {
604604
return .freeze(.init())
605605
case .thaw:
606606
return .thaw(.init())
607+
case .trim:
608+
return .trim(.init())
607609
}
608610
}
609611
}

vminitd/Sources/VminitdCore/Server+GRPC.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -744,13 +744,16 @@ extension Initd: Com_Apple_Containerization_Sandbox_V3_SandboxContext.SimpleServ
744744
}
745745
}
746746

747-
private static let FITRIM: UInt = 0xC004_5879
747+
private struct fitrim_range {
748+
var start: UInt64
749+
var len: UInt64
750+
var minimumLen: UInt64
751+
}
748752

749753
private func trimFilesystem(fd: Int32, params: Com_Apple_Containerization_Sandbox_V3_FiTrimParams) throws {
750-
751-
// TODO logic for trim filesystem
752-
753-
let rc: CInt = ioctl(fd, FITRIM, 0)
754+
let FITRIM: UInt = 0xC004_5879
755+
var trange = fitrim_range(start: UInt64(params.start), len: UInt64(params.len), minimumLen: UInt64(params.minimumLen))
756+
let rc: CInt = ioctl(fd, FITRIM, &trange)
754757
if rc != 0 {
755758
let error = swiftErrno("ioctl(FITRIM)")
756759
throw RPCError(code: .internalError, message: "trim failed", cause: error)

0 commit comments

Comments
 (0)