pub struct LeaseTable {
held: Mutex<HashMap<String, Vec<LeaseHolder>>>,
ack_waiters: Mutex<HashMap<[u8; 16], Vec<Sender<()>>>>,
}Expand description
Server-wide lease table: the set of caching-lease holders per file path.
Simplified relative to [MS-SMB2] §3.3.1.10 (leases are managed independently of oplocks), but READ and HANDLE caching are shareable, so multiple clients may hold a lease on the same path with distinct lease keys — notably several directory-lease holders that must each be broken on a conflicting access.
Fields§
§held: Mutex<HashMap<String, Vec<LeaseHolder>>>§ack_waiters: Mutex<HashMap<[u8; 16], Vec<Sender<()>>>>One-shot signals delivered when a lease key’s break is acknowledged, so a conflicting open can wait for a HANDLE-caching break ([MS-SMB2] §3.3.1.4).
Implementations§
Source§impl LeaseTable
impl LeaseTable
Sourcepub fn grant(&self, path: &str, holder: LeaseHolder) -> bool
pub fn grant(&self, path: &str, holder: LeaseHolder) -> bool
Record a lease holder on path. Multiple clients may hold shareable
(READ / HANDLE) caching on the same path with distinct lease keys
([MS-SMB2] §3.3.1.4); a duplicate of an existing key+open is ignored.
Sourcepub fn peek_key(&self, path: &str, key: [u8; 16]) -> Option<(u32, u16, bool)>
pub fn peek_key(&self, path: &str, key: [u8; 16]) -> Option<(u32, u16, bool)>
Snapshot a co-holder’s state on path sharing lease key key, if any:
(state, epoch, v2). A CREATE reusing an existing lease key shares that
caching state rather than establishing a new grant ([MS-SMB2]
§3.3.5.9.11).
Sourcepub fn has_holders(&self, path: &str) -> bool
pub fn has_holders(&self, path: &str) -> bool
True when any lease is currently held on path.
Sourcepub fn break_conflict(
&self,
path: &str,
owner: LockOwner,
req_key: Option<[u8; 16]>,
clear: u32,
) -> Vec<LeaseBreak> ⓘ
pub fn break_conflict( &self, path: &str, owner: LockOwner, req_key: Option<[u8; 16]>, clear: u32, ) -> Vec<LeaseBreak> ⓘ
Break every conflicting holder on path by clearing the clear caching
bits, skipping the caller’s own open (owner) and any co-holder sharing
req_key. Returns one notification tuple (key, old_state, new_state, epoch, outbound, crypto) per holder that must be broken ([MS-SMB2]
§3.3.4.7); READ / HANDLE caching is shareable, so multiple directory
holders may each require a break.
Sourcepub fn break_subtree(
&self,
dir: &str,
owner: LockOwner,
clear: u32,
) -> Vec<LeaseBreak> ⓘ
pub fn break_subtree( &self, dir: &str, owner: LockOwner, clear: u32, ) -> Vec<LeaseBreak> ⓘ
Break every holder whose path is dir or a descendant of it, clearing
the clear caching bits and skipping the caller’s own open (owner).
Renaming a directory invalidates the cached handles across its whole
subtree, so each such directory lease must be broken ([MS-SMB2]
§3.3.1.4). Returns one notification tuple per holder broken.
Sourcepub fn set_state(&self, key: [u8; 16], state: u32)
pub fn set_state(&self, key: [u8; 16], state: u32)
Record the state a holder settled on after acknowledging a break.
Sourcepub fn acknowledge(
&self,
client_guid: [u8; 16],
key: [u8; 16],
acked: u32,
) -> Result<u32, LeaseAckError>
pub fn acknowledge( &self, client_guid: [u8; 16], key: [u8; 16], acked: u32, ) -> Result<u32, LeaseAckError>
Validate and apply a client lease-break acknowledgment ([MS-SMB2]
§3.3.5.22.1): the lease must exist under this client GUID, be breaking,
and acked must be a subset of the break-to state.
Sourcepub fn release(&self, path: &str, owner: LockOwner) -> Option<LeaseHolder>
pub fn release(&self, path: &str, owner: LockOwner) -> Option<LeaseHolder>
Drop the lease held by owner on path (on close), returning it.
Sourcepub fn register_ack_wait(&self, key: [u8; 16]) -> Receiver<()>
pub fn register_ack_wait(&self, key: [u8; 16]) -> Receiver<()>
Register interest in a lease key’s break acknowledgment; the returned receiver fires when the holder acknowledges ([MS-SMB2] §3.3.1.4).
Sourcepub fn signal_ack(&self, key: [u8; 16])
pub fn signal_ack(&self, key: [u8; 16])
Wake any opens waiting on a lease key’s break acknowledgment.
Sourcepub fn release_session(&self, session_id: u64)
pub fn release_session(&self, session_id: u64)
Drop every lease held by any open of session_id.