[PATCH 1/4] Add ws overflow functions to vmod-debug
Lasse Karstensen
lkarsten at varnish-software.com
Fri Jul 31 09:48:26 CEST 2015
Add support for deterministic overflow of the different
workspaces in vtc.
---
lib/libvmod_debug/vmod.vcc | 16 ++++++++++
lib/libvmod_debug/vmod_debug.c | 70 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 86 insertions(+)
diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc
index 8b32e92..dad36ec 100644
--- a/lib/libvmod_debug/vmod.vcc
+++ b/lib/libvmod_debug/vmod.vcc
@@ -122,3 +122,19 @@ Return the dynamic backend.
$Method VOID .refresh(STRING addr, STRING port)
Dynamically refresh & (always!) replace the backend by a new one.
+
+$Function VOID workspace_allocate(ENUM { client, backend, session, thread }, INT SIZE)
+
+Allocate and zero out SIZE bytes from a workspace.
+
+$Function BOOL workspace_overflowed(ENUM { client, backend, session, thread })
+
+Return if the workspace overflow mark is set or not.
+
+$Function VOID workspace_overflow(ENUM { client, backend, session, thread })
+
+Mark a workspace as overflowed.
+
+$Function INT workspace_free(ENUM { client, backend, session, thread })
+
+Find how much unallocated space there is left in a workspace.
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index 4d86baa..47b1240 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -279,3 +279,73 @@ vmod_sleep(VRT_CTX, VCL_DURATION t)
CHECK_OBJ_ORNULL(ctx, VRT_CTX_MAGIC);
VTIM_sleep(t);
}
+
+static struct ws *
+wsfind(VRT_CTX, VCL_ENUM which) {
+ if (!strcmp(which, "client")) {
+ return ctx->ws;
+ } else if (!strcmp(which, "backend")) {
+ return ctx->bo->ws;
+ } else if (!strcmp(which, "session")) {
+ return ctx->req->sp->ws;
+ } else if (!strcmp(which, "thread")) {
+ return ctx->req->wrk->aws;
+ } else
+ WRONG("No such workspace.");
+}
+
+void
+vmod_workspace_allocate(VRT_CTX, VCL_ENUM which, VCL_INT size)
+{
+ struct ws *ws;
+ char *s;
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+
+ ws = wsfind(ctx, which);
+
+ WS_Assert(ws);
+ AZ(ws->r);
+
+ s = WS_Alloc(ws, size);
+ if (!s)
+ return;
+ memset(s, '\0', size);
+}
+
+VCL_INT
+vmod_workspace_free(VRT_CTX, VCL_ENUM which)
+{
+ struct ws *ws;
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+
+ ws = wsfind(ctx, which);
+
+ WS_Assert(ws);
+ AZ(ws->r);
+
+ return pdiff(ws->f, ws->e);
+}
+
+VCL_BOOL
+vmod_workspace_overflowed(VRT_CTX, VCL_ENUM which)
+{
+ struct ws *ws;
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+
+ ws = wsfind(ctx, which);
+ WS_Assert(ws);
+
+ return (WS_Overflowed(ws));
+}
+
+void
+vmod_workspace_overflow(VRT_CTX, VCL_ENUM which)
+{
+ struct ws *ws;
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+
+ ws = wsfind(ctx, which);
+ WS_Assert(ws);
+
+ WS_MarkOverflow(ws);
+}
--
2.1.4
--
Lasse Karstensen
Varnish Software AS
More information about the varnish-dev
mailing list