[SCM] Samba Shared Repository - branch v4-4-test updated

Karolin Seeger kseeger at samba.org
Tue Mar 14 15:31:03 UTC 2017


The branch, v4-4-test has been updated
       via  c248e53 WHATSNEW: Add release notes for Samba 4.4.11.
       via  699c336 manpages/vfs_fruit: document global options
       via  23389b7 s4/torture: some tests for kernel oplocks
       via  5c0b988 s3/selftest: adopt config.h check from source4
       via  7e436a3 s3/smbd: fix deferred open with streams and kernel oplocks
       via  ec6794d s3/smbd: all callers of defer_open() pass a lck
       via  9bbccbb s3/smbd: remove async_open arg from defer_open()
       via  5e94b38 s3/smbd: fix schedule_async_open() timer
       via  621abab s3/smbd: add and use retry_open() instead of defer_open() in two places
       via  ad3217c s3/smbd: simplify defer_open()
       via  a8db18a s3/smbd: req is already validated at the beginning of open_file_ntcreate()
       via  68c6af1 s3/smbd: add comments and some reformatting to open_file_ntcreate()
       via  1a15e42 s3/smbd: add const to get_lease_type() args
       via  6bd678c s3/wscript: fix Linux kernel oplock detection
       via  213759f replace: Include sysmacros.h
      from  9359b07 smbd: Do an early exit on negprot failure

https://git.samba.org/?p=samba.git;a=shortlog;h=v4-4-test


- Log -----------------------------------------------------------------
commit c248e53726ab30ca961457612a8084e22508315a
Author: Karolin Seeger <kseeger at samba.org>
Date:   Mon Mar 13 11:33:02 2017 +0100

    WHATSNEW: Add release notes for Samba 4.4.11.
    
    Signed-off-by: Karolin Seeger <kseeger at samba.org>
    
    Autobuild-User(v4-4-test): Karolin Seeger <kseeger at samba.org>
    Autobuild-Date(v4-4-test): Tue Mar 14 16:30:22 CET 2017 on sn-devel-144

commit 699c336454e4605e539da1db44534340b77b68c2
Author: Ralph Boehme <slow at samba.org>
Date:   Tue Mar 7 18:10:56 2017 +0100

    manpages/vfs_fruit: document global options
    
    Some options MUST be set in the global section, better document that.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=12615
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit 0c212c50b59081583572f807cf5214037d1517c4)

commit 23389b7b13902d668a632afd0ef7aed332754644
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Mar 1 18:13:35 2017 +0100

    s4/torture: some tests for kernel oplocks
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=7537
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (backported from commit fd03420c4f59d3248b80d07a302d1404ce78b09f)

commit 5c0b98801bbf1a24bb90bb99b3edac1a5095002f
Author: Ralph Boehme <slow at samba.org>
Date:   Wed Mar 8 07:18:36 2017 +0100

    s3/selftest: adopt config.h check from source4
    
    No change in behaviour.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=7537
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (backported from commit 6e54d8d2bda2c9232676f8c08c626f22de50f52b)

commit 7e436a37b9d5334ceae8c0e9195ffceb988152e9
Author: Ralph Boehme <slow at samba.org>
Date:   Tue Mar 7 16:27:39 2017 +0100

    s3/smbd: fix deferred open with streams and kernel oplocks
    
    I noticed smbd can get stuck in an open() call with kernel oplocks
    enabled and named streams (provided by vfs_streams_xattr):
    
    - client opens a file and with an exclusive oplock
    
    - client starts writing to the file
    
    - client opens an existing stream of the file
    
    - the smbd process gets stuck in an open()
    
    What happens is:
    
    we had setup a locking.tdb record watch in defer_open(), the watch was
    triggered, we reattempted the open and got stuck in a blocking open
    because the oplock holder (ourselves) hadn't given up the oplock yet.
    
    Cf e576bf5310bc9de9686a71539e9a1b60b4fba5cc for the commit that added
    the kernel oplock retry logic. tldr: with kernel oplocks the first open
    is non-blocking, but the second one is blocking.
    
    Detailed analysis follows.
    
    When opening a named stream of a file, Samba internally opens the
    underlying "base" file first. This internal open of the basefile suceeds
    and does *not* trigger an oplock break (because it is an internal open
    that doesn't call open() at all) but it is added as an entry to the
    locking.tdb record of the file.
    
    Next, the stream open ends up in streams_xattr where a non-blocking
    open() on the base file is called. This open fails with EWOULDBLOCK
    because we have another fd with a kernel oplock on the file.
    
    So we call defer_open() which sets up a watch on the locking.tdb record.
    
    In the subsequent error unwinding code in open_file_ntcreate() and
    callers we close the internal open file handle of the basefile which
    also removes the entry from the locking.tdb record and so *changes the
    record*.
    
    This fires the record watch and in the callback defer_open_done() we
    don't check whether the condition (oplock gone) we're interested in is
    actually met. The callback blindly reschedules the open request with
    schedule_deferred_open_message_smb().
    
    schedule_deferred_open_message_smb() schedules an immediate tevent event
    which has precedence over the IPC fd events in messaging, so the open is
    always (!) reattempted before processing the oplock break message.
    
    As explained above, this second open will be a blocking one so we get
    stuck in a blocking open.
    
    It doesn't help to make all opens non-blocking, that would just result
    in a busy loop failing the open, as we never process the oplock break
    message (remember, schedule_deferred_open_message_smb() used immediate
    tevent events).
    
    To fix this we must add some logic to the record watch callback to check
    whether the record watch was done for a kernel oplock file and if yes,
    check if the oplock state changed. If not, simply reschedule the
    deferred open and keep waiting.
    
    This logic is only needed for kernel oplocks, not for Samba-level
    oplocks, because there's no risk of deadlocking, the worst that can
    happen is a rescheduled open that fails again in the oplock checks and
    gets deferred again.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=7537
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (backported from commit b35a296a27a0807c780f2a9e7af2f2e93feefaa8)

commit ec6794d270d0b342f976f0a76675112c02ae5d12
Author: Ralph Boehme <slow at samba.org>
Date:   Tue Mar 7 15:48:05 2017 +0100

    s3/smbd: all callers of defer_open() pass a lck
    
    No change in behaviour. Update the function comment explaining how it
    works and relies on lck for a record watch.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=7537
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (backported from commit 1a6c82e5d5a3462827ee3fe1edab01f535f831a9)

commit 9bbccbb1d29298235744537cd6a68845b3f60e13
Author: Ralph Boehme <slow at samba.org>
Date:   Tue Mar 7 19:11:20 2017 +0100

    s3/smbd: remove async_open arg from defer_open()
    
    All remaining callers pass false.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=7537
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit 7fa2f1159437c9f1aa47f51e65655b4d9afa5c0a)

commit 5e94b38e14ea8090f904cc2d270ebdbb2f583e16
Author: Ralph Boehme <slow at samba.org>
Date:   Tue Mar 7 15:33:55 2017 +0100

    s3/smbd: fix schedule_async_open() timer
    
    schedule_async_open() was calling defer_open with sharemode lock = NULL,
    as a result there was never an active 20 s timeout.
    
    This has been broken since the commits in
    
    $ git log --reverse -p -10 8283fd0e0090ed12b0b12d5acb550642d621b026
    
    Just roll our own deferred record instead of calling defer_open() and
    also set up timer that, as a last resort, catches stuck opens and just
    exits for now.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=7537
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit ad8c36125f72e0d5f9ebfc94037a4ae9e7608aad)

commit 621abab71fd9457bc6586b7e7111e465cdbbe369
Author: Ralph Boehme <slow at samba.org>
Date:   Tue Mar 7 15:03:12 2017 +0100

    s3/smbd: add and use retry_open() instead of defer_open() in two places
    
    Add a new function that does an immediate open rescheduling.
    
    The first deferred open this commit changes was never scheduled, as the
    scheduling relies on a timeout of the watch on the sharemode lock.
    
    This has been broken since the commits in
    
    $ git log --reverse -p -10 8283fd0e0090ed12b0b12d5acb550642d621b026
    
    That patchset added the dbwrap watch record logic to defer_open() and
    removed the timers.
    
    I'm doing this mainly to untangle the defer_open() logic which is
    complicated by the lck arg.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=7537
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit beaba6222848fb4ff4392b2247c5be1094b1d65b)

commit ad3217c9d9a73dbf23a1f01fd5ded51f32eceee6
Author: Ralph Boehme <slow at samba.org>
Date:   Tue Mar 7 14:37:54 2017 +0100

    s3/smbd: simplify defer_open()
    
    Add a helper function deferred_open_record_create() that creates a
    deferred_open_record and let all callers pass all needed arguments
    individually.
    
    While we're at it, enhance the debug message in defer_open() to print
    all variables.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=7537
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit b17ff9b181b7b9730d32534e720c45faabfa6799)

commit a8db18aa97c5af73c1df5559e8c233469f033c7f
Author: Ralph Boehme <slow at samba.org>
Date:   Tue Mar 7 14:10:39 2017 +0100

    s3/smbd: req is already validated at the beginning of open_file_ntcreate()
    
    req can't be NULL because the if condition surrounding this code checks
    !(oplock_request & INTERNAL_OPEN_ONLY).
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=7537
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit 8580adc1d968304b69237f289d13950972394b48)

commit 68c6af1dd86d438941333fecaeab9be269165ddf
Author: Ralph Boehme <slow at samba.org>
Date:   Mon Mar 6 11:43:08 2017 +0100

    s3/smbd: add comments and some reformatting to open_file_ntcreate()
    
    No change in behaviour.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=7537
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit f5631f6b3520326d4c9a6bae5636fd8d53e66b29)

commit 1a15e42bcb4016c4c79d4d1e367deaa73da09ac3
Author: Ralph Boehme <slow at samba.org>
Date:   Sat Mar 4 13:55:55 2017 +0100

    s3/smbd: add const to get_lease_type() args
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=7537
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit 6924e72ade20e98ac470fcb6ba7120c61b06bb0f)

commit 6bd678c9d2c329ce00db1c1ded6a1c9e8e1b7f82
Author: Ralph Boehme <slow at samba.org>
Date:   Mon Mar 6 12:09:53 2017 +0100

    s3/wscript: fix Linux kernel oplock detection
    
    Fix a copy/paste error, the Linux kernel oplocks check was copied from
    the change notify support check.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=7537
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit fe473f805af885a23bb16046c9d26d756e164f30)

commit 213759fb65881280cb467d96eb7289e4b55ee07e
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Jan 5 09:34:36 2017 +0100

    replace: Include sysmacros.h
    
    In the GNU C Library, "makedev" is defined by <sys/sysmacros.h>. For
    historical compatibility, it is currently defined by <sys/types.h> as
    well, but it is planned to remove this soon.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12686
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Volker Lendecke <vl at samba.org>
    
    (cherry picked from commit 0127bdd33b251a52c6ffc44b6cb3b82b16a80741)

-----------------------------------------------------------------------

Summary of changes:
 WHATSNEW.txt                      |  59 +++++-
 docs-xml/manpages/vfs_fruit.8.xml | 155 +++++++++------
 lib/replace/replace.h             |   4 +
 selftest/target/Samba3.pm         |   4 +
 source3/selftest/tests.py         |  36 ++--
 source3/smbd/open.c               | 390 +++++++++++++++++++++++++++-----------
 source3/smbd/oplock.c             |   3 +-
 source3/smbd/proto.h              |   3 +-
 source3/wscript                   |   6 +-
 source4/selftest/tests.py         |   2 +-
 source4/torture/smb2/oplock.c     | 140 ++++++++++++++
 source4/torture/smb2/smb2.c       |   1 +
 12 files changed, 620 insertions(+), 183 deletions(-)


Changeset truncated at 500 lines:

diff --git a/WHATSNEW.txt b/WHATSNEW.txt
index 7f74f34..9d57c33 100644
--- a/WHATSNEW.txt
+++ b/WHATSNEW.txt
@@ -1,4 +1,59 @@
                    ==============================
+                   Release Notes for Samba 4.4.11
+                           March 13, 2017
+                   ==============================
+
+
+This is the latest stable release of Samba 4.4. Please note that this will
+very likely be the last maintenance release of the Samba 4.4 release branch.
+
+
+Changes since 4.4.10:
+---------------------
+
+o  Jeremy Allison <jra at samba.org>
+   * BUG 12608: s3: smbd: Restart reading the incoming SMB2 fd when the send
+     queue is drained.
+
+o  Ralph Boehme <slow at samba.org>
+   * BUG 7537: s3/smbd: Fix deferred open with streams and kernel oplocks.
+   * BUG 12604: vfs_fruit: Enabling AAPL extensions must be a global switch.
+   * BUG 12615: manpages/vfs_fruit: Document global options.
+
+o  Volker Lendecke <vl at samba.org>
+   * BUG 12610: smbd: Do an early exit on negprot failure.
+
+o  Stefan Metzmacher <metze at samba.org>
+   * BUG 11830: s3:winbindd: Fix endless forest trust scan.
+
+o  Andreas Schneider <asn at samba.org>
+   * BUG 12686: Fix build with newer glibc.
+
+
+#######################################
+Reporting bugs & Development Discussion
+#######################################
+
+Please discuss this release on the samba-technical mailing list or by
+joining the #samba-technical IRC channel on irc.freenode.net.
+
+If you do report problems then please try to send high quality
+feedback. If you don't provide vital information to help us track down
+the problem then you will probably be ignored.  All bug reports should
+be filed under the "Samba 4.1 and newer" product in the project's Bugzilla
+database (https://bugzilla.samba.org/).
+
+
+======================================================================
+== Our Code, Our Bugs, Our Responsibility.
+== The Samba Team
+======================================================================
+
+
+Release notes for older releases follow:
+----------------------------------------
+
+                   ==============================
                    Release Notes for Samba 4.4.10
                             March 1, 2017
                    ==============================
@@ -102,8 +157,8 @@ database (https://bugzilla.samba.org/).
 ======================================================================
 
 
-Release notes for older releases follow:
-----------------------------------------
+----------------------------------------------------------------------
+
 
                    =============================
                    Release Notes for Samba 4.4.9
diff --git a/docs-xml/manpages/vfs_fruit.8.xml b/docs-xml/manpages/vfs_fruit.8.xml
index 966bf10..74cdd5e 100644
--- a/docs-xml/manpages/vfs_fruit.8.xml
+++ b/docs-xml/manpages/vfs_fruit.8.xml
@@ -71,8 +71,81 @@
 </refsect1>
 
 <refsect1>
+	<title>GLOBAL OPTIONS</title>
+
+	<para>The following options must be set in the global smb.conf section
+	and won't take effect when set per share.</para>
+
+	<variablelist>
+
+	  <varlistentry>
+	    <term>fruit:aapl = yes | no</term>
+	    <listitem>
+	      <para>A <emphasis>global</emphasis> option whether to enable Apple's SMB2+
+	      extension codenamed AAPL. Default
+	      <emphasis>yes</emphasis>. This extension enhances
+	      several deficiencies when connecting from Macs:</para>
+
+	      <itemizedlist>
+		<listitem><para>directory enumeration is enriched with
+		Mac relevant filesystem metadata (UNIX mode,
+		FinderInfo, resource fork size and effective
+		permission), as a result the Mac client doesn't need
+		to fetch this metadata individuallly per directory
+		entry resulting in an often tremendous performance
+		increase.</para></listitem>
+
+		<listitem><para>The ability to query and modify the
+		UNIX mode of directory entries.</para></listitem>
+	      </itemizedlist>
+
+	      <para>There's a set of per share options that come into play when
+	      <emphasis>fruit:aapl</emphasis> is enabled. These opions, listed
+	      below, can be used to disable the computation of specific Mac
+	      metadata in the directory enumeration context, all are enabled by
+	      default:</para>
+
+	      <itemizedlist>
+		<listitem><para>readdir_attr:aapl_rsize = yes | no</para></listitem>
+		<listitem><para>readdir_attr:aapl_finder_info = yes | no</para></listitem>
+		<listitem><para>readdir_attr:aapl_max_access = yes | no</para></listitem>
+	      </itemizedlist>
+
+	      <para>See below for a description of these options.</para>
+
+	    </listitem>
+	  </varlistentry>
+
+	  <varlistentry>
+	    <term>fruit:nfs_aces = yes | no</term>
+	    <listitem>
+	      <para>A <emphasis>global</emphasis> option whether support for
+	      querying and modifying the UNIX mode of directory entries via NFS
+	      ACEs is enabled, default <emphasis>yes</emphasis>.</para>
+	    </listitem>
+	  </varlistentry>
+
+	  <varlistentry>
+	    <term>fruit:copyfile = yes | no</term>
+	    <listitem>
+	      <para>A <emphasis>global</emphasis> option whether to enable OS X
+	      specific copychunk ioctl that requests a copy of a whole file
+	      along with all attached metadata.</para>
+	      <para>WARNING: the copyfile request is blocking the
+	      client while the server does the copy.</para>.
+	      <para>The default is <emphasis>no</emphasis>.</para>
+	    </listitem>
+	  </varlistentry>
+
+	</variablelist>
+</refsect1>
+
+<refsect1>
 	<title>OPTIONS</title>
 
+	<para>The following options can be set either in the global smb.conf section
+	or per share.</para>
+
 	<variablelist>
 
 	  <varlistentry>
@@ -177,50 +250,6 @@
 	  </varlistentry>
 
 	  <varlistentry>
-	    <term>fruit:aapl = yes | no</term>
-	    <listitem>
-	      <para>A global option whether to enable Apple's SMB2+
-	      extension codenamed AAPL. Default
-	      <emphasis>yes</emphasis>. This extension enhances
-	      several deficiencies when connecting from Macs:</para>
-
-	      <itemizedlist>
-		<listitem><para>directory enumeration is enriched with
-		Mac relevant filesystem metadata (UNIX mode,
-		FinderInfo, resource fork size and effective
-		permission), as a result the Mac client doesn't need
-		to fetch this metadata individuallly per directory
-		entry resulting in an often tremendous performance
-		increase.</para></listitem>
-
-		<listitem><para>The ability to query and modify the
-		UNIX mode of directory entries.</para></listitem>
-	      </itemizedlist>
-
-	      <para>There's a set of per share options that can be
-	      used to disable the computation of specific Mac metadata
-	      in the directory enumeration context, all are enabled by
-	      default:</para>
-
-	      <itemizedlist>
-		<listitem><para>readdir_attr:aapl_rsize = true | false</para></listitem>
-		<listitem><para>readdir_attr:aapl_finder_info = true | false</para></listitem>
-		<listitem><para>readdir_attr:aapl_max_access = true | false</para></listitem>
-	      </itemizedlist>
-
-	    </listitem>
-	  </varlistentry>
-
-	  <varlistentry>
-	    <term>fruit:nfs_aces = yes | no</term>
-	    <listitem>
-	      <para>Whether support for querying and modifying the
-	      UNIX mode of directory entries via NFS ACEs is enabled,
-	      default <emphasis>yes</emphasis>.</para>
-	    </listitem>
-	  </varlistentry>
-
-	  <varlistentry>
 	    <term>fruit:veto_appledouble = yes | no</term>
 	    <listitem>
 	      <para><emphasis>Note:</emphasis> this option only applies when
@@ -242,18 +271,6 @@
 	  </varlistentry>
 
 	  <varlistentry>
-	    <term>fruit:copyfile = yes | no</term>
-	    <listitem>
-	      <para>Whether to enable OS X specific copychunk ioctl
-	      that requests a copy of a whole file along with all
-	      attached metadata.</para>
-	      <para>WARNING: the copyfile request is blocking the
-	      client while the server does the copy.</para>.
-	      <para>The default is <emphasis>no</emphasis>.</para>
-	    </listitem>
-	  </varlistentry>
-
-	  <varlistentry>
 	    <term>fruit:posix_rename = yes | no</term>
 	    <listitem>
 	      <para>Whether to enable POSIX directory rename behaviour
@@ -264,6 +281,32 @@
 	    </listitem>
 	  </varlistentry>
 
+	  <varlistentry>
+	    <term>readdir_attr:aapl_rsize = yes | no</term>
+	    <listitem>
+	      <para>Return resource fork size in SMB2 FIND responses.</para>
+	      <para>The default is <emphasis>yes</emphasis>.</para>
+	    </listitem>
+	  </varlistentry>
+
+	  <varlistentry>
+	    <term>readdir_attr:aapl_finder_info = yes | no</term>
+	    <listitem>
+	      <para>Return FinderInfo in SMB2 FIND responses.</para>
+	      <para>The default is <emphasis>yes</emphasis>.</para>
+	    </listitem>
+	  </varlistentry>
+
+	  <varlistentry>
+	    <term>readdir_attr:aapl_max_access = yes | no</term>
+	    <listitem>
+	      <para>Return the user's effective maximum permissions in SMB2 FIND
+	      responses. This is an expensive computation, setting this to off
+	      pretends the use has maximum effective permissions.</para>
+	      <para>The default is <emphasis>yes</emphasis>.</para>
+	    </listitem>
+	  </varlistentry>
+
 	</variablelist>
 </refsect1>
 
diff --git a/lib/replace/replace.h b/lib/replace/replace.h
index 7080373..926b353 100644
--- a/lib/replace/replace.h
+++ b/lib/replace/replace.h
@@ -171,6 +171,10 @@
 #include <sys/types.h>
 #endif
 
+#ifdef HAVE_SYS_SYSMACROS_H
+#include <sys/sysmacros.h>
+#endif
+
 #ifdef HAVE_SETPROCTITLE_H
 #include <setproctitle.h>
 #endif
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index 4596a0a..619ae1e 100755
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -1717,6 +1717,10 @@ sub provision($$$$$$$$)
 	copy = tmp
 	acl_xattr:ignore system acls = yes
 	acl_xattr:default acl style = windows
+[kernel_oplocks]
+	copy = tmp
+	kernel oplocks = yes
+	vfs objects = streams_xattr xattr_tdb
 	";
 	close(CONF);
 
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
index fd4f615..9915fb6 100755
--- a/source3/selftest/tests.py
+++ b/source3/selftest/tests.py
@@ -36,6 +36,26 @@ def plansmbtorture4testsuite(name, env, options, description=''):
     selftesthelpers.plansmbtorture4testsuite(
         name, env, options, target='samba3', modname=modname)
 
+# find config.h
+try:
+    config_h = os.environ["CONFIG_H"]
+except KeyError:
+    samba4bindir = bindir()
+    config_h = os.path.join(samba4bindir, "default/include/config.h")
+
+# check available features
+config_hash = dict()
+f = open(config_h, 'r')
+try:
+    lines = f.readlines()
+    config_hash = dict((x[0], ' '.join(x[1:]))
+            for x in map(lambda line: line.strip().split(' ')[1:],
+                         filter(lambda line: (line[0:7] == '#define') and (len(line.split(' ')) > 2), lines)))
+finally:
+    f.close()
+
+have_libarchive = ("HAVE_LIBARCHIVE" in config_hash)
+have_linux_kernel_oplocks = ("HAVE_KERNEL_OPLOCKS_LINUX" in config_hash)
 
 plantestsuite("samba3.blackbox.success", "nt4_dc:local", [os.path.join(samba3srcdir, "script/tests/test_success.sh")])
 plantestsuite("samba3.blackbox.failure", "nt4_dc:local", [os.path.join(samba3srcdir, "script/tests/test_failure.sh")])
@@ -194,19 +214,6 @@ for env in ["fileserver"]:
     # tar command tests
     #
 
-    # find config.h
-    try:
-        config_h = os.environ["CONFIG_H"]
-    except KeyError:
-        config_h = os.path.join(samba4bindir, "default/include/config.h")
-
-    # see if libarchive is supported
-    f = open(config_h, 'r')
-    try:
-        have_libarchive = ("HAVE_LIBARCHIVE 1" in f.read())
-    finally:
-        f.close()
-
     # tar command enabled only if built with libarchive
     if have_libarchive:
         # Test smbclient/tarmode
@@ -412,6 +419,9 @@ for t in tests:
         plansmbtorture4testsuite(t, "ad_dc", '//$SERVER/tmp -U$USERNAME%$PASSWORD --signing=required')
     elif t == "smb2.dosmode":
         plansmbtorture4testsuite(t, "simpleserver", '//$SERVER/dosmode -U$USERNAME%$PASSWORD')
+    elif t == "smb2.kernel-oplocks":
+        if have_linux_kernel_oplocks:
+            plansmbtorture4testsuite(t, "nt4_dc", '//$SERVER/kernel_oplocks -U$USERNAME%$PASSWORD')
     elif t == "vfs.acl_xattr":
         plansmbtorture4testsuite(t, "nt4_dc", '//$SERVER_IP/tmp -U$USERNAME%$PASSWORD')
     else:
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 25cf417..1c67684 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -44,6 +44,13 @@ struct deferred_open_record {
         bool delayed_for_oplocks;
 	bool async_open;
         struct file_id id;
+
+	/*
+	 * Timer for async opens, needed because they don't use a watch on
+	 * a locking.tdb record. This is currently only used for real async
+	 * opens and just terminates smbd if the async open times out.
+	 */
+	struct tevent_timer *te;
 };
 
 /****************************************************************************
@@ -1525,6 +1532,23 @@ static bool delay_for_oplock(files_struct *fsp,
 	return delay;
 }
 
+/**
+ * Return lease or oplock state from a share mode
+ **/
+static uint32_t get_lease_type_from_share_mode(const struct share_mode_data *d)
+{
+	uint32_t e_lease_type = 0;
+	uint32_t i;
+
+	for (i=0; i < d->num_share_modes; i++) {
+		struct share_mode_entry *e = &d->share_modes[i];
+
+		e_lease_type |= get_lease_type(d, e);
+	}
+
+	return e_lease_type;
+}
+
 static bool file_has_brlocks(files_struct *fsp)
 {
 	struct byte_range_lock *br_lck;
@@ -1913,71 +1937,112 @@ static bool request_timed_out(struct timeval request_time,
 	return (timeval_compare(&end_time, &now) < 0);
 }
 
+static struct deferred_open_record *deferred_open_record_create(
+	bool delayed_for_oplocks,
+	bool async_open,
+	struct file_id id)
+{
+	struct deferred_open_record *record = NULL;
+
+	record = talloc(NULL, struct deferred_open_record);
+	if (record == NULL) {
+		return NULL;
+	}
+
+	*record = (struct deferred_open_record) {
+		.delayed_for_oplocks = delayed_for_oplocks,
+		.async_open = async_open,
+		.id = id,
+	};
+
+	return record;
+}
+
 struct defer_open_state {
 	struct smbXsrv_connection *xconn;
 	uint64_t mid;
+	struct file_id file_id;
+	struct timeval request_time;
+	struct timeval timeout;
+	bool kernel_oplock;
+	uint32_t lease_type;
 };
 
 static void defer_open_done(struct tevent_req *req);
 
-/****************************************************************************
- Handle the 1 second delay in returning a SHARING_VIOLATION error.
-****************************************************************************/
-
+/**
+ * Defer an open and watch a locking.tdb record
+ *
+ * This defers an open that gets rescheduled once the locking.tdb record watch
+ * is triggered by a change to the record.
+ *
+ * It is used to defer opens that triggered an oplock break and for the SMB1
+ * sharing violation delay.
+ **/
 static void defer_open(struct share_mode_lock *lck,
 		       struct timeval request_time,
 		       struct timeval timeout,
 		       struct smb_request *req,
-		       struct deferred_open_record *state)
+		       bool delayed_for_oplocks,
+		       bool kernel_oplock,
+		       struct file_id id)
 {
-	struct deferred_open_record *open_rec;
+	struct deferred_open_record *open_rec = NULL;
+	struct timeval abs_timeout;
+	struct defer_open_state *watch_state;
+	struct tevent_req *watch_req;
+	bool ok;
+
+	abs_timeout = timeval_sum(&request_time, &timeout);
 
-	DEBUG(10,("defer_open_sharing_error: time [%u.%06u] adding deferred "
-		  "open entry for mid %llu\n",
-		  (unsigned int)request_time.tv_sec,
-		  (unsigned int)request_time.tv_usec,
-		  (unsigned long long)req->mid));
+	DBG_DEBUG("request time [%s] timeout [%s] mid [%" PRIu64 "] "
+		  "delayed_for_oplocks [%s] kernel_oplock [%s] file_id [%s]\n",
+		  timeval_string(talloc_tos(), &request_time, false),
+		  timeval_string(talloc_tos(), &abs_timeout, false),
+		  req->mid,
+		  delayed_for_oplocks ? "yes" : "no",
+		  kernel_oplock ? "yes" : "no",
+		  file_id_string_tos(&id));
 
-	open_rec = talloc(NULL, struct deferred_open_record);
+	open_rec = deferred_open_record_create(delayed_for_oplocks,
+					       false,
+					       id);
 	if (open_rec == NULL) {
 		TALLOC_FREE(lck);
 		exit_server("talloc failed");
 	}
 
-	*open_rec = *state;
-
-	if (lck) {
-		struct defer_open_state *watch_state;
-		struct tevent_req *watch_req;
-		bool ret;
-
-		watch_state = talloc(open_rec, struct defer_open_state);
-		if (watch_state == NULL) {
-			exit_server("talloc failed");
-		}
-		watch_state->xconn = req->xconn;


-- 
Samba Shared Repository



More information about the samba-cvs mailing list