[master] ff18a3c5b Add VRT_handled(), use it in VRT_call() and add red tape...
Nils Goroll
nils.goroll at uplex.de
Mon Feb 8 19:42:07 UTC 2021
commit ff18a3c5bf7cf02acaa5bc5672cc90c8bb805336
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Mon Feb 8 20:37:57 2021 +0100
Add VRT_handled(), use it in VRT_call() and add red tape...
... regarding multiple VRT_call()s from vmods.
Dridi noticed that we need to consider the handling for VRT_call(),
thank you!
diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index aab4b72e9..d674b728a 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -648,6 +648,14 @@ VRT_handling(VRT_CTX, unsigned hand)
*ctx->handling = hand;
}
+unsigned
+VRT_handled(VRT_CTX)
+{
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+ AN(ctx->handling);
+ return (*ctx->handling);
+}
+
/*--------------------------------------------------------------------*/
VCL_VOID
diff --git a/bin/varnishd/cache/cache_vrt_vcl.c b/bin/varnishd/cache/cache_vrt_vcl.c
index 8d20c7848..cda736eaa 100644
--- a/bin/varnishd/cache/cache_vrt_vcl.c
+++ b/bin/varnishd/cache/cache_vrt_vcl.c
@@ -562,6 +562,7 @@ VRT_call(VRT_CTX, VCL_SUB sub)
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(sub, VCL_SUB_MAGIC);
+ AZ(VRT_handled(ctx));
AN(sub->func);
sub->func(ctx, VSUB_DYNAMIC, NULL);
}
diff --git a/doc/changes.rst b/doc/changes.rst
index e98abd650..ceee8cd1d 100644
--- a/doc/changes.rst
+++ b/doc/changes.rst
@@ -62,6 +62,8 @@ Varnish Cache Next (2021-03-15)
subroutine accessing ``req`` from the backend side) and recursive
calls fail the VCL.
+ See :ref:`ref-vmod` for details.
+
* ``VRT_check_call()`` can be used to check if a ``VRT_call()`` would
succeed in order to avoid the potential VCL failure in case it would
not.
diff --git a/doc/sphinx/reference/vmod.rst b/doc/sphinx/reference/vmod.rst
index 8eb6baa8a..44499496a 100644
--- a/doc/sphinx/reference/vmod.rst
+++ b/doc/sphinx/reference/vmod.rst
@@ -475,6 +475,14 @@ VCL_SUB
(e.g. calling a subroutine accessing ``req`` from the backend
side).
+ For more than one invocation of ``VRT_call()``, VMODs *must*
+ check if ``VRT_handled()`` returns non-zero inbetween calls:
+ The called SUB may have returned with an action (any
+ ``return(x)`` other than plain ``return``) or may have failed
+ the VCL, and in both cases the calling VMOD *must* return
+ also, possibly after having conducted some cleanup. Note that
+ undoing the handling through ``VRT_handling()`` is a bug.
+
``VRT_check_call()`` can be used to check if a ``VRT_call()``
would succeed in order to avoid the potential VCL failure. It
returns ``NULL`` if ``VRT_call()`` would make the call or an
diff --git a/include/vrt.h b/include/vrt.h
index 4071756a7..08d217dd8 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -72,6 +72,7 @@
* VRT_regsub signature changed
* VRT_call() added
* VRT_check_call() added
+ * VRT_handled() added
* 12.0 (2020-09-15)
* Added VRT_DirectorResolve()
* Added VCL_STRING VRT_BLOB_string(VRT_CTX, VCL_BLOB)
@@ -566,6 +567,7 @@ VCL_VOID VRT_hit_for_pass(VRT_CTX, VCL_DURATION);
VCL_BOOL VRT_ValidHdr(VRT_CTX, VCL_STRANDS);
VCL_VOID VRT_SetHdr(VRT_CTX, VCL_HEADER, const char *, ...);
VCL_VOID VRT_handling(VRT_CTX, unsigned hand);
+unsigned VRT_handled(VRT_CTX);
VCL_VOID VRT_fail(VRT_CTX, const char *fmt, ...) v_printflike_(2,3);
VCL_VOID VRT_hashdata(VRT_CTX, VCL_STRANDS);
More information about the varnish-commit
mailing list