From 98f68cf115a30a101d3be2252ecbe1391720ed88 Mon Sep 17 00:00:00 2001 From: Yaniv Kaul Date: Sat, 13 Oct 2018 00:56:42 +0300 Subject: 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 Change-Id: Ic8fb94a56c4fa2d3b13e59767e13646fb39342ba --- xlators/features/quota/src/quota.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'xlators/features/quota/src/quota.c') 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); -- cgit