From 337e6d6b7c6612a4ce360c9e4d1a484436cdef57 Mon Sep 17 00:00:00 2001 From: Yaniv Kaul Date: Mon, 25 Nov 2019 21:00:59 +0200 Subject: posix-inode-fd-ops.c: excute sys_fstat() only when needed It appears that in posix_do_futimes() we may not need to unconditionally execute sys_fstat(). Avoid it and use the existing stbuf atime and mtime if possible. If not, we execute it. Change-Id: I0bdd471e5c821fcd28f057c75046c673a212d347 updates: bz#1193929 Signed-off-by: Yaniv Kaul --- xlators/storage/posix/src/posix-inode-fd-ops.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'xlators/storage/posix') diff --git a/xlators/storage/posix/src/posix-inode-fd-ops.c b/xlators/storage/posix/src/posix-inode-fd-ops.c index 17c2fe4fab4..b8104604ecc 100644 --- a/xlators/storage/posix/src/posix-inode-fd-ops.c +++ b/xlators/storage/posix/src/posix-inode-fd-ops.c @@ -522,18 +522,19 @@ posix_do_futimes(xlator_t *this, int fd, struct iatt *stbuf, int valid) struct stat stat = { 0, }; - - ret = sys_fstat(fd, &stat); - if (ret != 0) { - gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_FILE_OP_FAILED, "%d", - fd); - goto out; - } + gf_boolean_t fstat_executed = _gf_false; if ((valid & GF_SET_ATTR_ATIME) == GF_SET_ATTR_ATIME) { tv[0].tv_sec = stbuf->ia_atime; tv[0].tv_usec = stbuf->ia_atime_nsec / 1000; } else { + ret = sys_fstat(fd, &stat); + if (ret != 0) { + gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_FILE_OP_FAILED, + "%d", fd); + goto out; + } + fstat_executed = _gf_true; /* atime is not given, use current values */ tv[0].tv_sec = ST_ATIM_SEC(&stat); tv[0].tv_usec = ST_ATIM_NSEC(&stat) / 1000; @@ -543,6 +544,14 @@ posix_do_futimes(xlator_t *this, int fd, struct iatt *stbuf, int valid) tv[1].tv_sec = stbuf->ia_mtime; tv[1].tv_usec = stbuf->ia_mtime_nsec / 1000; } else { + if (!fstat_executed) { + ret = sys_fstat(fd, &stat); + if (ret != 0) { + gf_msg(this->name, GF_LOG_WARNING, errno, P_MSG_FILE_OP_FAILED, + "%d", fd); + goto out; + } + } /* mtime is not given, use current values */ tv[1].tv_sec = ST_MTIM_SEC(&stat); tv[1].tv_usec = ST_MTIM_NSEC(&stat) / 1000; -- cgit