The branch, master has been updated
       via  d4f18f99d3a s3:smbd: let delay_for_oplock_fn() only call 
leases_db_get() once
       via  60ae7a5a2ed s3:smbd: lease_match_break_fn() only needs 
leases_db_get() once
       via  76da56aa65b s3:smbd: inline fsp_lease_type_is_exclusive() logic 
into contend_level2_oplocks_begin_default
       via  bf8f2258497 s3:locking: move get_existing_share_mode_lock() to 
share_mode_lock.[ch]
       via  8b3b3166802 s3:locking: pass lease_key explicitly to 
set_share_mode()
       via  0fbca175ae4 s3:smbd: only run validate_oplock_types() with 
smbd:validate_oplock_types = yes
       via  c75de325710 s3:g_lock: avoid useless talloc_array(0) in 
g_lock_dump()
       via  bb3dddcdf11 s3:g_lock: add some const to the shared array passed 
via g_lock_dump*()
       via  bf1dd1a188c lib/util: add unlikely() to SMB_ASSERT()
      from  06f35edaf12 lib: Map ERANGE to NT_STATUS_INTEGER_OVERFLOW

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit d4f18f99d3a40a8df00beb006e2731959aa6fad9
Author: Stefan Metzmacher <me...@samba.org>
Date:   Mon Aug 15 09:56:15 2022 +0200

    s3:smbd: let delay_for_oplock_fn() only call leases_db_get() once
    
    get_lease_type() will just call leases_db_get() again for leases,
    so only call it for oplocks.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <me...@samba.org>
    Reviewed-by: Jeremy Allison <j...@samba.org>
    
    Autobuild-User(master): Jeremy Allison <j...@samba.org>
    Autobuild-Date(master): Fri Aug 19 19:39:18 UTC 2022 on sn-devel-184

commit 60ae7a5a2ed9a03d8693b9b455b7b3696386aeb1
Author: Stefan Metzmacher <me...@samba.org>
Date:   Mon Aug 15 09:45:43 2022 +0200

    s3:smbd: lease_match_break_fn() only needs leases_db_get() once
    
    get_lease_type() will just call leases_db_get() again...
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <me...@samba.org>
    Reviewed-by: Jeremy Allison <j...@samba.org>

commit 76da56aa65bb9fe7f2f8c4a2e30e278a61db1ff5
Author: Stefan Metzmacher <me...@samba.org>
Date:   Thu Aug 18 12:52:54 2022 +0200

    s3:smbd: inline fsp_lease_type_is_exclusive() logic into 
contend_level2_oplocks_begin_default
    
    SMB2_LEASE_WRITE is the indication for an exclusive lease,
    the fact that a SMB2_LEASE_WRITE can't exists without
    SMB2_LEASE_READ is not important here.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <me...@samba.org>
    Reviewed-by: Jeremy Allison <j...@samba.org>

commit bf8f2258497f7d2a5a5f8d1cacf1a30899ed455c
Author: Stefan Metzmacher <me...@samba.org>
Date:   Thu Aug 18 14:14:20 2022 +0200

    s3:locking: move get_existing_share_mode_lock() to share_mode_lock.[ch]
    
    This should be where get_share_mode_lock() is located.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <me...@samba.org>
    Reviewed-by: Jeremy Allison <j...@samba.org>

commit 8b3b316680221487f84a7cfe14f52e8ffd64ba85
Author: Stefan Metzmacher <me...@samba.org>
Date:   Wed Aug 10 08:27:15 2022 +0000

    s3:locking: pass lease_key explicitly to set_share_mode()
    
    We should avoid accessing fsp->lease if possible.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <me...@samba.org>
    Reviewed-by: Jeremy Allison <j...@samba.org>

commit 0fbca175ae4763d82f8a414ee3d6354c95d5294e
Author: Stefan Metzmacher <me...@samba.org>
Date:   Fri Aug 19 15:17:41 2022 +0000

    s3:smbd: only run validate_oplock_types() with smbd:validate_oplock_types = 
yes
    
    This is really expensive as share_mode_forall_entries() is currently
    doing a talloc_memdup() of the whole record...
    
    This is mainly used to avoid regressions, so only
    use smbd:validate_oplock_types = yes in make test,
    but skip it for production.
    
    This improves the following test:
    
     time smbtorture //127.0.0.1/m -Uroot%test \
            smb2.create.bench-path-contention-shared \
            --option='torture:bench_path=file.dat' \
            --option="torture:timelimit=60" \
            --option="torture:nprocs=256" \
            --option="torture:qdepth=1"
    
    From:
    
       open[num/s=8852,avslat=0.014999,minlat=0.000042,maxlat=0.054600]
       close[num/s=8850,avslat=0.014136,minlat=0.000025,maxlat=0.054537]
    
    to:
    
       open[num/s=11377,avslat=0.012075,minlat=0.000041,maxlat=0.054107]
       close[num/s=11375,avslat=0.010594,minlat=0.000023,maxlat=0.053620]
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <me...@samba.org>
    Reviewed-by: Jeremy Allison <j...@samba.org>

commit c75de325710c0fbbd50a0acd3af55404165440d6
Author: Stefan Metzmacher <me...@samba.org>
Date:   Thu Aug 18 17:32:43 2022 +0200

    s3:g_lock: avoid useless talloc_array(0) in g_lock_dump()
    
    In the common case we don't have any shared lock holders,
    so there's no need to allocate memory for the empty array.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <me...@samba.org>
    Reviewed-by: Jeremy Allison <j...@samba.org>

commit bb3dddcdf11e6c2f5319d64bf2ef20636d0ed82f
Author: Stefan Metzmacher <me...@samba.org>
Date:   Thu Aug 18 17:52:33 2022 +0200

    s3:g_lock: add some const to the shared array passed via g_lock_dump*()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <me...@samba.org>
    Reviewed-by: Jeremy Allison <j...@samba.org>

commit bf1dd1a188c096093bedc628a14bb037e3209630
Author: Stefan Metzmacher <me...@samba.org>
Date:   Thu Aug 18 16:06:02 2022 +0200

    lib/util: add unlikely() to SMB_ASSERT()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <me...@samba.org>
    Reviewed-by: Jeremy Allison <j...@samba.org>

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

Summary of changes:
 lib/util/fault.h                  |  2 +-
 selftest/target/Samba3.pm         |  1 +
 selftest/target/Samba4.pm         |  1 +
 source3/include/g_lock.h          |  4 ++--
 source3/lib/g_lock.c              | 20 +++++++++++---------
 source3/locking/leases_util.c     | 17 -----------------
 source3/locking/locking.c         | 11 -----------
 source3/locking/proto.h           |  3 ---
 source3/locking/share_mode_lock.c | 30 +++++++++++++++++++++---------
 source3/locking/share_mode_lock.h |  4 ++++
 source3/smbd/open.c               | 32 +++++++++++++++++++++++++++-----
 source3/smbd/server.c             |  2 +-
 source3/smbd/smb2_oplock.c        |  3 ++-
 source3/smbd/smbd.h               |  1 +
 source3/torture/test_g_lock.c     | 12 ++++++------
 source3/utils/net_g_lock.c        |  2 +-
 16 files changed, 79 insertions(+), 66 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/util/fault.h b/lib/util/fault.h
index f3b1666a172..6aceaf6dabc 100644
--- a/lib/util/fault.h
+++ b/lib/util/fault.h
@@ -33,7 +33,7 @@
 #ifdef _SAMBA_DEBUG_H
 #define SMB_ASSERT(b) \
 do { \
-       if (!(b)) { \
+       if (unlikely(!(b))) { \
                DEBUG(0,("PANIC: assert failed at %s(%d): %s\n", \
                         __FILE__, __LINE__, #b)); \
                smb_panic("assert failed: " #b); \
diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
index 88898807428..d413f14bacd 100755
--- a/selftest/target/Samba3.pm
+++ b/selftest/target/Samba3.pm
@@ -2772,6 +2772,7 @@ sub provision($$)
        panic action = cd $self->{srcdir} && 
$self->{srcdir}/selftest/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
        smbd:suicide mode = yes
        smbd:FSCTL_SMBTORTURE = yes
+       smbd:validate_oplock_types = yes
 
        client min protocol = SMB2_02
        server min protocol = SMB2_02
diff --git a/selftest/target/Samba4.pm b/selftest/target/Samba4.pm
index 1762ae4ae79..e5ae57cb7fc 100755
--- a/selftest/target/Samba4.pm
+++ b/selftest/target/Samba4.pm
@@ -778,6 +778,7 @@ sub provision_raw_step1($$)
        panic action = $RealBin/gdb_backtrace \%d
        smbd:suicide mode = yes
        smbd:FSCTL_SMBTORTURE = yes
+       smbd:validate_oplock_types = yes
        wins support = yes
        server role = $ctx->{server_role}
        server services = +echo $services
diff --git a/source3/include/g_lock.h b/source3/include/g_lock.h
index 3a94879d209..749cb57ed45 100644
--- a/source3/include/g_lock.h
+++ b/source3/include/g_lock.h
@@ -71,7 +71,7 @@ struct tevent_req *g_lock_dump_send(
        TDB_DATA key,
        void (*fn)(struct server_id exclusive,
                   size_t num_shared,
-                  struct server_id *shared,
+                  const struct server_id *shared,
                   const uint8_t *data,
                   size_t datalen,
                   void *private_data),
@@ -81,7 +81,7 @@ NTSTATUS g_lock_dump(struct g_lock_ctx *ctx,
                     TDB_DATA key,
                     void (*fn)(struct server_id exclusive,
                                size_t num_shared,
-                               struct server_id *shared,
+                               const struct server_id *shared,
                                const uint8_t *data,
                                size_t datalen,
                                void *private_data),
diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c
index d683c4ddee6..8a07949b3d9 100644
--- a/source3/lib/g_lock.c
+++ b/source3/lib/g_lock.c
@@ -1210,7 +1210,7 @@ struct g_lock_dump_state {
        TDB_DATA key;
        void (*fn)(struct server_id exclusive,
                   size_t num_shared,
-                  struct server_id *shared,
+                  const struct server_id *shared,
                   const uint8_t *data,
                   size_t datalen,
                   void *private_data);
@@ -1238,12 +1238,14 @@ static void g_lock_dump_fn(TDB_DATA key, TDB_DATA data,
                return;
        }
 
-       shared = talloc_array(
-               state->mem_ctx, struct server_id, lck.num_shared);
-       if (shared == NULL) {
-               DBG_DEBUG("talloc failed\n");
-               state->status = NT_STATUS_NO_MEMORY;
-               return;
+       if (lck.num_shared > 0) {
+               shared = talloc_array(
+                       state->mem_ctx, struct server_id, lck.num_shared);
+               if (shared == NULL) {
+                       DBG_DEBUG("talloc failed\n");
+                       state->status = NT_STATUS_NO_MEMORY;
+                       return;
+               }
        }
 
        for (i=0; i<lck.num_shared; i++) {
@@ -1265,7 +1267,7 @@ static void g_lock_dump_fn(TDB_DATA key, TDB_DATA data,
 NTSTATUS g_lock_dump(struct g_lock_ctx *ctx, TDB_DATA key,
                     void (*fn)(struct server_id exclusive,
                                size_t num_shared,
-                               struct server_id *shared,
+                               const struct server_id *shared,
                                const uint8_t *data,
                                size_t datalen,
                                void *private_data),
@@ -1300,7 +1302,7 @@ struct tevent_req *g_lock_dump_send(
        TDB_DATA key,
        void (*fn)(struct server_id exclusive,
                   size_t num_shared,
-                  struct server_id *shared,
+                  const struct server_id *shared,
                   const uint8_t *data,
                   size_t datalen,
                   void *private_data),
diff --git a/source3/locking/leases_util.c b/source3/locking/leases_util.c
index cb62bffbd7d..9ae4081cd7b 100644
--- a/source3/locking/leases_util.c
+++ b/source3/locking/leases_util.c
@@ -71,23 +71,6 @@ uint32_t fsp_lease_type(struct files_struct *fsp)
        return fsp->lease_type;
 }
 
-static uint32_t lease_type_is_exclusive(uint32_t lease_type)
-{
-       if ((lease_type & (SMB2_LEASE_READ | SMB2_LEASE_WRITE)) ==
-           (SMB2_LEASE_READ | SMB2_LEASE_WRITE)) {
-               return true;
-       }
-
-       return false;
-}
-
-bool fsp_lease_type_is_exclusive(struct files_struct *fsp)
-{
-       uint32_t lease_type = fsp_lease_type(fsp);
-
-       return lease_type_is_exclusive(lease_type);
-}
-
 const struct GUID *fsp_client_guid(const files_struct *fsp)
 {
        return &fsp->conn->sconn->client->global->client_guid;
diff --git a/source3/locking/locking.c b/source3/locking/locking.c
index b002e80fee4..befdc10f369 100644
--- a/source3/locking/locking.c
+++ b/source3/locking/locking.c
@@ -468,17 +468,6 @@ char *share_mode_str(TALLOC_CTX *ctx, int num,
                 (unsigned int)e->name_hash);
 }
 
-/*******************************************************************
- Fetch a share mode where we know one MUST exist. This call reference
- counts it internally to allow for nested lock fetches.
-********************************************************************/
-
-struct share_mode_lock *get_existing_share_mode_lock(TALLOC_CTX *mem_ctx,
-                                                    const struct file_id id)
-{
-       return get_share_mode_lock(mem_ctx, id, NULL, NULL, NULL);
-}
-
 struct rename_share_filename_state {
        struct share_mode_lock *lck;
        struct messaging_context *msg_ctx;
diff --git a/source3/locking/proto.h b/source3/locking/proto.h
index d6e7a54a766..7fc177d7aa6 100644
--- a/source3/locking/proto.h
+++ b/source3/locking/proto.h
@@ -128,8 +128,6 @@ void locking_close_file(files_struct *fsp,
 char *share_mode_str(TALLOC_CTX *ctx, int num,
                     const struct file_id *id,
                     const struct share_mode_entry *e);
-struct share_mode_lock *get_existing_share_mode_lock(TALLOC_CTX *mem_ctx,
-                                                    struct file_id id);
 
 bool rename_share_filename(struct messaging_context *msg_ctx,
                        struct share_mode_lock *lck,
@@ -212,7 +210,6 @@ bool release_posix_lock_posix_flavour(files_struct *fsp,
 /* The following definitions come from locking/leases_util.c */
 uint32_t map_oplock_to_lease_type(uint16_t op_type);
 uint32_t fsp_lease_type(struct files_struct *fsp);
-bool fsp_lease_type_is_exclusive(struct files_struct *fsp);
 const struct GUID *fsp_client_guid(const files_struct *fsp);
 
 #endif /* _LOCKING_PROTO_H_ */
diff --git a/source3/locking/share_mode_lock.c 
b/source3/locking/share_mode_lock.c
index dd19c53024b..75912ec5dc8 100644
--- a/source3/locking/share_mode_lock.c
+++ b/source3/locking/share_mode_lock.c
@@ -468,7 +468,7 @@ struct locking_tdb_data_fetch_state {
 static void locking_tdb_data_fetch_fn(
        struct server_id exclusive,
        size_t num_shared,
-       struct server_id *shared,
+       const struct server_id *shared,
        const uint8_t *data,
        size_t datalen,
        void *private_data)
@@ -768,7 +768,7 @@ struct get_static_share_mode_data_state {
 static void get_static_share_mode_data_fn(
        struct server_id exclusive,
        size_t num_shared,
-       struct server_id *shared,
+       const struct server_id *shared,
        const uint8_t *data,
        size_t datalen,
        void *private_data)
@@ -1005,6 +1005,17 @@ static int share_mode_lock_destructor(struct 
share_mode_lock *lck)
        return 0;
 }
 
+/*******************************************************************
+ Fetch a share mode where we know one MUST exist. This call reference
+ counts it internally to allow for nested lock fetches.
+********************************************************************/
+
+struct share_mode_lock *get_existing_share_mode_lock(TALLOC_CTX *mem_ctx,
+                                                    const struct file_id id)
+{
+       return get_share_mode_lock(mem_ctx, id, NULL, NULL, NULL);
+}
+
 struct share_mode_do_locked_state {
        TDB_DATA key;
        void (*fn)(const uint8_t *buf,
@@ -1017,7 +1028,7 @@ struct share_mode_do_locked_state {
 static void share_mode_do_locked_fn(
        struct server_id exclusive,
        size_t num_shared,
-       struct server_id *shared,
+       const struct server_id *shared,
        const uint8_t *data,
        size_t datalen,
        void *private_data)
@@ -1324,7 +1335,7 @@ struct fetch_share_mode_unlocked_state {
 static void fetch_share_mode_unlocked_parser(
        struct server_id exclusive,
        size_t num_shared,
-       struct server_id *shared,
+       const struct server_id *shared,
        const uint8_t *data,
        size_t datalen,
        void *private_data)
@@ -1395,7 +1406,7 @@ struct fetch_share_mode_state {
 static void fetch_share_mode_fn(
        struct server_id exclusive,
        size_t num_shared,
-       struct server_id *shared,
+       const struct server_id *shared,
        const uint8_t *data,
        size_t datalen,
        void *private_data);
@@ -1460,7 +1471,7 @@ struct tevent_req *fetch_share_mode_send(TALLOC_CTX 
*mem_ctx,
 static void fetch_share_mode_fn(
        struct server_id exclusive,
        size_t num_shared,
-       struct server_id *shared,
+       const struct server_id *shared,
        const uint8_t *data,
        size_t datalen,
        void *private_data)
@@ -1564,7 +1575,7 @@ struct share_mode_forall_state {
 static void share_mode_forall_dump_fn(
        struct server_id exclusive,
        size_t num_shared,
-       struct server_id *shared,
+       const struct server_id *shared,
        const uint8_t *data,
        size_t datalen,
        void *private_data)
@@ -1782,6 +1793,7 @@ bool set_share_mode(struct share_mode_lock *lck,
                    uid_t uid,
                    uint64_t mid,
                    uint16_t op_type,
+                   const struct smb2_lease_key *lease_key,
                    uint32_t share_access,
                    uint32_t access_mask)
 {
@@ -1839,7 +1851,7 @@ bool set_share_mode(struct share_mode_lock *lck,
        if (op_type == LEASE_OPLOCK) {
                const struct GUID *client_guid = fsp_client_guid(fsp);
                e.client_guid = *client_guid;
-               e.lease_key = fsp->lease->lease.lease_key;
+               e.lease_key = *lease_key;
        }
 
        ok = share_mode_entry_put(&e, &e_buf);
@@ -2108,7 +2120,7 @@ struct share_mode_count_entries_state {
 static void share_mode_count_entries_fn(
        struct server_id exclusive,
        size_t num_shared,
-       struct server_id *shared,
+       const struct server_id *shared,
        const uint8_t *data,
        size_t datalen,
        void *private_data)
diff --git a/source3/locking/share_mode_lock.h 
b/source3/locking/share_mode_lock.h
index bd4e98ccecd..4f47b6fbcbe 100644
--- a/source3/locking/share_mode_lock.h
+++ b/source3/locking/share_mode_lock.h
@@ -26,6 +26,7 @@ struct share_mode_lock;
 struct share_mode_entry;
 struct smb_filename;
 struct files_struct;
+struct smb2_lease_key;
 
 bool locking_init(void);
 bool locking_init_readonly(void);
@@ -37,6 +38,8 @@ struct share_mode_lock *get_share_mode_lock(
        const char *servicepath,
        const struct smb_filename *smb_fname,
        const struct timespec *old_write_time);
+struct share_mode_lock *get_existing_share_mode_lock(TALLOC_CTX *mem_ctx,
+                                                    struct file_id id);
 
 bool del_share_mode(struct share_mode_lock *lck,
                    struct files_struct *fsp);
@@ -52,6 +55,7 @@ bool set_share_mode(
        uid_t uid,
        uint64_t mid,
        uint16_t op_type,
+       const struct smb2_lease_key *lease_key,
        uint32_t share_access,
        uint32_t access_mask);
 bool reset_share_mode_entry(
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 1d6c3cfbfbc..d5c2f4c830f 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -2210,8 +2210,21 @@ static bool validate_oplock_types_fn(
 static bool validate_oplock_types(struct share_mode_lock *lck)
 {
        struct validate_oplock_types_state state = { .valid = true };
+       static bool skip_validation;
+       bool validate;
        bool ok;
 
+       if (skip_validation) {
+               return true;
+       }
+
+       validate = lp_parm_bool(-1, "smbd", "validate_oplock_types", false);
+       if (!validate) {
+               DBG_DEBUG("smbd:validate_oplock_types not set to yes\n");
+               skip_validation = true;
+               return true;
+       }
+
        ok = share_mode_forall_entries(lck, validate_oplock_types_fn, &state);
        if (!ok) {
                DBG_DEBUG("share_mode_forall_entries failed\n");
@@ -2523,7 +2536,7 @@ static bool delay_for_oplock_fn(
        struct files_struct *fsp = state->fsp;
        const struct smb2_lease *lease = state->lease;
        bool e_is_lease = (e->op_type == LEASE_OPLOCK);
-       uint32_t e_lease_type = get_lease_type(e, fsp->file_id);
+       uint32_t e_lease_type = SMB2_LEASE_NONE;
        uint32_t break_to;
        bool lease_is_breaking = false;
 
@@ -2542,7 +2555,7 @@ static bool delay_for_oplock_fn(
                        &e->client_guid,
                        &e->lease_key,
                        &fsp->file_id,
-                       NULL, /* current_state */
+                       &e_lease_type, /* current_state */
                        &lease_is_breaking,
                        NULL, /* breaking_to_requested */
                        NULL, /* breaking_to_required */
@@ -2584,6 +2597,8 @@ static bool delay_for_oplock_fn(
                                nt_errstr(status));
                        smb_panic("leases_db_get() failed");
                }
+       } else {
+               e_lease_type = get_lease_type(e, fsp->file_id);
        }
 
        if (!state->got_handle_lease &&
@@ -3535,6 +3550,7 @@ static NTSTATUS open_file_ntcreate(connection_struct 
*conn,
        uint32_t existing_dos_attributes = 0;
        struct share_mode_lock *lck = NULL;
        uint32_t open_access_mask = access_mask;
+       const struct smb2_lease_key *lease_key = NULL;
        NTSTATUS status;
        SMB_STRUCT_STAT saved_stat = smb_fname->st;
        struct timespec old_write_time;
@@ -4051,6 +4067,10 @@ static NTSTATUS open_file_ntcreate(connection_struct 
*conn,
                return status;
        }
 
+       if (fsp->oplock_type == LEASE_OPLOCK) {
+               lease_key = &lease->lease_key;
+       }
+
        share_mode_flags_restrict(lck, access_mask, share_access, 0);
 
        ok = set_share_mode(
@@ -4059,6 +4079,7 @@ static NTSTATUS open_file_ntcreate(connection_struct 
*conn,
                get_current_uid(fsp->conn),
                req ? req->mid : 0,
                fsp->oplock_type,
+               lease_key,
                share_access,
                access_mask);
        if (!ok) {
@@ -4739,6 +4760,7 @@ static NTSTATUS open_directory(connection_struct *conn,
                get_current_uid(conn),
                req ? req->mid : 0,
                NO_OPLOCK,
+               NULL,
                share_access,
                fsp->access_mask);
        if (!ok) {
@@ -5471,7 +5493,7 @@ static bool lease_match_break_fn(
 {
        struct lease_match_break_state *state = private_data;
        bool stale, equal;
-       uint32_t e_lease_type;
+       uint32_t e_lease_type = SMB2_LEASE_NONE;
        NTSTATUS status;
 
        stale = share_entry_stale_pid(e);
@@ -5488,7 +5510,7 @@ static bool lease_match_break_fn(
                &e->client_guid,
                &e->lease_key,
                &state->id,
-               NULL, /* current_state */
+               &e_lease_type, /* current_state */
                NULL, /* breaking */
                NULL, /* breaking_to_requested */
                NULL, /* breaking_to_required */
@@ -5499,9 +5521,9 @@ static bool lease_match_break_fn(
        } else {
                DBG_WARNING("Could not find version/epoch: %s\n",
                            nt_errstr(status));
+               return false;
        }
 
-       e_lease_type = get_lease_type(e, state->id);
        if (e_lease_type == SMB2_LEASE_NONE) {
                return false;
        }
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index 7e2a10532f6..25cb84ab9d0 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -1436,7 +1436,7 @@ struct smbd_claim_version_state {
 
 static void smbd_claim_version_parser(struct server_id exclusive,
                                      size_t num_shared,
-                                     struct server_id *shared,
+                                     const struct server_id *shared,
                                      const uint8_t *data,
                                      size_t datalen,
                                      void *private_data)
diff --git a/source3/smbd/smb2_oplock.c b/source3/smbd/smb2_oplock.c
index 1f143840b34..404746d6f6a 100644
--- a/source3/smbd/smb2_oplock.c
+++ b/source3/smbd/smb2_oplock.c
@@ -1248,6 +1248,7 @@ static void 
contend_level2_oplocks_begin_default(files_struct *fsp,
                .sconn = fsp->conn->sconn, .id = fsp->file_id,
        };
        struct share_mode_lock *lck = NULL;
+       uint32_t fsp_lease = fsp_lease_type(fsp);
        bool ok, has_read_lease;
 
        /*
@@ -1258,7 +1259,7 @@ static void 
contend_level2_oplocks_begin_default(files_struct *fsp,
         * the shared memory area whilst doing this.
         */
 
-       if (fsp_lease_type_is_exclusive(fsp)) {
+       if (fsp_lease & SMB2_LEASE_WRITE) {
                /*
                 * There can't be any level2 oplocks, we're alone.
                 */
diff --git a/source3/smbd/smbd.h b/source3/smbd/smbd.h
index f2c3abcda2d..6cf2b64a5a1 100644
--- a/source3/smbd/smbd.h
+++ b/source3/smbd/smbd.h
@@ -25,6 +25,7 @@ struct dptr_struct;
 #include "vfs.h"
 #include "smbd/proto.h"
 #include "locking/proto.h"
+#include "locking/share_mode_lock.h"
 #include "smbd/fd_handle.h"
 #if defined(WITH_SMB1SERVER)
 #include "smbd/smb1_message.h"
diff --git a/source3/torture/test_g_lock.c b/source3/torture/test_g_lock.c
index 002e390af19..51133393960 100644
--- a/source3/torture/test_g_lock.c
+++ b/source3/torture/test_g_lock.c
@@ -115,7 +115,7 @@ struct lock2_parser_state {
 
 static void lock2_parser(struct server_id exclusive,
                         size_t num_shared,
-                        struct server_id *shared,
+                        const struct server_id *shared,
                         const uint8_t *data,
                         size_t datalen,
                         void *private_data)
@@ -216,14 +216,14 @@ struct lock3_parser_state {
 


-- 
Samba Shared Repository

Reply via email to