]> 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)
committerJule Anger <janger@samba.org>
Thu, 17 Apr 2025 11:31:14 +0000 (11:31 +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>
(cherry picked from commit 4d680b6c17ee7674b9686aec2b69038f89e1989a)

source3/smbd/close.c

index c5b6c622d7035179026940945b4e79ad55369c93..cf0e0e6419db555b46e7fd6a6af81ed39d04f7a6 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) {
@@ -474,6 +485,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);
@@ -939,13 +956,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.