diff options
author | Yaniv Kaul <ykaul@redhat.com> | 2018-10-13 00:56:42 +0300 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-10-16 06:33:29 +0000 |
commit | 98f68cf115a30a101d3be2252ecbe1391720ed88 (patch) | |
tree | 4a9da66f8833a936eba95fc078a4605acd632f4f /xlators/features | |
parent | fd70a7d790710da01a8ddd56785a28ab54e07550 (diff) |
Multiple xlators: perform gettimeofday() not under lock
While it may slightly reduce accuracy, I think it's better to
acquire the time outside a lock and then memcpy the value while
under lock.
Compile-tested only!
updates: bz#1193929
Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
Change-Id: Ic8fb94a56c4fa2d3b13e59767e13646fb39342ba
Diffstat (limited to 'xlators/features')
-rw-r--r-- | xlators/features/locks/src/entrylk.c | 6 | ||||
-rw-r--r-- | xlators/features/locks/src/inodelk.c | 6 | ||||
-rw-r--r-- | xlators/features/quota/src/quota.c | 12 |
3 files changed, 16 insertions, 8 deletions
diff --git a/xlators/features/locks/src/entrylk.c b/xlators/features/locks/src/entrylk.c index ea78f92d200..60e7bed2a44 100644 --- a/xlators/features/locks/src/entrylk.c +++ b/xlators/features/locks/src/entrylk.c @@ -115,7 +115,6 @@ __stale_entrylk(xlator_t *this, pl_entry_lock_t *candidate_lock, { posix_locks_private_t *priv = NULL; struct timeval curr; - gettimeofday(&curr, NULL); priv = this->private; @@ -123,6 +122,7 @@ __stale_entrylk(xlator_t *this, pl_entry_lock_t *candidate_lock, * chance? Or just the locks we are attempting to acquire? */ if (names_conflict(candidate_lock->basename, requested_lock->basename)) { + gettimeofday(&curr, NULL); *lock_age_sec = curr.tv_sec - candidate_lock->granted_time.tv_sec; if (*lock_age_sec > priv->revocation_secs) return _gf_true; @@ -541,11 +541,11 @@ __lock_blocked_add(xlator_t *this, pl_inode_t *pinode, pl_dom_list_t *dom, { struct timeval now; - gettimeofday(&now, NULL); - if (nonblock) goto out; + gettimeofday(&now, NULL); + lock->blkd_time = now; list_add_tail(&lock->blocked_locks, &dom->blocked_entrylks); diff --git a/xlators/features/locks/src/inodelk.c b/xlators/features/locks/src/inodelk.c index eff58a79569..b8e005038d8 100644 --- a/xlators/features/locks/src/inodelk.c +++ b/xlators/features/locks/src/inodelk.c @@ -145,11 +145,11 @@ __stale_inodelk(xlator_t *this, pl_inode_lock_t *candidate_lock, struct timeval curr; priv = this->private; - gettimeofday(&curr, NULL); /* Question: Should we just prune them all given the * chance? Or just the locks we are attempting to acquire? */ if (inodelk_conflict(candidate_lock, requested_lock)) { + gettimeofday(&curr, NULL); *lock_age_sec = curr.tv_sec - candidate_lock->granted_time.tv_sec; if (*lock_age_sec > priv->revocation_secs) return _gf_true; @@ -403,12 +403,12 @@ __lock_blocked_add(xlator_t *this, pl_dom_list_t *dom, pl_inode_lock_t *lock, { struct timeval now; - gettimeofday(&now, NULL); - if (can_block == 0) { goto out; } + gettimeofday(&now, NULL); + lock->blkd_time = now; list_add_tail(&lock->blocked_locks, &dom->blocked_inodelks); diff --git a/xlators/features/quota/src/quota.c b/xlators/features/quota/src/quota.c index 6310967fc0d..0b81e370e43 100644 --- a/xlators/features/quota/src/quota.c +++ b/xlators/features/quota/src/quota.c @@ -591,6 +591,9 @@ quota_validate_cbk(call_frame_t *frame, void *cookie, xlator_t *this, quota_meta_t size = { 0, }; + struct timeval tv = { + 0, + }; local = frame->local; @@ -628,12 +631,13 @@ quota_validate_cbk(call_frame_t *frame, void *cookie, xlator_t *this, * loop of validation and checking * limit when timeout is zero. */ + gettimeofday(&tv, NULL); LOCK(&ctx->lock); { ctx->size = size.size; ctx->file_count = size.file_count; ctx->dir_count = size.dir_count; - gettimeofday(&ctx->tv, NULL); + memcpy(&ctx->tv, &tv, sizeof(struct timeval)); } UNLOCK(&ctx->lock); @@ -4306,6 +4310,9 @@ quota_statfs_validate_cbk(call_frame_t *frame, void *cookie, xlator_t *this, quota_meta_t size = { 0, }; + struct timeval tv = { + 0, + }; local = frame->local; @@ -4337,12 +4344,13 @@ quota_statfs_validate_cbk(call_frame_t *frame, void *cookie, xlator_t *this, op_errno = EINVAL; } + gettimeofday(&tv, NULL); LOCK(&ctx->lock); { ctx->size = size.size; ctx->file_count = size.file_count; ctx->dir_count = size.dir_count; - gettimeofday(&ctx->tv, NULL); + memcpy(&ctx->tv, &tv, sizeof(struct timeval)); } UNLOCK(&ctx->lock); |