summaryrefslogtreecommitdiffstats
path: root/api/src/glfs.c
diff options
context:
space:
mode:
authorPoornima G <pgurusid@redhat.com>2015-04-29 13:03:52 +0530
committerVijay Bellur <vbellur@redhat.com>2015-05-09 06:52:46 -0700
commit5fd6b3b7e2881d21a1b19fb22366e905314d71bc (patch)
tree7531a8c062fae1599aebbf4506af4ccf930e2413 /api/src/glfs.c
parent972458a74780923e7e867b9362dda1830eeefe5e (diff)
libgfapi: Store and restore THIS in every API exposed by libgfapi
Backport of http://review.gluster.org/#/c/9797 Storing and restoring THIS: When the APIs exposed by libgfapi are called by other xlators like snapview server etc. the THIS value is overwritten to contain the THIS of libgfapi(viz libgfapi master xlator). Hence using 'THIS' in any xlator after calling libgfapi API will lead to issues. One such issue was uncovered in snapview and the patch http://review.gluster.org/#/c/9469/ was sent to workaround this issue. Hence, storing and restoring THIS, at the entry and exit of every API exposed by libgfapi. Change-Id: I6f330dde25e7700fb26339d667a7ccd193ec6ba0 BUG: 1210934 Signed-off-by: Poornima G <pgurusid@redhat.com> Reviewed-on: http://review.gluster.org/9797 Reviewed-by: Raghavendra Talur <rtalur@redhat.com> Reviewed-by: soumya k <skoduri@redhat.com> Reviewed-by: Niels de Vos <ndevos@redhat.com> Tested-by: Gluster Build System <jenkins@build.gluster.com> (cherry picked from commit 1162bb36108ab8dba8303b86927a99835b791d79) Reviewed-on: http://review.gluster.org/10414 Reviewed-by: Shyamsundar Ranganathan <srangana@redhat.com>
Diffstat (limited to 'api/src/glfs.c')
-rw-r--r--api/src/glfs.c119
1 files changed, 88 insertions, 31 deletions
diff --git a/api/src/glfs.c b/api/src/glfs.c
index 23377f651d1..d6a6fe9c850 100644
--- a/api/src/glfs.c
+++ b/api/src/glfs.c
@@ -303,6 +303,9 @@ pub_glfs_set_xlator_option (struct glfs *fs, const char *xlator,
{
xlator_cmdline_option_t *option = NULL;
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
+
option = GF_CALLOC (1, sizeof (*option),
glfs_mt_xlator_cmdline_option_t);
if (!option)
@@ -322,18 +325,25 @@ pub_glfs_set_xlator_option (struct glfs *fs, const char *xlator,
list_add (&option->cmd_args, &fs->ctx->cmd_args.xlator_options);
+ __GLFS_EXIT_FS;
+
return 0;
enomem:
errno = ENOMEM;
- if (!option)
+ if (!option) {
+ __GLFS_EXIT_FS;
return -1;
+ }
GF_FREE (option->volume);
GF_FREE (option->key);
GF_FREE (option->value);
GF_FREE (option);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return -1;
}
@@ -353,6 +363,9 @@ pub_glfs_unset_volfile_server (struct glfs *fs, const char *transport,
return ret;
}
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
+
cmd_args = &fs->ctx->cmd_args;
list_for_each_entry(server, &cmd_args->curr_server->list, list) {
if ((!strcmp(server->volfile_server, host) &&
@@ -365,6 +378,9 @@ pub_glfs_unset_volfile_server (struct glfs *fs, const char *transport,
}
out:
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -385,6 +401,9 @@ pub_glfs_set_volfile_server (struct glfs *fs, const char *transport,
return ret;
}
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
+
cmd_args = &fs->ctx->cmd_args;
cmd_args->max_connect_attempts = 1;
@@ -444,6 +463,9 @@ out:
}
}
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -453,6 +475,9 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_set_volfile_server, 3.4.0);
int
pub_glfs_setfsuid (uid_t fsuid)
{
+ /* TODO:
+ * - Set the THIS and restore it appropriately
+ */
return syncopctx_setfsuid (&fsuid);
}
@@ -462,6 +487,9 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_setfsuid, 3.4.2);
int
pub_glfs_setfsgid (gid_t fsgid)
{
+ /* TODO:
+ * - Set the THIS and restore it appropriately
+ */
return syncopctx_setfsgid (&fsgid);
}
@@ -471,6 +499,9 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_setfsgid, 3.4.2);
int
pub_glfs_setfsgroups (size_t size, const gid_t *list)
{
+ /* TODO:
+ * - Set the THIS and restore it appropriately
+ */
return syncopctx_setfsgroups(size, list);
}
@@ -563,7 +594,7 @@ pub_glfs_new (const char *volname)
struct glfs *fs = NULL;
int ret = -1;
glusterfs_ctx_t *ctx = NULL;
- gf_boolean_t cleanup_fini = _gf_false;
+ xlator_t *old_THIS = NULL;
if (!volname) {
errno = EINVAL;
@@ -590,47 +621,49 @@ pub_glfs_new (const char *volname)
if (ret != 0)
goto cond_child_destroy;
- cleanup_fini = _gf_true;
-
ctx = glusterfs_ctx_new ();
if (!ctx)
- goto freefs;
+ goto fini;
/* first globals init, for gf_mem_acct_enable_set () */
ret = glusterfs_globals_init (ctx);
if (ret)
- goto freefs;
+ goto fini;
- if (!THIS->ctx)
- THIS->ctx = ctx;
+ 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;
/* then ctx_defaults_init, for xlator_mem_acct_init(THIS) */
ret = glusterfs_ctx_defaults_init (ctx);
if (ret)
- goto freefs;
+ goto fini;
fs->ctx = ctx;
ret = glfs_set_logging (fs, "/dev/null", 0);
if (ret)
- goto freefs;
+ goto fini;
fs->ctx->cmd_args.volfile_id = gf_strdup (volname);
if (!(fs->ctx->cmd_args.volfile_id))
- goto freefs;
+ goto fini;
fs->volname = strdup (volname);
if (!fs->volname)
- goto freefs;
+ goto fini;
INIT_LIST_HEAD (&fs->openfds);
INIT_LIST_HEAD (&fs->upcall_list);
fs->pin_refcnt = 0;
- return fs;
+ goto out;
cond_child_destroy:
pthread_cond_destroy (&fs->child_down_cond);
@@ -642,7 +675,10 @@ mutex_destroy:
pthread_mutex_destroy (&fs->mutex);
freefs:
-
+ FREE (fs);
+ fs = NULL;
+ goto out;
+fini:
/*
* When pthread_*init() fails there is no way for other cleanup
* funtions (glfs_fini/glfs_free_from_ctx) to know which of them succeded
@@ -651,14 +687,13 @@ freefs:
* directly call glfs_fini() to cleanup the resources.
*/
- if (!cleanup_fini)
- FREE(fs);
- else
- glfs_fini (fs);
- fs = NULL;
+ glfs_fini (fs);
+ fs = NULL;
+out:
+ if (old_THIS)
+ THIS = old_THIS;
return fs;
-
}
GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_new, 3.4.0);
@@ -750,9 +785,12 @@ 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 = 0;
+ int ret = -1;
char *tmplog = NULL;
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
+
if (!logfile) {
ret = gf_set_log_file_path (&fs->ctx->cmd_args);
if (ret)
@@ -775,6 +813,9 @@ pub_glfs_set_logging (struct glfs *fs, const char *logfile, int loglevel)
goto out;
out:
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -882,6 +923,8 @@ pub_glfs_init (struct glfs *fs)
{
int ret = -1;
+ DECLARE_OLD_THIS;
+
if (!fs || !fs->ctx) {
gf_msg ("glfs", GF_LOG_ERROR, EINVAL, API_MSG_INVALID_ENTRY,
"fs is not properly initialized.");
@@ -889,17 +932,22 @@ pub_glfs_init (struct glfs *fs)
return ret;
}
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
+
ret = glfs_init_common (fs);
if (ret)
- return ret;
+ goto out;
ret = glfs_init_wait (fs);
+out:
+ __GLFS_EXIT_FS;
/* Set the initial current working directory to "/" */
if (ret >= 0) {
ret = glfs_chdir (fs, "/");
}
+invalid_fs:
return ret;
}
@@ -985,19 +1033,15 @@ pub_glfs_fini (struct glfs *fs)
int fs_init = 0;
int err = -1;
+ DECLARE_OLD_THIS;
- if (!fs) {
- errno = EINVAL;
- return 0;
- }
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
ctx = fs->ctx;
if (!ctx) {
goto free_fs;
}
- __glfs_entry_fs (fs);
-
if (ctx->mgmt) {
rpc_clnt_disable (ctx->mgmt);
ctx->mgmt = NULL;
@@ -1141,6 +1185,9 @@ fail:
if (!ret)
ret = err;
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}
@@ -1150,7 +1197,10 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fini, 3.4.0);
ssize_t
pub_glfs_get_volfile (struct glfs *fs, void *buf, size_t len)
{
- ssize_t res;
+ ssize_t res = -1;
+
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
glfs_lock(fs);
if (len >= fs->oldvollen) {
@@ -1164,6 +1214,9 @@ pub_glfs_get_volfile (struct glfs *fs, void *buf, size_t len)
}
glfs_unlock(fs);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return res;
}
@@ -1173,9 +1226,10 @@ int
pub_glfs_ipc (struct glfs *fs, int opcode)
{
xlator_t *subvol = NULL;
- int ret;
+ int ret = -1;
- __glfs_entry_fs (fs);
+ DECLARE_OLD_THIS;
+ __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs);
subvol = glfs_active_subvol (fs);
if (!subvol) {
@@ -1189,6 +1243,9 @@ pub_glfs_ipc (struct glfs *fs, int opcode)
out:
glfs_subvol_done (fs, subvol);
+ __GLFS_EXIT_FS;
+
+invalid_fs:
return ret;
}