]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: call locking_close_file() while still holding a glock on the locking.tdb record
authorRalph Boehme <slow@samba.org>
Mon, 27 Jan 2025 14:22:26 +0000 (15:22 +0100)
committerRalph Boehme <slow@samba.org>
Wed, 2 Apr 2025 18:05:48 +0000 (18:05 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15767

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/smbd/close.c

index 290cae428c0d90b6dc5f5e2806e74cadb18f66c4..d249271a82f90bb77ae8b14515f531f637d72791 100644 (file)
@@ -321,6 +321,17 @@ static void close_share_mode_lock_prepare(struct share_mode_lock *lck,
         */
        *keep_locked = false;
 
+       if (fsp->current_lock_count > 0) {
+               /*
+                * Remove the byte-range locks under the glock
+                */
+               *keep_locked = true;
+       }
+
+       if (fh_get_refcount(fsp->fh) > 1) {
+               return;
+       }
+
        if (fsp->oplock_type != NO_OPLOCK) {
                ok = remove_share_oplock(lck, fsp);
                if (!ok) {
@@ -447,6 +458,12 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
                return status;
        }
 
+       locking_close_file(fsp, close_type);
+
+       if (fh_get_refcount(fsp->fh) > 1) {
+               goto done;
+       }
+
        /* Remove the oplock before potentially deleting the file. */
        if (fsp->oplock_type != NO_OPLOCK) {
                release_file_oplock(fsp);
@@ -876,13 +893,8 @@ static NTSTATUS close_normal_file(struct smb_request *req, files_struct *fsp,
           the same handle we only have one share mode. Ensure we only remove
           the share mode on the last close. */
 
-       if (fh_get_refcount(fsp->fh) == 1) {
-               /* Should we return on error here... ? */
-               tmp = close_remove_share_mode(fsp, close_type);
-               status = ntstatus_keeperror(status, tmp);
-       }
-
-       locking_close_file(fsp, close_type);
+       tmp = close_remove_share_mode(fsp, close_type);
+       status = ntstatus_keeperror(status, tmp);
 
        /*
         * Ensure pending modtime is set before closing underlying fd.