diff options
Diffstat (limited to 'xlators/features/marker/src/marker-quota-helper.c')
| -rw-r--r-- | xlators/features/marker/src/marker-quota-helper.c | 172 |
1 files changed, 110 insertions, 62 deletions
diff --git a/xlators/features/marker/src/marker-quota-helper.c b/xlators/features/marker/src/marker-quota-helper.c index b6a87698e..af5fed132 100644 --- a/xlators/features/marker/src/marker-quota-helper.c +++ b/xlators/features/marker/src/marker-quota-helper.c @@ -1,21 +1,12 @@ -/*Copyright (c) 2008-2010 Gluster, Inc. <http://www.gluster.com> - This file is part of GlusterFS. - - GlusterFS is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3 of the License, - or (at your option) any later version. - - GlusterFS is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see - <http://www.gnu.org/licenses/>. +/* + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. */ - #ifndef _CONFIG_H #define _CONFIG_H #include "config.h" @@ -28,16 +19,19 @@ #include "marker-mem-types.h" int -quota_loc_fill (loc_t *loc, inode_t *inode, inode_t *parent, char *path) +mq_loc_fill (loc_t *loc, inode_t *inode, inode_t *parent, char *path) { int ret = -1; - if (!loc) - return ret; + GF_VALIDATE_OR_GOTO ("marker", loc, out); + GF_VALIDATE_OR_GOTO ("marker", inode, out); + GF_VALIDATE_OR_GOTO ("marker", path, out); + /* Not checking for parent because while filling + * loc of root, parent will be NULL + */ if (inode) { loc->inode = inode_ref (inode); - loc->ino = inode->ino; } if (parent) @@ -59,13 +53,13 @@ quota_loc_fill (loc_t *loc, inode_t *inode, inode_t *parent, char *path) loc_wipe: if (ret < 0) loc_wipe (loc); - +out: return ret; } int32_t -quota_inode_loc_fill (const char *parent_gfid, inode_t *inode, loc_t *loc) +mq_inode_loc_fill (const char *parent_gfid, inode_t *inode, loc_t *loc) { char *resolvedpath = NULL; inode_t *parent = NULL; @@ -74,7 +68,7 @@ quota_inode_loc_fill (const char *parent_gfid, inode_t *inode, loc_t *loc) if ((!inode) || (!loc)) return ret; - if ((inode) && (inode->ino == 1)) { + if ((inode) && __is_root_gfid (inode->gfid)) { loc->parent = NULL; goto ignore_parent; } @@ -93,7 +87,7 @@ ignore_parent: if (ret < 0) goto err; - ret = quota_loc_fill (loc, inode, parent, resolvedpath); + ret = mq_loc_fill (loc, inode, parent, resolvedpath); if (ret < 0) goto err; @@ -108,7 +102,7 @@ err: quota_inode_ctx_t * -quota_alloc_inode_ctx () +mq_alloc_inode_ctx () { int32_t ret = -1; quota_inode_ctx_t *ctx = NULL; @@ -119,6 +113,7 @@ quota_alloc_inode_ctx () ctx->size = 0; ctx->dirty = 0; + ctx->updation_status = _gf_false; LOCK_INIT (&ctx->lock); INIT_LIST_HEAD (&ctx->contribution_head); out: @@ -126,13 +121,13 @@ out: } inode_contribution_t * -get_contribution_node (inode_t *inode, quota_inode_ctx_t *ctx) +mq_get_contribution_node (inode_t *inode, quota_inode_ctx_t *ctx) { inode_contribution_t *contri = NULL; inode_contribution_t *temp = NULL; - GF_VALIDATE_OR_GOTO ("marker", inode, out); - GF_VALIDATE_OR_GOTO ("marker", ctx, out); + if (!inode || !ctx) + goto out; list_for_each_entry (temp, &ctx->contribution_head, contri_list) { if (uuid_compare (temp->gfid, inode->gfid) == 0) { @@ -146,8 +141,8 @@ out: int32_t -delete_contribution_node (dict_t *dict, char *key, - inode_contribution_t *contribution) +mq_delete_contribution_node (dict_t *dict, char *key, + inode_contribution_t *contribution) { if (dict_get (dict, key) != NULL) goto out; @@ -159,13 +154,25 @@ out: inode_contribution_t * -__add_new_contribution_node (xlator_t *this, quota_inode_ctx_t *ctx, loc_t *loc) +__mq_add_new_contribution_node (xlator_t *this, quota_inode_ctx_t *ctx, loc_t *loc) { int32_t ret = 0; inode_contribution_t *contribution = NULL; + if (!loc->parent) { + if (!uuid_is_null (loc->pargfid)) + loc->parent = inode_find (loc->inode->table, + loc->pargfid); + if (!loc->parent) + loc->parent = inode_parent (loc->inode, loc->pargfid, + loc->name); + if (!loc->parent) + goto out; + } + list_for_each_entry (contribution, &ctx->contribution_head, contri_list) { - if (uuid_compare (contribution->gfid, loc->parent->gfid) == 0) { + if (loc->parent && + uuid_compare (contribution->gfid, loc->parent->gfid) == 0) { goto out; } } @@ -178,6 +185,9 @@ __add_new_contribution_node (xlator_t *this, quota_inode_ctx_t *ctx, loc_t *loc) uuid_copy (contribution->gfid, loc->parent->gfid); + LOCK_INIT (&contribution->lock); + INIT_LIST_HEAD (&contribution->contri_list); + list_add_tail (&contribution->contri_list, &ctx->contribution_head); out: @@ -186,11 +196,11 @@ out: inode_contribution_t * -add_new_contribution_node (xlator_t *this, quota_inode_ctx_t *ctx, loc_t *loc) +mq_add_new_contribution_node (xlator_t *this, quota_inode_ctx_t *ctx, loc_t *loc) { inode_contribution_t *contribution = NULL; - if (ctx == NULL || loc == NULL) + if ((ctx == NULL) || (loc == NULL)) return NULL; if (strcmp (loc->path, "/") == 0) @@ -198,7 +208,7 @@ add_new_contribution_node (xlator_t *this, quota_inode_ctx_t *ctx, loc_t *loc) LOCK (&ctx->lock); { - contribution = __add_new_contribution_node (this, ctx, loc); + contribution = __mq_add_new_contribution_node (this, ctx, loc); } UNLOCK (&ctx->lock); @@ -207,12 +217,17 @@ add_new_contribution_node (xlator_t *this, quota_inode_ctx_t *ctx, loc_t *loc) int32_t -dict_set_contribution (xlator_t *this, dict_t *dict, - loc_t *loc) +mq_dict_set_contribution (xlator_t *this, dict_t *dict, + loc_t *loc) { int32_t ret = -1; char contri_key [512] = {0, }; + GF_VALIDATE_OR_GOTO ("marker", this, out); + GF_VALIDATE_OR_GOTO ("marker", dict, out); + GF_VALIDATE_OR_GOTO ("marker", loc, out); + GF_VALIDATE_OR_GOTO ("marker", loc->parent, out); + GET_CONTRI_KEY (contri_key, loc->parent->gfid, ret); if (ret < 0) { ret = -1; @@ -222,7 +237,8 @@ dict_set_contribution (xlator_t *this, dict_t *dict, ret = dict_set_int64 (dict, contri_key, 0); if (ret < 0) { gf_log (this->name, GF_LOG_WARNING, - "unable to set dict value."); + "unable to set dict value on %s.", + loc->path); goto out; } @@ -233,8 +249,8 @@ out: int32_t -quota_inode_ctx_get (inode_t *inode, xlator_t *this, - quota_inode_ctx_t **ctx) +mq_inode_ctx_get (inode_t *inode, xlator_t *this, + quota_inode_ctx_t **ctx) { int32_t ret = -1; uint64_t ctx_int = 0; @@ -251,7 +267,7 @@ quota_inode_ctx_get (inode_t *inode, xlator_t *this, goto out; } - mark_ctx = (marker_inode_ctx_t *) ctx_int; + mark_ctx = (marker_inode_ctx_t *) (unsigned long)ctx_int; if (mark_ctx->quota_ctx == NULL) { ret = -1; goto out; @@ -267,7 +283,7 @@ out: quota_inode_ctx_t * -__quota_inode_ctx_new (inode_t *inode, xlator_t *this) +__mq_inode_ctx_new (inode_t *inode, xlator_t *this) { int32_t ret = -1; quota_inode_ctx_t *quota_ctx = NULL; @@ -283,48 +299,43 @@ __quota_inode_ctx_new (inode_t *inode, xlator_t *this) LOCK (&inode->lock); { if (mark_ctx->quota_ctx == NULL) { - quota_ctx = quota_alloc_inode_ctx (); + quota_ctx = mq_alloc_inode_ctx (); if (quota_ctx == NULL) { ret = -1; goto unlock; } mark_ctx->quota_ctx = quota_ctx; - } else + } else { quota_ctx = mark_ctx->quota_ctx; + } ret = 0; } -unlock: UNLOCK (&inode->lock); - +unlock: + UNLOCK (&inode->lock); out: return quota_ctx; } quota_inode_ctx_t * -quota_inode_ctx_new (inode_t * inode, xlator_t *this) +mq_inode_ctx_new (inode_t * inode, xlator_t *this) { - return __quota_inode_ctx_new (inode, this); + return __mq_inode_ctx_new (inode, this); } quota_local_t * -quota_local_new () +mq_local_new () { - int32_t ret = -1; quota_local_t *local = NULL; - QUOTA_ALLOC (local, quota_local_t, ret); - if (ret < 0) + local = mem_get0 (THIS->local_pool); + if (!local) goto out; local->ref = 1; - local->delta = 0; - local->err = 0; LOCK_INIT (&local->lock); - memset (&local->loc, 0, sizeof (loc_t)); - memset (&local->parent_loc, 0, sizeof (loc_t)); - local->ctx = NULL; local->contri = NULL; @@ -333,7 +344,7 @@ out: } quota_local_t * -quota_local_ref (quota_local_t *local) +mq_local_ref (quota_local_t *local) { LOCK (&local->lock); { @@ -346,21 +357,58 @@ quota_local_ref (quota_local_t *local) int32_t -quota_local_unref (xlator_t *this, quota_local_t *local) +mq_local_unref (xlator_t *this, quota_local_t *local) { + int32_t ref = 0; if (local == NULL) goto out; - QUOTA_SAFE_DECREMENT (&local->lock, local->ref); + QUOTA_SAFE_DECREMENT (&local->lock, local->ref, ref); - if (local->ref > 0) + if (ref != 0) goto out; + if (local->fd != NULL) + fd_unref (local->fd); + loc_wipe (&local->loc); loc_wipe (&local->parent_loc); LOCK_DESTROY (&local->lock); + + mem_put (local); out: return 0; } + + +inode_contribution_t * +mq_get_contribution_from_loc (xlator_t *this, loc_t *loc) +{ + int32_t ret = 0; + quota_inode_ctx_t *ctx = NULL; + inode_contribution_t *contribution = NULL; + + ret = mq_inode_ctx_get (loc->inode, this, &ctx); + if (ret < 0) { + gf_log_callingfn (this->name, GF_LOG_WARNING, + "cannot get marker-quota context from inode " + "(gfid:%s, path:%s)", + uuid_utoa (loc->inode->gfid), loc->path); + goto err; + } + + contribution = mq_get_contribution_node (loc->parent, ctx); + if (contribution == NULL) { + gf_log_callingfn (this->name, GF_LOG_WARNING, + "inode (gfid:%s, path:%s) has " + "no contribution towards parent (gfid:%s)", + uuid_utoa (loc->inode->gfid), + loc->path, uuid_utoa (loc->parent->gfid)); + goto err; + } + +err: + return contribution; +} |
