[master] 27349a30f support concurrent access to PRIV_TOP
Nils Goroll
nils.goroll at uplex.de
Wed Apr 1 08:12:07 UTC 2020
commit 27349a30fba4e77ab45c3c3905caebf7d1fe16de
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Sat Mar 21 18:54:47 2020 +0100
support concurrent access to PRIV_TOP
in varnish-cache, access to all ESI sub-requests happens in a single
thread, but vmods (VDPs) may add concurrency.
We thus protect access to PRIV_TOP with the session mutex.
Any vmods using this facility will likely need to add additional locking for
the actual data structures referenced through the PRIV_TOP and any other
access to the top request.
For alternatives previously considered, see #3139
diff --git a/bin/varnishd/cache/cache_vrt_priv.c b/bin/varnishd/cache/cache_vrt_priv.c
index 6493698b7..bcc7bfca5 100644
--- a/bin/varnishd/cache/cache_vrt_priv.c
+++ b/bin/varnishd/cache/cache_vrt_priv.c
@@ -166,6 +166,9 @@ struct vmod_priv *
VRT_priv_top(VRT_CTX, const void *vmod_id)
{
struct req *req;
+ struct sess *sp;
+ struct reqtop *top;
+ struct vmod_priv *priv;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (ctx->req == NULL) {
@@ -174,12 +177,15 @@ VRT_priv_top(VRT_CTX, const void *vmod_id)
}
req = ctx->req;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
- CHECK_OBJ_NOTNULL(req->top, REQTOP_MAGIC);
- return (vrt_priv_dynamic(
- req->ws,
- req->top->privs,
- (uintptr_t)vmod_id
- ));
+ sp = ctx->sp;
+ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+ top = req->top;
+ CHECK_OBJ_NOTNULL(top, REQTOP_MAGIC);
+
+ Lck_Lock(&sp->mtx);
+ priv = vrt_priv_dynamic(req->ws, top->privs, (uintptr_t)vmod_id);
+ Lck_Unlock(&sp->mtx);
+ return (priv);
}
/*--------------------------------------------------------------------
More information about the varnish-commit
mailing list