Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Sources/Containerization/Agent/Vminitd.swift
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,29 @@ extension Vminitd {
try await Task.sleep(for: .milliseconds(10))
try await self.sync()
}

/// Send a filesystem event notification to the guest.
public func notifyFileSystemEvent(path: String, eventType: Com_Apple_Containerization_Sandbox_V3_FileSystemEventType) async throws
-> Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse
{
let request = Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest.with {
$0.path = path
$0.eventType = eventType
}

let requests = AsyncStream<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest> { continuation in
continuation.yield(request)
continuation.finish()
}

let responses = client.notifyFileSystemEvent(requests)

for try await response in responses {
return response
}

throw ContainerizationError(.internalError, message: "No response received from notifyFileSystemEvent")
}
}

extension Hosts {
Expand Down
113 changes: 113 additions & 0 deletions Sources/Containerization/SandboxContext/SandboxContext.grpc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ public protocol Com_Apple_Containerization_Sandbox_V3_SandboxContextClientProtoc
_ request: Com_Apple_Containerization_Sandbox_V3_KillRequest,
callOptions: CallOptions?
) -> UnaryCall<Com_Apple_Containerization_Sandbox_V3_KillRequest, Com_Apple_Containerization_Sandbox_V3_KillResponse>

func notifyFileSystemEvent(
callOptions: CallOptions?,
handler: @escaping (Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse) -> Void
) -> BidirectionalStreamingCall<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest, Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse>
}

extension Com_Apple_Containerization_Sandbox_V3_SandboxContextClientProtocol {
Expand Down Expand Up @@ -638,6 +643,27 @@ extension Com_Apple_Containerization_Sandbox_V3_SandboxContextClientProtocol {
interceptors: self.interceptors?.makeKillInterceptors() ?? []
)
}

/// Notify guest of filesystem events from host.
///
/// Callers should use the `send` method on the returned object to send messages
/// to the server. The caller should send an `.end` after the final message has been sent.
///
/// - Parameters:
/// - callOptions: Call options.
/// - handler: A closure called when each response is received from the server.
/// - Returns: A `ClientStreamingCall` with futures for the metadata and status.
public func notifyFileSystemEvent(
callOptions: CallOptions? = nil,
handler: @escaping (Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse) -> Void
) -> BidirectionalStreamingCall<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest, Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse> {
return self.makeBidirectionalStreamingCall(
path: Com_Apple_Containerization_Sandbox_V3_SandboxContextClientMetadata.Methods.notifyFileSystemEvent.path,
callOptions: callOptions ?? self.defaultCallOptions,
interceptors: self.interceptors?.makeNotifyFileSystemEventInterceptors() ?? [],
handler: handler
)
}
}

@available(*, deprecated)
Expand Down Expand Up @@ -832,6 +858,10 @@ public protocol Com_Apple_Containerization_Sandbox_V3_SandboxContextAsyncClientP
_ request: Com_Apple_Containerization_Sandbox_V3_KillRequest,
callOptions: CallOptions?
) -> GRPCAsyncUnaryCall<Com_Apple_Containerization_Sandbox_V3_KillRequest, Com_Apple_Containerization_Sandbox_V3_KillResponse>

func makeNotifyFileSystemEventCall(
callOptions: CallOptions?
) -> GRPCAsyncBidirectionalStreamingCall<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest, Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse>
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
Expand Down Expand Up @@ -1155,6 +1185,16 @@ extension Com_Apple_Containerization_Sandbox_V3_SandboxContextAsyncClientProtoco
interceptors: self.interceptors?.makeKillInterceptors() ?? []
)
}

public func makeNotifyFileSystemEventCall(
callOptions: CallOptions? = nil
) -> GRPCAsyncBidirectionalStreamingCall<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest, Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse> {
return self.makeAsyncBidirectionalStreamingCall(
path: Com_Apple_Containerization_Sandbox_V3_SandboxContextClientMetadata.Methods.notifyFileSystemEvent.path,
callOptions: callOptions ?? self.defaultCallOptions,
interceptors: self.interceptors?.makeNotifyFileSystemEventInterceptors() ?? []
)
}
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
Expand Down Expand Up @@ -1470,6 +1510,30 @@ extension Com_Apple_Containerization_Sandbox_V3_SandboxContextAsyncClientProtoco
interceptors: self.interceptors?.makeKillInterceptors() ?? []
)
}

public func notifyFileSystemEvent<RequestStream>(
_ requests: RequestStream,
callOptions: CallOptions? = nil
) -> GRPCAsyncResponseStream<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse> where RequestStream: Sequence, RequestStream.Element == Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest {
return self.performAsyncBidirectionalStreamingCall(
path: Com_Apple_Containerization_Sandbox_V3_SandboxContextClientMetadata.Methods.notifyFileSystemEvent.path,
requests: requests,
callOptions: callOptions ?? self.defaultCallOptions,
interceptors: self.interceptors?.makeNotifyFileSystemEventInterceptors() ?? []
)
}

public func notifyFileSystemEvent<RequestStream>(
_ requests: RequestStream,
callOptions: CallOptions? = nil
) -> GRPCAsyncResponseStream<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse> where RequestStream: AsyncSequence & Sendable, RequestStream.Element == Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest {
return self.performAsyncBidirectionalStreamingCall(
path: Com_Apple_Containerization_Sandbox_V3_SandboxContextClientMetadata.Methods.notifyFileSystemEvent.path,
requests: requests,
callOptions: callOptions ?? self.defaultCallOptions,
interceptors: self.interceptors?.makeNotifyFileSystemEventInterceptors() ?? []
)
}
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
Expand Down Expand Up @@ -1568,6 +1632,9 @@ public protocol Com_Apple_Containerization_Sandbox_V3_SandboxContextClientInterc

/// - Returns: Interceptors to use when invoking 'kill'.
func makeKillInterceptors() -> [ClientInterceptor<Com_Apple_Containerization_Sandbox_V3_KillRequest, Com_Apple_Containerization_Sandbox_V3_KillResponse>]

/// - Returns: Interceptors to use when invoking 'notifyFileSystemEvent'.
func makeNotifyFileSystemEventInterceptors() -> [ClientInterceptor<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest, Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse>]
}

public enum Com_Apple_Containerization_Sandbox_V3_SandboxContextClientMetadata {
Expand Down Expand Up @@ -1601,6 +1668,7 @@ public enum Com_Apple_Containerization_Sandbox_V3_SandboxContextClientMetadata {
Com_Apple_Containerization_Sandbox_V3_SandboxContextClientMetadata.Methods.configureHosts,
Com_Apple_Containerization_Sandbox_V3_SandboxContextClientMetadata.Methods.sync,
Com_Apple_Containerization_Sandbox_V3_SandboxContextClientMetadata.Methods.kill,
Com_Apple_Containerization_Sandbox_V3_SandboxContextClientMetadata.Methods.notifyFileSystemEvent,
]
)

Expand Down Expand Up @@ -1760,6 +1828,12 @@ public enum Com_Apple_Containerization_Sandbox_V3_SandboxContextClientMetadata {
path: "/com.apple.containerization.sandbox.v3.SandboxContext/Kill",
type: GRPCCallType.unary
)

public static let notifyFileSystemEvent = GRPCMethodDescriptor(
name: "NotifyFileSystemEvent",
path: "/com.apple.containerization.sandbox.v3.SandboxContext/NotifyFileSystemEvent",
type: GRPCCallType.bidirectionalStreaming
)
}
}

Expand Down Expand Up @@ -1847,6 +1921,9 @@ public protocol Com_Apple_Containerization_Sandbox_V3_SandboxContextProvider: Ca

/// Send a signal to a process via the PID.
func kill(request: Com_Apple_Containerization_Sandbox_V3_KillRequest, context: StatusOnlyCallContext) -> EventLoopFuture<Com_Apple_Containerization_Sandbox_V3_KillResponse>

/// Notify guest of filesystem events from host.
func notifyFileSystemEvent(context: StreamingResponseCallContext<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse>) -> EventLoopFuture<(StreamEvent<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest>) -> Void>
}

extension Com_Apple_Containerization_Sandbox_V3_SandboxContextProvider {
Expand Down Expand Up @@ -2095,6 +2172,15 @@ extension Com_Apple_Containerization_Sandbox_V3_SandboxContextProvider {
userFunction: self.kill(request:context:)
)

case "NotifyFileSystemEvent":
return BidirectionalStreamingServerHandler(
context: context,
requestDeserializer: ProtobufDeserializer<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest>(),
responseSerializer: ProtobufSerializer<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse>(),
interceptors: self.interceptors?.makeNotifyFileSystemEventInterceptors() ?? [],
observerFactory: self.notifyFileSystemEvent(context:)
)

default:
return nil
}
Expand Down Expand Up @@ -2265,6 +2351,13 @@ public protocol Com_Apple_Containerization_Sandbox_V3_SandboxContextAsyncProvide
request: Com_Apple_Containerization_Sandbox_V3_KillRequest,
context: GRPCAsyncServerCallContext
) async throws -> Com_Apple_Containerization_Sandbox_V3_KillResponse

/// Notify guest of filesystem events from host.
func notifyFileSystemEvent(
requestStream: GRPCAsyncRequestStream<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest>,
responseStream: GRPCAsyncResponseStreamWriter<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse>,
context: GRPCAsyncServerCallContext
) async throws
}

@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
Expand Down Expand Up @@ -2520,6 +2613,15 @@ extension Com_Apple_Containerization_Sandbox_V3_SandboxContextAsyncProvider {
wrapping: { try await self.kill(request: $0, context: $1) }
)

case "NotifyFileSystemEvent":
return GRPCAsyncServerHandler(
context: context,
requestDeserializer: ProtobufDeserializer<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest>(),
responseSerializer: ProtobufSerializer<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse>(),
interceptors: self.interceptors?.makeNotifyFileSystemEventInterceptors() ?? [],
wrapping: { try await self.notifyFileSystemEvent(requestStream: $0, responseStream: $1, context: $2) }
)

default:
return nil
}
Expand Down Expand Up @@ -2631,6 +2733,10 @@ public protocol Com_Apple_Containerization_Sandbox_V3_SandboxContextServerInterc
/// - Returns: Interceptors to use when handling 'kill'.
/// Defaults to calling `self.makeInterceptors()`.
func makeKillInterceptors() -> [ServerInterceptor<Com_Apple_Containerization_Sandbox_V3_KillRequest, Com_Apple_Containerization_Sandbox_V3_KillResponse>]

/// - Returns: Interceptors to use when handling 'notifyFileSystemEvent'.
/// Defaults to calling `self.makeInterceptors()`.
func makeNotifyFileSystemEventInterceptors() -> [ServerInterceptor<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest, Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse>]
}

public enum Com_Apple_Containerization_Sandbox_V3_SandboxContextServerMetadata {
Expand Down Expand Up @@ -2664,6 +2770,7 @@ public enum Com_Apple_Containerization_Sandbox_V3_SandboxContextServerMetadata {
Com_Apple_Containerization_Sandbox_V3_SandboxContextServerMetadata.Methods.configureHosts,
Com_Apple_Containerization_Sandbox_V3_SandboxContextServerMetadata.Methods.sync,
Com_Apple_Containerization_Sandbox_V3_SandboxContextServerMetadata.Methods.kill,
Com_Apple_Containerization_Sandbox_V3_SandboxContextServerMetadata.Methods.notifyFileSystemEvent,
]
)

Expand Down Expand Up @@ -2823,5 +2930,11 @@ public enum Com_Apple_Containerization_Sandbox_V3_SandboxContextServerMetadata {
path: "/com.apple.containerization.sandbox.v3.SandboxContext/Kill",
type: GRPCCallType.unary
)

public static let notifyFileSystemEvent = GRPCMethodDescriptor(
name: "NotifyFileSystemEvent",
path: "/com.apple.containerization.sandbox.v3.SandboxContext/NotifyFileSystemEvent",
type: GRPCCallType.bidirectionalStreaming
)
}
}
Loading
Loading