[PATCH] Optimisation for readdir using fstatat.

Jeremy Allison jra at samba.org
Fri Jun 7 21:20:06 MDT 2013


Second version, with the waf fix that metze
pointed out.

Please review and push if you're happy !

Cheers,

Jeremy.
-------------- next part --------------
>From 5a2996ee7c4cb44f9a1a8e6548c15a92241e9677 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Fri, 7 Jun 2013 17:53:45 -0700
Subject: [PATCH 1/2] Check for fstatat.

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 source3/wscript |    1 +
 1 file changed, 1 insertion(+)

diff --git a/source3/wscript b/source3/wscript
index 98a486f..b23608c 100644
--- a/source3/wscript
+++ b/source3/wscript
@@ -89,6 +89,7 @@ def configure(conf):
     conf.CHECK_FUNCS('fseeko setluid')
     conf.CHECK_FUNCS('getpwnam', headers='sys/types.h pwd.h')
     conf.CHECK_FUNCS('fdopendir')
+    conf.CHECK_FUNCS('fstatat')
     conf.CHECK_FUNCS('getpwent_r setenv strcasecmp fcvt fcvtl')
     conf.CHECK_FUNCS('syslog vsyslog timegm setlocale')
     conf.CHECK_FUNCS_IN('nanosleep', 'rt')
-- 
1.7.9.5


>From 15ab508790fe50fb80b802a565ebf9e8cb7abd93 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Fri, 24 May 2013 10:33:38 -0700
Subject: [PATCH 2/2] Optimization on POSIX platforms that have fstatat.

Tests show significant speedup in directory listings
by using fstatat instead of a full pathname walk.

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 source3/modules/vfs_default.c |   27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c
index 8804e62..82d059c 100644
--- a/source3/modules/vfs_default.c
+++ b/source3/modules/vfs_default.c
@@ -376,11 +376,30 @@ static struct dirent *vfswrap_readdir(vfs_handle_struct *handle,
 
 	START_PROFILE(syscall_readdir);
 	result = readdir(dirp);
-	/* Default Posix readdir() does not give us stat info.
-	 * Set to invalid to indicate we didn't return this info. */
-	if (sbuf)
-		SET_STAT_INVALID(*sbuf);
 	END_PROFILE(syscall_readdir);
+	if (sbuf) {
+		/* Default Posix readdir() does not give us stat info.
+		 * Set to invalid to indicate we didn't return this info. */
+		SET_STAT_INVALID(*sbuf);
+#if defined(HAVE_DIRFD) && defined(HAVE_FSTATAT)
+		if (result != NULL) {
+			/* See if we can efficiently return this. */
+			struct stat st;
+			int flags = (lp_posix_pathnames() ?
+				AT_SYMLINK_NOFOLLOW : 0);
+			int ret = fstatat(dirfd(dirp),
+					result->d_name,
+					&st,
+					flags);
+			if (ret == 0) {
+				init_stat_ex_from_stat(sbuf,
+					&st,
+					lp_fake_dir_create_times(
+						SNUM(handle->conn)));
+			}
+		}
+#endif
+	}
 	return result;
 }
 
-- 
1.7.9.5



More information about the samba-technical mailing list