parser: make the parser thread safe.

The volfile parser thread safe by guarding the parsing phase
in a mutex. Thread safety becomes a problem when there are multiple
glfs_t objects created by gfapi and all of them potentially parse
the respective volfiles at the same time.

Change-Id: I4376019c4956994b72397ab36e6ac3ce849797ec
BUG: 1004519
Signed-off-by: Anand Avati <avati@redhat.com>
Reviewed-on: http://review.gluster.org/5790
Reviewed-by: Raghavendra G <rgowdapp@redhat.com>
Reviewed-by: Raghavendra Bhat <raghavendra@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@gluster.org>
This commit is contained in:
Anand Avati 2013-08-28 18:38:26 -07:00 committed by Anand Avati
parent 1955f7dc84
commit 2347a1a759

View File

@ -18,6 +18,7 @@
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <pthread.h>
#define RELAX_POISONING
@ -557,6 +558,7 @@ glusterfs_graph_construct (FILE *fp)
glusterfs_graph_t *graph = NULL;
FILE *tmp_file = NULL;
char template[PATH_MAX] = {0};
static pthread_mutex_t graph_mutex = PTHREAD_MUTEX_INITIALIZER;
graph = glusterfs_graph_new ();
if (!graph)
@ -583,10 +585,14 @@ glusterfs_graph_construct (FILE *fp)
goto err;
}
yyin = tmp_file;
construct = graph;
ret = yyparse ();
construct = NULL;
pthread_mutex_lock (&graph_mutex);
{
yyin = tmp_file;
construct = graph;
ret = yyparse ();
construct = NULL;
}
pthread_mutex_unlock (&graph_mutex);
if (ret == 1) {
gf_log ("parser", GF_LOG_DEBUG,