summaryrefslogtreecommitdiffstats
path: root/api/src/glfs.c
diff options
context:
space:
mode:
authorPoornima G <pgurusid@redhat.com>2016-03-19 04:38:47 -0400
committerNiels de Vos <ndevos@redhat.com>2016-03-30 07:22:40 -0700
commit450a853f0059a7ed076253caa982913b08d0485b (patch)
tree05ad49dc01493084dddd3f2449fb0f3285dc9836 /api/src/glfs.c
parent71d988919c75e1294eb417a92f0a495cf388002e (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. Credits: Rajesh Joseph, Raghavendra Talur, Anoop CS Back-port of: http://review.gluster.org/#/c/13784/ Change-Id: I8a8a0572bea0eec94ece6aa0d7afcf2f459b4a43 BUG: 1319989 Signed-off-by: Poornima G <pgurusid@redhat.com> Reviewed-on: http://review.gluster.org/13803 Smoke: Gluster Build System <jenkins@build.gluster.com> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Niels de Vos <ndevos@redhat.com>
Diffstat (limited to 'api/src/glfs.c')
-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 b3a3f9751dd..10658ef3819 100644
--- a/api/src/glfs.c
+++ b/api/src/glfs.c
@@ -620,6 +620,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)
{
@@ -648,11 +691,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) */
@@ -764,12 +805,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)
@@ -792,6 +837,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: