Here is a one line patch to make sure we request HANDLE leases on cached directories. I also want to make sure (in followon patch) that we check in the open response (ie the lease state granted) that we don't defer close of directory if we don't get both HANDLE and READ in response. On Tue, Oct 29, 2024 at 5:05 AM Ralph Boehme <slow@xxxxxxxxx> wrote: > > Hi Steve, > > On 10/28/24 10:11 PM, Steve French wrote: > > Doing some additional experiments to Windows and also to the updated > > Samba branch from Ralph, I see the directory lease request, and > > I see that after ls (which will cache the directory contents for about > > 30 second) we do get a big benefit from the metadata of the directory > > entries being cached e.g. "ls /mnt ; sleep 10; stat /mnt/file ; sleep > > 15 stat /mnt/file2 ; sleep 10 /mnt/file" - we only get the roundtrips > > for the initial ls - the stat calls don't cause any network traffic > > since the directory is cached. > indeed, I can confirm that some cache is used for stat. Unfortunately it > isn't used for readddir. > > Also, coming back on the issue that the client is deferring a close on > the directory with having a H lease: > > In my understanding that's at least going to cause problems if other > clients want to do anything on the server that is not allowed if there > are conflicting opens like renaming a directory (which is not allowed if > there are any opens below recursively). Unlinks will also be deferred as > long as the client sticks to its handle. > > The client should acquire a RH lease on directories if it wants to cache > the handle and that's a prerequisite in order to cache readdir. > > Afair the kernel is currently caching for 30 seconds. Increasing this > time should not be done without also having a H lease. > > -slow -- Thanks, Steve
From fec14128ef3a891e194066fedbe45e2d23f323d9 Mon Sep 17 00:00:00 2001 From: Steve French <stfrench@microsoft.com> Date: Mon, 18 Nov 2024 12:19:46 -0600 Subject: [PATCH] smb3: request handle caching when caching directories This client was only requesting READ caching, not READ and HANDLE caching in the LeaseState on the open requests we send for directories. To delay closing a handle (e.g. for caching directory contents) we should be requesting HANDLE as well as READ (as we already do for deferred close of files). See MS-SMB2 3.3.1.4 e.g. Cc: stable@vger.kernel.org Signed-off-by: Steve French <stfrench@microsoft.com> --- fs/smb/client/smb2ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index 6c4a7335a8a2..fa96ebed8310 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -4049,7 +4049,7 @@ map_oplock_to_lease(u8 oplock) if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) return SMB2_LEASE_WRITE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE; else if (oplock == SMB2_OPLOCK_LEVEL_II) - return SMB2_LEASE_READ_CACHING_LE; + return SMB2_LEASE_READ_CACHING_LE | SMB2_LEASE_HANDLE_CACHING_LE; else if (oplock == SMB2_OPLOCK_LEVEL_BATCH) return SMB2_LEASE_HANDLE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE | SMB2_LEASE_WRITE_CACHING_LE; -- 2.43.0