All of lore.kernel.org
 help / color / mirror / Atom feed
From: Trond Myklebust <trondmy@gmail.com>
To: SteveD@redhat.com
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH v3 05/11] Use xstat() with no synchronisation if available
Date: Tue, 28 May 2019 16:31:16 -0400	[thread overview]
Message-ID: <20190528203122.11401-6-trond.myklebust@hammerspace.com> (raw)
In-Reply-To: <20190528203122.11401-5-trond.myklebust@hammerspace.com>

We normally expect the exported system to be stable, so don't
revalidate attributes.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
---
 configure.ac         |  2 +-
 support/misc/xstat.c | 72 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index e870862a8abb..50002b4a5677 100644
--- a/configure.ac
+++ b/configure.ac
@@ -321,7 +321,7 @@ AC_CHECK_FUNC([getservbyname], ,
 AC_CHECK_LIB([crypt], [crypt], [LIBCRYPT="-lcrypt"])
 
 AC_CHECK_HEADERS([sched.h], [], [])
-AC_CHECK_FUNCS([unshare fstatat], [] , [])
+AC_CHECK_FUNCS([unshare fstatat statx], [] , [])
 AC_LIBPTHREAD([])
 
 if test "$enable_nfsv4" = yes; then
diff --git a/support/misc/xstat.c b/support/misc/xstat.c
index d092f73dfd65..fa047880cfd0 100644
--- a/support/misc/xstat.c
+++ b/support/misc/xstat.c
@@ -1,21 +1,93 @@
+#include <errno.h>
 #include <sys/types.h>
 #include <fcntl.h>
 #include <sys/stat.h>
+#include <sys/sysmacros.h>
 #include <unistd.h>
 
 #include "config.h"
 #include "xstat.h"
 
 #ifdef HAVE_FSTATAT
+#ifdef HAVE_STATX
+
+static void
+statx_copy(struct stat *stbuf, const struct statx *stxbuf)
+{
+	stbuf->st_dev = makedev(stxbuf->stx_dev_major, stxbuf->stx_dev_minor);
+	stbuf->st_ino = stxbuf->stx_ino;
+	stbuf->st_mode = stxbuf->stx_mode;
+	stbuf->st_nlink = stxbuf->stx_nlink;
+	stbuf->st_uid = stxbuf->stx_uid;
+	stbuf->st_gid = stxbuf->stx_gid;
+	stbuf->st_rdev = makedev(stxbuf->stx_rdev_major, stxbuf->stx_rdev_minor);
+	stbuf->st_size = stxbuf->stx_size;
+	stbuf->st_blksize = stxbuf->stx_blksize;
+	stbuf->st_blocks = stxbuf->stx_blocks;
+	stbuf->st_atim.tv_sec = stxbuf->stx_atime.tv_sec;
+	stbuf->st_atim.tv_nsec = stxbuf->stx_atime.tv_nsec;
+	stbuf->st_mtim.tv_sec = stxbuf->stx_mtime.tv_sec;
+	stbuf->st_mtim.tv_nsec = stxbuf->stx_mtime.tv_nsec;
+	stbuf->st_ctim.tv_sec = stxbuf->stx_ctime.tv_sec;
+	stbuf->st_ctim.tv_nsec = stxbuf->stx_ctime.tv_nsec;
+}
+
+static int
+statx_do_stat(int fd, const char *pathname, struct stat *statbuf, int flags)
+{
+	static int statx_supported = 1;
+	struct statx stxbuf;
+	int ret;
+
+	if (statx_supported) {
+		ret = statx(fd, pathname, flags,
+				STATX_BASIC_STATS,
+				&stxbuf);
+		if (ret == 0) {
+			statx_copy(statbuf, &stxbuf);
+			return 0;
+		}
+		if (errno == ENOSYS)
+			statx_supported = 0;
+	} else
+		errno = ENOSYS;
+	return -1;
+}
+
+static int
+statx_stat_nosync(int fd, const char *pathname, struct stat *statbuf, int flags)
+{
+	return statx_do_stat(fd, pathname, statbuf, flags | AT_STATX_DONT_SYNC);
+}
+
+#else
+
+static int
+statx_stat_nosync(int fd, const char *pathname, struct stat *statbuf, int flags)
+{
+	errno = ENOSYS;
+	return -1;
+}
+
+#endif /* HAVE_STATX */
 
 int xlstat(const char *pathname, struct stat *statbuf)
 {
+	if (statx_stat_nosync(AT_FDCWD, pathname, statbuf, AT_NO_AUTOMOUNT|
+				AT_SYMLINK_NOFOLLOW) == 0)
+		return 0;
+	else if (errno != ENOSYS)
+		return -1;
 	return fstatat(AT_FDCWD, pathname, statbuf, AT_NO_AUTOMOUNT |
 			AT_SYMLINK_NOFOLLOW);
 }
 
 int xstat(const char *pathname, struct stat *statbuf)
 {
+	if (statx_stat_nosync(AT_FDCWD, pathname, statbuf, AT_NO_AUTOMOUNT) == 0)
+		return 0;
+	else if (errno != ENOSYS)
+		return -1;
 	return fstatat(AT_FDCWD, pathname, statbuf, AT_NO_AUTOMOUNT);
 }
 
-- 
2.21.0


  reply	other threads:[~2019-05-28 20:33 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-28 20:31 [PATCH v3 00/11] Add the "[exports] rootdir" option to nfs.conf Trond Myklebust
2019-05-28 20:31 ` [PATCH v3 01/11] mountd: Ensure we don't share cache file descriptors among processes Trond Myklebust
2019-05-28 20:31   ` [PATCH v3 02/11] Add a simple workqueue mechanism Trond Myklebust
2019-05-28 20:31     ` [PATCH v3 03/11] Allow callers to check mountpoint status using a custom lstat function Trond Myklebust
2019-05-28 20:31       ` [PATCH v3 04/11] Add utilities for resolving nfsd paths and stat()ing them Trond Myklebust
2019-05-28 20:31         ` Trond Myklebust [this message]
2019-05-28 20:31           ` [PATCH v3 06/11] Add helpers to read/write to a file through the chrooted thread Trond Myklebust
2019-05-28 20:31             ` [PATCH v3 07/11] Add a helper to return the real path given an export entry Trond Myklebust
2019-05-28 20:31               ` [PATCH v3 08/11] Add support for the "[exports] rootdir" nfs.conf option to rpc.mountd Trond Myklebust
2019-05-28 20:31                 ` [PATCH v3 09/11] Add support for the "[exports] rootdir" nfs.conf option to exportfs Trond Myklebust
2019-05-28 20:31                   ` [PATCH v3 10/11] Add a helper for resolving symlinked nfsd paths via realpath() Trond Myklebust
2019-05-28 20:31                     ` [PATCH v3 11/11] Fix up symlinked mount path resolution when "[exports] rootdir" is set Trond Myklebust
2019-05-31 16:02                 ` [PATCH v3 08/11] Add support for the "[exports] rootdir" nfs.conf option to rpc.mountd J. Bruce Fields
2019-06-03 14:18                   ` Steve Dickson
2019-06-03 16:30                     ` Trond Myklebust
2019-05-29 14:38               ` [PATCH v3 07/11] Add a helper to return the real path given an export entry Steve Dickson
2019-05-29 14:55                 ` Trond Myklebust
2019-05-29 16:03                   ` Steve Dickson
2019-05-29 16:12                     ` Trond Myklebust
2019-05-29 17:17                       ` Steve Dickson
2019-05-31 15:52         ` [PATCH v3 04/11] Add utilities for resolving nfsd paths and stat()ing them J. Bruce Fields
2019-06-03 14:21           ` Steve Dickson
2019-06-03 16:32             ` Trond Myklebust
2019-06-10 13:53 ` [PATCH v3 00/11] Add the "[exports] rootdir" option to nfs.conf Steve Dickson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190528203122.11401-6-trond.myklebust@hammerspace.com \
    --to=trondmy@gmail.com \
    --cc=SteveD@redhat.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.