summaryrefslogtreecommitdiffstats
path: root/xlators/features/quota
diff options
context:
space:
mode:
authorVarun Shastry <vshastry@redhat.com>2014-04-11 17:31:32 +0530
committerVijay Bellur <vbellur@redhat.com>2014-04-29 09:46:07 -0700
commitb00ef83d2b15594526b1c58ef944a7edaa7e9dfe (patch)
treeddd604e746989e2b7f7135760643d630a5b34459 /xlators/features/quota
parent5e4a5a4c27f120102d4c2e3c7d558a20d838cf24 (diff)
feature/quota: Logging corrections
This patch solves the inconsistent quota usage logging when soft limit reached. Change-Id: I47e7f1e65ed4b8306a999a20cc8f6b1772d47627 BUG: 1087198 Signed-off-by: Varun Shastry <vshastry@redhat.com> Reviewed-on: http://review.gluster.org/7451 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'xlators/features/quota')
-rw-r--r--xlators/features/quota/src/quota.c57
1 files changed, 36 insertions, 21 deletions
diff --git a/xlators/features/quota/src/quota.c b/xlators/features/quota/src/quota.c
index 2ca4da0..d93911d 100644
--- a/xlators/features/quota/src/quota.c
+++ b/xlators/features/quota/src/quota.c
@@ -4017,6 +4017,29 @@ off:
return 0;
}
+void
+quota_log_helper (char **usage_str, int64_t cur_size, inode_t *inode,
+ char **path, struct timeval *cur_time)
+{
+ xlator_t *this = THIS;
+
+ if (!usage_str || !inode || !path || !cur_time) {
+ gf_log (this->name, GF_LOG_ERROR, "Received null argument");
+ return;
+ }
+
+ *usage_str = gf_uint64_2human_readable (cur_size);
+ if (!(*usage_str))
+ gf_log (this->name, GF_LOG_ERROR, "integer to string "
+ "conversion failed Reason:\"Cannot allocate memory\"");
+
+ inode_path (inode, NULL, path);
+ if (!(*path))
+ *path = uuid_utoa (inode->gfid);
+
+ gettimeofday (cur_time, NULL);
+}
+
/* Logs if
* i. Usage crossed soft limit
* ii. Usage above soft limit and alert-time elapsed
@@ -4027,47 +4050,39 @@ quota_log_usage (xlator_t *this, quota_inode_ctx_t *ctx, inode_t *inode,
{
struct timeval cur_time = {0,};
char *usage_str = NULL;
- char size_str[32] = {0};
char *path = NULL;
int64_t cur_size = 0;
quota_priv_t *priv = NULL;
- gf_boolean_t dyn_mem = _gf_true;
priv = this->private;
- if ((ctx->soft_lim <= 0) || (timerisset (&ctx->prev_log) &&
- !quota_timeout (&ctx->prev_log,
- priv->log_timeout))) {
- return;
- }
-
-
cur_size = ctx->size + delta;
- usage_str = gf_uint64_2human_readable (cur_size);
- if (!usage_str) {
- snprintf (size_str, sizeof (size_str), "%"PRId64, cur_size);
- usage_str = (char*) size_str;
- dyn_mem = _gf_false;
- }
- inode_path (inode, NULL, &path);
- if (!path)
- path = uuid_utoa (inode->gfid);
- gettimeofday (&cur_time, NULL);
+ if ((ctx->soft_lim <= 0) || cur_size < ctx->soft_lim)
+ return;
+
/* Usage crossed/reached soft limit */
if (DID_REACH_LIMIT (ctx->soft_lim, ctx->size, cur_size)) {
+ quota_log_helper (&usage_str, cur_size, inode,
+ &path, &cur_time);
+
gf_log (this->name, GF_LOG_ALERT, "Usage crossed "
"soft limit: %s used by %s", usage_str, path);
ctx->prev_log = cur_time;
}
/* Usage is above soft limit */
- else if (cur_size > ctx->soft_lim){
+ else if (cur_size > ctx->soft_lim &&
+ quota_timeout (&ctx->prev_log, priv->log_timeout)) {
+
+ quota_log_helper (&usage_str, cur_size, inode,
+ &path, &cur_time);
+
gf_log (this->name, GF_LOG_ALERT, "Usage is above "
"soft limit: %s used by %s", usage_str, path);
ctx->prev_log = cur_time;
}
- if (dyn_mem)
+ if (usage_str)
GF_FREE (usage_str);
}