[PATCH] Save one stat in update_write_time_on_close()

Ralph Böhme slow at samba.org
Tue Oct 11 15:52:12 UTC 2016


Hi!

To me it looks like in update_write_time_on_close() we could avoid
refreshing stat if we already have some valid stat info in the
smb_fname, as the code lines following thereafter don't seem to depend
on up2date mtime (or any other stat piece).

This is part of the devilish write time update insanity, so I'm not
100% sure this is correct. At least it passed a private autobuild and
iirc we have a set of tests that verify correct behaviour.

What do you think?

Cheerio!
-slow
-------------- next part --------------
From 2d0941718a685204491b445d7800aedbee8a829d Mon Sep 17 00:00:00 2001
From: Ralph Boehme <slow at samba.org>
Date: Tue, 11 Oct 2016 13:55:13 +0200
Subject: [PATCH] s3/smbd: in update_write_time_on_close() only stat() if we
 must

No need to update fsp->fsp_name->st via a stat call, the following code
doesn't look into it.

Signed-off-by: Ralph Boehme <slow at samba.org>
---
 source3/smbd/close.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/source3/smbd/close.c b/source3/smbd/close.c
index 22bd361..3278d1d 100644
--- a/source3/smbd/close.c
+++ b/source3/smbd/close.c
@@ -546,15 +546,17 @@ static NTSTATUS update_write_time_on_close(struct files_struct *fsp)
 		fsp->close_write_time = timespec_current();
 	}
 
-	/* Ensure we have a valid stat struct for the source. */
-	status = vfs_stat_fsp(fsp);
-	if (!NT_STATUS_IS_OK(status)) {
-		return status;
-	}
-
 	if (!VALID_STAT(fsp->fsp_name->st)) {
-		/* if it doesn't seem to be a real file */
-		return NT_STATUS_OK;
+		/* Ensure we have a valid stat struct for the source. */
+		status = vfs_stat_fsp(fsp);
+		if (!NT_STATUS_IS_OK(status)) {
+			return status;
+		}
+
+		if (!VALID_STAT(fsp->fsp_name->st)) {
+			/* if it doesn't seem to be a real file */
+			return NT_STATUS_OK;
+		}
 	}
 
 	/*
-- 
2.7.4



More information about the samba-technical mailing list