[master] 864f6cf4d support VCL_SUB calls from vcl_init and vcl_fini

Nils Goroll nils.goroll at uplex.de
Mon Sep 29 13:21:06 UTC 2025


commit 864f6cf4d7fdfd0caacd30923a5c4f480c246510
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Fri Sep 19 13:57:10 2025 +0200

    support VCL_SUB calls from vcl_init and vcl_fini
    
    The housekeeping subs did not yet support calling sub handles because the
    recursion bitmap was missing in the VRT context.
    
    Fixes #4394

diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index 84980003b..2c2195739 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -44,6 +44,7 @@
 
 #include "cache_director.h"
 #include "cache_vcl.h"
+#include "vbm.h"
 #include "vcli_serve.h"
 #include "vte.h"
 #include "vtim.h"
@@ -215,6 +216,8 @@ vcl_send_event(struct vcl *vcl, enum vcl_event_e ev, struct vsb **msg)
 	int r, havemsg;
 	unsigned method = 0;
 	struct vrt_ctx *ctx;
+	void *vbm_alloc = NULL;
+	size_t sz;
 
 	ASSERT_CLI();
 	ASSERT_VCL_ACTIVE();
@@ -251,6 +254,13 @@ vcl_send_event(struct vcl *vcl, enum vcl_event_e ev, struct vsb **msg)
 	ctx->syntax = ctx->vcl->conf->syntax;
 	ctx->method = method;
 
+	if (vcl->conf->nsub > 0) {
+		sz = VBITMAP_SZ(vcl->conf->nsub);
+		vbm_alloc = malloc(sz);
+		AN(vbm_alloc);
+		ctx->called = vbit_init(vbm_alloc, sz);
+	}
+
 	VCL_TaskEnter(cli_task_privs);
 	r = ctx->vcl->conf->event_vcl(ctx, ev);
 	VCL_TaskLeave(ctx, cli_task_privs);
@@ -261,6 +271,8 @@ vcl_send_event(struct vcl *vcl, enum vcl_event_e ev, struct vsb **msg)
 	if (r && (ev == VCL_EVENT_COLD || ev == VCL_EVENT_DISCARD))
 		WRONG("A VMOD cannot fail COLD or DISCARD events");
 
+	free(vbm_alloc);
+
 	return (r);
 }
 
diff --git a/bin/varnishtest/tests/m00053.vtc b/bin/varnishtest/tests/m00053.vtc
index 72e54ab89..dff088270 100644
--- a/bin/varnishtest/tests/m00053.vtc
+++ b/bin/varnishtest/tests/m00053.vtc
@@ -240,3 +240,22 @@ client c2 {
 
 client c1 -wait
 client c2 -wait
+
+varnish v1 -vcl {
+	import debug;
+	import std;
+
+	backend b None;
+
+	sub logger {
+		std.log("logger called");
+	}
+
+	sub vcl_init {
+		debug.call(logger);
+	}
+
+	sub vcl_fini {
+		debug.call(logger);
+	}
+}


More information about the varnish-commit mailing list