[master] c0f7fc3 TASK_PRIV in cli contexts (vcl_init/vcl_fini) needs to be per-vmod

Nils Goroll nils.goroll at uplex.de
Fri Oct 6 13:01:05 UTC 2017


commit c0f7fc3646bd0859c1d15ccc34888e5c095db7d3
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Fri Oct 6 14:55:55 2017 +0200

    TASK_PRIV in cli contexts (vcl_init/vcl_fini) needs to be per-vmod
    
    Fixes #2451

diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index 6ef4221..7792ab1 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -101,6 +101,7 @@ static struct vrt_ctx ctx_cli;
 static unsigned handling_cli;
 static struct ws ws_cli;
 static uintptr_t ws_snapshot_cli;
+extern struct vrt_privs cli_task_privs[1];
 
 /*--------------------------------------------------------------------*/
 
@@ -118,6 +119,7 @@ vcl_get_ctx(unsigned method, int msg)
 	}
 	ctx_cli.ws = &ws_cli;
 	WS_Assert(ctx_cli.ws);
+	VRTPRIV_init(cli_task_privs);
 	return (&ctx_cli);
 }
 
@@ -132,7 +134,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);
+	VRTPRIV_dynamic_kill(cli_task_privs, (uintptr_t)cli_task_privs);
 }
 
 /*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/cache/cache_vrt_priv.c b/bin/varnishd/cache/cache_vrt_priv.c
index b344756..8e65c8f 100644
--- a/bin/varnishd/cache/cache_vrt_priv.c
+++ b/bin/varnishd/cache/cache_vrt_priv.c
@@ -48,7 +48,7 @@ struct vrt_priv {
 	uintptr_t			vmod_id;
 };
 
-static struct vmod_priv cli_task_priv;
+struct vrt_privs cli_task_privs[1];
 
 /*--------------------------------------------------------------------
  */
@@ -105,9 +105,12 @@ vrt_priv_dynamic(VRT_CTX, uintptr_t id, uintptr_t vmod_id)
 		CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
 		CHECK_OBJ_NOTNULL(ctx->req->sp, SESS_MAGIC);
 		CAST_OBJ_NOTNULL(vps, ctx->req->sp->privs, VRT_PRIVS_MAGIC);
-	} else {
+	} else if (ctx->bo) {
 		CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
 		CAST_OBJ_NOTNULL(vps, ctx->bo->privs, VRT_PRIVS_MAGIC);
+	} else {
+		ASSERT_CLI();
+		CAST_OBJ_NOTNULL(vps, cli_task_privs, VRT_PRIVS_MAGIC);
 	}
 
 	VTAILQ_FOREACH(vp, &vps->privs, list) {
@@ -130,12 +133,6 @@ 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);
-		memset(&cli_task_priv, 0, sizeof cli_task_priv);
-		return;
-	}
 	CHECK_OBJ_NOTNULL(privs, VRT_PRIVS_MAGIC);
 	AN(id);
 
@@ -163,7 +160,7 @@ VRT_priv_task(VRT_CTX, const void *vmod_id)
 		id = (uintptr_t)ctx->bo;
 	} else {
 		ASSERT_CLI();
-		return (&cli_task_priv);
+		id = (uintptr_t)cli_task_privs;
 	}
 	return (vrt_priv_dynamic(ctx, id, (uintptr_t)vmod_id));
 }
diff --git a/bin/varnishtest/tests/r02451.vtc b/bin/varnishtest/tests/r02451.vtc
new file mode 100644
index 0000000..ef3c45c
--- /dev/null
+++ b/bin/varnishtest/tests/r02451.vtc
@@ -0,0 +1,63 @@
+varnishtest "test PRIV_TASK in vcl_init is per vmod"
+
+server s1 {
+	rxreq
+	txresp -body "ech3Ooj"
+} -start
+
+server s2 {
+	rxreq
+	txresp -body "ieQu2qua"
+} -start
+
+server s3 {
+	rxreq
+	txresp -body "xiuFi3Pe"
+} -start
+
+varnish v1 -vcl+backend {
+	import directors;
+	import debug;
+	import std;
+
+	sub vcl_init {
+		new obj = debug.obj();
+		new vd = directors.shard();
+		debug.test_priv_task("something");
+		debug.test_priv_task("to remember");
+
+		vd.add_backend(s1);
+		vd.add_backend(s2);
+		vd.add_backend(s3);
+		vd.reconfigure(replicas=25);
+
+		std.log("func " + debug.test_priv_task());
+		std.log("obj "	+ obj.test_priv_task());
+	}
+
+	sub vcl_recv {
+		set req.backend_hint = vd.backend();
+		return(pass);
+	}
+
+} -start
+
+logexpect l1 -v v1 -g raw -d 1 {
+	expect 0 0    CLI		{^Rd vcl.load}
+	expect 0 =    VCL_Log		{^func something to remember}
+	expect 0 =    VCL_Log		{^obj something to remember}
+} -start
+
+client c1 {
+	txreq -url /Boo0aixe
+	rxresp
+	expect resp.body == "ech3Ooj"
+
+	txreq -url /eishoSu2
+	rxresp
+	expect resp.body == "ieQu2qua"
+
+	txreq -url /Aunah3uo
+	rxresp
+	expect resp.body == "xiuFi3Pe"
+} -run


More information about the varnish-commit mailing list