[master] 8b3e91687 Teach the debug storage engine to return less space then requested

Nils Goroll nils.goroll at uplex.de
Tue Sep 28 19:26:03 UTC 2021


commit 8b3e9168742378469eadf1c67f174ad6fc844931
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Tue Sep 28 20:05:41 2021 +0200

    Teach the debug storage engine to return less space then requested
    
    for the objgetspace callback
    
    This makes b17.vtc fail with fc1ce6daf6a966df3aa8b7519228f60b040ff072 reverted.

diff --git a/bin/varnishd/storage/storage_debug.c b/bin/varnishd/storage/storage_debug.c
index f91c74f1e..23cd5040c 100644
--- a/bin/varnishd/storage/storage_debug.c
+++ b/bin/varnishd/storage/storage_debug.c
@@ -33,20 +33,57 @@
 #include "config.h"
 
 #include "cache/cache_varnishd.h"
+#include "cache/cache_obj.h"
+
+#include <stdlib.h>
 
 #include "storage/storage.h"
 #include "storage/storage_simple.h"
 
+/* returns one byte less than requested */
+static int v_matchproto_(objgetspace_f)
+smd_lsp_getspace(struct worker *wrk, struct objcore *oc, ssize_t *sz,
+    uint8_t **ptr)
+{
+	AN(sz);
+	if (*sz > 1)
+		(*sz)--;
+	return (SML_methods.objgetspace(wrk, oc, sz, ptr));
+}
+
 static void
-smd_init(struct stevedore *parent, int ac, char * const *av)
+smd_init(struct stevedore *parent, int aac, char * const *aav)
 {
+	struct obj_methods *methods;
 	const char *ident;
+	int i, ac = 0;
+	char **av;
 
 	ident = parent->ident;
 	memcpy(parent, &sma_stevedore, sizeof *parent);
 	parent->ident = ident;
 	parent->name = smd_stevedore.name;
 
+	methods = malloc(sizeof *methods);
+	AN(methods);
+	memcpy(methods, &SML_methods, sizeof *methods);
+	parent->methods = methods;
+
+	av = malloc(sizeof *av * (aac + 1));
+	AN(av);
+	for (i = 0; i < aac; i++) {
+		if (aav[i] == NULL) {
+			av[ac++] = NULL;
+			continue;
+		}
+		if (! strcmp(aav[i], "lessspace")) {
+			methods->objgetspace = smd_lsp_getspace;
+			continue;
+		}
+		av[ac++] = strdup(aav[i]);
+	}
+	av[ac] = NULL;
+
 	sma_stevedore.init(parent, ac, av);
 }
 
diff --git a/bin/varnishtest/tests/b00017.vtc b/bin/varnishtest/tests/b00017.vtc
index c886e17e1..b205a8064 100644
--- a/bin/varnishtest/tests/b00017.vtc
+++ b/bin/varnishtest/tests/b00017.vtc
@@ -1,6 +1,6 @@
 varnishtest "Check set resp.body in vcl_synth"
 
-varnish v1 -arg "-sTransient=debug" -vcl {
+varnish v1 -arg "-sTransient=debug,lessspace" -vcl {
 	backend foo {
 		.host = "${bad_backend}";
 	}


More information about the varnish-commit mailing list