[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Wed Sep 18 00:08:02 UTC 2019


The branch, master has been updated
       via  fd61e550ace smbd: Don't always walk the share mode array in open_mode_check()
       via  ac85ec5ed85 smbd: Add share mode flags
       via  86b4907853e smbd: Make "share_mode_flags" 16-bit wide
       via  9c99675bcbc smbd: Introduce share_entries.tdb - ADD COMMENT FIXME !!
       via  15a8af075a2 lib: Enable watching and storing dbwrap_watch records.
       via  72ac1764d69 smbd: Allow another database between brlock.tdb and leases.tdb
       via  ded3f91d807 lib: Allow a 4th lock order
       via  d3b0ed13c22 torture3: Remove cleanup3
       via  87e42c73d37 smbd: Remove stale share mode entries while walking the array
       via  f96aa7063e8 smbd: Make remove_stale_share_mode_entries() static in share_mode_lock.c
       via  5151b6d58be smbd: Avoid calling remove_stale_share_mode_entries() in open.c
       via  72a019d4e32 smbd: Use share_mode_forall_entries() in remove_lease_if_stale()
       via  4d512f40f9f smbd: Pass share_mode_lock to remove_lease_if_stale()
       via  ad23d0f4f57 smbd: Pass share_mode_lock to remove_share_mode_lease()
       via  5709856138d smbd: Avoid duplicate assignments
       via  609143adb68 smbd: Remove unused share_mode_stale_pid()
       via  e4a5a017c5d smbd: Use share_mode_forall_entries() in share_entry_forall()
       via  6a58f29c620 smbd: Use share_mode_forall_leases() in share_mode_cleanup_disconnected()
       via  8eda954d6d7 smbd: Use share_mode_forall_leases() in lease_match()
       via  c7a9e0e4cdf smbd: Use share_mode_forall_leases() in delay_rename_for_lease_break()
       via  2d9bb67d251 smbd: Use share_mode_forall_entries() in vfs_default_durable_reconnect()
       via  b3473efa9d3 smbd: Add reset_share_mode_entry
       via  2185db6c610 smbd: Pass pid/share_file_id to find_share_mode_entry()
       via  ac119c411c4 smbd: Use share_mode_forall_entries() in share_mode_forall_leases()
       via  f6931067250 smbd: Stop passing "share_mode_lock" via share_mode_forall_leases()
       via  4955481a678 smbd: Avoid "share_mode_lock" dependency cleanup_disconnected_lease()
       via  f82aebe9435 smbd: Avoid "share_mode_lock" dependency in rename_lease_fn()
       via  2a784883a88 smbd: Use share_mode_forall_entries() in delay_for_oplock()
       via  30e62710c6e smbd: Pass "struct file_id" to get_lease_type()
       via  aa945899045 smbd: Use share_mode_forall_entries() in validate_oplock_types()
       via  18c8b46e817 smbd: Use share_mode_forall_entries() in file_has_open_streams()
       via  43402851840 smbd: Use share_mode_forall_entries() in rename_share_filename()
       via  fb0b107ac2d smbd: Use share_mode_forall_entries() in open_mode_check()
       via  cb4b20b79fb smbd: Use share_mode_forall_entries() for validate_my_share_entries()
       via  5b1fd018a2c smbd: Use share_mode_forall_entries() in has_delete_on_close()
       via  14cc16948f0 smbd: Use share_mode_forall_entries() in has_other_nonposix_opens_fn()
       via  f5a6fa40928 smbd: Use share_mode_forall_entries() in set_delete_on_close_lck()
       via  5cbd3e46714 smbd: Use share_mode_forall_entries() in contend_level2_oplocks_begin_default()
       via  eb99635d0f2 smbd: Add share_mode_forall_entries()
       via  be799acb455 smbd: Use share_entry_stale_pid() in share_mode_stale_pid()
       via  55e47ada9f8 smbd: Add share_entry_stale_pid()
       via  dc7dfb12573 smbd: Avoid passing a share mode entry to share_conflict()
       via  e69c4faeb71 smbd: Rewrite share_conflict()
       via  e0aa1e09988 smbd: Fix a debug message hickup
       via  27b63641828 lib: Use server_id_cmp() in server_id_equal()
       via  d9ce9c42cb6 lib: Add server_id_cmp()
       via  ba1234d877b smbd: Introduce helper variables in open_mode_check()
       via  d12421ace45 smbd: Let fsp_lease_type() look at leases.tdb
       via  cc2e5b41646 smbd: Add quick leases_db_get_current_state()
       via  8d63b622df4 smbd: Make "current_state" show up first in the blob
       via  735439765a2 smbd: Make lease_type_is_exclusive() static
       via  41393a64889 smbd: Remove unused smbXsrv_open_hash()
       via  e00e53344df smbd: Make fsp->fh->gen_id unique per process
       via  4f8db9b3cff vfs: Make "fd_handle->gen_id" 64-bit everywhere
       via  3d1da1ac308 idl: Fix a typo
       via  78fce47fc23 smbd: Use direct struct assignments in smbXsrv_*.c
      from  e0a3cc469f2 vfs/full_audit: always log full filenames

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


- Log -----------------------------------------------------------------
commit fd61e550acec6e9924a71712eef739b58c7d68e8
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Sep 16 16:16:40 2019 -0700

    smbd: Don't always walk the share mode array in open_mode_check()
    
    share_mode_data->flags contains the "most restrictive" share mode of
    the whole array. This is maintained lazily: Whenever set_share_mode()
    is called, d->flags is updated if the new share mode got more
    restrictive. It is not updated when a file is closed, as this would
    mean we would have to walk the whole array, making sure that the
    closed handle was indeed the only most restrictive one. Instead, we
    walk the share mode array only when a conflict happens: Then we need
    to know "the truth" and recalculate it by walking the share mode
    array.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Wed Sep 18 00:07:13 UTC 2019 on sn-devel-184

commit ac85ec5ed855d8d0bc2564cbd33a580a8db6818e
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Aug 9 16:27:48 2019 +0200

    smbd: Add share mode flags
    
    This will contain a summary of the "most restrictive" share mode and
    lease, i.e. intersection of all share_access entries and the union of
    all access_mask and leases in the share mode array. This way
    open_mode_check in the non-conflicting case will only have to look at
    the summary and not walk the share mode array.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 86b4907853e8df20ebe3ec6871aa3210f1bde201
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Aug 9 16:16:21 2019 +0200

    smbd: Make "share_mode_flags" 16-bit wide
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 9c99675bcbc530f8054de77b1a5f660dde015c62
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Sep 16 10:01:36 2019 -0700

    smbd: Introduce share_entries.tdb - ADD COMMENT FIXME !!
    
    This moves share_modes[] from "struct share_mode_data" into a separate
    share_entries.tdb with a sorted array of fixed-length (132 byte)
    "struct share_mode_entry" entries.
    
    I know it's one huge commit, but I did not see a way to keep both data
    structures and associated code working together without a lot of code
    duplication after having centralized all the code accessing the
    share_modes[] array into a few routines.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 15a8af075a2d7b59f4d97d9804599b26325e5640
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Aug 13 14:18:05 2019 +0200

    lib: Enable watching and storing dbwrap_watch records.
    
    Samba so far on a dbwrap_watch record either watches or stores a
    record, but never both from the same db_record instance acquired from
    a dbwrap_fetch_locked(). In one of the next commits this will change,
    we will watch a record and at the same time store data into it. This
    patch enables a watch_send() followed by a storev() by properly
    keeping the watchers around.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 72ac1764d69e165052220f2c1b5bc0d5613ef201
Author: Volker Lendecke <vl at samba.org>
Date:   Sun Sep 15 11:58:43 2019 +0200

    smbd: Allow another database between brlock.tdb and leases.tdb
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit ded3f91d80763edfab242a48baa834e669e16ed5
Author: Volker Lendecke <vl at samba.org>
Date:   Sun Sep 15 11:56:25 2019 +0200

    lib: Allow a 4th lock order
    
    We will have another tdb soon
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit d3b0ed13c223a2e4ff22026cddbc55992f35288d
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 3 14:37:26 2019 +0200

    torture3: Remove cleanup3
    
    This goes directly into the database, for which the format changes
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 87e42c73d379738a5f87569ea630c28c9d66c148
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Sep 2 16:25:28 2019 +0200

    smbd: Remove stale share mode entries while walking the array
    
    Previously, we did this only when writing out the locking.tdb
    record. That was because we had places where the index of a particular
    share mode entry mattered while operating on the array. This is no
    longer the case, so we can remove stale entries early.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit f96aa7063e846021b69403cc9caa091c8e09b578
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Aug 26 18:59:44 2019 +0200

    smbd: Make remove_stale_share_mode_entries() static in share_mode_lock.c
    
    ... to the place where the record is stored in the database
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 5151b6d58be54d210795e7769033cb33e6c75b0a
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Aug 26 18:56:24 2019 +0200

    smbd: Avoid calling remove_stale_share_mode_entries() in open.c
    
    All places that matter explicitly check for staleness. This cleanup
    action should only happen before writing the database
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 72a019d4e32d46ae160ecfe2c90348d005ec2449
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Aug 26 17:09:57 2019 +0200

    smbd: Use share_mode_forall_entries() in remove_lease_if_stale()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 4d512f40f9f6c1689cc4e0ace541079fda98c611
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Aug 26 16:51:56 2019 +0200

    smbd: Pass share_mode_lock to remove_lease_if_stale()
    
    We'll want to use share_mode_forall_entries next
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit ad23d0f4f57e24a36960a1fa85f527e96753e4d2
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Aug 26 16:47:44 2019 +0200

    smbd: Pass share_mode_lock to remove_share_mode_lease()
    
    Later we'll need "lck" further down
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 5709856138d3149caf019bf70f9acf673efedec7
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Aug 26 16:45:14 2019 +0200

    smbd: Avoid duplicate assignments
    
    remove_share_mode_lease() already does this
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 609143adb68b05dbfa13db0f9289a33b53919a71
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Aug 23 17:44:25 2019 +0200

    smbd: Remove unused share_mode_stale_pid()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit e4a5a017c5d8c4aac14e3440f498374700dd7fbd
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Sep 12 13:03:53 2019 +0200

    smbd: Use share_mode_forall_entries() in share_entry_forall()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 6a58f29c6205d6a4cc7f98ad0f5c6ebf1dadd385
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Sep 12 12:41:14 2019 +0200

    smbd: Use share_mode_forall_leases() in share_mode_cleanup_disconnected()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 8eda954d6d7469c54855d22a97bf625f32ebdad7
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Aug 19 13:16:53 2019 +0200

    smbd: Use share_mode_forall_leases() in lease_match()
    
    We have to break leases referenced from multiple share modes only
    once.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit c7a9e0e4cdfb22e66533b5c8e20af3cfdb8ae78c
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Sep 12 11:35:34 2019 +0200

    smbd: Use share_mode_forall_leases() in delay_rename_for_lease_break()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 2d9bb67d25181eba79b95df661e5a5d613b4a850
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Aug 23 14:30:07 2019 +0200

    smbd: Use share_mode_forall_entries() in vfs_default_durable_reconnect()
    
    The durable reconnect mainly has to check that there is one and only one
    entry, and it has to reset it with the new values.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit b3473efa9d3ab7ccd364ab29a3e93e900b5a49e2
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Aug 23 14:13:41 2019 +0200

    smbd: Add reset_share_mode_entry
    
    Mostly for durable reconnect at this point
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 2185db6c610433e0651543b7179cf1fbd0e2c9eb
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Sep 11 16:50:24 2019 +0200

    smbd: Pass pid/share_file_id to find_share_mode_entry()
    
    Avoid the full fsp, this makes the indexing of the share mode array
    clearer, and it makes the next commit easier
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit ac119c411c4e268d7fe3c6766d3f9023ea4df456
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Aug 26 22:05:14 2019 +0200

    smbd: Use share_mode_forall_entries() in share_mode_forall_leases()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit f69310672501c0e2d0afe638a18a0e21fec17298
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 10 21:21:01 2019 +0200

    smbd: Stop passing "share_mode_lock" via share_mode_forall_leases()
    
    Why? Next commit will make share_mode_forall_leases() use
    share_mode_forall_entries(), and that does not necessarily have to
    depend on "share_mode_lock". And as we can pass the required
    information via "private_data", don't embed the "share_mode_lock"
    reference into this lowlevel library routine.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 4955481a678eb69df380c3c915cef95feec92443
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 10 21:17:34 2019 +0200

    smbd: Avoid "share_mode_lock" dependency cleanup_disconnected_lease()
    
    share_mode_forall_leases() will stop passing "lck" soon.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit f82aebe943534d5ab9b89dcec2150f985b574115
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 10 21:12:23 2019 +0200

    smbd: Avoid "share_mode_lock" dependency in rename_lease_fn()
    
    share_mode_forall_leases() will stop passing "lck" soon.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 2a784883a889b517b86cce328f0798c92b69a2d5
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Aug 20 14:47:27 2019 +0200

    smbd: Use share_mode_forall_entries() in delay_for_oplock()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 30e62710c6e323028555deb0eaee238c1713d7e9
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Sep 10 21:00:29 2019 +0200

    smbd: Pass "struct file_id" to get_lease_type()
    
    It does not have to depend on the whole struct share_mode_data.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit aa94589904518e74b533dc47d56ba6811b6b997f
Author: Volker Lendecke <vl at samba.org>
Date:   Sun Aug 18 17:49:23 2019 +0200

    smbd: Use share_mode_forall_entries() in validate_oplock_types()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 18c8b46e8176ea56f24a853d1f6c5ca484df7d81
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Aug 16 15:56:23 2019 +0200

    smbd: Use share_mode_forall_entries() in file_has_open_streams()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 434028518403e7e1d216a4acb9b229caccc44149
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Aug 16 15:40:55 2019 +0200

    smbd: Use share_mode_forall_entries() in rename_share_filename()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit fb0b107ac2dc594fd9343f3767b3fb298909879d
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Aug 16 13:08:23 2019 +0200

    smbd: Use share_mode_forall_entries() in open_mode_check()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit cb4b20b79fb426682cdc5c84a88443e590df3df8
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Aug 16 12:48:15 2019 +0200

    smbd: Use share_mode_forall_entries() for validate_my_share_entries()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 5b1fd018a2c47106102deb74bbd72fdf0c9faf02
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Aug 16 11:11:36 2019 +0200

    smbd: Use share_mode_forall_entries() in has_delete_on_close()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 14cc16948f0da00119cc85ebe7f9ab51b2275ece
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Aug 14 21:40:07 2019 +0200

    smbd: Use share_mode_forall_entries() in has_other_nonposix_opens_fn()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit f5a6fa40928f9e8c9b91f38f287fd9264de9d826
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Aug 14 17:29:19 2019 +0200

    smbd: Use share_mode_forall_entries() in set_delete_on_close_lck()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 5cbd3e46714f5bfdbfa54c8cef0f8145bee08094
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Aug 13 15:21:59 2019 +0200

    smbd: Use share_mode_forall_entries() in contend_level2_oplocks_begin_default()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit eb99635d0f2a8dbd52d4a5143efe5a9716401b08
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Aug 13 15:09:51 2019 +0200

    smbd: Add share_mode_forall_entries()
    
    Abstract away the fact that we store the share modes as an array inside
    "struct share_mode_data".
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit be799acb4558f347c6e6a82874897c7af0c0c3d8
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Aug 13 16:04:13 2019 +0200

    smbd: Use share_entry_stale_pid() in share_mode_stale_pid()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 55e47ada9f85d5152b342d7d39226dc18bbaf162
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Aug 13 16:00:09 2019 +0200

    smbd: Add share_entry_stale_pid()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit dc7dfb1257397491f8f02d1e1c42253103235d5f
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Sep 6 11:15:27 2019 +0200

    smbd: Avoid passing a share mode entry to share_conflict()
    
    Make the real data dependencies clearer, we don't need a full
    share_entry, only its access and sharemode masks
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit e69c4faeb7187922674d85c90134324725993671
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Aug 12 12:44:39 2019 +0200

    smbd: Rewrite share_conflict()
    
    It was hard for me to understand share_conflict(), so once I understood
    it I thought this version would be easier to follow.  It violates
    README.Coding (one argument per line), but grouping the parameters to
    mask_conflict makes it clearer to me what belongs together.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit e0aa1e09988690ecb8f5caa7201b4a622fc22be5
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Sep 5 09:52:10 2019 +0200

    smbd: Fix a debug message hickup
    
    Mind the missing space before "(e.g. another...". While there, avoid
    casts.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 27b63641828f6f1e7e3c8b97cb34795a75688b8f
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Sep 7 18:56:54 2019 +0200

    lib: Use server_id_cmp() in server_id_equal()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit d9ce9c42cb6abd3263d639d6474a92b85776ba8d
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Sep 7 18:55:57 2019 +0200

    lib: Add server_id_cmp()
    
    Will be used later for sorting the share mode array
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit ba1234d877b3364be3b2f6793e3a6fe6c238da0f
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Sep 6 11:30:23 2019 +0200

    smbd: Introduce helper variables in open_mode_check()
    
    Less bytes .text, the compiler now does not have to expect other threads to
    alter the pointers.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit d12421ace457d1fdca0d97e2c680e90edf556967
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Aug 15 12:10:52 2019 +0200

    smbd: Let fsp_lease_type() look at leases.tdb
    
    The same lease can be used via different TCP connections (yes, we have
    tests for this!). At the end of downgrade_lease() we update all fsp's
    with fsps_lease_update() that link to the lease that just was
    changed. However, this is only in the local process, this is not
    cross-smbd. So other smbds using the same lease can use stale
    information and for example get the mandatory locking wrong.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit cc2e5b41646f6c18288ffb4b0ea16f4ea2cb4874
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Aug 13 22:07:47 2019 +0200

    smbd: Add quick leases_db_get_current_state()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 8d63b622df42111b603d5f6fe2fa31490eb7cd98
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Aug 15 16:33:57 2019 +0200

    smbd: Make "current_state" show up first in the blob
    
    Believe it or not, but without this change "num_files" was first.
    Thanks Metze for this (to me at least) really, really surprising
    insight!
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 735439765a29b0b31e530998e0d46b11c298c50b
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Aug 15 11:59:11 2019 +0200

    smbd: Make lease_type_is_exclusive() static
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 41393a648899ab2ce61c69e673240e9821735c06
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Sep 16 11:18:00 2019 -0700

    smbd: Remove unused smbXsrv_open_hash()
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit e00e53344df78b54bb5978de7062bf4c1242bd46
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Sep 16 03:54:32 2019 -0700

    smbd: Make fsp->fh->gen_id unique per process
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 4f8db9b3cff9ef548a66b45f998573aea103db8c
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Sep 16 03:50:02 2019 -0700

    vfs: Make "fd_handle->gen_id" 64-bit everywhere
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 3d1da1ac308538e47017091123361cc927d8d778
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Sep 16 05:04:06 2019 -0700

    idl: Fix a typo
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 78fce47fc23173885143b730552599023c845963
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Sep 16 05:26:05 2019 -0700

    smbd: Use direct struct assignments in smbXsrv_*.c
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

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

Summary of changes:
 lib/dbwrap/dbwrap.h               |    3 +-
 lib/dbwrap/dbwrap_private.h       |    2 +-
 lib/util/server_id.c              |   22 +-
 lib/util/server_id.h              |    1 +
 source3/include/vfs.h             |   12 +-
 source3/lib/dbwrap/dbwrap_watch.c |   69 ++-
 source3/librpc/idl/leases_db.idl  |    2 +-
 source3/librpc/idl/open_files.idl |   13 +-
 source3/librpc/idl/smbXsrv.idl    |    2 +-
 source3/locking/leases_db.c       |   79 ++-
 source3/locking/leases_db.h       |    5 +
 source3/locking/leases_util.c     |   28 +-
 source3/locking/locking.c         |  707 ++++++++++--------------
 source3/locking/proto.h           |   27 +-
 source3/locking/share_mode_lock.c | 1063 ++++++++++++++++++++++++++++++++++---
 source3/selftest/tests.py         |    4 -
 source3/smbd/close.c              |   68 ++-
 source3/smbd/durable.c            |   88 +--
 source3/smbd/files.c              |   14 +-
 source3/smbd/globals.h            |    1 -
 source3/smbd/open.c               | 1044 +++++++++++++++++++++++-------------
 source3/smbd/oplock.c             |  117 ++--
 source3/smbd/oplock_linux.c       |   25 +-
 source3/smbd/proto.h              |    4 +-
 source3/smbd/smb2_setinfo.c       |   83 +--
 source3/smbd/smbXsrv_client.c     |   27 +-
 source3/smbd/smbXsrv_open.c       |   55 +-
 source3/smbd/smbXsrv_session.c    |   18 +-
 source3/smbd/smbXsrv_tcon.c       |   18 +-
 source3/torture/proto.h           |    1 -
 source3/torture/test_cleanup.c    |  175 ------
 source3/torture/torture.c         |    4 -
 32 files changed, 2447 insertions(+), 1334 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/dbwrap/dbwrap.h b/lib/dbwrap/dbwrap.h
index 42998b78139..591eac5c63a 100644
--- a/lib/dbwrap/dbwrap.h
+++ b/lib/dbwrap/dbwrap.h
@@ -33,7 +33,8 @@ enum dbwrap_lock_order {
 	DBWRAP_LOCK_ORDER_NONE = 0, /* Don't check lock orders for this db. */
 	DBWRAP_LOCK_ORDER_1 = 1,
 	DBWRAP_LOCK_ORDER_2 = 2,
-	DBWRAP_LOCK_ORDER_3 = 3
+	DBWRAP_LOCK_ORDER_3 = 3,
+	DBWRAP_LOCK_ORDER_4 = 4
 };
 
 #define DBWRAP_FLAG_NONE                     0x0000000000000000ULL
diff --git a/lib/dbwrap/dbwrap_private.h b/lib/dbwrap/dbwrap_private.h
index e757215d389..b548168b9a9 100644
--- a/lib/dbwrap/dbwrap_private.h
+++ b/lib/dbwrap/dbwrap_private.h
@@ -84,7 +84,7 @@ struct db_context {
 };
 
 #define DBWRAP_LOCK_ORDER_MIN DBWRAP_LOCK_ORDER_1
-#define DBWRAP_LOCK_ORDER_MAX DBWRAP_LOCK_ORDER_3
+#define DBWRAP_LOCK_ORDER_MAX DBWRAP_LOCK_ORDER_4
 
 #define DBWRAP_LOCK_ORDER_VALID(order) \
 	(((order) >= DBWRAP_LOCK_ORDER_MIN) && \
diff --git a/lib/util/server_id.c b/lib/util/server_id.c
index 2904e803196..e66c9791007 100644
--- a/lib/util/server_id.c
+++ b/lib/util/server_id.c
@@ -30,21 +30,27 @@ bool server_id_same_process(const struct server_id *p1,
 	return ((p1->pid == p2->pid) && (p1->vnn == p2->vnn));
 }
 
-bool server_id_equal(const struct server_id *p1, const struct server_id *p2)
+int server_id_cmp(const struct server_id *p1, const struct server_id *p2)
 {
-	if (!server_id_same_process(p1, p2)) {
-		return false;
+	if (p1->vnn != p2->vnn) {
+		return (p1->vnn < p2->vnn) ? -1 : 1;
+	}
+	if (p1->pid != p2->pid) {
+		return (p1->pid < p2->pid) ? -1 : 1;
 	}
-
 	if (p1->task_id != p2->task_id) {
-		return false;
+		return (p1->task_id < p2->task_id) ? -1 : 1;
 	}
-
 	if (p1->unique_id != p2->unique_id) {
-		return false;
+		return (p1->unique_id < p2->unique_id) ? -1 : 1;
 	}
+	return 0;
+}
 
-	return true;
+bool server_id_equal(const struct server_id *p1, const struct server_id *p2)
+{
+	int cmp = server_id_cmp(p1, p2);
+	return (cmp == 0);
 }
 
 char *server_id_str_buf(struct server_id id, struct server_id_buf *dst)
diff --git a/lib/util/server_id.h b/lib/util/server_id.h
index 6dda86ced73..5b723d5cda4 100644
--- a/lib/util/server_id.h
+++ b/lib/util/server_id.h
@@ -28,6 +28,7 @@ struct server_id_buf { char buf[48]; }; /* probably a bit too large ... */
 
 bool server_id_same_process(const struct server_id *p1,
 			    const struct server_id *p2);
+int server_id_cmp(const struct server_id *p1, const struct server_id *p2);
 bool server_id_equal(const struct server_id *p1, const struct server_id *p2);
 char *server_id_str_buf(struct server_id id, struct server_id_buf *dst);
 size_t server_id_str_buf_unique(struct server_id id, char *buf, size_t buflen);
diff --git a/source3/include/vfs.h b/source3/include/vfs.h
index 3b024355168..47147821ffd 100644
--- a/source3/include/vfs.h
+++ b/source3/include/vfs.h
@@ -321,7 +321,7 @@ struct fd_handle {
 				 * DELETE_ON_CLOSE is not stored in the share
 				 * mode database.
 				 */
-	unsigned long gen_id;
+	uint64_t gen_id;
 };
 
 struct fsp_lease {
@@ -354,6 +354,14 @@ typedef struct files_struct {
 	bool write_time_forced;
 
 	int oplock_type;
+
+	/*
+	 * Cache of our lease_type, stored as "current_state" in
+	 * leases.tdb
+	 */
+	int leases_db_seqnum;
+	uint32_t lease_type;
+
 	struct fsp_lease *lease;
 	int sent_oplock_break;
 	struct tevent_timer *oplock_timeout;
@@ -388,7 +396,7 @@ typedef struct files_struct {
 	 * Cache of share_mode_data->flags
 	 */
 	int share_mode_flags_seqnum;
-	uint8_t share_mode_flags;
+	uint16_t share_mode_flags;
 
 	/*
 	 * Read-only cached brlock record, thrown away when the
diff --git a/source3/lib/dbwrap/dbwrap_watch.c b/source3/lib/dbwrap/dbwrap_watch.c
index 6bbd68df859..b1a82d86006 100644
--- a/source3/lib/dbwrap/dbwrap_watch.c
+++ b/source3/lib/dbwrap/dbwrap_watch.c
@@ -223,6 +223,7 @@ static struct db_record *dbwrap_watched_fetch_locked(
 		db->private_data, struct db_watched_ctx);
 	struct db_record *rec;
 	struct db_watched_subrec *subrec;
+	uint8_t *watchers = NULL;
 	TDB_DATA subrec_value;
 	bool ok;
 
@@ -251,6 +252,26 @@ static struct db_record *dbwrap_watched_fetch_locked(
 	subrec_value = dbwrap_record_get_value(subrec->subrec);
 
 	ok = dbwrap_watch_rec_parse(subrec_value, &subrec->wrec);
+	if (!ok) {
+		return rec;	/* fresh record */
+	}
+
+	/*
+	 * subrec->wrec.watchers points *directly* into the
+	 * returned data in the record. We need to talloc a
+	 * copy of this so it belongs to subrec.
+	 */
+
+	watchers = talloc_memdup(
+		subrec,
+		subrec->wrec.watchers,
+		subrec->wrec.num_watchers * SERVER_ID_BUF_LENGTH);
+	if (watchers == NULL) {
+		TALLOC_FREE(rec);
+		return NULL;
+	}
+	subrec->wrec.watchers = watchers;
+
 	if (ok) {
 		rec->value = subrec->wrec.data;
 	}
@@ -314,6 +335,20 @@ static void dbwrap_watched_do_locked_fn(struct db_record *subrec,
 
 	ok = dbwrap_watch_rec_parse(subrec_value, &state->subrec.wrec);
 	if (ok) {
+		uint8_t *watchers = NULL;
+
+		/*
+		 * state->subrec.wrec.watchers points *directly* into the
+		 * returned data in the record. We need to talloc a
+		 * copy of this so it belongs to state->mem_ctx.
+		 */
+		watchers = talloc_memdup(
+			state->mem_ctx,
+			state->subrec.wrec.watchers,
+			state->subrec.wrec.num_watchers * SERVER_ID_BUF_LENGTH);
+		SMB_ASSERT(watchers != NULL);
+		state->subrec.wrec.watchers = watchers;
+
 		rec.value = state->subrec.wrec.data;
 	}
 
@@ -407,32 +442,38 @@ static NTSTATUS dbwrap_watched_save(struct db_record *rec,
 {
 	uint32_t num_watchers_buf;
 	uint8_t sizebuf[4];
-	uint8_t addbuf[SERVER_ID_BUF_LENGTH];
 	NTSTATUS status;
-	struct TDB_DATA dbufs[num_databufs+3];
+	struct TDB_DATA dbufs[num_databufs+2];
 
 	dbufs[0] = (TDB_DATA) {
 		.dptr = sizebuf, .dsize = sizeof(sizebuf)
 	};
 
-	dbufs[1] = (TDB_DATA) {
-		.dptr = wrec->watchers,
-		.dsize = wrec->num_watchers * SERVER_ID_BUF_LENGTH
-	};
-
 	if (addwatch != NULL) {
-		server_id_put(addbuf, *addwatch);
+		uint8_t *watchers, *new_watch;
+
+		watchers = talloc_realloc(
+			NULL,
+			wrec->watchers,
+			uint8_t,
+			(wrec->num_watchers+1) * SERVER_ID_BUF_LENGTH);
+		if (watchers == NULL) {
+			return NT_STATUS_NO_MEMORY;
+		}
+		wrec->watchers = watchers;
 
-		dbufs[2] = (TDB_DATA) {
-			.dptr = addbuf, .dsize = SERVER_ID_BUF_LENGTH
-		};
+		new_watch = &watchers[wrec->num_watchers*SERVER_ID_BUF_LENGTH];
+		server_id_put(new_watch, *addwatch);
 		wrec->num_watchers += 1;
-	} else {
-		dbufs[2] = (TDB_DATA) { 0 };
 	}
 
+	dbufs[1] = (TDB_DATA) {
+		.dptr = wrec->watchers,
+		.dsize = wrec->num_watchers * SERVER_ID_BUF_LENGTH
+	};
+
 	if (num_databufs != 0) {
-		memcpy(&dbufs[3], databufs, sizeof(TDB_DATA) * num_databufs);
+		memcpy(&dbufs[2], databufs, sizeof(TDB_DATA) * num_databufs);
 	}
 
 	num_watchers_buf = wrec->num_watchers;
diff --git a/source3/librpc/idl/leases_db.idl b/source3/librpc/idl/leases_db.idl
index ed9f27643ab..2551dfc2ba0 100644
--- a/source3/librpc/idl/leases_db.idl
+++ b/source3/librpc/idl/leases_db.idl
@@ -49,6 +49,6 @@ interface leases_db
 		uint16			epoch;
 
 		uint32 num_files;
-		[size_is(num_files)] leases_db_file files[];
+		leases_db_file files[num_files];
 	} leases_db_value;
 }
diff --git a/source3/librpc/idl/open_files.idl b/source3/librpc/idl/open_files.idl
index bf832821b89..d3e537a9d42 100644
--- a/source3/librpc/idl/open_files.idl
+++ b/source3/librpc/idl/open_files.idl
@@ -40,8 +40,16 @@ interface open_files
 		security_unix_token *delete_token;
 	} delete_token;
 
-	typedef [public,bitmap8bit] bitmap {
-		SHARE_MODE_HAS_READ_LEASE	= 0x01
+	typedef [public,bitmap16bit] bitmap {
+		SHARE_MODE_SHARE_DELETE		= 0x100,
+		SHARE_MODE_SHARE_WRITE		= 0x080,
+		SHARE_MODE_SHARE_READ		= 0x040,
+		SHARE_MODE_ACCESS_DELETE	= 0x020,
+		SHARE_MODE_ACCESS_WRITE		= 0x010,
+		SHARE_MODE_ACCESS_READ		= 0x008,
+		SHARE_MODE_LEASE_HANDLE		= 0x004,
+		SHARE_MODE_LEASE_WRITE		= 0x002,
+		SHARE_MODE_LEASE_READ		= 0x001
 	} share_mode_flags;
 
 	typedef [public] struct {
@@ -51,7 +59,6 @@ interface open_files
 		[string,charset(UTF8)] char *base_name;
 		[string,charset(UTF8)] char *stream_name;
 		uint32 num_share_modes;
-		[size_is(num_share_modes)] share_mode_entry share_modes[];
 		uint32 num_delete_tokens;
 		[size_is(num_delete_tokens)] delete_token delete_tokens[];
 		timespec old_write_time;
diff --git a/source3/librpc/idl/smbXsrv.idl b/source3/librpc/idl/smbXsrv.idl
index 330c6896114..b8f3dc679ea 100644
--- a/source3/librpc/idl/smbXsrv.idl
+++ b/source3/librpc/idl/smbXsrv.idl
@@ -18,7 +18,7 @@ interface smbXsrv
 	 * rolling code upgrades in future (within a cluster).
 	 *
 	 * This just adds the infrastructure,
-	 * but we does not implement it yet!
+	 * but it does not implement it yet!
 	 *
 	 * Currently it only prevents that
 	 * nodes with a different version numbers
diff --git a/source3/locking/leases_db.c b/source3/locking/leases_db.c
index 17778050acc..19c5a612ecc 100644
--- a/source3/locking/leases_db.c
+++ b/source3/locking/leases_db.c
@@ -47,10 +47,13 @@ bool leases_db_init(bool read_only)
 	}
 
 	leases_db = db_open(NULL, db_path, 0,
-			    TDB_DEFAULT|TDB_VOLATILE|TDB_CLEAR_IF_FIRST|
+			    TDB_DEFAULT|
+			    TDB_VOLATILE|
+			    TDB_CLEAR_IF_FIRST|
+			    TDB_SEQNUM|
 			    TDB_INCOMPATIBLE_HASH,
 			    read_only ? O_RDONLY : O_RDWR|O_CREAT, 0644,
-			    DBWRAP_LOCK_ORDER_2, DBWRAP_FLAG_NONE);
+			    DBWRAP_LOCK_ORDER_4, DBWRAP_FLAG_NONE);
 	TALLOC_FREE(db_path);
 	if (leases_db == NULL) {
 		DEBUG(1, ("ERROR: Failed to initialise leases database\n"));
@@ -625,7 +628,79 @@ NTSTATUS leases_db_get(const struct GUID *client_guid,
 		return status;
 	}
 	return state.status;
+}
+
+struct leases_db_get_current_state_state {
+	int seqnum;
+	uint32_t current_state;
+	NTSTATUS status;
+};
+
+/*
+ * This function is an optimization that
+ * relies on the fact that the
+ * smb2_lease_state current_state
+ * (which is a uint32_t size)
+ * from struct leases_db_value is the first
+ * entry in the ndr-encoded struct leases_db_value.
+ * Read it without having to ndr decode all
+ * the values in struct leases_db_value.
+ */
+
+static void leases_db_get_current_state_fn(
+	TDB_DATA key, TDB_DATA data, void *private_data)
+{
+	struct leases_db_get_current_state_state *state = private_data;
+	struct ndr_pull ndr;
+	enum ndr_err_code ndr_err;
+
+	if (data.dsize < sizeof(uint32_t)) {
+		state->status = NT_STATUS_INTERNAL_DB_CORRUPTION;
+		return;
+	}
+
+	state->seqnum = dbwrap_get_seqnum(leases_db);
+
+	ndr = (struct ndr_pull) {
+		.data = data.dptr, .data_size = data.dsize,
+	};
+	ndr_err = ndr_pull_uint32(&ndr, NDR_SCALARS, &state->current_state);
+	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+		state->status = ndr_map_error2ntstatus(ndr_err);
+	}
+}
 
+NTSTATUS leases_db_get_current_state(
+	const struct GUID *client_guid,
+	const struct smb2_lease_key *lease_key,
+	int *database_seqnum,
+	uint32_t *current_state)
+{
+	struct leases_db_get_current_state_state state = { 0 };
+	struct leases_db_key_buf keybuf;
+	TDB_DATA db_key = { 0 };
+	NTSTATUS status;
+
+	if (!leases_db_init(true)) {
+		return NT_STATUS_INTERNAL_ERROR;
+	}
+
+	state.seqnum = dbwrap_get_seqnum(leases_db);
+	if (*database_seqnum == state.seqnum) {
+		return NT_STATUS_OK;
+	}
+
+	db_key = leases_db_key(&keybuf, client_guid, lease_key);
+
+	status = dbwrap_parse_record(
+		leases_db, db_key, leases_db_get_current_state_fn, &state);
+	if (!NT_STATUS_IS_OK(status)) {
+		return status;
+	}
+	*database_seqnum = state.seqnum;
+	*current_state = state.current_state;
+
+	return NT_STATUS_OK;
 }
 
 NTSTATUS leases_db_copy_file_ids(TALLOC_CTX *mem_ctx,
diff --git a/source3/locking/leases_db.h b/source3/locking/leases_db.h
index 99a4a78315c..9c149c19f07 100644
--- a/source3/locking/leases_db.h
+++ b/source3/locking/leases_db.h
@@ -68,6 +68,11 @@ NTSTATUS leases_db_get(const struct GUID *client_guid,
 		       uint32_t	*breaking_to_required,
 		       uint16_t *lease_version,
 		       uint16_t *epoch);
+NTSTATUS leases_db_get_current_state(
+	const struct GUID *client_guid,
+	const struct smb2_lease_key *lease_key,
+	int *database_seqnum,
+	uint32_t *current_state);
 NTSTATUS leases_db_copy_file_ids(TALLOC_CTX *mem_ctx,
 			uint32_t num_files,
 			const struct leases_db_file *files,
diff --git a/source3/locking/leases_util.c b/source3/locking/leases_util.c
index f10c91f0d32..d307f420c7c 100644
--- a/source3/locking/leases_util.c
+++ b/source3/locking/leases_util.c
@@ -24,6 +24,7 @@
 #include "../librpc/gen_ndr/open_files.h"
 #include "locking/proto.h"
 #include "smbd/globals.h"
+#include "locking/leases_db.h"
 
 uint32_t map_oplock_to_lease_type(uint16_t op_type)
 {
@@ -47,15 +48,30 @@ uint32_t map_oplock_to_lease_type(uint16_t op_type)
 	return ret;
 }
 
-uint32_t fsp_lease_type(const struct files_struct *fsp)
+uint32_t fsp_lease_type(struct files_struct *fsp)
 {
-	if (fsp->oplock_type == LEASE_OPLOCK) {
-		return fsp->lease->lease.lease_state;
+	NTSTATUS status;
+
+	if (fsp->oplock_type != LEASE_OPLOCK) {
+		uint32_t type = map_oplock_to_lease_type(fsp->oplock_type);
+		return type;
+	}
+
+	status = leases_db_get_current_state(
+		fsp_client_guid(fsp),
+		&fsp->lease->lease.lease_key,
+		&fsp->leases_db_seqnum,
+		&fsp->lease_type);
+	if (!NT_STATUS_IS_OK(status)) {
+		DBG_DEBUG("leases_db_get_current_state failed: %s\n",
+			  nt_errstr(status));
+		fsp->lease_type = 0; /* no lease */
 	}
-	return map_oplock_to_lease_type(fsp->oplock_type);
+
+	return fsp->lease_type;
 }
 
-uint32_t lease_type_is_exclusive(uint32_t 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)) {
@@ -65,7 +81,7 @@ uint32_t lease_type_is_exclusive(uint32_t lease_type)
 	return false;
 }
 
-bool fsp_lease_type_is_exclusive(const struct files_struct *fsp)
+bool fsp_lease_type_is_exclusive(struct files_struct *fsp)
 {
 	uint32_t lease_type = fsp_lease_type(fsp);
 
diff --git a/source3/locking/locking.c b/source3/locking/locking.c
index 72235113fbb..568d2002229 100644
--- a/source3/locking/locking.c
+++ b/source3/locking/locking.c
@@ -48,6 +48,7 @@
 #include "util_tdb.h"
 #include "../librpc/gen_ndr/ndr_open_files.h"
 #include "librpc/gen_ndr/ndr_file_id.h"
+#include "librpc/gen_ndr/ndr_leases_db.h"
 #include "locking/leases_db.h"
 
 #undef DBGC_CLASS
@@ -469,11 +470,20 @@ struct share_mode_lock *get_existing_share_mode_lock(TALLOC_CTX *mem_ctx,
 	return get_share_mode_lock(mem_ctx, id, NULL, NULL, NULL);
 }
 
-static bool rename_lease_fn(struct share_mode_lock *lck,
-			    struct share_mode_entry *e,
+struct rename_share_filename_state {
+	struct share_mode_lock *lck;
+	struct messaging_context *msg_ctx;
+	struct server_id self;
+	uint32_t orig_name_hash;
+	uint32_t new_name_hash;
+	struct file_rename_message msg;
+};
+
+static bool rename_lease_fn(struct share_mode_entry *e,
 			    void *private_data)
 {
-	struct share_mode_data *d = lck->data;
+	struct rename_share_filename_state *state = private_data;
+	struct share_mode_data *d = state->lck->data;
 	NTSTATUS status;
 
 	status = leases_db_rename(&e->client_guid,
@@ -502,6 +512,57 @@ static bool rename_lease_fn(struct share_mode_lock *lck,
  Based on an initial code idea from SATOH Fumiyasu <fumiya at samba.gr.jp>
 ********************************************************************/
 
+static bool rename_share_filename_fn(
+	struct share_mode_entry *e,


-- 
Samba Shared Repository



More information about the samba-cvs mailing list