[master] 2235d9ed3 Introduce a debug storage which is just malloc with a different name

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


commit 2235d9ed3a7c0f0d65d2d96baa7fa737dcd31379
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Tue Sep 28 19:15:59 2021 +0200

    Introduce a debug storage which is just malloc with a different name
    
    To avoid code duplication, we only provide an init callback, which
    copies all other callbacks from the malloc storage.

diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index 27d931ab3..af04e2995 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -101,6 +101,7 @@ varnishd_SOURCES = \
 	storage/storage_file.c \
 	storage/storage_lru.c \
 	storage/storage_malloc.c \
+	storage/storage_debug.c \
 	storage/storage_simple.c \
 	storage/storage_umem.c \
 	waiter/cache_waiter.c \
diff --git a/bin/varnishd/storage/mgt_stevedore.c b/bin/varnishd/storage/mgt_stevedore.c
index f96f841ce..c593c4d9d 100644
--- a/bin/varnishd/storage/mgt_stevedore.c
+++ b/bin/varnishd/storage/mgt_stevedore.c
@@ -152,6 +152,7 @@ static const struct stevedore smp_fake_stevedore = {
 static const struct choice STV_choice[] = {
 	{ "file",			&smf_stevedore },
 	{ "malloc",			&sma_stevedore },
+	{ "debug",			&smd_stevedore },
 #ifdef WITH_PERSISTENT_STORAGE
 	{ "deprecated_persistent",	&smp_stevedore },
 	{ "persistent",			&smp_fake_stevedore },
diff --git a/bin/varnishd/storage/storage.h b/bin/varnishd/storage/storage.h
index 060c41a24..e6c0a0cfd 100644
--- a/bin/varnishd/storage/storage.h
+++ b/bin/varnishd/storage/storage.h
@@ -144,5 +144,6 @@ void LRU_Touch(struct worker *, struct objcore *, vtim_real now);
 /*--------------------------------------------------------------------*/
 extern const struct stevedore smu_stevedore;
 extern const struct stevedore sma_stevedore;
+extern const struct stevedore smd_stevedore;
 extern const struct stevedore smf_stevedore;
 extern const struct stevedore smp_stevedore;
diff --git a/bin/varnishd/storage/storage_debug.c b/bin/varnishd/storage/storage_debug.c
new file mode 100644
index 000000000..f91c74f1e
--- /dev/null
+++ b/bin/varnishd/storage/storage_debug.c
@@ -0,0 +1,58 @@
+/*-
+ * Copyright 2021 UPLEX - Nils Goroll Systemoptimierung
+ * All rights reserved.
+ *
+ * Author: Nils Goroll <nils.goroll at uplex.de>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * debug helper storage based on malloc
+ */
+
+#include "config.h"
+
+#include "cache/cache_varnishd.h"
+
+#include "storage/storage.h"
+#include "storage/storage_simple.h"
+
+static void
+smd_init(struct stevedore *parent, int ac, char * const *av)
+{
+	const char *ident;
+
+	ident = parent->ident;
+	memcpy(parent, &sma_stevedore, sizeof *parent);
+	parent->ident = ident;
+	parent->name = smd_stevedore.name;
+
+	sma_stevedore.init(parent, ac, av);
+}
+
+const struct stevedore smd_stevedore = {
+	.magic		=	STEVEDORE_MAGIC,
+	.name		=	"debug",
+	.init		=	smd_init,
+	// other callbacks initialized in smd_init()
+};
diff --git a/bin/varnishd/storage/storage_malloc.c b/bin/varnishd/storage/storage_malloc.c
index 6bb789e8b..cf0bf2544 100644
--- a/bin/varnishd/storage/storage_malloc.c
+++ b/bin/varnishd/storage/storage_malloc.c
@@ -187,19 +187,20 @@ sma_init(struct stevedore *parent, int ac, char * const *av)
 
 	AZ(av[ac]);
 	if (ac > 1)
-		ARGV_ERR("(-smalloc) too many arguments\n");
+		ARGV_ERR("(-s%s) too many arguments\n", parent->name);
 
 	if (ac == 0 || *av[0] == '\0')
 		 return;
 
 	e = VNUM_2bytes(av[0], &u, 0);
 	if (e != NULL)
-		ARGV_ERR("(-smalloc) size \"%s\": %s\n", av[0], e);
+		ARGV_ERR("(-s%s) size \"%s\": %s\n", parent->name, av[0], e);
 	if ((u != (uintmax_t)(size_t)u))
-		ARGV_ERR("(-smalloc) size \"%s\": too big\n", av[0]);
+		ARGV_ERR("(-s%s) size \"%s\": too big\n", parent->name, av[0]);
 	if (u < 1024*1024)
-		ARGV_ERR("(-smalloc) size \"%s\": too small, "
-			 "did you forget to specify M or G?\n", av[0]);
+		ARGV_ERR("(-s%s) size \"%s\": too small, "
+		    "did you forget to specify M or G?\n", parent->name,
+		    av[0]);
 
 	sc->sma_max = u;
 }
diff --git a/bin/varnishtest/tests/b00017.vtc b/bin/varnishtest/tests/b00017.vtc
index 29fbe9e69..c886e17e1 100644
--- a/bin/varnishtest/tests/b00017.vtc
+++ b/bin/varnishtest/tests/b00017.vtc
@@ -1,6 +1,6 @@
-varnishtest "Check that we do not close one error"
+varnishtest "Check set resp.body in vcl_synth"
 
-varnish v1 -vcl {
+varnish v1 -arg "-sTransient=debug" -vcl {
 	backend foo {
 		.host = "${bad_backend}";
 	}


More information about the varnish-commit mailing list