<html><body><div style="font-family: times new roman,new york,times,serif; font-size: 12pt; color: #000000"><div>Hi,<br><br>We recently uncovered an issue with THIS and libgfapi, it can be generalized to any process having multiple glusterfs_ctxs.<br></div><div><br></div><div>Before the master xlator (fuse/libgfapi) is created, all the code that access THIS will be using global_xlator object,<br>defined globally for the whole of the process.<br></div><div>The problem is when multiple threads start modifying THIS, and overwrite thr global_xlators' ctx eg: glfs_new:<br>glfs_new () {<br>...<br>ctx = glusterfs_ctx_new();<br>glusterfs_globals_inti();<br>THIS = NULL;&nbsp; /* implies THIS = &amp;global_xlator */<br>THIS-&gt;ctx = ctx;<br>...<br>}<br>The issue is more severe than it appears, as the other threads like epoll, timer, sigwaiter, when not executing in<br>fop context will always refer to the global_xlator and global_xlator-&gt;ctx. Because of the probable race condition</div><div>explained above we may be referring to the stale ctxs and could lead to crashes.<br><br>Probable solution:<br>Currently THIS is thread specific, but the global xlator object it modifies is global to all threads!!<br>The obvious association would be to have global_xlator per ctx instead of per process.<br>The changes would be as follows:<br>- Have a new global_xlator object in glusterfs_ctx.<br>- After every creation of new ctx assign<br>&nbsp; &lt;store THIS&gt;<br>&nbsp; THIS = new_ctx-&gt;global_xlator<br>&nbsp; &lt;restore THIS&gt;<br>- But how to set the THIS in every thread(epoll, timer etc) that gets created as a part of that ctx.<br>&nbsp; Replace all the pthread_create for the ctx threads, with gf_pthread_create:<br>&nbsp;</div><div>&nbsp;gf_pthread_create (fn,..., ctx) {<br>&nbsp; ...<br>&nbsp; thr_id = pthread_create (global_thread_init, fn, ctx...);<br>&nbsp; ...<br>&nbsp; }<br><br>&nbsp; global_thread_init (fn, ctx, args) {<br>&nbsp; THIS = ctx-&gt;global_xlator;<br>&nbsp; fn(args);<br>&nbsp; }<br><br>&nbsp;The other solution would be to not associate threads with ctx, instead shared among ctxs</div><div><br>Please let me know your thoughts on the same.<br><br></div><div>Regards,<br></div><div>Poornima<br></div></div></body></html>