summaryrefslogtreecommitdiffstats
path: root/xlators/features/quota/src/quota.c
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/features/quota/src/quota.c')
-rw-r--r--xlators/features/quota/src/quota.c105
1 files changed, 84 insertions, 21 deletions
diff --git a/xlators/features/quota/src/quota.c b/xlators/features/quota/src/quota.c
index a531ab123..5cbd9f02d 100644
--- a/xlators/features/quota/src/quota.c
+++ b/xlators/features/quota/src/quota.c
@@ -879,8 +879,7 @@ quota_fill_inodectx (xlator_t *this, inode_t *inode, dict_t *dict,
ctx = (quota_inode_ctx_t *)(unsigned long)value;
if ((((ctx == NULL) || (ctx->hard_lim == hard_lim))
- && (hard_lim < 0) && !((IA_ISREG (buf->ia_type))
- || (IA_ISLNK (buf->ia_type))))) {
+ && (hard_lim < 0) && !QUOTA_REG_OR_LNK_FILE (buf->ia_type))) {
ret = 0;
goto out;
}
@@ -902,7 +901,7 @@ quota_fill_inodectx (xlator_t *this, inode_t *inode, dict_t *dict,
ctx->buf = *buf;
- if (!(IA_ISREG (buf->ia_type) || IA_ISLNK (buf->ia_type))) {
+ if (!QUOTA_REG_OR_LNK_FILE (buf->ia_type)) {
goto unlock;
}
@@ -1869,8 +1868,7 @@ quota_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
goto out;
}
- if (IA_ISREG (local->oldloc.inode->ia_type)
- || IA_ISLNK (local->oldloc.inode->ia_type)) {
+ if (QUOTA_REG_OR_LNK_FILE (local->oldloc.inode->ia_type)) {
size = buf->ia_blocks * 512;
}
@@ -1881,8 +1879,7 @@ quota_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
size);
}
- if (!(IA_ISREG (local->oldloc.inode->ia_type)
- || IA_ISLNK (local->oldloc.inode->ia_type))) {
+ if (!QUOTA_REG_OR_LNK_FILE (local->oldloc.inode->ia_type)) {
goto out;
}
@@ -1997,6 +1994,46 @@ unwind:
}
+static int32_t
+quota_rename_get_size_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, inode_t *inode,
+ struct iatt *buf, dict_t *xdata,
+ struct iatt *postparent)
+{
+ quota_local_t *local = NULL;
+ int32_t ret = 0;
+ int64_t *size = 0;
+
+ GF_ASSERT (frame);
+ GF_VALIDATE_OR_GOTO_WITH_ERROR ("quota", this, out, op_errno,
+ EINVAL);
+ GF_VALIDATE_OR_GOTO_WITH_ERROR (this->name, xdata, out, op_errno,
+ EINVAL);
+ local = frame->local;
+ GF_ASSERT (local);
+ local->link_count = 1;
+
+ if (op_ret < 0)
+ goto out;
+
+
+ ret = dict_get_bin (xdata, QUOTA_SIZE_KEY, (void **) &size);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_WARNING,
+ "size key not present in dict");
+ op_errno = EINVAL;
+ goto out;
+ }
+ local->delta = ntoh64 (*size);
+ quota_check_limit (frame, local->newloc.parent, this,
+ NULL, NULL);
+ return 0;
+
+out:
+ quota_handle_validate_error (local, -1, op_errno);
+ return 0;
+}
+
int32_t
quota_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc,
loc_t *newloc, dict_t *xdata)
@@ -2039,8 +2076,7 @@ quota_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc,
local->link_count = 1;
local->stub = stub;
- if (IA_ISREG (oldloc->inode->ia_type)
- || IA_ISLNK (oldloc->inode->ia_type)) {
+ if (QUOTA_REG_OR_LNK_FILE (oldloc->inode->ia_type)) {
ret = quota_inode_ctx_get (oldloc->inode, this, &ctx, 0);
if (ctx == NULL) {
gf_log (this->name, GF_LOG_WARNING,
@@ -2050,11 +2086,32 @@ quota_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc,
oldloc->inode ? uuid_utoa (oldloc->inode->gfid)
: "0");
local->delta = 0;
+
} else {
- local->delta = ctx->buf.ia_blocks * 512;
+
+ /* FIXME: We need to account for the size occupied by this
+ * inode on the target directory. To avoid double
+ * accounting, we need to modify enforcer to perform
+ * quota_check_limit only uptil the least common ancestor
+ * directory inode*/
+
+ /* FIXME: The following code assumes that regular files and
+ *linkfiles are present, in their entirety, in a single
+ brick. This *assumption is invalid in the case of
+ stripe.*/
+
+ local->delta = ctx->buf.ia_blocks * 512;
}
- } else {
- local->delta = 0;
+
+ } else if (IA_ISDIR (oldloc->inode->ia_type)) {
+ ret = quota_validate (frame, oldloc->inode, this,
+ quota_rename_get_size_cbk);
+ if (ret){
+ op_errno = -ret;
+ goto err;
+ }
+
+ return 0;
}
quota_check_limit (frame, newloc->parent, this, NULL, NULL);
@@ -3461,13 +3518,13 @@ quota_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
if (ctx->hard_lim <= 0) {
inode_ctx_get (inode->table->root, this, &value);
ctx = (quota_inode_ctx_t *)(unsigned long) value;
- if (!ctx)
+ if (!ctx || ctx->hard_lim < 0)
goto unwind;
}
- usage = (ctx->size) / buf->f_bsize;
+ { /* statfs is adjusted in this code block */
+ usage = (ctx->size) / buf->f_bsize;
- if (ctx->hard_lim > 0) {
blocks = ctx->hard_lim / buf->f_bsize;
buf->f_blocks = blocks;
@@ -3935,7 +3992,7 @@ wind:
/* Logs if
* i. Usage crossed soft limit
-* ii. Usage above soft limit and alert-time timed out
+* ii. Usage above soft limit and alert-time elapsed
*/
void
quota_log_usage (xlator_t *this, quota_inode_ctx_t *ctx, inode_t *inode,
@@ -3943,39 +4000,45 @@ 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;
priv = this->private;
- cur_size = ctx->size + delta;
if ((ctx->soft_lim <= 0) || (timerisset (&ctx->prev_log) &&
!quota_timeout (&ctx->prev_log,
priv->log_timeout))) {
return;
}
- gettimeofday (&cur_time, NULL);
- ctx->prev_log = cur_time;
+ 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;
+ }
inode_path (inode, NULL, &path);
if (!path)
path = uuid_utoa (inode->gfid);
+ gettimeofday (&cur_time, NULL);
/* Usage crossed/reached soft limit */
if (DID_REACH_LIMIT (ctx->soft_lim, ctx->size, cur_size)) {
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){
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 (usage_str)
- GF_FREE (usage_str);
+
+ GF_FREE (usage_str);
}
int32_t