smbd: move a few common operations to fsp_new() in order to have them just once
authorStefan Metzmacher <metze@samba.org>
Fri, 26 Feb 2021 06:43:17 +0000 (07:43 +0100)
committerStefan Metzmacher <metze@samba.org>
Wed, 8 Feb 2023 09:29:18 +0000 (10:29 +0100)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
source3/smbd/durable.c
source3/smbd/files.c

index b21c223b2e4466e9523f8fdbda4f60c3d3c3d5bc..72681ea4474b44bd5a9bcf12dd123f83f2f92518 100644 (file)
@@ -683,7 +683,6 @@ NTSTATUS vfs_default_durable_reconnect(struct connection_struct *conn,
        fsp->fsp_flags.can_read = ((fsp->access_mask & FILE_READ_DATA) != 0);
        fsp->fsp_flags.can_write = ((fsp->access_mask & (FILE_WRITE_DATA|FILE_APPEND_DATA)) != 0);
        fsp->fnum = op->local_id;
-       fsp_set_gen_id(fsp);
 
        /*
         * TODO:
index 792e9424bdce592fb2b59287b4850a1a635ac4a2..29665b5066a2d4075c0c55befcbb5cf88ecf4dab 100644 (file)
@@ -68,6 +68,16 @@ NTSTATUS fsp_new(struct connection_struct *conn, TALLOC_CTX *mem_ctx,
        fsp->conn = conn;
        fsp->close_write_time = make_omit_timespec();
 
+       GetTimeOfDay(&fsp->open_time);
+       fsp_set_gen_id(fsp);
+       /*
+        * A new fsp invalidates the positive and
+        * negative fsp_fi_cache as the new fsp is pushed
+        * at the start of the list and we search from
+        * a cache hit to the *end* of the list.
+        */
+       ZERO_STRUCT(conn->sconn->fsp_fi_cache);
+
        DLIST_ADD(sconn->files, fsp);
        sconn->num_files += 1;
 
@@ -140,7 +150,6 @@ NTSTATUS fsp_bind_smb(struct files_struct *fsp, struct smb_request *req)
 NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
                  files_struct **result)
 {
-       struct smbd_server_connection *sconn = conn->sconn;
        files_struct *fsp;
        NTSTATUS status;
 
@@ -149,16 +158,12 @@ NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
                return status;
        }
 
-       GetTimeOfDay(&fsp->open_time);
-
        status = fsp_bind_smb(fsp, req);
        if (!NT_STATUS_IS_OK(status)) {
                file_free(NULL, fsp);
                return status;
        }
 
-       fsp_set_gen_id(fsp);
-
        /*
         * Create an smb_filename with "" for the base_name.  There are very
         * few NULL checks, so make sure it's initialized with something. to
@@ -177,13 +182,6 @@ NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
 
        DBG_INFO("new file %s\n", fsp_fnum_dbg(fsp));
 
-       /* A new fsp invalidates the positive and
-         negative fsp_fi_cache as the new fsp is pushed
-         at the start of the list and we search from
-         a cache hit to the *end* of the list. */
-
-       ZERO_STRUCT(sconn->fsp_fi_cache);
-
        *result = fsp;
        return NT_STATUS_OK;
 }
@@ -466,10 +464,6 @@ static NTSTATUS openat_pathref_fullname(
                return status;
        }
 
-       GetTimeOfDay(&fsp->open_time);
-       fsp_set_gen_id(fsp);
-       ZERO_STRUCT(conn->sconn->fsp_fi_cache);
-
        fsp->fsp_flags.is_pathref = true;
 
        status = fsp_attach_smb_fname(fsp, full_fname);