[master] 6d4447c Add support for PRIV_TASK in CLI induced VCL events.

Poul-Henning Kamp phk at FreeBSD.org
Sat Sep 10 11:20:11 CEST 2016


commit 6d4447cedee482cfb6cb2019bb982250100007e4
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Sat Sep 10 09:18:58 2016 +0000

    Add support for PRIV_TASK in CLI induced VCL events.
    
    See also: #2061

diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index 57952cf..461931f 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -127,6 +127,7 @@ vcl_rel_ctx(struct vrt_ctx **ctx)
 	WS_Reset(&ws_cli, ws_snapshot_cli);
 	INIT_OBJ(*ctx, VRT_CTX_MAGIC);
 	*ctx = NULL;
+	VRTPRIV_dynamic_kill(NULL, 0);
 }
 
 /*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/cache/cache_vrt_priv.c b/bin/varnishd/cache/cache_vrt_priv.c
index 1cfa281..44d95d3 100644
--- a/bin/varnishd/cache/cache_vrt_priv.c
+++ b/bin/varnishd/cache/cache_vrt_priv.c
@@ -48,23 +48,27 @@ struct vrt_priv {
 	uintptr_t			vmod_id;
 };
 
+struct vmod_priv cli_task_priv;
+
 /*--------------------------------------------------------------------
  */
 
 void
 VRTPRIV_init(struct vrt_privs *privs)
 {
-	privs->magic = VRT_PRIVS_MAGIC;
+
+	INIT_OBJ(privs, VRT_PRIVS_MAGIC);
 	VTAILQ_INIT(&privs->privs);
 }
 
 static struct vmod_priv *
-VRT_priv_dynamic(VRT_CTX, uintptr_t id, uintptr_t vmod_id)
+vrt_priv_dynamic(VRT_CTX, uintptr_t id, uintptr_t vmod_id)
 {
 	struct vrt_privs *vps;
 	struct vrt_priv *vp;
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	AN(vmod_id);
 	if (ctx->req) {
 		CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
 		CHECK_OBJ_NOTNULL(ctx->req->sp, SESS_MAGIC);
@@ -94,7 +98,13 @@ VRTPRIV_dynamic_kill(struct vrt_privs *privs, uintptr_t id)
 {
 	struct vrt_priv *vp, *vp1;
 
+	if (privs == NULL && id == 0) {
+		ASSERT_CLI();
+		VRT_priv_fini(&cli_task_priv);
+		return;
+	}
 	CHECK_OBJ_NOTNULL(privs, VRT_PRIVS_MAGIC);
+	AN(id);
 
 	VTAILQ_FOREACH_SAFE(vp, &privs->privs, list, vp1) {
 		CHECK_OBJ_NOTNULL(vp, VRT_PRIV_MAGIC);
@@ -118,9 +128,11 @@ VRT_priv_task(VRT_CTX, void *vmod_id)
 	} else if (ctx->bo) {
 		CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
 		id = (uintptr_t)ctx->bo;
-	} else
-		WRONG("PRIV_TASK is only accessible in client or backend VCL contexts");
-	return (VRT_priv_dynamic(ctx, id, (uintptr_t)vmod_id));
+	} else {
+		ASSERT_CLI();
+		return (&cli_task_priv);
+	}
+	return (vrt_priv_dynamic(ctx, id, (uintptr_t)vmod_id));
 }
 
 struct vmod_priv *
@@ -133,7 +145,7 @@ VRT_priv_top(VRT_CTX, void *vmod_id)
 		CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
 		CHECK_OBJ_NOTNULL(ctx->req->top, REQ_MAGIC);
 		id = (uintptr_t)&ctx->req->top->top;
-		return (VRT_priv_dynamic(ctx, id, (uintptr_t)vmod_id));
+		return (vrt_priv_dynamic(ctx, id, (uintptr_t)vmod_id));
 	} else
 		WRONG("PRIV_TOP is only accessible in client VCL context");
 	NEEDLESS_RETURN(NULL);
@@ -146,6 +158,6 @@ void
 VRT_priv_fini(const struct vmod_priv *p)
 {
 
-	if (p->priv != (void*)0 && p->free != (void*)0)
+	if (p->priv != NULL && p->free != NULL)
 		p->free(p->priv);
 }



More information about the varnish-commit mailing list