diff options
author | vmallika <vmallika@redhat.com> | 2015-10-15 12:41:13 +0530 |
---|---|---|
committer | Raghavendra G <rgowdapp@redhat.com> | 2015-11-02 21:03:46 -0800 |
commit | 3d3176958b7da48dbacb1a5a0fedf26322a38297 (patch) | |
tree | 542b4e2ed19dc2dff66317d8f5b99536cce2f3e6 /xlators/features/marker/src/marker-quota.c | |
parent | 0b6f0e09715fb2ba8f86bd80b05d552ae75aeda9 (diff) |
quota: add version to quota xattrs
This is a backport of http://review.gluster.org/#/c/12386/
When a quota is disable and the clean-up process terminated
without completely cleaning-up the quota xattrs.
Now when quota is enabled again, this can mess-up the accounting
A version number is suffixed for all quota xattrs and this version
number is specific to marker xaltor, i.e when quota xattrs are
requested by quotad/client marker will remove the version suffix in the
key before sending the response
> Change-Id: I1ca2c11460645edba0f6b68db70d476d8d26e1eb
> BUG: 1272411
> Signed-off-by: vmallika <vmallika@redhat.com>
> Reviewed-on: http://review.gluster.org/12386
> Tested-by: NetBSD Build System <jenkins@build.gluster.org>
> Reviewed-by: Krishnan Parthasarathi <kparthas@redhat.com>
> Tested-by: Gluster Build System <jenkins@build.gluster.com>
> Reviewed-by: Manikandan Selvaganesh <mselvaga@redhat.com>
> Reviewed-by: Raghavendra G <rgowdapp@redhat.com>
Change-Id: I67b1b930b28411d76b2d476a4e5250c52aa495a0
BUG: 1277080
Signed-off-by: vmallika <vmallika@redhat.com>
Reviewed-on: http://review.gluster.org/12487
Tested-by: NetBSD Build System <jenkins@build.gluster.org>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Raghavendra G <rgowdapp@redhat.com>
Tested-by: Raghavendra G <rgowdapp@redhat.com>
Diffstat (limited to 'xlators/features/marker/src/marker-quota.c')
-rw-r--r-- | xlators/features/marker/src/marker-quota.c | 72 |
1 files changed, 46 insertions, 26 deletions
diff --git a/xlators/features/marker/src/marker-quota.c b/xlators/features/marker/src/marker-quota.c index 645faa445c2..bb65c8787b2 100644 --- a/xlators/features/marker/src/marker-quota.c +++ b/xlators/features/marker/src/marker-quota.c @@ -211,10 +211,12 @@ _quota_dict_get_meta (xlator_t *this, dict_t *dict, char *key, } int32_t -quota_dict_set_size_meta (dict_t *dict, const quota_meta_t *meta) +quota_dict_set_size_meta (xlator_t *this, dict_t *dict, + const quota_meta_t *meta) { - int32_t ret = -ENOMEM; - quota_meta_t *value = NULL; + int32_t ret = -ENOMEM; + quota_meta_t *value = NULL; + char size_key[QUOTA_KEY_MAX] = {0, }; value = GF_CALLOC (2, sizeof (quota_meta_t), gf_common_quota_meta_t); if (value == NULL) { @@ -228,7 +230,10 @@ quota_dict_set_size_meta (dict_t *dict, const quota_meta_t *meta) value[1].file_count = 0; value[1].dir_count = hton64 (1); - ret = dict_set_bin (dict, QUOTA_SIZE_KEY, value, + GET_SIZE_KEY (this, size_key, ret); + if (ret < 0) + goto out; + ret = dict_set_bin (dict, size_key, value, (sizeof (quota_meta_t) * 2)); if (ret < 0) { gf_log_callingfn ("quota", GF_LOG_ERROR, "dict set failed"); @@ -285,7 +290,8 @@ mq_are_xattrs_set (xlator_t *this, loc_t *loc, gf_boolean_t *contri_set, gf_boolean_t *size_set) { int32_t ret = -1; - char contri_key[CONTRI_KEY_MAX] = {0, }; + char contri_key[QUOTA_KEY_MAX] = {0, }; + char size_key[QUOTA_KEY_MAX] = {0, }; quota_meta_t meta = {0, }; struct iatt stbuf = {0,}; dict_t *dict = NULL; @@ -297,7 +303,7 @@ mq_are_xattrs_set (xlator_t *this, loc_t *loc, gf_boolean_t *contri_set, goto out; } - ret = mq_req_xattr (this, loc, dict, contri_key); + ret = mq_req_xattr (this, loc, dict, contri_key, size_key); if (ret < 0) goto out; @@ -316,8 +322,7 @@ mq_are_xattrs_set (xlator_t *this, loc_t *loc, gf_boolean_t *contri_set, *contri_set = _gf_true; *size_set = _gf_true; if (loc->inode->ia_type == IA_IFDIR) { - ret = quota_dict_get_inode_meta (rsp_dict, QUOTA_SIZE_KEY, - &meta); + ret = quota_dict_get_inode_meta (rsp_dict, size_key, &meta); if (ret < 0 || meta.dir_count == 0) *size_set = _gf_false; } @@ -361,7 +366,7 @@ mq_create_size_xattrs (xlator_t *this, quota_inode_ctx_t *ctx, loc_t *loc) goto out; } - ret = quota_dict_set_size_meta (dict, &size); + ret = quota_dict_set_size_meta (this, dict, &size); if (ret < 0) goto out; @@ -582,7 +587,8 @@ _mq_get_metadata (xlator_t *this, loc_t *loc, quota_meta_t *contri, { int32_t ret = -1; quota_meta_t meta = {0, }; - char contri_key[CONTRI_KEY_MAX] = {0, }; + char contri_key[QUOTA_KEY_MAX] = {0, }; + char size_key[QUOTA_KEY_MAX] = {0, }; dict_t *dict = NULL; dict_t *rsp_dict = NULL; struct iatt stbuf = {0,}; @@ -600,7 +606,10 @@ _mq_get_metadata (xlator_t *this, loc_t *loc, quota_meta_t *contri, } if (size && loc->inode->ia_type == IA_IFDIR) { - ret = dict_set_int64 (dict, QUOTA_SIZE_KEY, 0); + GET_SIZE_KEY (this, size_key, ret); + if (ret < 0) + goto out; + ret = dict_set_int64 (dict, size_key, 0); if (ret < 0) { gf_log (this->name, GF_LOG_ERROR, "dict_set failed."); goto out; @@ -625,7 +634,7 @@ _mq_get_metadata (xlator_t *this, loc_t *loc, quota_meta_t *contri, if (size) { if (loc->inode->ia_type == IA_IFDIR) { - ret = quota_dict_get_meta (rsp_dict, QUOTA_SIZE_KEY, + ret = quota_dict_get_meta (rsp_dict, size_key, &meta); if (ret < 0) { gf_log (this->name, GF_LOG_ERROR, @@ -754,9 +763,9 @@ mq_remove_contri (xlator_t *this, loc_t *loc, quota_inode_ctx_t *ctx, inode_contribution_t *contri, quota_meta_t *delta) { int32_t ret = -1; - char contri_key[CONTRI_KEY_MAX] = {0, }; + char contri_key[QUOTA_KEY_MAX] = {0, }; - GET_CONTRI_KEY (contri_key, contri->gfid, ret); + GET_CONTRI_KEY (this, contri_key, contri->gfid, ret); if (ret < 0) { gf_log (this->name, GF_LOG_ERROR, "get contri_key " "failed for %s", uuid_utoa(contri->gfid)); @@ -803,7 +812,7 @@ mq_update_contri (xlator_t *this, loc_t *loc, inode_contribution_t *contri, quota_meta_t *delta) { int32_t ret = -1; - char contri_key[CONTRI_KEY_MAX] = {0, }; + char contri_key[QUOTA_KEY_MAX] = {0, }; dict_t *dict = NULL; GF_VALIDATE_OR_GOTO ("marker", loc, out); @@ -823,7 +832,7 @@ mq_update_contri (xlator_t *this, loc_t *loc, inode_contribution_t *contri, goto out; } - GET_CONTRI_KEY (contri_key, contri->gfid, ret); + GET_CONTRI_KEY (this, contri_key, contri->gfid, ret); if (ret < 0) { gf_log (this->name, GF_LOG_ERROR, "get contri_key " "failed for %s", uuid_utoa(contri->gfid)); @@ -889,7 +898,7 @@ mq_update_size (xlator_t *this, loc_t *loc, quota_meta_t *delta) goto out; } - ret = quota_dict_set_size_meta (dict, delta); + ret = quota_dict_set_size_meta (this, dict, delta); if (ret < 0) goto out; @@ -1800,12 +1809,13 @@ mq_inspect_directory_xattr (xlator_t *this, quota_inode_ctx_t *ctx, inode_contribution_t *contribution, loc_t *loc, dict_t *dict, struct iatt buf) { - int32_t ret = 0; + int32_t ret = -1; int8_t dirty = -1; quota_meta_t size = {0, }; quota_meta_t contri = {0, }; quota_meta_t delta = {0, }; - char contri_key[CONTRI_KEY_MAX] = {0, }; + char contri_key[QUOTA_KEY_MAX] = {0, }; + char size_key[QUOTA_KEY_MAX] = {0, }; gf_boolean_t status = _gf_false; ret = dict_get_int8 (dict, QUOTA_DIRTY_KEY, &dirty); @@ -1817,13 +1827,16 @@ mq_inspect_directory_xattr (xlator_t *this, quota_inode_ctx_t *ctx, dirty = 0; } - ret = _quota_dict_get_meta (this, dict, QUOTA_SIZE_KEY, &size, + GET_SIZE_KEY (this, size_key, ret); + if (ret < 0) + goto out; + ret = _quota_dict_get_meta (this, dict, size_key, &size, IA_IFDIR, _gf_false); if (ret < 0) goto create_xattr; if (!loc_is_root(loc)) { - GET_CONTRI_KEY (contri_key, contribution->gfid, ret); + GET_CONTRI_KEY (this, contri_key, contribution->gfid, ret); if (ret < 0) goto out; @@ -1888,7 +1901,7 @@ mq_inspect_file_xattr (xlator_t *this, quota_inode_ctx_t *ctx, quota_meta_t size = {0, }; quota_meta_t contri = {0, }; quota_meta_t delta = {0, }; - char contri_key[CONTRI_KEY_MAX] = {0, }; + char contri_key[QUOTA_KEY_MAX] = {0, }; gf_boolean_t status = _gf_false; LOCK (&ctx->lock); @@ -1903,7 +1916,7 @@ mq_inspect_file_xattr (xlator_t *this, quota_inode_ctx_t *ctx, } UNLOCK (&ctx->lock); - GET_CONTRI_KEY (contri_key, contribution->gfid, ret); + GET_CONTRI_KEY (this, contri_key, contribution->gfid, ret); if (ret < 0) goto out; @@ -1980,9 +1993,10 @@ out: int32_t mq_req_xattr (xlator_t *this, loc_t *loc, dict_t *dict, - char *contri_key) + char *contri_key, char *size_key) { - int32_t ret = -1; + int32_t ret = -1; + char key[QUOTA_KEY_MAX] = {0, }; GF_VALIDATE_OR_GOTO ("marker", this, out); GF_VALIDATE_OR_GOTO ("marker", loc, out); @@ -1995,7 +2009,13 @@ mq_req_xattr (xlator_t *this, loc_t *loc, dict_t *dict, goto out; } - ret = dict_set_uint64 (dict, QUOTA_SIZE_KEY, 0); + GET_SIZE_KEY (this, key, ret); + if (ret < 0) + goto out; + if (size_key) + strncpy (size_key, key, QUOTA_KEY_MAX); + + ret = dict_set_uint64 (dict, key, 0); if (ret < 0) goto out; |