summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVijay Bellur <vbellur@redhat.com>2013-08-08 12:01:28 +0530
committerVijay Bellur <vbellur@redhat.com>2013-08-08 12:21:23 +0530
commit4a8c60e941caa61df5ff2a6a6d47826f1deeb0ad (patch)
treea121fa11ab951a0bee97bb91c2baa765c51bcfb0
parent82890b0a753af50eb64271ba633e8da5527eb097 (diff)
features/quota: Introduce quota log helper function.
Change-Id: I38077c7adc497b314f4037cbbb116458a26ed589
-rw-r--r--xlators/features/quota/src/quota.c53
-rw-r--r--xlators/features/quota/src/quota.h2
2 files changed, 55 insertions, 0 deletions
diff --git a/xlators/features/quota/src/quota.c b/xlators/features/quota/src/quota.c
index bf0666cb..c7cd7667 100644
--- a/xlators/features/quota/src/quota.c
+++ b/xlators/features/quota/src/quota.c
@@ -3298,6 +3298,59 @@ wind:
return 0;
}
+/* Logs if
+* i. Usage crossed soft limit
+* ii. Usage above soft limit and alert-time timed out
+*/
+void
+quota_log_usage (xlator_t *this, quota_inode_ctx_t *ctx, inode_t *inode,
+ int64_t delta)
+{
+ struct timeval cur_time = {0,};
+ char *usage_str = NULL;
+ char *path = NULL;
+ int64_t cur_size = 0;
+ quota_priv_t *priv = NULL;
+
+ priv = this->private;
+ cur_size = ctx->size + delta;
+ gettimeofday (&cur_time, NULL);
+
+ /* Usage crossed/reached soft limit? */
+ if (DID_REACH_LIMIT (ctx->soft_lim, ctx->size, cur_size)) {
+ ctx->prev_log = cur_time;
+ usage_str = gf_uint64_2human_readable (ctx->soft_lim);
+ inode_path (inode, NULL, &path);
+
+ gf_log (this->name, GF_LOG_ALERT, "Usage crossed soft limit: "
+ "%s for %s", usage_str,
+ path? path: uuid_utoa (inode->gfid));
+ }
+ /* Usage crossed/reached hard limit? */
+ else if (DID_REACH_LIMIT (ctx->hard_lim, ctx->size, cur_size)) {
+ ctx->prev_log = cur_time;
+ usage_str = gf_uint64_2human_readable (ctx->hard_lim);
+ inode_path (inode, NULL, &path);
+
+ gf_log (this->name, GF_LOG_ALERT, "Usage reached hard limit: "
+ "%s for %s", usage_str,
+ path? path: uuid_utoa (inode->gfid));
+ }
+ /* Usage is above soft limit and 'alert-time' timed out */
+ else if (cur_size > ctx->soft_lim &&
+ quota_timeout (&ctx->prev_log, priv->log_timeout)) {
+ ctx->prev_log = cur_time;
+ usage_str = gf_uint64_2human_readable (cur_size);
+ inode_path (inode, NULL, &path);
+
+ gf_log (this->name, GF_LOG_ALERT, "Usage %s %s limit for %s ",
+ usage_str, (cur_size < ctx->hard_lim)?
+ "is above soft": "has reached hard",
+ path? path: uuid_utoa (inode->gfid));
+ }
+ if (usage_str)
+ GF_FREE (usage_str);
+}
int32_t
mem_acct_init (xlator_t *this)
diff --git a/xlators/features/quota/src/quota.h b/xlators/features/quota/src/quota.h
index 84e7f917..3f1458a3 100644
--- a/xlators/features/quota/src/quota.h
+++ b/xlators/features/quota/src/quota.h
@@ -142,6 +142,7 @@ struct quota_inode_ctx {
struct iatt buf;
struct list_head parents;
struct timeval tv;
+ struct timeval prev_log;
gf_lock_t lock;
};
typedef struct quota_inode_ctx quota_inode_ctx_t;
@@ -169,6 +170,7 @@ typedef struct quota_local quota_local_t;
struct quota_priv {
uint32_t soft_timeout;
uint32_t hard_timeout;
+ uint32_t log_timeout;
double default_soft_lim;
gf_boolean_t is_quota_on;
gf_boolean_t consider_statfs;