]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: add option "smb3 directory leases"
authorRalph Boehme <slow@samba.org>
Wed, 12 May 2021 09:24:45 +0000 (11:24 +0200)
committerRalph Boehme <slow@samba.org>
Tue, 5 Nov 2024 14:39:30 +0000 (14:39 +0000)
By default enabled on non-clustered Samba, disabled on clustered Samba, the
reason being the expected additional load caused by forcing strict rename to be
enabled.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
docs-xml/smbdotconf/locking/smb3directoryleases.xml [new file with mode: 0644]
docs-xml/smbdotconf/tuning/strictrename.xml
lib/param/loadparm.c
source3/param/loadparm.c
source3/param/loadparm.h
source3/smbd/smb2_negprot.c

diff --git a/docs-xml/smbdotconf/locking/smb3directoryleases.xml b/docs-xml/smbdotconf/locking/smb3directoryleases.xml
new file mode 100644 (file)
index 0000000..2d36d3c
--- /dev/null
@@ -0,0 +1,40 @@
+<samba:parameter name="smb3 directory leases"
+                 context="G"
+                 type="enum"
+                 enumlist="enum_bool_auto"
+                function="_smb3_directory_leases"
+                 xmlns:samba="http://www.samba.org/samba/DTD/samba-doc">
+<description>
+  <para>
+    This is an enumerated type that controls <command
+    moreinfo="none">smbd</command> whether SMB3 directory leases are
+    enabled. Directory Leasing is an SMB3-only feature which allows
+    clients to cache directories.
+  </para>
+  <para>
+    Possible values for <smbconfoption name="smb3 directory leases"/>
+    are <constant>yes</constant>, <constant>no</constant> and
+    <constant>auto</constant>, <constant>auto</constant> being the
+    default.
+  </para>
+  <para>
+    When set to <constant>auto</constant>, the effective value depends on the
+    option <smbconfoption name="clustering"/>. If <smbconfoption
+    name="clustering"/> is enabled, <smbconfoption name="smb3 directory
+    leases"/> are disabled and the other way around.
+  </para>
+  <para>
+    <smbconfoption name="smb3 directory leases"/> are only available
+    with <smbconfoption name="smb2 leases">yes</smbconfoption>,
+    <smbconfoption name="oplocks">yes</smbconfoption> and
+    <smbconfoption name="kernel oplocks">no</smbconfoption>.
+  </para>
+  <para>
+    Enabling <smbconfoption name="smb3 directory leases"/> implicitly enables
+    <smbconfoption name="strict rename"/>.
+  </para>
+</description>
+
+<related>smb2 leases</related>
+<value type="default">auto</value>
+</samba:parameter>
index 8da94c012cce74fcdccc2fa93a7a8a770378ae1b..446f83378bb613cbb6583d1f3a1d80e6005d3156 100644 (file)
@@ -1,6 +1,7 @@
 <samba:parameter name="strict rename"
                  context="S"
                  type="boolean"
+                function="_strict_rename"
                  xmlns:samba="http://www.samba.org/samba/DTD/samba-doc">
 <description>
     <para>By default a Windows SMB server prevents directory
@@ -28,6 +29,9 @@
     pathnames) then renames are always allowed and this parameter
     has no effect.</para>
 
+    <para>Enabling <smbconfoption name="smb3 directory leases"/> implicitly
+    enables <smbconfoption name="strict rename"/>.</para>
+
 </description>
 
 <value type="default">no</value>
index db434e6626266858fee0f83b534f8d15d39a221e..c867527f2557db408019dbe9c535372475c9020c 100644 (file)
@@ -3077,6 +3077,8 @@ struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
 
        lpcfg_do_global_parameter(lp_ctx, "smb2 leases", "yes");
 
+       lpcfg_do_global_parameter(lp_ctx, "smb3 directory leases", "Auto");
+
        lpcfg_do_global_parameter(lp_ctx, "server multi channel support", "yes");
 
        lpcfg_do_global_parameter(lp_ctx, "kerberos encryption types", "all");
index 0596573176dfe6ccd395bbdd5b9ca6630368979f..03506fd912ed2261e20027705611fcb75cdd0ee6 100644 (file)
@@ -215,7 +215,7 @@ static const struct loadparm_service _sDefault =
        .follow_symlinks = true,
        .sync_always = false,
        .strict_allocate = false,
-       .strict_rename = false,
+       ._strict_rename = false,
        .strict_sync = true,
        .mangling_char = '~',
        .copymap = NULL,
@@ -879,6 +879,7 @@ void loadparm_s3_init_globals(struct loadparm_context *lp_ctx,
        Globals.smb2_max_trans = DEFAULT_SMB2_MAX_TRANSACT;
        Globals.smb2_max_credits = DEFAULT_SMB2_MAX_CREDITS;
        Globals.smb2_leases = true;
+       Globals._smb3_directory_leases = Auto;
        Globals.server_multi_channel_support = true;
 
        lpcfg_string_set(Globals.ctx, &Globals.ncalrpc_dir,
@@ -4921,3 +4922,25 @@ uint32_t lp_get_async_dns_timeout(void)
         */
        return MAX(Globals.async_dns_timeout, 1);
 }
+
+bool lp_strict_rename(int snum)
+{
+       if (lp_smb3_directory_leases()){
+               return true;
+       }
+       return lp__strict_rename(snum);
+}
+
+int lp_smb3_directory_leases(void)
+{
+       bool dirleases = lp__smb3_directory_leases();
+
+       if (lp__smb3_directory_leases() == Auto) {
+               dirleases &= !lp_clustering();
+       }
+
+       dirleases &= lp_smb2_leases();
+       dirleases &= lp_oplocks(GLOBAL_SECTION_SNUM);
+       dirleases &= !lp_kernel_oplocks(GLOBAL_SECTION_SNUM);
+       return dirleases;
+}
index e8f06ddbc2caba0017151e8a2705bb376016f2d6..a33f1ae9a3b815ea998a8099d91448854be74de2 100644 (file)
@@ -69,6 +69,8 @@ int lp_rpc_high_port(void);
 const char *lp_dns_hostname(void);
 bool lp_lanman_auth(void);
 enum samba_weak_crypto lp_weak_crypto(void);
+bool lp_strict_rename(int snum);
+int lp_smb3_directory_leases(void);
 
 int lp_wi_scan_global_parametrics(
        const char *regex, size_t max_matches,
index b656865a2c88409cb958461fbbb97253d951ac3d..d44ce7c78632d2636bdf4a75e9a899c90cad0c5a 100644 (file)
@@ -414,6 +414,13 @@ NTSTATUS smbd_smb2_request_process_negprot(struct smbd_smb2_request *req)
                capabilities |= SMB2_CAP_ENCRYPTION;
        }
 
+       if (protocol >= PROTOCOL_SMB3_00 &&
+           in_capabilities & SMB2_CAP_DIRECTORY_LEASING &&
+           lp_smb3_directory_leases())
+       {
+               capabilities |= SMB2_CAP_DIRECTORY_LEASING;
+       }
+
        /*
         * 0x10000 (65536) is the maximum allowed message size
         * for SMB 2.0