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