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

@@ -103,6 +103,20 @@ pub trait VfsFile: Send {
fn stat(&mut self) -> Result<VfsStat, VfsError>;
fn set_len(&mut self, size: u64) -> Result<(), VfsError>;
/// Read at `offset` without changing the seek position (like pread).
/// Default implementation does seek + read.
fn read_at(&mut self, buf: &mut [u8], offset: u64) -> Result<usize, VfsError> {
self.seek(std::io::SeekFrom::Start(offset))?;
self.read(buf)
}
/// Write at `offset` without changing the seek position (like pwrite).
/// Default implementation does seek + write.
fn write_at(&mut self, buf: &[u8], offset: u64) -> Result<usize, VfsError> {
self.seek(std::io::SeekFrom::Start(offset))?;
self.write(buf)
}
/// Write all bytes (convenience, default loops write() until done)
fn write_all(&mut self, mut buf: &[u8]) -> Result<(), VfsError> {
while !buf.is_empty() {