[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Tue Sep 20 01:35:01 UTC 2022


The branch, master has been updated
       via  3b6255b5b90 s3:locking: remove unused get_share_mode_lock()
       via  680c7907325 s3:smbd: make use of share_mode_entry_prepare_{lock_add,unlock}() in open_{file_ntcreate,directory}()
       via  12f6c129219 s3:smbd: let open_file_ntcreate() calculate info = FILE_WAS_* before get_share_mode_lock()
       via  1ae7e47a6b0 s3:smbd: make use of share_mode_entry_prepare_{lock_del,unlock}() in close_{remove_share_mode,directory}()
       via  d04b6e9dd0d s3:smbd: make use of close_share_mode_lock_{prepare,cleanup}() in close_directory()
       via  f9ea7839894 s3:smbd: split out some generic code from close_remove_share_mode()
       via  0f02f68f9f1 s3:smbd: avoid remove_oplock() in close_remove_share_mode()
       via  ac811f6f8cb s3:smbd: let close_directory() only change the user if needed
       via  b0082076f9f s3:smbd: remove one indentation level in close_directory()
       via  dab7df93211 s3:smbd: let close_directory() use the same delete_dir logic as close_remove_share_mode()
       via  ce868b095c0 s3:smbd: improve !delete_file logic in close_remove_share_mode()
       via  095da847e74 s3:smbd: let close_directory() hold the lock during delete_all_streams/rmdir_internals
       via  387f126d074 s3:smbd: remove static from release_file_oplock()
       via  a4dd4d5f0fd s3:smbd: maintain all SHARE_MODE_LEASE_* flags not only _READ
       via  26669613e2d s3:smbd: split out check_and_store_share_mode()
       via  9e619f535fa s3:smbd: also call handle_share_mode_lease for directories
       via  0a8619c8458 s3:smbd: prepare delay_for_oplock() for directories
       via  0bfdae92db0 s3:smbd: call set_file_oplock() after set_share_mode()
       via  4d06aa1550b s3:smbd: call grant_fsp_lease() after set_share_mode()
       via  aae504cdaa0 s3:smbd: move grant_fsp_lease()/set_file_oplock() out of handle_share_mode_lease()
       via  0796c5de6f3 s3:smbd: move grant_fsp_lease()/set_file_oplock() out of delay_for_oplocks()
       via  150308d1d0d s3:smbd: add more detailed debugging to delay_for_oplock()
       via  775dc007d21 s3:locking: add share_mode_entry_prepare_{lock,unlock}() infrastructure
       via  cba169252ea s3:locking: optimize share_mode_do_locked_vfs_denied() with g_lock_lock callback
       via  b971a21aa34 s3:locking: add current_share_mode_glck helper functions
       via  17e496c6f91 s3:g_lock: add callback function to g_lock_lock()
       via  37c9600ff1b s3:g_lock: add callback function to g_lock_lock_send()
       via  01c629a4098 s3:g_lock: add callback function to g_lock_lock_simple_fn()
       via  63291ea5c5d s3:g_lock: add callback function to g_lock_trylock()
       via  6bda68910e2 s3:g_lock: reorder the logic in g_lock_trylock()
       via  7cac6eb5d81 s3:g_lock: remove redundant code in g_lock_trylock()
       via  d19fa657d72 s3:g_lock: add g_lock_ctx->busy and assert it to false
       via  a75194d41b4 s3:g_lock: add g_lock_lock_cb_state infrastructure
       via  3a5174136d6 s3:g_lock: reorder the logic in g_lock_lock_simple_fn()
       via  3c26ee84ce8 lib/dbwrap: allow dbwrap_merge_dbufs() to update an existing buffer
       via  6f2ce1fd346 s3:dbwrap_watch: add dbwrap_watched_watch_force_alerting()
       via  3829acc4743 s3:dbwrap_watch: add dbwrap_watched_watch_reset_alerting() helper
       via  c1ec8310496 s3:dbwrap_watch: let dbwrap_watched_watch_skip_alerting() also clear the selected watcher
       via  d7f42946928 s3:locking: let _share_mode_do_locked_vfs_* use get/put_share_mode_lock_internal
       via  a2f6f96ac74 s3:locking: split out put_share_mode_lock_internal()
       via  977498d3eb8 s3:locking: split out get_share_mode_lock_internal()
       via  0b94695ebf8 s3:locking: remove static_share_mode_data_refcount
       via  ca9014d0378 s3:locking: move from uint8_t share_mode_lock_key_data[] to struct file_id
       via  0fbd125453f s3:smb2_trans2: make use of share_mode_do_locked_vfs_allowed() in smb_posix_unlink()
       via  b80bc6307cf s3:smbd: let update_write_time_on_close() use share_mode_do_locked_vfs_denied()
       via  1288989f0f5 s3:smbd: let update_write_time_on_close() use share_mode_{old,changed}_write_time()
       via  b9edf3c6428 s3:locking: make use of share_mode_do_locked_vfs_denied() in set_sticky_write_time()
       via  2474b063da9 s3:locking: make use of share_mode_do_locked_vfs_denied() in set_write_time()
       via  1198e8c0f6c s3:locking: make use of share_mode_do_locked_vfs_denied() in file_has_open_streams()
       via  42f96d29335 s3:smbd: let lease_match() use share_mode_do_locked_vfs_denied()
       via  c8458f237cd s3:locking: let set_delete_on_close() use share_mode_do_locked_vfs_denied()
       via  bb7d7656638 s3:locking: make use of new share_mode_set_{changed,old}_write_time() helpers
       via  432272a7c83 s3:locking: add share_mode_set_{changed,old}_write_time() helpers
       via  c5c7a377c3d s3:smbd: let setup_poll_open() use share_mode_do_locked_vfs_denied()
       via  47f1d9362e9 s3:smbd: move get_existing_share_mode_lock() into setup_poll_open()
       via  8979311c6bd s3:locking: make 'struct share_mode_lock' private to share_mode_lock.c
       via  06e2aa3cba7 s3:locking: make use of share_mode_lock_access_private_data() in reset_share_mode_entry()
       via  e6ef5474009 s3:locking: pass struct share_mode_data to share_mode_entry_do()
       via  f63b9b5311f s3:locking: make use of share_mode_lock_access_private_data() in share_mode_forall_entries()
       via  eef0c8e25bc s3:locking: make use of share_mode_lock_file_id() in share_mode_watch_send()
       via  557323ca037 s3:locking: add and use share_mode_lock_assert_private_data()
       via  faf9388e960 s3:locking: let get_share_mode_write_time() use share_mode_lock_access_private_data()
       via  db0e6732929 s3:locking: let set_write_time() use share_mode_lock_access_private_data()
       via  e018c6347f1 s3:locking: let set_sticky_write_time() use share_mode_lock_access_private_data()
       via  ee78d948129 s3:locking: let is_delete_on_close_set() use share_mode_lock_access_private_data()
       via  c5334b0db49 s3:locking: let get_delete_on_close_token() use share_mode_lock_access_private_data()
       via  2e7ccb72a07 s3:locking: let set_delete_on_close_lck() use share_mode_lock_access_private_data()
       via  7d982e85585 s3:locking: let reset_delete_on_close_lck() use share_mode_lock_access_private_data()
       via  45253acc81e s3:locking: let remove_lease_if_stale() use share_mode_lock_file_id()
       via  d42bb5d831c s3:locking: add share_mode_lock_file_id()
       via  357adc2f27e s3:locking: make use of share_mode_lock_access_private_data() in rename_share_filename()
       via  4d697278386 s3:locking: let rename_share_filename_state maintain a struct share_mode_data pointer
       via  b6789ff1c07 s3:locking: add share_mode_lock_access_private_data()
       via  b508c5a0be6 s3:locking: let share_mode_wakeup_waiters() use share_mode_do_locked_vfs_denied()
       via  7e2ec6ee567 s3:locking: make share_mode_do_locked() static
       via  0d5a9603816 s3:locking: protect do_lock() with share_mode_do_locked_vfs_allowed()
       via  7c6113de2b6 s3:smbd: protect smbd_do_unlocking() with share_mode_do_locked_vfs_allowed()
       via  f971a4ae31f s3:locking: add share_mode_do_locked_vfs_{denied,allowed}()
       via  aa7df0fb9fa s3:smbd: add smb_vfs_assert_allowed() to kernel oplock code
       via  f2fdeb17ec4 s3:smbd: add helpers to deny vfs calls in some sections
       via  641bfc5905b s3:smbd: move VFS_FIND() to smbd/vfs.c
       via  e7cf1b07b69 s3:smbd: move locking related vfs functions to smbd/vfs.c
       via  6ab4457b4be s3:locking: just use g_lock_dump() for fsp_update_share_mode_flags()
       via  65715e3431a s3:locking: move fsp_update_share_mode_flags* related functions further down
       via  f4e0a6fe00b s3:locking: replace locking_tdb_data_store() with share_mode_data_ltdb_store()
       via  db78fe13a37 s3:locking: let share_mode_forall_entries() call TALLOC_FREE(ltdb)
       via  703a4ff5256 s3:locking: split out share_mode_data_ltdb_store()
       via  5bba79d639b s3:locking: introduce share_mode_data->not_stored
       via  e1d1b3403e5 s3:locking: change some debug messages to level unless we got NT_STATUS_NOT_FOUND
       via  96fe4239131 s3:locking: log all share_mode_forall_entries() errors at level 0
       via  ca2dce3147d s3:locking: let share_mode_forall_leases() log all errors at level 0
       via  f0e0c0af20d s3:locking: let set_delete_on_close_lck() log errors and panic
       via  dd4a94ec925 s3:locking: log g_lock_dump() error in locking_tdb_data_fetch() at level 0
       via  b19e50634a8 s3:locking: log add locking_tdb_data_store() errors at level 0
       via  e12c3b56dae s3:locking: log g_lock_locks() error at level 0
       via  3e5775084aa s3:locking: let fsp_update_share_mode_flags() log all errors at level 0
       via  c61a375f14b s3:locking: log all g_lock_writev_data() errors at level 0
       via  d8de42c1558 s3:locking: log all locking_tdb_data_{get,fetch}() errors at level 0
       via  bd088b46392 s3:open_files.idl: add share_mode_entry_op_type
       via  170a4812a6b s3:smbd: let smbXsrv_{session,tcon,open}_global.tdb use TDB_VOLATILE
       via  3ef567472e1 s3:g_lock: fix error handling in g_lock_watch_data_send()
       via  9b815ab65ba s3:smbd: let lease_match() call TALLOC_FREE(lck); on error
       via  50188fb441b s3:locking: let reset_share_mode_entry() report errors to the caller
       via  fb2776f790c s3:locking: remove unused NO_LOCKING_COUNT
       via  7014475f5b8 s3:torture: fix strict aliasing warnings in cmd_vfs.c
      from  36c5f31d77a libsmb: Use find_snapshot_token() for clistr_is_previous_version_path()

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


- Log -----------------------------------------------------------------
commit 3b6255b5b902a062744912a6a3a82f7fb7279b23
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Aug 31 15:51:21 2022 +0200

    s3:locking: remove unused get_share_mode_lock()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Tue Sep 20 01:34:55 UTC 2022 on sn-devel-184

commit 680c7907325b433856ac1dd916ab63e671fbe4ab
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Aug 29 16:48:04 2022 +0200

    s3:smbd: make use of share_mode_entry_prepare_{lock_add,unlock}() in open_{file_ntcreate,directory}()
    
    This gives a nice speed up...
    
    The following test with 256 commections all looping with open/close
    on the same inode (share root) is improved drastically:
    
      smbtorture //127.0.0.1/m -Uroot%test smb2.bench.path-contention-shared \
             --option='torture:bench_path=' \
             --option="torture:timelimit=60" \
             --option="torture:nprocs=256" \
             --option="torture:qdepth=1"
    
    From something like this:
    
        open[num/s=11536,avslat=0.011450,minlat=0.000039,maxlat=0.052707]
        close[num/s=11534,avslat=0.010878,minlat=0.000022,maxlat=0.052342]
    
    (only this commit with the close part reverted) to:
    
        open[num/s=12722,avslat=0.009548,minlat=0.000051,maxlat=0.054338]
        close[num/s=12720,avslat=0.010701,minlat=0.000033,maxlat=0.054372]
    
    (with both patches) to:
    
        open[num/s=37680,avslat=0.003471,minlat=0.000040,maxlat=0.061411]
        close[num/s=37678,avslat=0.003440,minlat=0.000022,maxlat=0.051536]
    
    So we are finally perform similar like we did in Samba 4.12,
    which resulted in:
    
        open[num/s=36846,avslat=0.003574,minlat=0.000043,maxlat=0.020378]
        close[num/s=36844,avslat=0.003552,minlat=0.000026,maxlat=0.020321]
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 12f6c129219670ab0d7392434f88751dedace6ed
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Sep 13 02:41:14 2022 +0200

    s3:smbd: let open_file_ntcreate() calculate info = FILE_WAS_* before get_share_mode_lock()
    
    This will simplify further changes.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 1ae7e47a6b0e47c8c78af91188007eafc1239835
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Aug 30 05:31:41 2022 +0000

    s3:smbd: make use of share_mode_entry_prepare_{lock_del,unlock}() in close_{remove_share_mode,directory}()
    
    This gives a nice speed up...
    
    The following test with 256 commections all looping with open/close
    on the same inode (share root) is improved drastically:
    
      smbtorture //127.0.0.1/m -Uroot%test smb2.bench.path-contention-shared \
             --option='torture:bench_path=' \
             --option="torture:timelimit=60" \
             --option="torture:nprocs=256" \
             --option="torture:qdepth=1"
    
    From some like this:
    
        open[num/s=11536,avslat=0.011450,minlat=0.000039,maxlat=0.052707]
        close[num/s=11534,avslat=0.010878,minlat=0.000022,maxlat=0.052342]
    
    to:
        open[num/s=13225,avslat=0.010504,minlat=0.000042,maxlat=0.054023]
        close[num/s=13223,avslat=0.008971,minlat=0.000022,maxlat=0.053838]
    
    But this is only half of the solution, the next commits will
    add a similar optimization to the open code, at the end we'll
    perform like we did in Samba 4.12:
    
        open[num/s=37680,avslat=0.003471,minlat=0.000040,maxlat=0.061411]
        close[num/s=37678,avslat=0.003440,minlat=0.000022,maxlat=0.051536]
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit d04b6e9dd0d933e99848547efc9d17edc437c1be
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Aug 30 05:31:41 2022 +0000

    s3:smbd: make use of close_share_mode_lock_{prepare,cleanup}() in close_directory()
    
    It's good to have this in common as close_remove_share_mode()
    and in the end we'll avoid get_existing_share_mode_lock()
    and call them via share_mode_entry_prepare_{lock,unlock}(),
    so that they can run under a tdb chainlock.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit f9ea78398949109ba7fec90cbaaf294a446042ca
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Aug 30 05:31:41 2022 +0000

    s3:smbd: split out some generic code from close_remove_share_mode()
    
    close_share_mode_lock_prepare() will operates on share_mode_lock
    in order to check if the object needs to be deleted or if
    we can remove the share_mode_entry directly.
    
    close_share_mode_lock_cleanup() will finish after the object
    has been deleted.
    
    We can reuse these function in close_directory() soon and
    in the end we'll avoid get_existing_share_mode_lock()
    and call them via share_mode_entry_prepare_{lock,unlock}(),
    so that they can run under a tdb chainlock.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 0f02f68f9f197ee7ec4b24a32a7b5a4b985ebe9b
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Sep 13 01:30:48 2022 +0200

    s3:smbd: avoid remove_oplock() in close_remove_share_mode()
    
    This inlines remove_oplock() into close_remove_share_mode() and
    calls remove_share_oplock() and release_file_oplock() directly.
    
    The idea is that we'll soon call remove_share_oplock()
    under a tdb chainlock, while release_file_oplock() needs to be called outside.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit ac811f6f8cbc268d95f1204214614640b928fb3f
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Sep 12 19:49:09 2022 +0200

    s3:smbd: let close_directory() only change the user if needed
    
    The logic is now similar to close_remove_share_mode().
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit b0082076f9f3d81a6b47a692c7263be5b85ff99d
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Sep 12 19:41:25 2022 +0200

    s3:smbd: remove one indentation level in close_directory()
    
    We now use a goto done in order to skip the deletion part.
    
    This means the code flow is now almost idential compared to
    close_remove_share_mode().
    
    It prepares to split common code to be shared by
    close_remove_share_mode() and close_directory().
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit dab7df932119ab10bb9fa88c8adbe02064bfee16
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Sep 12 19:35:38 2022 +0200

    s3:smbd: let close_directory() use the same delete_dir logic as close_remove_share_mode()
    
    This will make further changes simpler.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit ce868b095c0154401e3f4af7f296a575c8701863
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Sep 12 18:00:39 2022 +0200

    s3:smbd: improve !delete_file logic in close_remove_share_mode()
    
    This makes it much easier to understand the logic (at least for me).
    
    It will make the following changes easier.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 095da847e747b732c16c0a7f8516fb535b0f0f1c
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Sep 12 19:15:58 2022 +0200

    s3:smbd: let close_directory() hold the lock during delete_all_streams/rmdir_internals
    
    Now that we're using g_lock, it doesn't mean we're holding a tdb
    chainlock.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 387f126d0749355eed32f75708d488ef6ad17349
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Aug 30 09:48:40 2022 +0200

    s3:smbd: remove static from release_file_oplock()
    
    It will be used in close.c in the next commit.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit a4dd4d5f0fdb8cb242dde93cf620f238fccf9e9c
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Aug 15 17:42:33 2022 +0200

    s3:smbd: maintain all SHARE_MODE_LEASE_* flags not only _READ
    
    Remember SMB2 Create is the only was to upgrade a lease.
    
    The strategy is that opening of a file will always result
    in storing the total lease bits.
    
    But we're lazy clearing the flags on close.
    
    We'll only clear them by traversing all entries when
    we break a NONE or when opening a new handle.
    
    We don't do any decision on SHARE_MODE_LEASE_{HANDLE,WRITE},
    maybe we'll do in future, but at least it should be much more
    sane for debugging now!
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 26669613e2dc673d55e0f8977d7758477eab6fd6
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Aug 15 08:08:37 2022 +0200

    s3:smbd: split out check_and_store_share_mode()
    
    This shows that the code in open_file_ntcreate() and
    open_directory() is basically the same now, which
    simplifies things a lot.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 9e619f535fa561a5d37d98f3809726bffd6ff91d
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Aug 10 09:23:25 2022 +0000

    s3:smbd: also call handle_share_mode_lease for directories
    
    It means we call open_mode_check() now only via handle_share_mode_lease()
    and the fact that we never grant any directory leases (yet), means
    that delay_for_oplocks() avoids the share_mode_forall_entries() loop.
    
    This is a way into supporting directory leases, but that's not
    the point for this commit, the point is that.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 0a8619c8458fe1ab3445b9b6b22ec8ffd86e9e06
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 19 12:00:15 2022 +0200

    s3:smbd: prepare delay_for_oplock() for directories
    
    We don't support directory leases yet, so it should be
    an noop for now.
    
    The point is that we want to call
    delay_for_oplock(oplock_request=NO_OPLOCK)
    for directories soon.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 0bfdae92db09a2943a531f9dc0aa53c1c5c70f00
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Aug 10 08:48:25 2022 +0000

    s3:smbd: call set_file_oplock() after set_share_mode()
    
    The important part is the call to get a kernel oplock is deferred
    until after set_share_mode(). The goal is to get the code
    between get_share_mode_lock() and set_share_mode() free of any
    blocking operation.
    
    As we were optimistic to get the oplock that was asked for,
    we need to remove_share_oplock() in order to set NO_OPLOCK
    also in the share_mode entry.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 4d06aa1550bbc980a983e881a5f1394fb6f87c1b
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Aug 10 08:48:25 2022 +0000

    s3:smbd: call grant_fsp_lease() after set_share_mode()
    
    This means we don't have to call remove_lease_if_stale() if
    set_share_mode() fails. It's easier to cleanup the share mode entry.
    
    And it makes the code flow easier to the following changes.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit aae504cdaa086735150ce1108075a9d926d65bec
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Aug 10 08:30:18 2022 +0000

    s3:smbd: move grant_fsp_lease()/set_file_oplock() out of handle_share_mode_lease()
    
    The aim is to call set_file_oplock() after set_share_mode(), so that we
    only ask for kernel oplocks after set_share_mode().
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 0796c5de6f382b96cfb65bc659a0c34ab0b0af58
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Aug 10 07:58:02 2022 +0000

    s3:smbd: move grant_fsp_lease()/set_file_oplock() out of delay_for_oplocks()
    
    It means delay_for_oplocks() is no longer asking for kernel oplocks.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 150308d1d0d891bd86e46da0134ad15c251dc5f9
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Aug 21 11:46:16 2022 +0200

    s3:smbd: add more detailed debugging to delay_for_oplock()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 775dc007d211b8153fbc5741f52dc77f92d9c314
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Aug 29 13:44:00 2022 +0200

    s3:locking: add share_mode_entry_prepare_{lock,unlock}() infrastructure
    
    When adding or deleting share mode entries elements, we typically
    have a pattern like this:
    
    1. get the g_lock via get_[existing_]share_mode_lock()
    2. do some checking of the existing record
    3. add/delete a share_mode_entry to the record
    4. do some vfs operations still protected by the g_lock
    5. (optional) cleanup of the record on failure
    6. release the g_lock
    
    We can optimize this to:
    
    - Run 1-3. under a tdb chainlock
    - Only protect vfs operations with the g_lock
      if a new file was created/will be deleted
    - Regrab the g_lock for a cleanup.
    
    The new share_mode_entry_prepare_lock()
    allows the caller to run a function within a tdb chainlock
    similar to share_mode_do_locked_vfs_denied() where vfs calls are denied
    and the execution is done within a tdb chainlock.
    
    But the callback function is allowed to decide if it wants to
    keep the lock at the g_lock layer on return.
    
    The decision is kept in struct share_mode_entry_prepare_state,
    which is then passed to share_mode_entry_prepare_unlock()
    with an optional callback to do some cleanup under the
    still existing g_lock or a regrabed g_lock.
    
    In the ideal case the callback function passed to
    share_mode_entry_prepare_lock() is able to decide that
    it can drop the g_lock and the share_mode_entry_prepare_unlock().
    gets a NULL callback as there's nothing to cleanup.
    In this case share_mode_entry_prepare_unlock() is a noop.
    
    This will allow us to avoid fallbacks to the dbwrap_watch based
    waiting for the g_lock in the SMB2 Create and Close code paths.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit cba169252ea270bb725ec06aff71d841492099f5
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Aug 29 12:50:20 2022 +0200

    s3:locking: optimize share_mode_do_locked_vfs_denied() with g_lock_lock callback
    
    It means that in callers function will run under a single tdb chainlock,
    which means callers from the outside will never see the record being
    locked at g_lock level, as the g_lock is only held in memory.
    within the single tdb chainlock. As a result we'll very unlikely hit
    the case where we need to wait for a g_lock using the dbwrap_watch
    logic.
    
    Review with: git show -w
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit b971a21aa3494d1ac57bfebdb9e1d224e5d79c9c
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Aug 29 12:50:20 2022 +0200

    s3:locking: add current_share_mode_glck helper functions
    
    We'll soon make use of callback functions passed to g_lock_lock(),
    during these callback function we'll only be allowed to
    call 'g_lock_lock_cb_state' based functions.
    
    Given that nesting of share_mode call, we need to
    make it transparent to the callers and the detail
    that we optimize using g_lock_lock() callbacks.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 17e496c6f91ec464766fc562f31381e057cebe65
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Aug 28 13:08:48 2022 +0200

    s3:g_lock: add callback function to g_lock_lock()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 37c9600ff1babbb3e1fc2db3d29dfb12ca0c707a
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Aug 28 12:38:24 2022 +0200

    s3:g_lock: add callback function to g_lock_lock_send()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 01c629a409860e5cccfc64e78fa63c90303a4b7a
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Aug 28 11:41:46 2022 +0200

    s3:g_lock: add callback function to g_lock_lock_simple_fn()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 63291ea5c5d32e295b3638afd530e805ec59a190
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Aug 28 12:38:24 2022 +0200

    s3:g_lock: add callback function to g_lock_trylock()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 6bda68910e2a2d9b986d6d65c9790684b2f15e48
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Aug 28 12:31:23 2022 +0200

    s3:g_lock: reorder the logic in g_lock_trylock()
    
    We now have only one code path that stores the fully
    granted lock.
    
    This is not change in behavior, but it will simplify further
    changes.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 7cac6eb5d810f78e52292964808f7e163ced105c
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Aug 28 11:58:14 2022 +0200

    s3:g_lock: remove redundant code in g_lock_trylock()
    
    g_lock_cleanup_shared() handles lck.num_shared == 0 just fine...
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit d19fa657d725e887ec0cd2f19b479e827230faa6
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Aug 28 11:41:46 2022 +0200

    s3:g_lock: add g_lock_ctx->busy and assert it to false
    
    This prepares some helper functions in order to
    allow callers of g_lock_lock() to pass in a callback function
    that will run under the tdb chainlock when G_LOCK_WRITE was granted.
    
    The idea is that the callers callback function would run with
    g_lock_ctx->busy == true and all key based function are not be allowed
    during the execution of the callback function. Only the
    g_lock_lock_cb_state based helper function are allowed to be used.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit a75194d41b4257800595e2036772953318285d4c
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Aug 28 11:41:46 2022 +0200

    s3:g_lock: add g_lock_lock_cb_state infrastructure
    
    This prepares some helper functions in order to
    allow callers of g_lock_lock() to pass in a callback function
    that will run under the tdb chainlock when G_LOCK_WRITE was granted.
    
    The idea is that the callers callback function would only be allowed
    to run these new helper functions, while all key based function are
    not to be allowed.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 3a5174136d6706540ace5567d4e8193534dbd13a
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Aug 28 10:30:38 2022 +0200

    s3:g_lock: reorder the logic in g_lock_lock_simple_fn()
    
    First we fully check if we'll get the lock
    and then store the lock.
    
    This is not change in behavior, but it will simplify further changes.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 3c26ee84ce8bcd50e3788b1c4df5ebe2d101899c
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sat Sep 10 17:33:31 2022 +0200

    lib/dbwrap: allow dbwrap_merge_dbufs() to update an existing buffer
    
    This will be useful in future...
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 6f2ce1fd34642e56a68b0997decbf50255063ea4
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sat Sep 10 18:13:24 2022 +0200

    s3:dbwrap_watch: add dbwrap_watched_watch_force_alerting()
    
    This is useful when we want to wakeup the next watcher
    without modifying the record.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 3829acc4743db0f395ed3c3945c343a11a9e9486
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Aug 28 13:34:25 2022 +0200

    s3:dbwrap_watch: add dbwrap_watched_watch_reset_alerting() helper
    
    This can be used if the decision of using dbwrap_watched_watch_skip_alerting()
    needs to be reverted...
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit c1ec8310496ef7355b950bcf1e4b2d882740aa94
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Aug 28 13:32:59 2022 +0200

    s3:dbwrap_watch: let dbwrap_watched_watch_skip_alerting() also clear the selected watcher
    
    If a watcher was already selected for a wakeup notification reset it...
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit d7f429469280676594f0c98882c5d82dc358da6e
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 13:06:40 2022 +0200

    s3:locking: let _share_mode_do_locked_vfs_* use get/put_share_mode_lock_internal
    
    This avoids calling talloc(mem_ctx, struct share_mode_lock)
    and uses stack variables instead.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit a2f6f96ac74b25e99c9765bff341bfc9060a7bbf
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Aug 28 09:58:51 2022 +0200

    s3:locking: split out put_share_mode_lock_internal()
    
    This pairs with get_share_mode_lock_internal() and will allow us
    to use a struct share_mode_lock stack variable in future,
    which will be much cheaper.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 977498d3eb821c6c30c5a991949054f796579966
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 13:03:33 2022 +0200

    s3:locking: split out get_share_mode_lock_internal()
    
    This detaches the logic from the talloc(mem_ctx, struct share_mode_lock).
    In future we will have cases where we use a stack variable instead,
    which will be much cheaper.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 0b94695ebf8eb2edd6de7fc549857393461e4d50
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 09:50:00 2022 +0200

    s3:locking: remove static_share_mode_data_refcount
    
    The effective value of share_mode_lock_key_refcount
    is 'share_mode_lock_key_refcount + static_share_mode_data_refcount',
    which is quite confusing.
    
    This complexity is not needed and we can just use
    share_mode_lock_key_refcount.
    
    This will also simplify further changes.
    
    Review with: git show -U15 -w
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit ca9014d0378e1da8c30da4aae99a05005fe89b10
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 09:42:45 2022 +0200

    s3:locking: move from uint8_t share_mode_lock_key_data[] to struct file_id
    
    This will allow us to have better debug messages and will also make
    further changes easier.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 0fbd125453f7cf63e158d56b130b500e362fcbcb
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Sep 1 13:25:06 2022 +0200

    s3:smb2_trans2: make use of share_mode_do_locked_vfs_allowed() in smb_posix_unlink()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit b80bc6307cf4ec7d54284e1b940ce9f7430e6716
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Aug 30 08:11:12 2022 +0200

    s3:smbd: let update_write_time_on_close() use share_mode_do_locked_vfs_denied()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 1288989f0f5043f3a3dff9fda217f41b16d33958
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Aug 30 05:57:48 2022 +0000

    s3:smbd: let update_write_time_on_close() use share_mode_{old,changed}_write_time()
    
    We're already holding a share_mode_lock, so we can use it directly.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit b9edf3c6428652671eae8a5ec8e18460c6d31196
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Sep 1 12:54:35 2022 +0200

    s3:locking: make use of share_mode_do_locked_vfs_denied() in set_sticky_write_time()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 2474b063da95d3ef8662f9c7c27ed96e37f7a722
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Sep 1 12:49:51 2022 +0200

    s3:locking: make use of share_mode_do_locked_vfs_denied() in set_write_time()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 1198e8c0f6c0277e0c32a6c1091b222a6d8a5f14
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Sep 1 12:34:16 2022 +0200

    s3:locking: make use of share_mode_do_locked_vfs_denied() in file_has_open_streams()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 42f96d29335dd1ee361f6af70460aa9ff8d33d63
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Aug 31 17:14:09 2022 +0200

    s3:smbd: let lease_match() use share_mode_do_locked_vfs_denied()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit c8458f237cd415f35dd5582876c80a9b44d0a053
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Aug 31 16:34:40 2022 +0200

    s3:locking: let set_delete_on_close() use share_mode_do_locked_vfs_denied()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit bb7d765663813875a5391df203038edc9747bf0d
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Aug 30 05:55:57 2022 +0000

    s3:locking: make use of new share_mode_set_{changed,old}_write_time() helpers
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 432272a7c834b3ebf56d335a1f458fdc392f7e51
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Aug 30 05:55:03 2022 +0000

    s3:locking: add share_mode_set_{changed,old}_write_time() helpers
    
    These will be used in future to call them unter an existing share mode
    lock...
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit c5c7a377c3d395883a9d9cad3bb4256044aac0dc
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Aug 29 16:01:20 2022 +0200

    s3:smbd: let setup_poll_open() use share_mode_do_locked_vfs_denied()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 47f1d9362e93b0d6262df6642b495afe010d8149
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Aug 29 15:53:11 2022 +0200

    s3:smbd: move get_existing_share_mode_lock() into setup_poll_open()
    
    This will simplify the next steps...
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 8979311c6bde49d6210ce64b37c28b6f6fa527fb
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 10:44:59 2022 +0200

    s3:locking: make 'struct share_mode_lock' private to share_mode_lock.c
    
    There are no callers left dereferencing it.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 06e2aa3cba7af00bd8f9ee92496cd6e4e94f14a1
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 12:11:44 2022 +0200

    s3:locking: make use of share_mode_lock_access_private_data() in reset_share_mode_entry()
    
    We should avoid dereference 'struct share_mode_lock' as much as possible.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit e6ef5474009be017a3d8dc4edbad0b15d12ae877
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 12:10:55 2022 +0200

    s3:locking: pass struct share_mode_data to share_mode_entry_do()
    
    We should avoid dereference 'struct share_mode_lock' as much as possible.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit f63b9b5311f3a51dcc5cfe2c1ed0adb960033933
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 12:09:06 2022 +0200

    s3:locking: make use of share_mode_lock_access_private_data() in share_mode_forall_entries()
    
    We should avoid dereference 'struct share_mode_lock' as much as possible.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit eef0c8e25bcedb6b0028866c7540c6feeabb0dd0
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 12:08:03 2022 +0200

    s3:locking: make use of share_mode_lock_file_id() in share_mode_watch_send()
    
    We should avoid dereference 'struct share_mode_lock' as much as possible.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 557323ca03713c0f0f7b1b5d0f6116095ec405e0
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 12:05:04 2022 +0200

    s3:locking: add and use share_mode_lock_assert_private_data()
    
    We should avoid dereference 'struct share_mode_lock' as much as possible.
    
    In some places we just rely on share_mode_lock_access_private_data()
    to work, if needed the caller should already check it's result...
    
    Note that share_mode_lock_assert_private_data() can't fail up to
    now, but we want to change that in future and only load it on
    demand.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit faf9388e96028bb499f0ec9e34d5bb12ad26a0e8
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 11:17:51 2022 +0200

    s3:locking: let get_share_mode_write_time() use share_mode_lock_access_private_data()
    
    We should avoid dereference 'struct share_mode_lock' as much as possible.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit db0e67329297e34ade2062e73ec023a6d46efb00
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 11:17:51 2022 +0200

    s3:locking: let set_write_time() use share_mode_lock_access_private_data()
    
    We should avoid dereference 'struct share_mode_lock' as much as possible.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit e018c6347f1e5d306f801458ab7e68434bd582c3
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 11:17:51 2022 +0200

    s3:locking: let set_sticky_write_time() use share_mode_lock_access_private_data()
    
    We should avoid dereference 'struct share_mode_lock' as much as possible.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit ee78d948129bca8650bf1729b7d15826f2e564cd
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 11:17:51 2022 +0200

    s3:locking: let is_delete_on_close_set() use share_mode_lock_access_private_data()
    
    We should avoid dereference 'struct share_mode_lock' as much as possible.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit c5334b0db4910a252c4eb9434385a5b70cf194d8
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 11:17:51 2022 +0200

    s3:locking: let get_delete_on_close_token() use share_mode_lock_access_private_data()
    
    We should avoid dereference 'struct share_mode_lock' as much as possible.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 2e7ccb72a075f39ea6a406cba0ae53a1fd5314ff
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 11:17:51 2022 +0200

    s3:locking: let set_delete_on_close_lck() use share_mode_lock_access_private_data()
    
    We should avoid dereference 'struct share_mode_lock' as much as possible.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 7d982e8558567c6baaae888e023bde5a83ca1714
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 11:17:51 2022 +0200

    s3:locking: let reset_delete_on_close_lck() use share_mode_lock_access_private_data()
    
    We should avoid dereference 'struct share_mode_lock' as much as possible.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 45253acc81e613d0ab6a47d55c008f95af421bf1
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 10:43:12 2022 +0200

    s3:locking: let remove_lease_if_stale() use share_mode_lock_file_id()
    
    We should avoid dereference 'struct share_mode_lock' as much as possible.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit d42bb5d831ccc2e5134a2c3776546e1dda2736ac
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 10:40:44 2022 +0200

    s3:locking: add share_mode_lock_file_id()
    
    This will simplify some (mostly debug) code soon.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 357adc2f27e3efaeb4c38d84de06176175b6c39b
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 10:24:52 2022 +0200

    s3:locking: make use of share_mode_lock_access_private_data() in rename_share_filename()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 4d697278386b924441f5119dc998f06755aee915
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 10:21:25 2022 +0200

    s3:locking: let rename_share_filename_state maintain a struct share_mode_data pointer
    
    We only need to access lck->data once...
    
    This will simplify further changes.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit b6789ff1c07202d43822c5c7cc0c51df84aba4cd
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 10:24:52 2022 +0200

    s3:locking: add share_mode_lock_access_private_data()
    
    In future we should avoid dereference 'struct share_mode_lock'
    as much as possible.
    
    This will also allow us to load struct share_mode_data
    only if required in future.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit b508c5a0be6565355351cb036ce6495e35d76862
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Aug 26 09:27:44 2022 +0200

    s3:locking: let share_mode_wakeup_waiters() use share_mode_do_locked_vfs_denied()
    
    This allows us get rid of the otherwise unused share_mode_do_locked().
    
    It means we only have one code path that handles the g_lock handling.
    
    This looks like a performance degradation, but all callers of
    share_mode_wakeup_waiters() already took the share_mode_lock,
    so we only increment the refcount. Note the additional
    talloc(mem_ctx, struct share_mode_lock) will be optimized away
    in the next commits.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 7e2ec6ee5670c42bdbb88507fa82c657c035c865
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Aug 18 14:38:55 2022 +0200

    s3:locking: make share_mode_do_locked() static
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 0d5a96038164aef951473c94e97edd743ef0c593
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Aug 18 13:57:56 2022 +0200

    s3:locking: protect do_lock() with share_mode_do_locked_vfs_allowed()
    
    share_mode_do_locked() will be make static soon.
    
    Here we just want to avoid concurrent access to brlock.tdb
    in order to maintain the lock order, we're not interested in the
    locking.tdb content at all, expect that there's at least one
    entry.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 7c6113de2b61f9a87906bb56c1b2a1f4c7974e89
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Aug 18 13:57:56 2022 +0200

    s3:smbd: protect smbd_do_unlocking() with share_mode_do_locked_vfs_allowed()
    
    share_mode_do_locked() will be make static soon.
    
    Here we just want to avoid concurrent access to brlock.tdb
    in order to maintain the lock order, we're not interested in the
    locking.tdb content at all, expect that there's at least one
    entry and we want to wake potential watchers.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit f971a4ae31fd664ecb0ab3fd2c2ab1fc2275e68d
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Aug 18 13:26:47 2022 +0200

    s3:locking: add share_mode_do_locked_vfs_{denied,allowed}()
    
    These function will add an abstraction to protect
    a function that is not allowed to call vfs functions
    or allow vfs functions to be called.
    
    Currently these are implemented similar,
    but we'll optimize them in the next commits.
    
    The idea is that share_mode_do_locked_vfs_denied()
    will be able to run fast enough in order to run
    under a tdb chainlock (just a pthread mutex).
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit aa7df0fb9fa62cf2f6bc774c020da26ce878e7b0
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sat Sep 3 02:46:34 2022 +0200

    s3:smbd: add smb_vfs_assert_allowed() to kernel oplock code
    
    Kernel oplocks can block in the same way vfs operations can do.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit f2fdeb17ec432314a81c06863f59110aad4f558c
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Aug 21 15:37:18 2022 +0200

    s3:smbd: add helpers to deny vfs calls in some sections
    
    Code denying vfs calls can do:
    
    {
       struct smb_vfs_deny_state vfs_deny = {};
    
       smb_vfs_deny_push(&vfs_deny);
    
       VFS calls are not allowed here...
    
       smb_vfs_deny_pop(&vfs_deny);
    }
    
    This will allow us to safely run some code under a
    tdb chainlock later...
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 641bfc5905b0ec21ec7c65cda5139cb676d24917
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Aug 21 15:19:59 2022 +0200

    s3:smbd: move VFS_FIND() to smbd/vfs.c
    
    It's only used there...
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit e7cf1b07b6928f18b0147f4b6b74a97ae3fb667b
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Aug 21 15:15:09 2022 +0200

    s3:smbd: move locking related vfs functions to smbd/vfs.c
    
    This allows us to make VFS_FIND local to smbd/vfs.c in the
    next step.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 6ab4457b4be139c4e5a3f44ce9bf8018ad09a58b
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Aug 22 16:19:40 2022 +0200

    s3:locking: just use g_lock_dump() for fsp_update_share_mode_flags()
    
    We don't need to protect this with g_lock_lock/g_lock_unlock
    as we just want the current flags, we're still protected by the
    dbwrap layer lock.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 65715e3431a87f519528b0daa7d877f668875a84
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Aug 22 23:26:06 2022 +0200

    s3:locking: move fsp_update_share_mode_flags* related functions further down
    
    It will soon need to use 'struct locking_tdb_data'
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit f4e0a6fe00bc61b052ab3f1094bbce113e127d1d
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Aug 22 16:53:38 2022 +0200

    s3:locking: replace locking_tdb_data_store() with share_mode_data_ltdb_store()
    
    This means we flush share_mode_data at the same time...
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit db78fe13a37d7143f622d8f2e710f2ebd2d97abc
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sat Sep 3 23:35:06 2022 +0000

    s3:locking: let share_mode_forall_entries() call TALLOC_FREE(ltdb)
    
    We should free ltdb as soon as possible...
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 703a4ff525655c6f99ac24351be7eb898d4ded28
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Aug 22 16:53:38 2022 +0200

    s3:locking: split out share_mode_data_ltdb_store()
    
    This will allow us to use it in other places too
    and we'll avoid to storing multiple times.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 5bba79d639b6498073e3917b8112bb50b4aa0c39
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Aug 22 16:53:38 2022 +0200

    s3:locking: introduce share_mode_data->not_stored
    
    share_mode_data->fresh was very similar, but only set
    and never used.
    
    Now we remember 'not_stored' instead, the 'not_' is easier
    as ndr_pull sets [skip] elements to 0.
    
    We use this as indication to move the value to
    memcache.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit e1d1b3403e58f96947ebfaa3c633a75c3edb2cc8
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sat Sep 10 20:39:19 2022 +0200

    s3:locking: change some debug messages to level unless we got NT_STATUS_NOT_FOUND
    
    NT_STATUS_NOT_FOUND is not a real error in most cases so we should keep
    it on level 10, but all other errors should never be without notice...
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 96fe4239131f4cf7749ed25f48ba435ddee9d166
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sat Sep 10 20:39:19 2022 +0200

    s3:locking: log all share_mode_forall_entries() errors at level 0
    
    These should never fail without notice...
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit ca2dce3147d6d011db9526a4658271619274992a
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sat Sep 10 20:39:19 2022 +0200

    s3:locking: let share_mode_forall_leases() log all errors at level 0
    
    These should never fail without notice...
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit f0e0c0af20d93456241cc2079b7282c07ab1ad62
Author: Stefan Metzmacher <metze at samba.org>
Date:   Mon Sep 12 07:18:00 2022 +0000

    s3:locking: let set_delete_on_close_lck() log errors and panic
    
    Most of the calls in set_delete_on_close_lck() are checked with
    asserts, so do panic in all situation where things go wrong in an
    unexpected way.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit dd4a94ec925cf09da20c6c4f40a879131ef4be67
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sat Sep 10 20:39:19 2022 +0200

    s3:locking: log g_lock_dump() error in locking_tdb_data_fetch() at level 0
    
    This should never fail without notice...
    
    Note we already checked for NT_STATUS_NOT_FOUND before.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit b19e50634a8abd569a0170113000a37998d28f30
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sat Sep 10 20:39:19 2022 +0200

    s3:locking: log add locking_tdb_data_store() errors at level 0
    
    These should never fail without notice...
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit e12c3b56daed806b79076ad8f0fd7c0c9bbb4ae4
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sat Sep 10 20:39:19 2022 +0200

    s3:locking: log g_lock_locks() error at level 0
    
    These should never fail without notice...
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 3e5775084aa423d946c0264df594497f64bf2b82
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sat Sep 10 20:39:19 2022 +0200

    s3:locking: let fsp_update_share_mode_flags() log all errors at level 0
    
    These should never fail without notice, share_mode_do_locked() should
    never fail with NT_STATUS_NOT_FOUND for an existing fsp.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit c61a375f14b7a3d98472eedf9873ab0973010211
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sat Sep 10 20:39:19 2022 +0200

    s3:locking: log all g_lock_writev_data() errors at level 0
    
    These should never fail without notice.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit d8de42c1558559107bbb22e0c05738621a4ac753
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sat Sep 10 20:39:19 2022 +0200

    s3:locking: log all locking_tdb_data_{get,fetch}() errors at level 0
    
    These should never fail without notice.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit bd088b4639213af8a2ee8c700e2c1105ba095674
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Aug 21 11:17:19 2022 +0200

    s3:open_files.idl: add share_mode_entry_op_type
    
    This makes it easier to read log files...
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 170a4812a6b05b667ea6fd7a73d417e09e24e010
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Jun 30 10:25:47 2022 +0000

    s3:smbd: let smbXsrv_{session,tcon,open}_global.tdb use TDB_VOLATILE
    
    This avoids using fcntl() locks for dbwrap_delete()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 3ef567472e1d1c6b0c59445d6dcb792e0ded26dd
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sat Sep 10 19:03:44 2022 +0200

    s3:g_lock: fix error handling in g_lock_watch_data_send()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15167
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 9b815ab65ba5b28fd86797202cc5bd6236e9ab81
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Aug 31 17:11:15 2022 +0200

    s3:smbd: let lease_match() call TALLOC_FREE(lck); on error
    
    We ignore the error from share_mode_forall_leases(), but
    we still need to cleanup the share_mode_lock we are holding...
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 50188fb441b43d84daca607e3d74f1c2187cedae
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sat Sep 10 20:39:37 2022 +0200

    s3:locking: let reset_share_mode_entry() report errors to the caller
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15166
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit fb2776f790cc6f8a4da38339c13ebde1f56e9550
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sat Sep 10 20:41:17 2022 +0200

    s3:locking: remove unused NO_LOCKING_COUNT
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 7014475f5b8d22b267e8805c710fa6f46f2d23ca
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Aug 21 20:47:13 2022 +0200

    s3:torture: fix strict aliasing warnings in cmd_vfs.c
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

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

Summary of changes:
 lib/dbwrap/dbwrap.c                       |   22 +-
 lib/dbwrap/dbwrap.h                       |    2 +-
 lib/dbwrap/dbwrap_rbt.c                   |    9 +-
 libcli/auth/netlogon_creds_cli.c          |    6 +-
 source3/include/g_lock.h                  |   35 +-
 source3/include/vfs.h                     |   16 +-
 source3/lib/dbwrap/dbwrap_ctdb.c          |   10 +-
 source3/lib/dbwrap/dbwrap_watch.c         |   16 +
 source3/lib/dbwrap/dbwrap_watch.h         |    2 +
 source3/lib/g_lock.c                      |  551 ++++++++++--
 source3/librpc/idl/open_files.idl         |   13 +-
 source3/libsmb/trusts_util.c              |    2 +-
 source3/locking/brlock.c                  |   16 -
 source3/locking/locking.c                 |  334 ++++++--
 source3/locking/posix.c                   |   17 -
 source3/locking/share_mode_lock.c         | 1295 ++++++++++++++++++++++-------
 source3/locking/share_mode_lock.h         |   85 +-
 source3/locking/share_mode_lock_private.h |    7 +-
 source3/smbd/close.c                      |  438 ++++++----
 source3/smbd/open.c                       |  715 ++++++++++------
 source3/smbd/proto.h                      |    1 +
 source3/smbd/server.c                     |   24 +-
 source3/smbd/smb2_oplock.c                |   23 +-
 source3/smbd/smb2_reply.c                 |   10 +-
 source3/smbd/smb2_trans2.c                |   69 +-
 source3/smbd/smbXsrv_open.c               |    1 +
 source3/smbd/smbXsrv_session.c            |    1 +
 source3/smbd/smbXsrv_tcon.c               |    1 +
 source3/smbd/vfs.c                        |   76 ++
 source3/torture/cmd_vfs.c                 |   10 +-
 source3/torture/test_g_lock.c             |   85 +-
 source3/utils/net_g_lock.c                |    4 +-
 source3/utils/net_registry.c              |    7 +-
 source3/wscript_build                     |    1 +
 34 files changed, 2878 insertions(+), 1026 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/dbwrap/dbwrap.c b/lib/dbwrap/dbwrap.c
index 7555efaa3ab..9bdbd67dce1 100644
--- a/lib/dbwrap/dbwrap.c
+++ b/lib/dbwrap/dbwrap.c
@@ -680,22 +680,28 @@ static ssize_t tdb_data_buf(const TDB_DATA *dbufs, int num_dbufs,
 }
 
 
-TDB_DATA dbwrap_merge_dbufs(TALLOC_CTX *mem_ctx,
+NTSTATUS dbwrap_merge_dbufs(TDB_DATA *buf, TALLOC_CTX *mem_ctx,
 			    const TDB_DATA *dbufs, int num_dbufs)
 {
 	ssize_t len = tdb_data_buf(dbufs, num_dbufs, NULL, 0);
-	uint8_t *buf;
 
 	if (len == -1) {
-		return (TDB_DATA) {0};
+		return NT_STATUS_INVALID_PARAMETER;
 	}
 
-	buf = talloc_array(mem_ctx, uint8_t, len);
-	if (buf == NULL) {
-		return (TDB_DATA) {0};
+	if (buf->dsize != len) {
+		uint8_t *tmp;
+
+		tmp = talloc_realloc(mem_ctx, buf->dptr, uint8_t, len);
+		if (tmp == NULL && len != 0) {
+			return NT_STATUS_NO_MEMORY;
+		}
+
+		buf->dptr = tmp;
+		buf->dsize = len;
 	}
 
-	tdb_data_buf(dbufs, num_dbufs, buf, len);
+	tdb_data_buf(dbufs, num_dbufs, buf->dptr, buf->dsize);
 
-	return (TDB_DATA) { .dptr = buf, .dsize = len };
+	return NT_STATUS_OK;
 }
diff --git a/lib/dbwrap/dbwrap.h b/lib/dbwrap/dbwrap.h
index 9b8bf811ca6..cfae403b178 100644
--- a/lib/dbwrap/dbwrap.h
+++ b/lib/dbwrap/dbwrap.h
@@ -222,7 +222,7 @@ NTSTATUS dbwrap_parse_marshall_buf(const uint8_t *buf, size_t buflen,
 NTSTATUS dbwrap_unmarshall(struct db_context *db, const uint8_t *buf,
 			   size_t buflen);
 
-TDB_DATA dbwrap_merge_dbufs(TALLOC_CTX *mem_ctx,
+NTSTATUS dbwrap_merge_dbufs(TDB_DATA *buf, TALLOC_CTX *mem_ctx,
 			    const TDB_DATA *dbufs, int num_dbufs);
 
 
diff --git a/lib/dbwrap/dbwrap_rbt.c b/lib/dbwrap/dbwrap_rbt.c
index db456dfffba..691acef688d 100644
--- a/lib/dbwrap/dbwrap_rbt.c
+++ b/lib/dbwrap/dbwrap_rbt.c
@@ -149,9 +149,12 @@ static NTSTATUS db_rbt_storev(struct db_record *rec,
 	if (num_dbufs == 1) {
 		data = dbufs[0];
 	} else {
-		data = dbwrap_merge_dbufs(rec, dbufs, num_dbufs);
-		if (data.dptr == NULL) {
-			return NT_STATUS_NO_MEMORY;
+		NTSTATUS status;
+
+		data = (TDB_DATA) {0};
+		status = dbwrap_merge_dbufs(&data, rec, dbufs, num_dbufs);
+		if (!NT_STATUS_IS_OK(status)) {
+			return status;
 		}
 		to_free = data.dptr;
 	}
diff --git a/libcli/auth/netlogon_creds_cli.c b/libcli/auth/netlogon_creds_cli.c
index 716a565128d..fec192bdae2 100644
--- a/libcli/auth/netlogon_creds_cli.c
+++ b/libcli/auth/netlogon_creds_cli.c
@@ -813,7 +813,8 @@ struct tevent_req *netlogon_creds_cli_lock_send(TALLOC_CTX *mem_ctx,
 	subreq = g_lock_lock_send(state, ev,
 				  context->db.g_ctx,
 				  string_term_tdb_data(context->db.key_name),
-				  G_LOCK_WRITE);
+				  G_LOCK_WRITE,
+				  NULL, NULL);
 	if (tevent_req_nomem(subreq, req)) {
 		return tevent_req_post(req, ev);
 	}
@@ -1027,7 +1028,8 @@ struct tevent_req *netlogon_creds_cli_lck_send(
 	subreq = g_lock_lock_send(state, ev,
 				  context->db.g_ctx,
 				  string_term_tdb_data(context->db.key_name),
-				  gtype);
+				  gtype,
+				  NULL, NULL);
 	if (tevent_req_nomem(subreq, req)) {
 		return tevent_req_post(req, ev);
 	}
diff --git a/source3/include/g_lock.h b/source3/include/g_lock.h
index 749cb57ed45..d6c1521a52c 100644
--- a/source3/include/g_lock.h
+++ b/source3/include/g_lock.h
@@ -25,6 +25,7 @@
 #include "dbwrap/dbwrap.h"
 
 struct g_lock_ctx;
+struct g_lock_lock_cb_state;
 struct messaging_context;
 
 enum g_lock_type {
@@ -43,14 +44,44 @@ void g_lock_set_lock_order(struct g_lock_ctx *ctx,
 struct g_lock_ctx *g_lock_ctx_init(TALLOC_CTX *mem_ctx,
 				   struct messaging_context *msg);
 
+typedef void (*g_lock_lock_cb_fn_t)(struct g_lock_lock_cb_state *glck,
+				    void *cb_private);
+
+NTSTATUS g_lock_lock_cb_dump(struct g_lock_lock_cb_state *glck,
+			     void (*fn)(struct server_id exclusive,
+					size_t num_shared,
+					const struct server_id *shared,
+					const uint8_t *data,
+					size_t datalen,
+					void *private_data),
+			     void *private_data);
+NTSTATUS g_lock_lock_cb_writev(struct g_lock_lock_cb_state *glck,
+			       const TDB_DATA *dbufs,
+			       size_t num_dbufs);
+void g_lock_lock_cb_unlock(struct g_lock_lock_cb_state *glck);
+struct tevent_req *g_lock_lock_cb_watch_data_send(
+	TALLOC_CTX *mem_ctx,
+	struct tevent_context *ev,
+	struct g_lock_lock_cb_state *cb_state,
+	struct server_id blocker);
+NTSTATUS g_lock_lock_cb_watch_data_recv(
+	struct tevent_req *req,
+	bool *blockerdead,
+	struct server_id *blocker);
+void g_lock_lock_cb_wake_watchers(struct g_lock_lock_cb_state *cb_state);
+
 struct tevent_req *g_lock_lock_send(TALLOC_CTX *mem_ctx,
 				    struct tevent_context *ev,
 				    struct g_lock_ctx *ctx,
 				    TDB_DATA key,
-				    enum g_lock_type type);
+				    enum g_lock_type type,
+				    g_lock_lock_cb_fn_t cb_fn,
+				    void *cb_private);
 NTSTATUS g_lock_lock_recv(struct tevent_req *req);
 NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, TDB_DATA key,
-		     enum g_lock_type lock_type, struct timeval timeout);
+		     enum g_lock_type lock_type, struct timeval timeout,
+		     g_lock_lock_cb_fn_t cb_fn,
+		     void *cb_private);
 NTSTATUS g_lock_unlock(struct g_lock_ctx *ctx, TDB_DATA key);
 
 NTSTATUS g_lock_writev_data(
diff --git a/source3/include/vfs.h b/source3/include/vfs.h
index 20b6eb57900..1cc3b91a9e0 100644
--- a/source3/include/vfs.h
+++ b/source3/include/vfs.h
@@ -891,10 +891,6 @@ struct smb_filename {
 
 #define SMB_FILENAME_POSIX_PATH		FSP_POSIX_FLAGS_PATHNAMES
 
-#define VFS_FIND(__fn__) while (handle->fns->__fn__##_fn==NULL) { \
-				handle = handle->next; \
-			 }
-
 enum vfs_translate_direction {
 	vfs_translate_to_unix = 0,
 	vfs_translate_to_windows
@@ -1409,6 +1405,18 @@ struct vfs_statvfs_struct {
 
 #include "vfs_macros.h"
 
+struct smb_vfs_deny_state {
+	struct smb_vfs_deny_state *parent;
+	const char *location;
+};
+
+void smb_vfs_assert_allowed(void);
+
+void _smb_vfs_deny_push(struct smb_vfs_deny_state *state, const char *location);
+#define smb_vfs_deny_push(__state) _smb_vfs_deny_push(__state, __location__);
+void _smb_vfs_deny_pop(struct smb_vfs_deny_state *state, const char *location);
+#define smb_vfs_deny_pop(__state) _smb_vfs_deny_pop(__state, __location__);
+
 int smb_vfs_call_connect(struct vfs_handle_struct *handle,
 			 const char *service, const char *user);
 void smb_vfs_call_disconnect(struct vfs_handle_struct *handle);
diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c
index c0af5729f32..46165e8fbfb 100644
--- a/source3/lib/dbwrap/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap/dbwrap_ctdb.c
@@ -382,7 +382,7 @@ static int db_ctdb_transaction_start(struct db_context *db)
 	 * Wait a day, i.e. forever...
 	 */
 	status = g_lock_lock(ctx->lock_ctx, string_term_tdb_data(h->lock_name),
-			     G_LOCK_WRITE, timeval_set(86400, 0));
+			     G_LOCK_WRITE, timeval_set(86400, 0), NULL, NULL);
 	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(0, ("g_lock_lock failed: %s\n", nt_errstr(status)));
 		TALLOC_FREE(h);
@@ -674,11 +674,11 @@ static NTSTATUS db_ctdb_storev_transaction(
 	struct db_ctdb_transaction_handle *h = talloc_get_type_abort(
 		rec->private_data, struct db_ctdb_transaction_handle);
 	NTSTATUS status;
-	TDB_DATA data;
+	TDB_DATA data = {0};
 
-	data = dbwrap_merge_dbufs(rec, dbufs, num_dbufs);
-	if (data.dptr == NULL) {
-		return NT_STATUS_NO_MEMORY;
+	status = dbwrap_merge_dbufs(&data, rec, dbufs, num_dbufs);
+	if (!NT_STATUS_IS_OK(status)) {
+		return status;
 	}
 
 	status = db_ctdb_transaction_store(h, rec->key, data);
diff --git a/source3/lib/dbwrap/dbwrap_watch.c b/source3/lib/dbwrap/dbwrap_watch.c
index e5b11aa124e..df931192c21 100644
--- a/source3/lib/dbwrap/dbwrap_watch.c
+++ b/source3/lib/dbwrap/dbwrap_watch.c
@@ -1034,9 +1034,25 @@ void dbwrap_watched_watch_skip_alerting(struct db_record *rec)
 {
 	struct db_watched_record *wrec = db_record_get_watched_record(rec);
 
+	wrec->wakeup.watcher = (struct dbwrap_watcher) { .instance = 0, };
 	wrec->watchers.alerted = true;
 }
 
+void dbwrap_watched_watch_reset_alerting(struct db_record *rec)
+{
+	struct db_watched_record *wrec = db_record_get_watched_record(rec);
+
+	wrec->wakeup.watcher = (struct dbwrap_watcher) { .instance = 0, };
+	wrec->watchers.alerted = false;
+}
+
+void dbwrap_watched_watch_force_alerting(struct db_record *rec)
+{
+	struct db_watched_record *wrec = db_record_get_watched_record(rec);
+
+	dbwrap_watched_record_prepare_wakeup(wrec);
+}
+
 struct dbwrap_watched_watch_state {
 	struct db_context *db;
 	TDB_DATA key;
diff --git a/source3/lib/dbwrap/dbwrap_watch.h b/source3/lib/dbwrap/dbwrap_watch.h
index 0731ad91641..1b93e137853 100644
--- a/source3/lib/dbwrap/dbwrap_watch.h
+++ b/source3/lib/dbwrap/dbwrap_watch.h
@@ -30,6 +30,8 @@ struct db_context *db_open_watched(TALLOC_CTX *mem_ctx,
 uint64_t dbwrap_watched_watch_add_instance(struct db_record *rec);
 void dbwrap_watched_watch_remove_instance(struct db_record *rec, uint64_t instance);
 void dbwrap_watched_watch_skip_alerting(struct db_record *rec);
+void dbwrap_watched_watch_reset_alerting(struct db_record *rec);
+void dbwrap_watched_watch_force_alerting(struct db_record *rec);
 struct tevent_req *dbwrap_watched_watch_send(TALLOC_CTX *mem_ctx,
 					     struct tevent_context *ev,
 					     struct db_record *rec,
diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c
index 8a07949b3d9..40687f47526 100644
--- a/source3/lib/g_lock.c
+++ b/source3/lib/g_lock.c
@@ -37,6 +37,7 @@ struct g_lock_ctx {
 	struct db_context *db;
 	struct messaging_context *msg;
 	enum dbwrap_lock_order lock_order;
+	bool busy;
 };
 
 struct g_lock {
@@ -198,7 +199,7 @@ struct g_lock_ctx *g_lock_ctx_init_backend(
 {
 	struct g_lock_ctx *result;
 
-	result = talloc(mem_ctx, struct g_lock_ctx);
+	result = talloc_zero(mem_ctx, struct g_lock_ctx);
 	if (result == NULL) {
 		return NULL;
 	}
@@ -334,12 +335,334 @@ static void g_lock_cleanup_shared(struct g_lock *lck)
 	}
 }
 
+struct g_lock_lock_cb_state {
+	struct g_lock_ctx *ctx;
+	struct db_record *rec;
+	struct g_lock *lck;
+	struct server_id *new_shared;
+	g_lock_lock_cb_fn_t cb_fn;
+	void *cb_private;
+	TALLOC_CTX *update_mem_ctx;
+	TDB_DATA updated_data;
+	bool existed;
+	bool modified;
+	bool unlock;
+};
+
+NTSTATUS g_lock_lock_cb_dump(struct g_lock_lock_cb_state *cb_state,
+			     void (*fn)(struct server_id exclusive,
+					size_t num_shared,
+					const struct server_id *shared,
+					const uint8_t *data,
+					size_t datalen,
+					void *private_data),
+			     void *private_data)
+{
+	struct g_lock *lck = cb_state->lck;
+
+	/* We allow a cn_fn only for G_LOCK_WRITE for now... */
+	SMB_ASSERT(lck->num_shared == 0);
+
+	fn(lck->exclusive,
+	   0, /* num_shared */
+	   NULL, /* shared */
+	   lck->data,
+	   lck->datalen,
+	   private_data);
+
+	return NT_STATUS_OK;
+}
+
+NTSTATUS g_lock_lock_cb_writev(struct g_lock_lock_cb_state *cb_state,
+			       const TDB_DATA *dbufs,
+			       size_t num_dbufs)
+{
+	NTSTATUS status;
+
+	status = dbwrap_merge_dbufs(&cb_state->updated_data,
+				    cb_state->update_mem_ctx,
+				    dbufs, num_dbufs);
+	if (!NT_STATUS_IS_OK(status)) {
+		return status;
+	}
+
+	cb_state->modified = true;
+	cb_state->lck->data = cb_state->updated_data.dptr;
+	cb_state->lck->datalen = cb_state->updated_data.dsize;
+
+	return NT_STATUS_OK;
+}
+
+void g_lock_lock_cb_unlock(struct g_lock_lock_cb_state *cb_state)
+{
+	cb_state->unlock = true;
+}
+
+struct g_lock_lock_cb_watch_data_state {
+	struct tevent_context *ev;
+	struct g_lock_ctx *ctx;
+	TDB_DATA key;
+	struct server_id blocker;
+	bool blockerdead;
+	uint64_t unique_lock_epoch;
+	uint64_t unique_data_epoch;
+	uint64_t watch_instance;
+	NTSTATUS status;
+};
+
+static void g_lock_lock_cb_watch_data_done(struct tevent_req *subreq);
+
+struct tevent_req *g_lock_lock_cb_watch_data_send(
+	TALLOC_CTX *mem_ctx,
+	struct tevent_context *ev,
+	struct g_lock_lock_cb_state *cb_state,
+	struct server_id blocker)
+{
+	struct tevent_req *req = NULL;
+	struct g_lock_lock_cb_watch_data_state *state = NULL;
+	struct tevent_req *subreq = NULL;
+	TDB_DATA key = dbwrap_record_get_key(cb_state->rec);
+
+	req = tevent_req_create(
+		mem_ctx, &state, struct g_lock_lock_cb_watch_data_state);
+	if (req == NULL) {
+		return NULL;
+	}
+	state->ev = ev;
+	state->ctx = cb_state->ctx;
+	state->blocker = blocker;
+
+	state->key = tdb_data_talloc_copy(state, key);
+	if (tevent_req_nomem(state->key.dptr, req)) {
+		return tevent_req_post(req, ev);
+	}
+
+	state->unique_lock_epoch = cb_state->lck->unique_lock_epoch;
+	state->unique_data_epoch = cb_state->lck->unique_data_epoch;
+
+	DBG_DEBUG("state->unique_data_epoch=%"PRIu64"\n", state->unique_data_epoch);
+
+	subreq = dbwrap_watched_watch_send(
+		state, state->ev, cb_state->rec, 0, state->blocker);
+	if (tevent_req_nomem(subreq, req)) {
+		return tevent_req_post(req, ev);
+	}
+	tevent_req_set_callback(subreq, g_lock_lock_cb_watch_data_done, req);
+
+	return req;
+}
+
+static void g_lock_lock_cb_watch_data_done_fn(
+	struct db_record *rec,
+	TDB_DATA value,
+	void *private_data)
+{
+	struct tevent_req *req = talloc_get_type_abort(
+		private_data, struct tevent_req);
+	struct g_lock_lock_cb_watch_data_state *state = tevent_req_data(
+		req, struct g_lock_lock_cb_watch_data_state);
+	struct tevent_req *subreq = NULL;
+	struct g_lock lck;
+	bool ok;
+
+	ok = g_lock_parse(value.dptr, value.dsize, &lck);
+	if (!ok) {
+		dbwrap_watched_watch_remove_instance(rec, state->watch_instance);
+		state->status = NT_STATUS_INTERNAL_DB_CORRUPTION;
+		return;
+	}
+
+	if (lck.unique_data_epoch != state->unique_data_epoch) {
+		dbwrap_watched_watch_remove_instance(rec, state->watch_instance);
+		DBG_DEBUG("lck.unique_data_epoch=%"PRIu64", "
+			  "state->unique_data_epoch=%"PRIu64"\n",
+			  lck.unique_data_epoch,
+			  state->unique_data_epoch);
+		state->status = NT_STATUS_OK;
+		return;
+	}
+
+	/*
+	 * The lock epoch changed, so we better
+	 * remove ourself from the waiter list
+	 * (most likely the first position)
+	 * and re-add us at the end of the list.
+	 *
+	 * This gives other lock waiters a change
+	 * to make progress.
+	 *
+	 * Otherwise we'll keep our waiter instance alive,
+	 * keep waiting (most likely at first position).
+	 */
+	if (lck.unique_lock_epoch != state->unique_lock_epoch) {
+		dbwrap_watched_watch_remove_instance(rec, state->watch_instance);
+		state->watch_instance = dbwrap_watched_watch_add_instance(rec);
+		state->unique_lock_epoch = lck.unique_lock_epoch;
+	}
+
+	subreq = dbwrap_watched_watch_send(
+		state, state->ev, rec, state->watch_instance, state->blocker);
+	if (subreq == NULL) {
+		dbwrap_watched_watch_remove_instance(rec, state->watch_instance);
+		state->status = NT_STATUS_NO_MEMORY;
+		return;
+	}
+	tevent_req_set_callback(subreq, g_lock_lock_cb_watch_data_done, req);
+
+	state->status = NT_STATUS_EVENT_PENDING;
+}
+
+static void g_lock_lock_cb_watch_data_done(struct tevent_req *subreq)
+{
+	struct tevent_req *req = tevent_req_callback_data(
+		subreq, struct tevent_req);
+	struct g_lock_lock_cb_watch_data_state *state = tevent_req_data(
+		req, struct g_lock_lock_cb_watch_data_state);
+	NTSTATUS status;
+	uint64_t instance = 0;
+
+	status = dbwrap_watched_watch_recv(
+		subreq, &instance, &state->blockerdead, &state->blocker);
+	TALLOC_FREE(subreq);
+	if (tevent_req_nterror(req, status)) {
+		DBG_DEBUG("dbwrap_watched_watch_recv returned %s\n",
+			  nt_errstr(status));
+		return;
+	}
+
+	state->watch_instance = instance;
+
+	status = dbwrap_do_locked(
+		state->ctx->db, state->key, g_lock_lock_cb_watch_data_done_fn, req);
+	if (tevent_req_nterror(req, status)) {
+		DBG_DEBUG("dbwrap_do_locked returned %s\n", nt_errstr(status));
+		return;
+	}
+	if (NT_STATUS_EQUAL(state->status, NT_STATUS_EVENT_PENDING)) {
+		return;
+	}
+	if (tevent_req_nterror(req, state->status)) {
+		return;
+	}
+	tevent_req_done(req);
+}
+


-- 
Samba Shared Repository



More information about the samba-cvs mailing list