SMB performance optimization: pread/pwrite, tokio::sync::Mutex, direct response, fast-path

- VfsFile trait: add read_at()/write_at() with seek+read default impl
- LocalFs: override with real pread/pwrite (FileExt::read_at/write_at) — 1 syscall vs 2
- smb_server_backend: use read_at/write_at + tokio::sync::Mutex (non-blocking async)
- read handler: build response directly, avoid Bytes→Vec<u8> copy + intermediate struct
- oplock break: fast-path skip when ≤1 open entry (single-user scenario)
This commit is contained in:
Warren
2026-06-23 09:58:19 +08:00
parent e7863a3034
commit d4f60929fa
6 changed files with 58 additions and 31 deletions

View File

@@ -91,16 +91,15 @@ pub async fn handle(
if bytes.is_empty() && req.length > 0 {
return HandlerResponse::err(ntstatus::STATUS_END_OF_FILE);
}
let resp = ReadResponse {
structure_size: 17,
data_offset: ReadResponse::STANDARD_DATA_OFFSET,
reserved: 0,
data_length: bytes.len() as u32,
data_remaining: 0,
flags: 0,
data: bytes.to_vec(),
};
let mut buf = Vec::new();
resp.write_to(&mut buf).expect("encode");
// Build response directly to avoid Bytes→Vec<u8> copy and intermediate struct
let data_len = bytes.len() as u32;
let mut buf = Vec::with_capacity(16 + bytes.len());
buf.extend_from_slice(&17u16.to_le_bytes()); // structure_size
buf.push(ReadResponse::STANDARD_DATA_OFFSET); // data_offset
buf.push(0); // reserved
buf.extend_from_slice(&data_len.to_le_bytes()); // data_length
buf.extend_from_slice(&0u32.to_le_bytes()); // data_remaining
buf.extend_from_slice(&0u32.to_le_bytes()); // flags
buf.extend_from_slice(&bytes); // data
HandlerResponse::ok(buf)
}