]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Introduce close_file_smb()
authorVolker Lendecke <vl@samba.org>
Wed, 9 Feb 2022 17:03:33 +0000 (18:03 +0100)
committerJeremy Allison <jra@samba.org>
Thu, 10 Feb 2022 18:16:36 +0000 (18:16 +0000)
This does almost everything that close_file_free() does, but it leaves
the fsp around.

A normal close_file() now calls fsp_unbind_smb() twice. Functionally
this is not a problem, fsp_unbind_smb() is idempotent. The only
potential performance penalty might come from the loops in
remove_smb2_chained_fsp(), but those only are potentially large with
deeply queued smb2 requests. If that turns out to be a problem, we'll
cope with it later. The alternative would be to split up file_free()
into even more routines and make it more difficult to figure out which
of the "rundown/unbind/free" routines to call in any particular
situation.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/close.c
source3/smbd/proto.h

index 9e7f89a304f76c93e644305eba483faa5641df3d..206515202e06f7159d37616e4b1490283fb48238 100644 (file)
@@ -1475,15 +1475,14 @@ static NTSTATUS close_directory(struct smb_request *req, files_struct *fsp,
 }
 
 /****************************************************************************
- Close a files_struct.
+ Rundown all SMB-related dependencies of a files struct
 ****************************************************************************/
   
-NTSTATUS close_file_free(struct smb_request *req,
-                        struct files_struct **_fsp,
-                        enum file_close_type close_type)
+NTSTATUS close_file_smb(struct smb_request *req,
+                       struct files_struct *fsp,
+                       enum file_close_type close_type)
 {
        NTSTATUS status;
-       struct files_struct *fsp = *_fsp;
 
        /*
         * This fsp can never be an internal dirfsp. They must
@@ -1541,9 +1540,22 @@ NTSTATUS close_file_free(struct smb_request *req,
                close_file_free(req, &fsp->base_fsp, close_type);
        }
 
-       file_free(req, fsp);
+       fsp_unbind_smb(req, fsp);
 
-       *_fsp = NULL;
+       return status;
+}
+
+NTSTATUS close_file_free(struct smb_request *req,
+                        struct files_struct **_fsp,
+                        enum file_close_type close_type)
+{
+       struct files_struct *fsp = *_fsp;
+       NTSTATUS status;
+
+       status = close_file_smb(req, fsp, close_type);
+
+       file_free(req, fsp);
+        *_fsp = NULL;
 
        return status;
 }
index 008de8baf37aa0a7a899fd2c2a867cb123be490c..db70dfb27b9c5cb67112cbea4f9f2a80672cf436 100644 (file)
@@ -130,6 +130,9 @@ bool smbd_smb1_brl_finish_by_mid(
 /* The following definitions come from smbd/close.c  */
 
 void set_close_write_time(struct files_struct *fsp, struct timespec ts);
+NTSTATUS close_file_smb(struct smb_request *req,
+                       struct files_struct *fsp,
+                       enum file_close_type close_type);
 NTSTATUS close_file_free(struct smb_request *req,
                         struct files_struct **_fsp,
                         enum file_close_type close_type);