summaryrefslogtreecommitdiffstats
path: root/api/src
diff options
context:
space:
mode:
authorPoornima G <pgurusid@redhat.com>2016-03-19 04:38:47 -0400
committerPranith Kumar Karampuri <pkarampu@redhat.com>2016-03-22 22:47:31 -0700
commit7fb3abaeae763b99ef387804b46943051ac6cbbc (patch)
tree2480b7193d39d8967d2a176143dac333c3863122 /api/src
parentafbdcda3f4d6ffb906976064e0fa6f6b824718c8 (diff)
gfapi: Fix the crashes caused by global_xlator and THIS
Issue: http://thread.gmane.org/gmane.comp.file-systems.gluster.devel/10922 The right fix for this is elaborate and intrusive, until it is in place, this patch provides a temperory fix. This fix is necessary, as without this libgfapi applications like qemu, samba, NFS ganesha are prone to crashes. This patch will be reverted completely, once the actual fix gets accepted. Change-Id: Ic975ab0bb03ba415cdf9bddba1534ba4d2d2820c BUG: 1319374 Signed-off-by: Poornima G <pgurusid@redhat.com> Reviewed-on: http://review.gluster.org/13784 Smoke: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Shyamsundar Ranganathan <srangana@redhat.com> Reviewed-by: Jeff Darcy <jdarcy@redhat.com> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
Diffstat (limited to 'api/src')
-rw-r--r--api/src/glfs.c60
1 files changed, 53 insertions, 7 deletions
diff --git a/api/src/glfs.c b/api/src/glfs.c
index 037b579225f..6c152ae56ed 100644
--- a/api/src/glfs.c
+++ b/api/src/glfs.c
@@ -651,6 +651,49 @@ err:
return NULL;
}
+extern xlator_t global_xlator;
+extern glusterfs_ctx_t *global_ctx;
+extern pthread_mutex_t global_ctx_mutex;
+
+static int
+glfs_init_global_ctx ()
+{
+ int ret = 0;
+ glusterfs_ctx_t *ctx = NULL;
+
+ pthread_mutex_lock (&global_ctx_mutex);
+ {
+ if (global_xlator.ctx)
+ goto unlock;
+
+ ctx = glusterfs_ctx_new ();
+ if (!ctx) {
+ ret = -1;
+ goto unlock;
+ }
+
+ gf_log_globals_init (ctx, GF_LOG_NONE);
+
+ global_ctx = ctx;
+ global_xlator.ctx = global_ctx;
+
+ ret = glusterfs_ctx_defaults_init (ctx);
+ if (ret) {
+ global_ctx = NULL;
+ global_xlator.ctx = NULL;
+ goto unlock;
+ }
+ }
+unlock:
+ pthread_mutex_unlock (&global_ctx_mutex);
+
+ if (ret)
+ FREE (ctx);
+
+ return ret;
+}
+
+
struct glfs *
pub_glfs_new (const char *volname)
{
@@ -679,11 +722,9 @@ pub_glfs_new (const char *volname)
goto fini;
old_THIS = THIS;
- /* THIS is set to NULL so that we do not modify the caller xlators'
- * ctx, instead we set the global_xlator->ctx
- */
- THIS = NULL;
- THIS->ctx = ctx;
+ ret = glfs_init_global_ctx ();
+ if (ret)
+ goto fini;
/* then ctx_defaults_init, for xlator_mem_acct_init(THIS) */
@@ -795,12 +836,16 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_set_volfile, 3.4.0);
int
pub_glfs_set_logging (struct glfs *fs, const char *logfile, int loglevel)
{
- int ret = -1;
- char *tmplog = NULL;
+ int ret = -1;
+ char *tmplog = NULL;
+ glusterfs_ctx_t *old_ctx = NULL;
DECLARE_OLD_THIS;
__GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
+ old_ctx = THIS->ctx;
+ THIS->ctx = fs->ctx;
+
if (!logfile) {
ret = gf_set_log_file_path (&fs->ctx->cmd_args);
if (ret)
@@ -823,6 +868,7 @@ pub_glfs_set_logging (struct glfs *fs, const char *logfile, int loglevel)
goto out;
out:
+ THIS->ctx = old_ctx;
__GLFS_EXIT_FS;
invalid_fs: