Skip to content

Commit 816c698

Browse files
committed
Add filesystem notification (FSNotify) support
1 parent f3641e6 commit 816c698

File tree

9 files changed

+589
-0
lines changed

9 files changed

+589
-0
lines changed

Sources/Containerization/Agent/Vminitd.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,17 @@ extension Vminitd {
363363
try await Task.sleep(for: .milliseconds(10))
364364
try await self.sync()
365365
}
366+
367+
/// Send a filesystem event notification to the guest.
368+
public func notifyFileSystemEvent(path: String, eventType: Com_Apple_Containerization_Sandbox_V3_FileSystemEventType) async throws
369+
-> Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse
370+
{
371+
let request = Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest.with {
372+
$0.path = path
373+
$0.eventType = eventType
374+
}
375+
return try await client.notifyFileSystemEvent(request)
376+
}
366377
}
367378

368379
extension Hosts {

Sources/Containerization/SandboxContext/SandboxContext.grpc.swift

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ public protocol Com_Apple_Containerization_Sandbox_V3_SandboxContextClientProtoc
163163
_ request: Com_Apple_Containerization_Sandbox_V3_KillRequest,
164164
callOptions: CallOptions?
165165
) -> UnaryCall<Com_Apple_Containerization_Sandbox_V3_KillRequest, Com_Apple_Containerization_Sandbox_V3_KillResponse>
166+
167+
func notifyFileSystemEvent(
168+
_ request: Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest,
169+
callOptions: CallOptions?
170+
) -> UnaryCall<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest, Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse>
166171
}
167172

168173
extension Com_Apple_Containerization_Sandbox_V3_SandboxContextClientProtocol {
@@ -638,6 +643,24 @@ extension Com_Apple_Containerization_Sandbox_V3_SandboxContextClientProtocol {
638643
interceptors: self.interceptors?.makeKillInterceptors() ?? []
639644
)
640645
}
646+
647+
/// Notify guest of filesystem events from host.
648+
///
649+
/// - Parameters:
650+
/// - request: Request to send to NotifyFileSystemEvent.
651+
/// - callOptions: Call options.
652+
/// - Returns: A `UnaryCall` with futures for the metadata, status and response.
653+
public func notifyFileSystemEvent(
654+
_ request: Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest,
655+
callOptions: CallOptions? = nil
656+
) -> UnaryCall<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest, Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse> {
657+
return self.makeUnaryCall(
658+
path: Com_Apple_Containerization_Sandbox_V3_SandboxContextClientMetadata.Methods.notifyFileSystemEvent.path,
659+
request: request,
660+
callOptions: callOptions ?? self.defaultCallOptions,
661+
interceptors: self.interceptors?.makeNotifyFileSystemEventInterceptors() ?? []
662+
)
663+
}
641664
}
642665

643666
@available(*, deprecated)
@@ -832,6 +855,11 @@ public protocol Com_Apple_Containerization_Sandbox_V3_SandboxContextAsyncClientP
832855
_ request: Com_Apple_Containerization_Sandbox_V3_KillRequest,
833856
callOptions: CallOptions?
834857
) -> GRPCAsyncUnaryCall<Com_Apple_Containerization_Sandbox_V3_KillRequest, Com_Apple_Containerization_Sandbox_V3_KillResponse>
858+
859+
func makeNotifyFileSystemEventCall(
860+
_ request: Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest,
861+
callOptions: CallOptions?
862+
) -> GRPCAsyncUnaryCall<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest, Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse>
835863
}
836864

837865
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@@ -1155,6 +1183,18 @@ extension Com_Apple_Containerization_Sandbox_V3_SandboxContextAsyncClientProtoco
11551183
interceptors: self.interceptors?.makeKillInterceptors() ?? []
11561184
)
11571185
}
1186+
1187+
public func makeNotifyFileSystemEventCall(
1188+
_ request: Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest,
1189+
callOptions: CallOptions? = nil
1190+
) -> GRPCAsyncUnaryCall<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest, Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse> {
1191+
return self.makeAsyncUnaryCall(
1192+
path: Com_Apple_Containerization_Sandbox_V3_SandboxContextClientMetadata.Methods.notifyFileSystemEvent.path,
1193+
request: request,
1194+
callOptions: callOptions ?? self.defaultCallOptions,
1195+
interceptors: self.interceptors?.makeNotifyFileSystemEventInterceptors() ?? []
1196+
)
1197+
}
11581198
}
11591199

11601200
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@@ -1470,6 +1510,18 @@ extension Com_Apple_Containerization_Sandbox_V3_SandboxContextAsyncClientProtoco
14701510
interceptors: self.interceptors?.makeKillInterceptors() ?? []
14711511
)
14721512
}
1513+
1514+
public func notifyFileSystemEvent(
1515+
_ request: Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest,
1516+
callOptions: CallOptions? = nil
1517+
) async throws -> Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse {
1518+
return try await self.performAsyncUnaryCall(
1519+
path: Com_Apple_Containerization_Sandbox_V3_SandboxContextClientMetadata.Methods.notifyFileSystemEvent.path,
1520+
request: request,
1521+
callOptions: callOptions ?? self.defaultCallOptions,
1522+
interceptors: self.interceptors?.makeNotifyFileSystemEventInterceptors() ?? []
1523+
)
1524+
}
14731525
}
14741526

14751527
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@@ -1568,6 +1620,9 @@ public protocol Com_Apple_Containerization_Sandbox_V3_SandboxContextClientInterc
15681620

15691621
/// - Returns: Interceptors to use when invoking 'kill'.
15701622
func makeKillInterceptors() -> [ClientInterceptor<Com_Apple_Containerization_Sandbox_V3_KillRequest, Com_Apple_Containerization_Sandbox_V3_KillResponse>]
1623+
1624+
/// - Returns: Interceptors to use when invoking 'notifyFileSystemEvent'.
1625+
func makeNotifyFileSystemEventInterceptors() -> [ClientInterceptor<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest, Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse>]
15711626
}
15721627

15731628
public enum Com_Apple_Containerization_Sandbox_V3_SandboxContextClientMetadata {
@@ -1601,6 +1656,7 @@ public enum Com_Apple_Containerization_Sandbox_V3_SandboxContextClientMetadata {
16011656
Com_Apple_Containerization_Sandbox_V3_SandboxContextClientMetadata.Methods.configureHosts,
16021657
Com_Apple_Containerization_Sandbox_V3_SandboxContextClientMetadata.Methods.sync,
16031658
Com_Apple_Containerization_Sandbox_V3_SandboxContextClientMetadata.Methods.kill,
1659+
Com_Apple_Containerization_Sandbox_V3_SandboxContextClientMetadata.Methods.notifyFileSystemEvent,
16041660
]
16051661
)
16061662

@@ -1760,6 +1816,12 @@ public enum Com_Apple_Containerization_Sandbox_V3_SandboxContextClientMetadata {
17601816
path: "/com.apple.containerization.sandbox.v3.SandboxContext/Kill",
17611817
type: GRPCCallType.unary
17621818
)
1819+
1820+
public static let notifyFileSystemEvent = GRPCMethodDescriptor(
1821+
name: "NotifyFileSystemEvent",
1822+
path: "/com.apple.containerization.sandbox.v3.SandboxContext/NotifyFileSystemEvent",
1823+
type: GRPCCallType.unary
1824+
)
17631825
}
17641826
}
17651827

@@ -1847,6 +1909,9 @@ public protocol Com_Apple_Containerization_Sandbox_V3_SandboxContextProvider: Ca
18471909

18481910
/// Send a signal to a process via the PID.
18491911
func kill(request: Com_Apple_Containerization_Sandbox_V3_KillRequest, context: StatusOnlyCallContext) -> EventLoopFuture<Com_Apple_Containerization_Sandbox_V3_KillResponse>
1912+
1913+
/// Notify guest of filesystem events from host.
1914+
func notifyFileSystemEvent(request: Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest, context: StatusOnlyCallContext) -> EventLoopFuture<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse>
18501915
}
18511916

18521917
extension Com_Apple_Containerization_Sandbox_V3_SandboxContextProvider {
@@ -2095,6 +2160,15 @@ extension Com_Apple_Containerization_Sandbox_V3_SandboxContextProvider {
20952160
userFunction: self.kill(request:context:)
20962161
)
20972162

2163+
case "NotifyFileSystemEvent":
2164+
return UnaryServerHandler(
2165+
context: context,
2166+
requestDeserializer: ProtobufDeserializer<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest>(),
2167+
responseSerializer: ProtobufSerializer<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse>(),
2168+
interceptors: self.interceptors?.makeNotifyFileSystemEventInterceptors() ?? [],
2169+
userFunction: self.notifyFileSystemEvent(request:context:)
2170+
)
2171+
20982172
default:
20992173
return nil
21002174
}
@@ -2265,6 +2339,12 @@ public protocol Com_Apple_Containerization_Sandbox_V3_SandboxContextAsyncProvide
22652339
request: Com_Apple_Containerization_Sandbox_V3_KillRequest,
22662340
context: GRPCAsyncServerCallContext
22672341
) async throws -> Com_Apple_Containerization_Sandbox_V3_KillResponse
2342+
2343+
/// Notify guest of filesystem events from host.
2344+
func notifyFileSystemEvent(
2345+
request: Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest,
2346+
context: GRPCAsyncServerCallContext
2347+
) async throws -> Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse
22682348
}
22692349

22702350
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
@@ -2520,6 +2600,15 @@ extension Com_Apple_Containerization_Sandbox_V3_SandboxContextAsyncProvider {
25202600
wrapping: { try await self.kill(request: $0, context: $1) }
25212601
)
25222602

2603+
case "NotifyFileSystemEvent":
2604+
return GRPCAsyncServerHandler(
2605+
context: context,
2606+
requestDeserializer: ProtobufDeserializer<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest>(),
2607+
responseSerializer: ProtobufSerializer<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse>(),
2608+
interceptors: self.interceptors?.makeNotifyFileSystemEventInterceptors() ?? [],
2609+
wrapping: { try await self.notifyFileSystemEvent(request: $0, context: $1) }
2610+
)
2611+
25232612
default:
25242613
return nil
25252614
}
@@ -2631,6 +2720,10 @@ public protocol Com_Apple_Containerization_Sandbox_V3_SandboxContextServerInterc
26312720
/// - Returns: Interceptors to use when handling 'kill'.
26322721
/// Defaults to calling `self.makeInterceptors()`.
26332722
func makeKillInterceptors() -> [ServerInterceptor<Com_Apple_Containerization_Sandbox_V3_KillRequest, Com_Apple_Containerization_Sandbox_V3_KillResponse>]
2723+
2724+
/// - Returns: Interceptors to use when handling 'notifyFileSystemEvent'.
2725+
/// Defaults to calling `self.makeInterceptors()`.
2726+
func makeNotifyFileSystemEventInterceptors() -> [ServerInterceptor<Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventRequest, Com_Apple_Containerization_Sandbox_V3_NotifyFileSystemEventResponse>]
26342727
}
26352728

26362729
public enum Com_Apple_Containerization_Sandbox_V3_SandboxContextServerMetadata {
@@ -2664,6 +2757,7 @@ public enum Com_Apple_Containerization_Sandbox_V3_SandboxContextServerMetadata {
26642757
Com_Apple_Containerization_Sandbox_V3_SandboxContextServerMetadata.Methods.configureHosts,
26652758
Com_Apple_Containerization_Sandbox_V3_SandboxContextServerMetadata.Methods.sync,
26662759
Com_Apple_Containerization_Sandbox_V3_SandboxContextServerMetadata.Methods.kill,
2760+
Com_Apple_Containerization_Sandbox_V3_SandboxContextServerMetadata.Methods.notifyFileSystemEvent,
26672761
]
26682762
)
26692763

@@ -2823,5 +2917,11 @@ public enum Com_Apple_Containerization_Sandbox_V3_SandboxContextServerMetadata {
28232917
path: "/com.apple.containerization.sandbox.v3.SandboxContext/Kill",
28242918
type: GRPCCallType.unary
28252919
)
2920+
2921+
public static let notifyFileSystemEvent = GRPCMethodDescriptor(
2922+
name: "NotifyFileSystemEvent",
2923+
path: "/com.apple.containerization.sandbox.v3.SandboxContext/NotifyFileSystemEvent",
2924+
type: GRPCCallType.unary
2925+
)
28262926
}
28272927
}

0 commit comments

Comments
 (0)