summaryrefslogtreecommitdiffstats
path: root/xlators/storage/posix/src
diff options
context:
space:
mode:
authorYaniv Kaul <ykaul@redhat.com>2019-11-25 21:00:59 +0200
committerAmar Tumballi <amarts@gmail.com>2019-11-27 07:16:10 +0000
commit337e6d6b7c6612a4ce360c9e4d1a484436cdef57 (patch)
tree2860dfed1cd46b62f44b0ba1f5bebb4cba2e8742 /xlators/storage/posix/src
parentb7411e36514f2e564b3808679732ad8a5c1d9efd (diff)
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 <ykaul@redhat.com>
Diffstat (limited to 'xlators/storage/posix/src')
-rw-r--r--xlators/storage/posix/src/posix-inode-fd-ops.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/xlators/storage/posix/src/posix-inode-fd-ops.c b/xlators/storage/posix/src/posix-inode-fd-ops.c
index 17c2fe4..b810460 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;