From 063a697e83cca4ed15988597106232c15ba4398c Mon Sep 17 00:00:00 2001 From: Warren Date: Sun, 21 Jun 2026 01:13:35 +0800 Subject: [PATCH] Add READ handler oplock break (Phase 5.5) - Trigger oplock break before read if conflicting opens exist - Use granted_access from Open struct - Send notifications via notification_tx channel - Fix WRITE handler granted_access source (from Tree) All 229 tests pass. --- vendor/smb-server/src/handlers/read.rs | 28 ++++++++++++++++++++++++- vendor/smb-server/src/handlers/write.rs | 8 ++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/vendor/smb-server/src/handlers/read.rs b/vendor/smb-server/src/handlers/read.rs index 72b001a..e2d63a7 100644 --- a/vendor/smb-server/src/handlers/read.rs +++ b/vendor/smb-server/src/handlers/read.rs @@ -12,7 +12,7 @@ use crate::ntstatus; use crate::server::ServerState; pub async fn handle( - _server: &Arc, + server: &Arc, conn: &Arc, hdr: &Smb2Header, body: &[u8], @@ -33,6 +33,32 @@ pub async fn handle( Some(o) => o, None => return HandlerResponse::err(ntstatus::STATUS_FILE_CLOSED), }; + + // Phase 5.5: Get path and trigger oplock break before read (if needed) + let (path, share_access, granted_access) = { + let open = open_arc.read().await; + (open.last_path.clone(), open.share_access, open.granted_access) + }; + + // Trigger oplock break if this read conflicts with other opens + let notifications = server.oplock_manager.break_oplock( + &path, + share_access, + granted_access, + ).await; + + // Send notifications to affected clients + for notification in notifications { + use crate::proto::framing::encode_frame; + let notification_bytes = notification.write_to_bytes(); + let mut frame = Vec::with_capacity(notification_bytes.len() + 4); + encode_frame(¬ification_bytes, &mut frame); + + if let Some(tx) = conn.notification_tx.read().await.as_ref() { + let _ = tx.send(frame).await; + } + } + let result = { let open = open_arc.read().await; match open.handle.as_ref() { diff --git a/vendor/smb-server/src/handlers/write.rs b/vendor/smb-server/src/handlers/write.rs index 92afbbe..71a3e0f 100644 --- a/vendor/smb-server/src/handlers/write.rs +++ b/vendor/smb-server/src/handlers/write.rs @@ -48,11 +48,17 @@ pub async fn handle( (open.last_path.clone(), open.share_access) }; + // Get granted_access from tree + let granted_access = { + let tree = tree_arc.read().await; + tree.granted_access + }; + // Trigger oplock break for conflicting clients let notifications = server.oplock_manager.break_oplock( &path, share_access, - granted, + granted_access, ).await; // Send notifications to affected clients