Commit 606d4856 authored by Martin Blix Grydeland's avatar Martin Blix Grydeland

Straighten locking wrt vcl_active

The locking around the use of vcl_active does not include the checking
of its magic value or the temperature asserts, leading to a race when
changing vcl_active.

Fixes: #2390
parent cc5df0ef
...@@ -252,13 +252,13 @@ VCL_Method_Name(unsigned m) ...@@ -252,13 +252,13 @@ VCL_Method_Name(unsigned m)
static void static void
vcl_get(struct vcl **vcc, struct vcl *vcl) vcl_get(struct vcl **vcc, struct vcl *vcl)
{ {
AN(vcc);
CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
AZ(errno=pthread_rwlock_rdlock(&vcl->temp_rwl));
assert(VCL_WARM(vcl));
AZ(errno=pthread_rwlock_unlock(&vcl->temp_rwl));
Lck_Lock(&vcl_mtx); Lck_Lock(&vcl_mtx);
AN(vcl); if (vcl == NULL)
vcl = vcl_active; /* Sample vcl_active under lock to avoid
* race */
CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
if (vcl->label == NULL) { if (vcl->label == NULL) {
AN(strcmp(vcl->state, VCL_TEMP_LABEL)); AN(strcmp(vcl->state, VCL_TEMP_LABEL));
*vcc = vcl; *vcc = vcl;
...@@ -266,16 +266,18 @@ vcl_get(struct vcl **vcc, struct vcl *vcl) ...@@ -266,16 +266,18 @@ vcl_get(struct vcl **vcc, struct vcl *vcl)
AZ(strcmp(vcl->state, VCL_TEMP_LABEL)); AZ(strcmp(vcl->state, VCL_TEMP_LABEL));
*vcc = vcl->label; *vcc = vcl->label;
} }
AN(*vcc); CHECK_OBJ_NOTNULL(*vcc, VCL_MAGIC);
AZ((*vcc)->discard); AZ((*vcc)->discard);
(*vcc)->busy++; (*vcc)->busy++;
Lck_Unlock(&vcl_mtx); Lck_Unlock(&vcl_mtx);
AZ(errno=pthread_rwlock_rdlock(&(*vcc)->temp_rwl));
assert(VCL_WARM(*vcc));
AZ(errno=pthread_rwlock_unlock(&(*vcc)->temp_rwl));
} }
void void
VCL_Refresh(struct vcl **vcc) VCL_Refresh(struct vcl **vcc)
{ {
CHECK_OBJ_NOTNULL(vcl_active, VCL_MAGIC);
if (*vcc == vcl_active) if (*vcc == vcl_active)
return; return;
if (*vcc != NULL) if (*vcc != NULL)
...@@ -284,7 +286,7 @@ VCL_Refresh(struct vcl **vcc) ...@@ -284,7 +286,7 @@ VCL_Refresh(struct vcl **vcc)
while (vcl_active == NULL) while (vcl_active == NULL)
(void)usleep(100000); (void)usleep(100000);
vcl_get(vcc, vcl_active); vcl_get(vcc, NULL);
} }
void void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment