smbd: Pull mtime handling into open_file_ntcreate
authorVolker Lendecke <vl@samba.org>
Fri, 22 Nov 2013 16:24:42 +0000 (16:24 +0000)
committerJeremy Allison <jra@samba.org>
Fri, 22 Nov 2013 23:40:49 +0000 (00:40 +0100)
This is a performance improvement for heavily contended files, in
particular in a cluster. The separate call to get_file_infos makes us
pull the locking.tdb record twice per open. For a contended file this
can be a performance penalty, this gets the # of record accesses for
the open/close cycle down from 3 to 2.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Sat Nov 23 00:40:49 CET 2013 on sn-devel-104

source3/smbd/nttrans.c
source3/smbd/open.c
source3/smbd/reply.c
source3/smbd/smb2_create.c

index 94be9f6d8d0df96bf33e5567f4cc8680d4c72e73..e901ff2797194503d3a7716d46a0e1ef5a94e62a 100644 (file)
@@ -457,7 +457,6 @@ void reply_ntcreate_and_X(struct smb_request *req)
        struct timespec c_timespec;
        struct timespec a_timespec;
        struct timespec m_timespec;
-       struct timespec write_time_ts;
        NTSTATUS status;
        int oplock_request;
        uint8_t oplock_granted = NO_OPLOCK_RETURN;
@@ -657,14 +656,6 @@ void reply_ntcreate_and_X(struct smb_request *req)
                fattr = FILE_ATTRIBUTE_NORMAL;
        }
 
-       /* Deal with other possible opens having a modified
-          write time. JRA. */
-       ZERO_STRUCT(write_time_ts);
-       get_file_infos(fsp->file_id, 0, NULL, &write_time_ts);
-       if (!null_timespec(write_time_ts)) {
-               update_stat_ex_mtime(&smb_fname->st, write_time_ts);
-       }
-
        /* Create time. */
        create_timespec = get_create_timespec(conn, fsp, smb_fname);
        a_timespec = smb_fname->st.st_ex_atime;
@@ -1001,7 +992,6 @@ static void call_nt_transact_create(connection_struct *conn,
        struct timespec c_timespec;
        struct timespec a_timespec;
        struct timespec m_timespec;
-       struct timespec write_time_ts;
        struct ea_list *ea_list = NULL;
        NTSTATUS status;
        size_t param_len;
@@ -1270,14 +1260,6 @@ static void call_nt_transact_create(connection_struct *conn,
                fattr = FILE_ATTRIBUTE_NORMAL;
        }
 
-       /* Deal with other possible opens having a modified
-          write time. JRA. */
-       ZERO_STRUCT(write_time_ts);
-       get_file_infos(fsp->file_id, 0, NULL, &write_time_ts);
-       if (!null_timespec(write_time_ts)) {
-               update_stat_ex_mtime(&smb_fname->st, write_time_ts);
-       }
-
        /* Create time. */
        create_timespec = get_create_timespec(conn, fsp, smb_fname);
        a_timespec = smb_fname->st.st_ex_atime;
index 5370cb8ab1120f7b9592be89ba8829c98a3e9e1a..2d866bbce52047df4ac0e042e8cad75fcc78b32e 100644 (file)
@@ -2845,6 +2845,17 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
                                  (unsigned int)new_unx_mode));
        }
 
+       {
+               /*
+                * Deal with other opens having a modified write time.
+                */
+               struct timespec write_time = get_share_mode_write_time(lck);
+
+               if (!null_timespec(write_time)) {
+                       update_stat_ex_mtime(&fsp->fsp_name->st, write_time);
+               }
+       }
+
        TALLOC_FREE(lck);
 
        return NT_STATUS_OK;
@@ -3281,6 +3292,18 @@ static NTSTATUS open_directory(connection_struct *conn,
                }
        }
 
+       {
+               /*
+                * Deal with other opens having a modified write time. Is this
+                * possible for directories?
+                */
+               struct timespec write_time = get_share_mode_write_time(lck);
+
+               if (!null_timespec(write_time)) {
+                       update_stat_ex_mtime(&fsp->fsp_name->st, write_time);
+               }
+       }
+
        TALLOC_FREE(lck);
 
        if (pinfo) {
index c11c318ef9b661c0d8b4d26fa40b77004c392f6c..87bda99411c1cd3dd72d17dfa08a1d737cc1a09d 100644 (file)
@@ -1967,18 +1967,6 @@ void reply_open(struct smb_request *req)
        size = smb_fname->st.st_ex_size;
        fattr = dos_mode(conn, smb_fname);
 
-       /* Deal with other possible opens having a modified
-          write time. JRA. */
-       if (ask_sharemode) {
-               struct timespec write_time_ts;
-
-               ZERO_STRUCT(write_time_ts);
-               get_file_infos(fsp->file_id, 0, NULL, &write_time_ts);
-               if (!null_timespec(write_time_ts)) {
-                       update_stat_ex_mtime(&smb_fname->st, write_time_ts);
-               }
-       }
-
        mtime = convert_timespec_to_time_t(smb_fname->st.st_ex_mtime);
 
        if (fattr & FILE_ATTRIBUTE_DIRECTORY) {
index f48c8ee3790dce5f1b664462660f9b7addfe8783..38eba4f9ceb5e2f6fedb7ae99202d4edf25ee761 100644 (file)
@@ -411,7 +411,6 @@ static struct tevent_req *smbd_smb2_create_send(TALLOC_CTX *mem_ctx,
        struct smb_request *smb1req = NULL;
        files_struct *result = NULL;
        int info;
-       struct timespec write_time_ts;
        struct smb2_create_blobs out_context_blobs;
        int requested_oplock_level;
        struct smb2_create_blob *dhnc = NULL;
@@ -1066,13 +1065,6 @@ static struct tevent_req *smbd_smb2_create_send(TALLOC_CTX *mem_ctx,
        }
        state->out_file_attributes = dos_mode(result->conn,
                                           result->fsp_name);
-       /* Deal with other possible opens having a modified
-          write time. JRA. */
-       ZERO_STRUCT(write_time_ts);
-       get_file_infos(result->file_id, 0, NULL, &write_time_ts);
-       if (!null_timespec(write_time_ts)) {
-               update_stat_ex_mtime(&result->fsp_name->st, write_time_ts);
-       }
 
        unix_timespec_to_nt_time(&state->out_creation_time,
                        get_create_timespec(smb1req->conn, result,