syncop: save and restore THIS from the time of context switch

The current yield() code assumes that the point of yielding
is always in the translator where the synctask was created. This
can be a problem for nested syncops and/or where syncop is issued
by a different translator.

So, save the THIS pointer just before swapcontext() and restore
it right after resuming.

Change-Id: I86aad2329ccbc3ac1f04fbec3835136ff3fa79fb
BUG: 862838
Signed-off-by: Anand Avati <avati@redhat.com>
Reviewed-on: http://review.gluster.org/4085
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
Tested-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
This commit is contained in:
Anand Avati 2012-10-14 12:08:25 -07:00
parent bccb4b7a63
commit f59494ba65

View File

@ -82,6 +82,8 @@ __wait (struct synctask *task)
void
synctask_yield (struct synctask *task)
{
xlator_t *oldTHIS = THIS;
#if defined(__NetBSD__) && defined(_UC_TLSBASE)
/* Preserve pthread private pointer through swapcontex() */
task->proc->sched.uc_flags &= ~_UC_TLSBASE;
@ -91,6 +93,8 @@ synctask_yield (struct synctask *task)
gf_log ("syncop", GF_LOG_ERROR,
"swapcontext failed (%s)", strerror (errno));
}
THIS = oldTHIS;
}