summaryrefslogtreecommitdiffstats
path: root/libglusterfsclient/src
diff options
context:
space:
mode:
authorShehjar Tikoo <shehjart@gluster.com>2009-08-13 02:57:18 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-08-17 14:37:38 -0700
commita55616242a4f883a864ac03b5282a12c6b8da03e (patch)
treeb7f4165e5a5d7d022f54a0d8a345d3c0963a8884 /libglusterfsclient/src
parent425f895f0f89831221451c5aa8e0a7e31e95f2aa (diff)
libglusterfsclient: Sync access to VMP list on new entry addition
Some weeks back, I'd separated the big lock into vmplock and mountlock. See commit 304e4274ca9b0339539581c5413e3339078c1182 in mainline. At that time, we did not have a solution to the problem of when to init the vmplist in a thread-safe manner, since there was no lock to protect the vmplock specifically, and that when libgf_vmp_map_ghandle was called inside glusterfs_mount so the "lock" was already being held. Now that we have separate mount and vmp locks, the accesses can be synced correctly. Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 211 (libglusterfsclient: Race condition against vmplist in libgf_vmp_map_ghandle) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=211
Diffstat (limited to 'libglusterfsclient/src')
-rwxr-xr-xlibglusterfsclient/src/libglusterfsclient.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c
index e0d47d9f3bf..24e73a82703 100755
--- a/libglusterfsclient/src/libglusterfsclient.c
+++ b/libglusterfsclient/src/libglusterfsclient.c
@@ -1514,16 +1514,16 @@ libgf_vmp_map_ghandle (char *vmp, glusterfs_handle_t *vmphandle)
if (!vmpentry)
goto out;
- /*
- FIXME: this is not thread-safe, but I couldn't find other place to
- do initialization.
- */
- if (vmplist.entries == 0) {
- INIT_LIST_HEAD (&vmplist.list);
- }
+ pthread_mutex_lock (&vmplock);
+ {
+ if (vmplist.entries == 0) {
+ INIT_LIST_HEAD (&vmplist.list);
+ }
- list_add_tail (&vmpentry->list, &vmplist.list);
- ++vmplist.entries;
+ list_add_tail (&vmpentry->list, &vmplist.list);
+ ++vmplist.entries;
+ }
+ pthread_mutex_unlock (&vmplock);
ret = 0;
out: