diff options
-rw-r--r-- | libglusterfs/src/glusterfs.h | 3 | ||||
-rw-r--r-- | xlators/features/quota/src/quota.c | 72 | ||||
-rw-r--r-- | xlators/features/quota/src/quota.h | 5 |
3 files changed, 34 insertions, 46 deletions
diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h index 3985e004..50620573 100644 --- a/libglusterfs/src/glusterfs.h +++ b/libglusterfs/src/glusterfs.h @@ -114,8 +114,7 @@ #define GLUSTERFS_PARENT_ENTRYLK "glusterfs.parent-entrylk" #define GLUSTERFS_INODELK_DOM_COUNT "glusterfs.inodelk-dom-count" #define QUOTA_SIZE_KEY "trusted.glusterfs.quota.size" -#define QUOTA_HARD_LIMIT_KEY "trusted.glusterfs.quota.hard-limit" -#define QUOTA_SOFT_LIMIT_KEY "trusted.glusterfs.quota.soft-limit" +#define QUOTA_LIMIT_KEY "trusted.glusterfs.quota.limit-set" #define GFID_TO_PATH_KEY "glusterfs.gfid2path" #define GF_XATTR_STIME_PATTERN "trusted.glusterfs.*.stime" diff --git a/xlators/features/quota/src/quota.c b/xlators/features/quota/src/quota.c index 94f3183c..85ee3718 100644 --- a/xlators/features/quota/src/quota.c +++ b/xlators/features/quota/src/quota.c @@ -16,6 +16,7 @@ int32_t quota_check_limit (call_frame_t *frame, inode_t *inode, xlator_t *this, char *name, uuid_t par); + struct volume_options options[]; @@ -605,22 +606,20 @@ quota_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, quota_dentry_t *dentry = NULL; uint64_t value = 0; int64_t *size = NULL; - int64_t hard_lim = -1, soft_lim = -1, *ptr = NULL; + quota_limit_t *limit = NULL; + int64_t hard_lim = -1, soft_lim_percent = -1, *ptr = NULL; quota_local_t *local = NULL; if (op_ret < 0) goto unwind; if (dict != NULL) { - ret = dict_get_bin (dict, QUOTA_SOFT_LIMIT_KEY, (void **) &ptr); - if (ptr != NULL) { - soft_lim = ntoh64 (*ptr); - } + ret = dict_get_bin (dict, QUOTA_LIMIT_KEY, (void **) &ptr); + limit = ptr; - ptr = NULL; - ret = dict_get_bin (dict, QUOTA_HARD_LIMIT_KEY, (void **) &ptr); - if (ptr != NULL) { - hard_lim = ntoh64 (*ptr); + if (limit) { + hard_lim = ntoh64 (limit->hard_lim); + soft_lim_percent = ntoh64 (limit->soft_lim_percent); } } @@ -630,8 +629,8 @@ quota_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, 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) && !((IA_ISREG (buf->ia_type)) + || (IA_ISLNK (buf->ia_type))))) { goto unwind; } @@ -649,17 +648,11 @@ quota_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, LOCK (&ctx->lock); { ctx->hard_lim = hard_lim; - ctx->soft_lim = soft_lim; + ctx->soft_lim = (hard_lim > 0) ? + (soft_lim_percent * hard_lim)/100 : -1; ctx->buf = *buf; - /* will be useful for quotad to determine whether quota xlator's - context is maintaining the correct size. - */ - size = GF_CALLOC (1, sizeof (*size), gf_quota_mt_int64_t); - *size = hton64 (ctx->size); - ret = dict_set_bin (dict, "trusted.limit.set", size, 8); - if (!(IA_ISREG (buf->ia_type) || IA_ISLNK (buf->ia_type))) { goto unlock; } @@ -682,7 +675,7 @@ quota_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, local->loc.parent->gfid); if (dentry == NULL) { /* - gf_log (this->name, GF_LOG_WARNING, + gf_log (this->name, GF_LOG_WARNING, "cannot create a new dentry (par:%" PRId64", name:%s) for inode(ino:%" PRId64", gfid:%s)", @@ -716,34 +709,25 @@ quota_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, WIND_IF_QUOTAOFF (priv->is_quota_on, wind); - if (priv->is_quota_on) { - local = quota_local_new (); - if (local == NULL) { - goto err; - } - - frame->local = local; - loc_copy (&local->loc, loc); + local = quota_local_new (); + if (local == NULL) { + goto err; + } - if (xattr_req == NULL) { - xattr_req = dict_new (); - if (xattr_req == NULL) - goto err; - } + frame->local = local; + loc_copy (&local->loc, loc); - ret = dict_set_int8 (xattr_req, QUOTA_HARD_LIMIT_KEY, 1); - if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, - "dict set of key for hard-limit failed"); + if (xattr_req == NULL) { + xattr_req = dict_new (); + if (xattr_req == NULL) goto err; - } + } - ret = dict_set_int8 (xattr_req, QUOTA_SOFT_LIMIT_KEY, 1); - if (ret < 0) { - gf_log (this->name, GF_LOG_WARNING, - "dict set of key for soft-limit failed"); - goto err; - } + ret = dict_set_int8 (xattr_req, QUOTA_LIMIT_KEY, 1); + if (ret < 0) { + gf_log (this->name, GF_LOG_WARNING, + "dict set of key for hard-limit failed"); + goto err; } wind: diff --git a/xlators/features/quota/src/quota.h b/xlators/features/quota/src/quota.h index 3f1458a3..c4d5c6ad 100644 --- a/xlators/features/quota/src/quota.h +++ b/xlators/features/quota/src/quota.h @@ -184,6 +184,11 @@ struct quota_priv { }; typedef struct quota_priv quota_priv_t; +typedef struct quota_limit { + int64_t hard_lim; + int64_t soft_lim_percent; +} quota_limit_t __attribute__ ((packed)); + int quota_enforcer_lookup (call_frame_t *frame, xlator_t *this, loc_t *loc, dict_t *xdata, fop_lookup_cbk_t cbk); |