locking: combine get_delete_on_close_flag() and get_write_time() into get_file_infos()
authorStefan Metzmacher <metze@samba.org>
Tue, 1 Apr 2008 09:40:23 +0000 (11:40 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 7 Apr 2008 10:29:29 +0000 (12:29 +0200)
This means we need to fetch the record only once.

metze
(This used to be commit 4130b873291d39e363184fe4e38dc1f24ebe5056)

source3/locking/locking.c
source3/smbd/dir.c
source3/smbd/filename.c
source3/smbd/trans2.c

index 8d8c0347a5682c6212a2f14f77bb428e210dd6d5..5faebef1fe70b6286baf599699bcccb3eac5e3d1 100644 (file)
@@ -940,37 +940,40 @@ bool rename_share_filename(struct messaging_context *msg_ctx,
        return True;
 }
 
-struct timespec get_write_time(struct file_id id)
+void get_file_infos(struct file_id id,
+                   bool *delete_on_close,
+                   struct timespec *write_time)
 {
-       struct timespec result;
        struct share_mode_lock *lck;
 
-       ZERO_STRUCT(result);
+       if (delete_on_close) {
+               *delete_on_close = false;
+       }
+
+       if (write_time) {
+               ZERO_STRUCTP(write_time);
+       }
 
        if (!(lck = fetch_share_mode_unlocked(talloc_tos(), id, NULL, NULL))) {
-               return result;
+               return;
        }
-       result = lck->changed_write_time;
 
-       if (null_timespec(result)) {
-               result = lck->old_write_time;
+       if (delete_on_close) {
+               *delete_on_close = lck->delete_on_close;
        }
 
-       TALLOC_FREE(lck);
-       return result;
-}
+       if (write_time) {
+               struct timespec wt;
 
-bool get_delete_on_close_flag(struct file_id id)
-{
-       bool result;
-       struct share_mode_lock *lck;
-  
-       if (!(lck = fetch_share_mode_unlocked(talloc_tos(), id, NULL, NULL))) {
-               return False;
+               wt = lck->changed_write_time;
+               if (null_timespec(wt)) {
+                       wt = lck->old_write_time;
+               }
+
+               *write_time = wt;
        }
-       result = lck->delete_on_close;
+
        TALLOC_FREE(lck);
-       return result;
 }
 
 bool is_valid_share_mode_entry(const struct share_mode_entry *e)
index 8531d6250da5bd5c7d172e046b28173bf0220204..5fc2e3719eff2d7573b90de502f8e0a3118de7c3 100644 (file)
@@ -886,7 +886,7 @@ bool get_dir_entry(TALLOC_CTX *ctx,
                        *date = sbuf.st_mtime;
 
                        fileid = vfs_file_id_from_sbuf(conn, &sbuf);
-                       write_time_ts = get_write_time(fileid);
+                       get_file_infos(fileid, NULL, &write_time_ts);
                        if (!null_timespec(write_time_ts)) {
                                *date = convert_timespec_to_time_t(write_time_ts);
                        }
index 10e958304905c05ca8714d81c508c338fb224871..4323e843d21cd9871efcb5c355bf8f216cea3466 100644 (file)
@@ -611,11 +611,19 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
                } /* end else */
 
 #ifdef DEVELOPER
-               if (VALID_STAT(st) &&
-                   get_delete_on_close_flag(vfs_file_id_from_sbuf(conn,
-                                   &st))) {
-                       result = NT_STATUS_DELETE_PENDING;
-                       goto fail;
+               /*
+                * This sucks!
+                * We should never provide different behaviors
+                * depending on DEVELOPER!!!
+                */
+               if (VALID_STAT(st)) {
+                       bool delete_pending;
+                       get_file_infos(vfs_file_id_from_sbuf(conn, &st),
+                                      &delete_pending, NULL);
+                       if (delete_pending) {
+                               result = NT_STATUS_DELETE_PENDING;
+                               goto fail;
+                       }
                }
 #endif
 
index 06bb31622ffd7c4fd9a98eaf220ca9762955ea9e..9e56434d5c1818c26d7642732bee0b44e29daafb 100644 (file)
@@ -1398,8 +1398,8 @@ static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
                        adate_ts = get_atimespec(&sbuf);
                        create_date_ts = get_create_timespec(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
 
-                       write_time_ts = get_write_time(
-                               vfs_file_id_from_sbuf(conn, &sbuf));
+                       get_file_infos(vfs_file_id_from_sbuf(conn, &sbuf),
+                                      NULL, &write_time_ts);
                        if (!null_timespec(write_time_ts)) {
                                mdate_ts = write_time_ts;
                        }
@@ -3870,8 +3870,7 @@ static void call_trans2qfilepathinfo(connection_struct *conn,
                        }
 
                        fileid = vfs_file_id_from_sbuf(conn, &sbuf);
-                       delete_pending = get_delete_on_close_flag(fileid);
-                       write_time_ts = get_write_time(fileid);
+                       get_file_infos(fileid, &delete_pending, &write_time_ts);
                } else {
                        /*
                         * Original code - this is an open file.
@@ -3887,8 +3886,7 @@ static void call_trans2qfilepathinfo(connection_struct *conn,
                        }
                        pos = fsp->fh->position_information;
                        fileid = vfs_file_id_from_sbuf(conn, &sbuf);
-                       delete_pending = get_delete_on_close_flag(fileid);
-                       write_time_ts = get_write_time(fileid);
+                       get_file_infos(fileid, &delete_pending, &write_time_ts);
                        access_mask = fsp->access_mask;
                }
 
@@ -3959,12 +3957,11 @@ static void call_trans2qfilepathinfo(connection_struct *conn,
                }
 
                fileid = vfs_file_id_from_sbuf(conn, &sbuf);
-               delete_pending = get_delete_on_close_flag(fileid);
+               get_file_infos(fileid, &delete_pending, &write_time_ts);
                if (delete_pending) {
                        reply_nterror(req, NT_STATUS_DELETE_PENDING);
                        return;
                }
-               write_time_ts = get_write_time(fileid);
        }
 
        if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {