s3: Introduce get_share_mode_lock_fresh()
authorVolker Lendecke <vl@samba.org>
Mon, 9 Jan 2012 13:30:53 +0000 (14:30 +0100)
committerJeremy Allison <jra@samba.org>
Thu, 12 Jan 2012 22:59:22 +0000 (23:59 +0100)
This slightly simplifies the code path for all callers which assume
that a share mode exists already. Only the callers in open_file_ntcreate
and open_directory will ever create new share modes.

Signed-off-by: Jeremy Allison <jra@samba.org>
source3/locking/locking.c
source3/locking/proto.h
source3/smbd/close.c
source3/smbd/open.c
source3/smbd/oplock.c
source3/smbd/reply.c
source3/smbd/trans2.c

index 95710cdd7562479cc4bbc8004875d0951a13875a..2e400ac8ef0e7b6468f553173018deee9cd9ca45 100644 (file)
@@ -675,6 +675,11 @@ static struct share_mode_lock *fresh_share_mode_lock(
 {
        struct share_mode_lock *lck;
 
+       if ((servicepath == NULL) || (smb_fname == NULL) ||
+           (old_write_time == NULL)) {
+               return NULL;
+       }
+
        lck = talloc_zero(mem_ctx, struct share_mode_lock);
        if (lck == NULL) {
                goto fail;
@@ -703,11 +708,11 @@ fail:
        return NULL;
 }
 
-struct share_mode_lock *get_share_mode_lock(TALLOC_CTX *mem_ctx,
-                                           const struct file_id id,
-                                           const char *servicepath,
-                                           const struct smb_filename *smb_fname,
-                                           const struct timespec *old_write_time)
+struct share_mode_lock *get_share_mode_lock_fresh(TALLOC_CTX *mem_ctx,
+                                                 const struct file_id id,
+                                                 const char *servicepath,
+                                                 const struct smb_filename *smb_fname,
+                                                 const struct timespec *old_write_time)
 {
        struct share_mode_lock *lck;
        struct file_id tmp;
@@ -735,14 +740,18 @@ struct share_mode_lock *get_share_mode_lock(TALLOC_CTX *mem_ctx,
                TALLOC_FREE(rec);
                return NULL;
        }
-
        lck->id = id;
        lck->record = talloc_move(lck, &rec);
        talloc_set_destructor(lck, share_mode_lock_destructor);
-
        return lck;
 }
 
+struct share_mode_lock *get_share_mode_lock(TALLOC_CTX *mem_ctx,
+                                           const struct file_id id)
+{
+       return get_share_mode_lock_fresh(mem_ctx, id, NULL, NULL, NULL);
+}
+
 struct share_mode_lock *fetch_share_mode_unlocked(TALLOC_CTX *mem_ctx,
                                                  const struct file_id id)
 {
@@ -1260,8 +1269,7 @@ bool set_delete_on_close(files_struct *fsp, bool delete_on_close, const struct s
                  delete_on_close ? "Adding" : "Removing", fsp->fnum,
                  fsp_str_dbg(fsp)));
 
-       lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
-                                 NULL);
+       lck = get_share_mode_lock(talloc_tos(), fsp->file_id);
        if (lck == NULL) {
                return False;
        }
@@ -1314,7 +1322,7 @@ bool set_sticky_write_time(struct file_id fileid, struct timespec write_time)
                            convert_timespec_to_time_t(write_time)),
                 file_id_string_tos(&fileid)));
 
-       lck = get_share_mode_lock(talloc_tos(), fileid, NULL, NULL, NULL);
+       lck = get_share_mode_lock(talloc_tos(), fileid);
        if (lck == NULL) {
                return False;
        }
@@ -1337,7 +1345,7 @@ bool set_write_time(struct file_id fileid, struct timespec write_time)
                            convert_timespec_to_time_t(write_time)),
                 file_id_string_tos(&fileid)));
 
-       lck = get_share_mode_lock(talloc_tos(), fileid, NULL, NULL, NULL);
+       lck = get_share_mode_lock(talloc_tos(), fileid);
        if (lck == NULL) {
                return False;
        }
index d6f1c1bf4ae6c8925a5a9068f49c1974cc766759..25f3d196b83efd3aa4a6b4bf9e5cb797c47d4149 100644 (file)
@@ -147,10 +147,13 @@ bool locking_init_readonly(void);
 bool locking_end(void);
 char *share_mode_str(TALLOC_CTX *ctx, int num, const struct share_mode_entry *e);
 struct share_mode_lock *get_share_mode_lock(TALLOC_CTX *mem_ctx,
-                                           const struct file_id id,
-                                           const char *servicepath,
-                                           const struct smb_filename *smb_fname,
-                                           const struct timespec *old_write_time);
+                                           const struct file_id id);
+struct share_mode_lock *get_share_mode_lock_fresh(
+       TALLOC_CTX *mem_ctx,
+       const struct file_id id,
+       const char *servicepath,
+       const struct smb_filename *smb_fname,
+       const struct timespec *old_write_time);
 struct share_mode_lock *fetch_share_mode_unlocked(TALLOC_CTX *mem_ctx,
                                                  const struct file_id id);
 bool rename_share_filename(struct messaging_context *msg_ctx,
index 26656f47a2725447ddda09690303f15228c9f418..a07ab4b42cb4e23c850b8505aebc3dc0906cf78d 100644 (file)
@@ -347,9 +347,7 @@ static NTSTATUS close_remove_share_mode(files_struct *fsp,
         * This prevents race conditions with the file being created. JRA.
         */
 
-       lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
-                                 NULL);
-
+       lck = get_share_mode_lock(talloc_tos(), fsp->file_id);
        if (lck == NULL) {
                DEBUG(0, ("close_remove_share_mode: Could not get share mode "
                          "lock for file %s\n", fsp_str_dbg(fsp)));
@@ -617,7 +615,7 @@ static NTSTATUS update_write_time_on_close(struct files_struct *fsp)
         * must update it in the open file db too. */
        (void)set_write_time(fsp->file_id, fsp->close_write_time);
 
-       lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL, NULL);
+       lck = get_share_mode_lock(talloc_tos(), fsp->file_id);
        if (lck) {
                /* Close write times overwrite sticky write times
                   so we must replace any sticky write time here. */
@@ -1019,9 +1017,7 @@ static NTSTATUS close_directory(struct smb_request *req, files_struct *fsp,
         * reference to a directory also.
         */
 
-       lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
-                                 NULL);
-
+       lck = get_share_mode_lock(talloc_tos(), fsp->file_id);
        if (lck == NULL) {
                DEBUG(0, ("close_directory: Could not get share mode lock for "
                          "%s\n", fsp_str_dbg(fsp)));
index dbc4dba4487e58171bb96b2b436722bc25cadcc2..46d5d28863250a486e3752d3e37b45630d59b344 100644 (file)
@@ -1584,8 +1584,7 @@ NTSTATUS smbd_calculate_access_mask(connection_struct *conn,
 void remove_deferred_open_entry(struct file_id id, uint64_t mid,
                                struct server_id pid)
 {
-       struct share_mode_lock *lck = get_share_mode_lock(talloc_tos(), id,
-                       NULL, NULL, NULL);
+       struct share_mode_lock *lck = get_share_mode_lock(talloc_tos(), id);
        if (lck == NULL) {
                DEBUG(0, ("could not get share mode lock\n"));
                return;
@@ -1629,11 +1628,8 @@ static bool acquire_ordered_locks(TALLOC_CTX *mem_ctx,
                   lock on the brlock database. */
        }
 
-       *p_lck = get_share_mode_lock(mem_ctx,
-                               id,
-                               connectpath,
-                               smb_fname,
-                               p_old_write_time);
+       *p_lck = get_share_mode_lock_fresh(
+               mem_ctx, id, connectpath, smb_fname, p_old_write_time);
 
        if (*p_lck == NULL) {
                DEBUG(0, ("Could not get share mode lock\n"));
@@ -2928,8 +2924,9 @@ static NTSTATUS open_directory(connection_struct *conn,
                return NT_STATUS_ACCESS_DENIED;
        }
 
-       lck = get_share_mode_lock(talloc_tos(), fsp->file_id,
-                                 conn->connectpath, smb_dname, &mtimespec);
+       lck = get_share_mode_lock_fresh(talloc_tos(), fsp->file_id,
+                                       conn->connectpath, smb_dname,
+                                       &mtimespec);
 
        if (lck == NULL) {
                DEBUG(0, ("open_directory: Could not get share mode lock for "
index 7a810d9a2005a216fa0daa8ca4a0d095c3d475b7..e1731f1e10901a7e96d391f7eec9c2811be50515 100644 (file)
@@ -162,8 +162,7 @@ bool remove_oplock(files_struct *fsp)
        struct share_mode_lock *lck;
 
        /* Remove the oplock flag from the sharemode. */
-       lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
-                                 NULL);
+       lck = get_share_mode_lock(talloc_tos(), fsp->file_id);
        if (lck == NULL) {
                DEBUG(0,("remove_oplock: failed to lock share entry for "
                         "file %s\n", fsp_str_dbg(fsp)));
@@ -189,8 +188,7 @@ bool downgrade_oplock(files_struct *fsp)
        bool ret;
        struct share_mode_lock *lck;
 
-       lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
-                                 NULL);
+       lck = get_share_mode_lock(talloc_tos(), fsp->file_id);
        if (lck == NULL) {
                DEBUG(0,("downgrade_oplock: failed to lock share entry for "
                         "file %s\n", fsp_str_dbg(fsp)));
@@ -760,8 +758,7 @@ static void contend_level2_oplocks_begin_default(files_struct *fsp,
        if (!LEVEL_II_OPLOCK_TYPE(fsp->oplock_type))
                return;
 
-       lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
-                                 NULL);
+       lck = get_share_mode_lock(talloc_tos(), fsp->file_id);
        if (lck == NULL) {
                DEBUG(0,("release_level_2_oplocks_on_change: failed to lock "
                         "share mode entry for file %s.\n", fsp_str_dbg(fsp)));
index 4954098de7d513e936949d57dfbe2e5cff96e05a..b8da33549c9fba03b79d22ed018285168c6a70f8 100644 (file)
@@ -6207,8 +6207,7 @@ NTSTATUS rename_internals_fsp(connection_struct *conn,
                status = NT_STATUS_ACCESS_DENIED;
        }
 
-       lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
-                                 NULL);
+       lck = get_share_mode_lock(talloc_tos(), fsp->file_id);
 
        /*
         * We have the file open ourselves, so not being able to get the
index ec9901b99e7a98f1ffa01842cdec6e8b846459b6..4e86fbfcddd19361b1b46ca8ae9e13e9a2dd4044 100644 (file)
@@ -7572,8 +7572,7 @@ static NTSTATUS smb_posix_unlink(connection_struct *conn,
         * non-POSIX opens return SHARING_VIOLATION.
         */
 
-       lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
-                                 NULL);
+       lck = get_share_mode_lock(talloc_tos(), fsp->file_id);
        if (lck == NULL) {
                DEBUG(0, ("smb_posix_unlink: Could not get share mode "
                          "lock for file %s\n", fsp_str_dbg(fsp)));