7f4c2a
From 2f31a7673b559f7764f9bb44a89e161cb4242711 Mon Sep 17 00:00:00 2001
7f4c2a
From: vmallika <vmallika@redhat.com>
7f4c2a
Date: Thu, 9 Jul 2015 15:14:14 +0530
7f4c2a
Subject: [PATCH 220/234] quota/marker: fix mem leak in marker
7f4c2a
7f4c2a
This is a backport of http://review.gluster.org/#/c/11457/
7f4c2a
Part of the fix is available in:
7f4c2a
https://code.engineering.redhat.com/gerrit/#/c/52303/
7f4c2a
7f4c2a
This patch optimizes the me consumption.
7f4c2a
create syntask txn only for linked inodes
7f4c2a
7f4c2a
Change-Id: I2f9eefc115ce36b3fac29746655fa3c8cecbbcab
7f4c2a
BUG: 1224177
7f4c2a
Signed-off-by: vmallika <vmallika@redhat.com>
7f4c2a
Reviewed-on: https://code.engineering.redhat.com/gerrit/52658
7f4c2a
Reviewed-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
7f4c2a
Tested-by: Raghavendra Gowdappa <rgowdapp@redhat.com>
7f4c2a
---
7f4c2a
 xlators/features/marker/src/marker-quota.c |  161 +++++++++++++++++-----------
7f4c2a
 1 files changed, 96 insertions(+), 65 deletions(-)
7f4c2a
7f4c2a
diff --git a/xlators/features/marker/src/marker-quota.c b/xlators/features/marker/src/marker-quota.c
7f4c2a
index 97946f8..400e9ae 100644
7f4c2a
--- a/xlators/features/marker/src/marker-quota.c
7f4c2a
+++ b/xlators/features/marker/src/marker-quota.c
7f4c2a
@@ -2841,6 +2841,49 @@ out:
7f4c2a
         return ret;
7f4c2a
 }
7f4c2a
 
7f4c2a
+int32_t
7f4c2a
+mq_prevalidate_txn (xlator_t *this, loc_t *origin_loc, loc_t *loc,
7f4c2a
+                    quota_inode_ctx_t **ctx)
7f4c2a
+{
7f4c2a
+        int32_t               ret     = -1;
7f4c2a
+        quota_inode_ctx_t    *ctxtmp  = NULL;
7f4c2a
+
7f4c2a
+        if (origin_loc == NULL || origin_loc->inode == NULL ||
7f4c2a
+            (gf_uuid_is_null(origin_loc->gfid) &&
7f4c2a
+             gf_uuid_is_null(origin_loc->inode->gfid)))
7f4c2a
+                goto out;
7f4c2a
+
7f4c2a
+        loc_copy (loc, origin_loc);
7f4c2a
+
7f4c2a
+        if (gf_uuid_is_null (loc->gfid))
7f4c2a
+                gf_uuid_copy (loc->gfid, loc->inode->gfid);
7f4c2a
+
7f4c2a
+        if (ctx)
7f4c2a
+                ret = mq_inode_ctx_get (loc->inode, this, ctx);
7f4c2a
+        else
7f4c2a
+                ret = mq_inode_ctx_get (loc->inode, this, &ctxtmp);
7f4c2a
+
7f4c2a
+        if (ret < 0) {
7f4c2a
+                if (ctx) {
7f4c2a
+                        *ctx = mq_inode_ctx_new (loc->inode, this);
7f4c2a
+                        if (*ctx == NULL) {
7f4c2a
+                                gf_log_callingfn (this->name, GF_LOG_WARNING,
7f4c2a
+                                                  "mq_inode_ctx_new failed for "
7f4c2a
+                                                  "%s", loc->path);
7f4c2a
+                                ret = -1;
7f4c2a
+                                goto out;
7f4c2a
+                        }
7f4c2a
+                } else {
7f4c2a
+                        gf_log_callingfn (this->name, GF_LOG_WARNING, "ctx for "
7f4c2a
+                                          "is NULL for %s", loc->path);
7f4c2a
+                }
7f4c2a
+        }
7f4c2a
+
7f4c2a
+        ret = 0;
7f4c2a
+out:
7f4c2a
+        return ret;
7f4c2a
+}
7f4c2a
+
7f4c2a
 int
7f4c2a
 mq_start_quota_txn_v2 (xlator_t *this, loc_t *loc, quota_inode_ctx_t *ctx,
7f4c2a
                        inode_contribution_t *contri)
7f4c2a
@@ -2866,16 +2909,6 @@ mq_start_quota_txn_v2 (xlator_t *this, loc_t *loc, quota_inode_ctx_t *ctx,
7f4c2a
                 goto out;
7f4c2a
         }
7f4c2a
 
7f4c2a
-        if (gf_uuid_is_null (child_loc.gfid))
7f4c2a
-                gf_uuid_copy (child_loc.gfid, child_loc.inode->gfid);
7f4c2a
-
7f4c2a
-        if (gf_uuid_is_null (child_loc.gfid)) {
7f4c2a
-                ret = -1;
7f4c2a
-                gf_log (this->name, GF_LOG_DEBUG, "UUID is null for %s",
7f4c2a
-                        child_loc.path);
7f4c2a
-                goto out;
7f4c2a
-        }
7f4c2a
-
7f4c2a
         while (!__is_root_gfid (child_loc.gfid)) {
7f4c2a
                 /* To improve performance, abort current transaction
7f4c2a
                  * if one is already in progress for same inode
7f4c2a
@@ -3005,16 +3038,6 @@ mq_create_xattrs_task (void *opaque)
7f4c2a
         this = args->this;
7f4c2a
         THIS = this;
7f4c2a
 
7f4c2a
-        if (gf_uuid_is_null (loc->gfid))
7f4c2a
-                gf_uuid_copy (loc->gfid, loc->inode->gfid);
7f4c2a
-
7f4c2a
-        if (gf_uuid_is_null (loc->gfid)) {
7f4c2a
-                ret = -1;
7f4c2a
-                gf_log (this->name, GF_LOG_DEBUG, "UUID is null for %s",
7f4c2a
-                        loc->path);
7f4c2a
-                goto out;
7f4c2a
-        }
7f4c2a
-
7f4c2a
         ret = mq_inode_ctx_get (loc->inode, this, &ctx;;
7f4c2a
         if (ret < 0) {
7f4c2a
                 gf_log (this->name, GF_LOG_WARNING, "Failed to"
7f4c2a
@@ -3056,34 +3079,30 @@ out:
7f4c2a
 }
7f4c2a
 
7f4c2a
 static int
7f4c2a
-_mq_create_xattrs_txn (xlator_t *this, loc_t *loc, gf_boolean_t spawn)
7f4c2a
+_mq_create_xattrs_txn (xlator_t *this, loc_t *origin_loc, gf_boolean_t spawn)
7f4c2a
 {
7f4c2a
         int32_t                  ret        = -1;
7f4c2a
         quota_inode_ctx_t       *ctx        = NULL;
7f4c2a
         gf_boolean_t             status     = _gf_true;
7f4c2a
+        loc_t                    loc        = {0, };
7f4c2a
 
7f4c2a
-        ret = mq_inode_ctx_get (loc->inode, this, &ctx;;
7f4c2a
-        if (ret < 0) {
7f4c2a
-                ctx = mq_inode_ctx_new (loc->inode, this);
7f4c2a
-                if (ctx == NULL) {
7f4c2a
-                        gf_log (this->name, GF_LOG_WARNING,
7f4c2a
-                                "mq_inode_ctx_new failed");
7f4c2a
-                        ret = -1;
7f4c2a
-                        goto out;
7f4c2a
-                }
7f4c2a
-        }
7f4c2a
+        ret = mq_prevalidate_txn (this, origin_loc, &loc, &ctx;;
7f4c2a
+        if (ret < 0)
7f4c2a
+                goto out;
7f4c2a
 
7f4c2a
         ret = mq_test_and_set_ctx_create_status (ctx, &status);
7f4c2a
         if (ret < 0 || status == _gf_true)
7f4c2a
                 goto out;
7f4c2a
 
7f4c2a
-        ret = mq_synctask (this, mq_create_xattrs_task, spawn, loc, 0);
7f4c2a
+        ret = mq_synctask (this, mq_create_xattrs_task, spawn, &loc, 0);
7f4c2a
 out:
7f4c2a
         if (ret < 0 && status == _gf_false)
7f4c2a
                 mq_set_ctx_create_status (ctx, _gf_false);
7f4c2a
 
7f4c2a
+        loc_wipe (&loc;;
7f4c2a
         return ret;
7f4c2a
 }
7f4c2a
+
7f4c2a
 int
7f4c2a
 mq_create_xattrs_txn (xlator_t *this, loc_t *loc)
7f4c2a
 {
7f4c2a
@@ -3237,17 +3256,33 @@ out:
7f4c2a
 }
7f4c2a
 
7f4c2a
 int32_t
7f4c2a
-mq_reduce_parent_size_txn (xlator_t *this, loc_t *loc, int64_t contri)
7f4c2a
+mq_reduce_parent_size_txn (xlator_t *this, loc_t *origin_loc, int64_t contri)
7f4c2a
 {
7f4c2a
         int32_t                  ret           = -1;
7f4c2a
+        loc_t                    loc           = {0, };
7f4c2a
 
7f4c2a
         GF_VALIDATE_OR_GOTO ("marker", this, out);
7f4c2a
-        GF_VALIDATE_OR_GOTO ("marker", loc, out);
7f4c2a
-        GF_VALIDATE_OR_GOTO ("marker", loc->inode, out);
7f4c2a
+        GF_VALIDATE_OR_GOTO ("marker", origin_loc, out);
7f4c2a
+
7f4c2a
+        ret = mq_prevalidate_txn (this, origin_loc, &loc, NULL);
7f4c2a
+        if (ret < 0)
7f4c2a
+                goto out;
7f4c2a
+
7f4c2a
+        if (loc_is_root(&loc)) {
7f4c2a
+                ret = 0;
7f4c2a
+                goto out;
7f4c2a
+        }
7f4c2a
 
7f4c2a
-        ret = mq_synctask (this, mq_reduce_parent_size_task, _gf_true, loc,
7f4c2a
+        if (loc.parent == NULL) {
7f4c2a
+                gf_log (this->name, GF_LOG_WARNING, "parent is NULL for %s, "
7f4c2a
+                        "aborting reduce parent size txn", loc.path);
7f4c2a
+                goto out;
7f4c2a
+        }
7f4c2a
+
7f4c2a
+        ret = mq_synctask (this, mq_reduce_parent_size_task, _gf_true, &loc,
7f4c2a
                            contri);
7f4c2a
 out:
7f4c2a
+        loc_wipe (&loc;;
7f4c2a
         return ret;
7f4c2a
 }
7f4c2a
 
7f4c2a
@@ -3325,16 +3360,25 @@ out:
7f4c2a
 }
7f4c2a
 
7f4c2a
 int
7f4c2a
-_mq_initiate_quota_txn (xlator_t *this, loc_t *loc, gf_boolean_t spawn)
7f4c2a
+_mq_initiate_quota_txn (xlator_t *this, loc_t *origin_loc, gf_boolean_t spawn)
7f4c2a
 {
7f4c2a
         int32_t                 ret          = -1;
7f4c2a
         quota_inode_ctx_t      *ctx          = NULL;
7f4c2a
         gf_boolean_t            status       = _gf_true;
7f4c2a
+        loc_t                   loc          = {0,};
7f4c2a
 
7f4c2a
-        ret = mq_inode_ctx_get (loc->inode, this, &ctx;;
7f4c2a
-        if (ret == -1) {
7f4c2a
-                gf_log (this->name, GF_LOG_WARNING,
7f4c2a
-                        "inode ctx get failed, aborting quota txn");
7f4c2a
+        ret = mq_prevalidate_txn (this, origin_loc, &loc, &ctx;;
7f4c2a
+        if (ret < 0)
7f4c2a
+                goto out;
7f4c2a
+
7f4c2a
+        if (loc_is_root(&loc)) {
7f4c2a
+                ret = 0;
7f4c2a
+                goto out;
7f4c2a
+        }
7f4c2a
+
7f4c2a
+        if (loc.parent == NULL) {
7f4c2a
+                gf_log (this->name, GF_LOG_WARNING, "parent is NULL for %s, "
7f4c2a
+                        "aborting updation txn", loc.path);
7f4c2a
                 goto out;
7f4c2a
         }
7f4c2a
 
7f4c2a
@@ -3342,12 +3386,13 @@ _mq_initiate_quota_txn (xlator_t *this, loc_t *loc, gf_boolean_t spawn)
7f4c2a
         if (ret < 0 || status == _gf_true)
7f4c2a
                 goto out;
7f4c2a
 
7f4c2a
-        ret = mq_synctask (this, mq_initiate_quota_task, spawn, loc, 0);
7f4c2a
+        ret = mq_synctask (this, mq_initiate_quota_task, spawn, &loc, 0);
7f4c2a
 
7f4c2a
 out:
7f4c2a
         if (ret < 0 && status == _gf_false)
7f4c2a
                 mq_set_ctx_updation_status (ctx, _gf_false);
7f4c2a
 
7f4c2a
+        loc_wipe (&loc;;
7f4c2a
         return ret;
7f4c2a
 }
7f4c2a
 
7f4c2a
@@ -3407,16 +3452,6 @@ mq_update_dirty_inode_task (void *opaque)
7f4c2a
         this = args->this;
7f4c2a
         THIS = this;
7f4c2a
 
7f4c2a
-        if (gf_uuid_is_null (loc->gfid))
7f4c2a
-                gf_uuid_copy (loc->gfid, loc->inode->gfid);
7f4c2a
-
7f4c2a
-        if (gf_uuid_is_null (loc->gfid)) {
7f4c2a
-                ret = -1;
7f4c2a
-                gf_log (this->name, GF_LOG_DEBUG, "UUID is null for %s",
7f4c2a
-                        loc->path);
7f4c2a
-                goto out;
7f4c2a
-        }
7f4c2a
-
7f4c2a
         ret = mq_lock (this, loc, F_WRLCK);
7f4c2a
         if (ret < 0)
7f4c2a
                 goto out;
7f4c2a
@@ -3707,29 +3742,25 @@ out:
7f4c2a
 }
7f4c2a
 
7f4c2a
 int32_t
7f4c2a
-mq_xattr_state (xlator_t *this, loc_t *loc, dict_t *dict, struct iatt buf)
7f4c2a
+mq_xattr_state (xlator_t *this, loc_t *origin_loc, dict_t *dict,
7f4c2a
+                struct iatt buf)
7f4c2a
 {
7f4c2a
         int32_t               ret     = -1;
7f4c2a
         quota_inode_ctx_t    *ctx     = NULL;
7f4c2a
+        loc_t                 loc     = {0, };
7f4c2a
 
7f4c2a
-        ret = mq_inode_ctx_get (loc->inode, this, &ctx;;
7f4c2a
-        if (ret < 0) {
7f4c2a
-                ctx = mq_inode_ctx_new (loc->inode, this);
7f4c2a
-                if (ctx == NULL) {
7f4c2a
-                        gf_log (this->name, GF_LOG_WARNING,
7f4c2a
-                                "mq_inode_ctx_new failed");
7f4c2a
-                        ret = -1;
7f4c2a
-                        goto out;
7f4c2a
-                }
7f4c2a
-        }
7f4c2a
+        ret = mq_prevalidate_txn (this, origin_loc, &loc, &ctx;;
7f4c2a
+        if (ret < 0)
7f4c2a
+                goto out;
7f4c2a
 
7f4c2a
         if (((buf.ia_type == IA_IFREG) && !dht_is_linkfile (&buf, dict))
7f4c2a
             || (buf.ia_type == IA_IFLNK))  {
7f4c2a
-                mq_inspect_file_xattr (this, ctx, loc, dict, buf);
7f4c2a
+                mq_inspect_file_xattr (this, ctx, &loc, dict, buf);
7f4c2a
         } else if (buf.ia_type == IA_IFDIR)
7f4c2a
-                mq_inspect_directory_xattr (this, loc, ctx, dict, buf);
7f4c2a
+                mq_inspect_directory_xattr (this, &loc, ctx, dict, buf);
7f4c2a
 
7f4c2a
 out:
7f4c2a
+        loc_wipe (&loc;;
7f4c2a
         return ret;
7f4c2a
 }
7f4c2a
 
7f4c2a
-- 
7f4c2a
1.7.1
7f4c2a