From c6b0adb483c1d0c4922e6d4cb77abfb69d314a8e Mon Sep 17 00:00:00 2001 From: Jeff Darcy Date: Mon, 5 Dec 2016 13:01:41 -0500 Subject: libglusterfs: serialize init/reconfigure calls These functions do not generally "expect" to be called more than once in parallel, and many are likely to misbehave in that case (one case in DHT already). Such parallel calls have not generally happened because there are only a few places where we call these functions, and those have been implicitly serialized until recently. However, recent changes in the epoll layer change that, as does brick multiplexing. Therefore, the serialization is now explicit at the init/reconfigure level. It would be sufficient to serialize calls to a particular translator's init and reconfigure functions, but that would require per-translator locks and a bit more complexity in maintaining/using them. Since there's no clear reason why we would need or want to support a higher level of parallelism, the simpler approach of a global lock should suffice. Change-Id: I26296c2826e91dc00b7f0c2061bcc2964ef90c4c BUG: 1399134 Signed-off-by: Jeff Darcy Reviewed-on: http://review.gluster.org/16030 Smoke: Gluster Build System NetBSD-regression: NetBSD Build System CentOS-regression: Gluster Build System Reviewed-by: Raghavendra G --- libglusterfs/src/options.c | 2 ++ libglusterfs/src/xlator.c | 17 +++++++++++++++++ libglusterfs/src/xlator.h | 3 +++ 3 files changed, 22 insertions(+) diff --git a/libglusterfs/src/options.c b/libglusterfs/src/options.c index 53bd779861c..a28f3b7ea4f 100644 --- a/libglusterfs/src/options.c +++ b/libglusterfs/src/options.c @@ -1107,7 +1107,9 @@ xlator_reconfigure_rec (xlator_t *old_xl, xlator_t *new_xl) old_THIS = THIS; THIS = old_xl; + xlator_init_lock (); ret = old_xl->reconfigure (old_xl, new_xl->options); + xlator_init_unlock (); THIS = old_THIS; diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c index 3c1cde50fa0..2edebc0aec2 100644 --- a/libglusterfs/src/xlator.c +++ b/libglusterfs/src/xlator.c @@ -25,6 +25,21 @@ xl->cbks->fn = default_##fn; \ } while (0) +pthread_mutex_t xlator_init_mutex = PTHREAD_MUTEX_INITIALIZER; + +void +xlator_init_lock (void) +{ + (void) pthread_mutex_lock (&xlator_init_mutex); +} + + +void +xlator_init_unlock (void) +{ + (void) pthread_mutex_unlock (&xlator_init_mutex); +} + static void fill_defaults (xlator_t *xl) @@ -400,7 +415,9 @@ __xlator_init(xlator_t *xl) old_THIS = THIS; THIS = xl; + xlator_init_lock (); ret = xl->init (xl); + xlator_init_unlock (); THIS = old_THIS; diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h index b11d1a96f32..e28790cc034 100644 --- a/libglusterfs/src/xlator.h +++ b/libglusterfs/src/xlator.h @@ -1048,4 +1048,7 @@ glusterfs_reachable_leaves(xlator_t *base, dict_t *leaves); int xlator_subvolume_count (xlator_t *this); +void xlator_init_lock (void); +void xlator_init_unlock (void); + #endif /* _XLATOR_H */ -- cgit