[6.0] 9fe43bdf8 Add a 'debug.reqpool.fail F__F____F_FFF' command

Reza Naghibi reza at naghibi.com
Thu Oct 17 16:33:07 UTC 2019


commit 9fe43bdf89fb02344ead9b8fa2bad939f51d8169
Author: Andrew Wiik <andrew at varnish-software.com>
Date:   Mon Oct 7 11:25:08 2019 -0400

    Add a 'debug.reqpool.fail F__F____F_FFF' command
    
    0ad32622710c1787d85333faea844d4ab4dd760d
    
    Co-authored-by: Poul-Henning Kamp <phk at FreeBSD.org>

diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c
index c86db2887..da5d1befd 100644
--- a/bin/varnishd/cache/cache_main.c
+++ b/bin/varnishd/cache/cache_main.c
@@ -391,6 +391,8 @@ child_main(int sigmagic, size_t altstksz)
 
 	VMOD_Init();
 
+	WRK_Init();
+
 	BAN_Compile();
 
 	VRND_SeedAll();
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index 45aba733a..ad5e0be6d 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -414,6 +414,9 @@ extern struct vrt_privs cli_task_privs[1];
 void VMOD_Init(void);
 void VMOD_Panic(struct vsb *);
 
+/* cache_wrk.c */
+void WRK_Init(void);
+
 /* http1/cache_http1_pipe.c */
 void V1P_Init(void);
 
diff --git a/bin/varnishd/cache/cache_wrk.c b/bin/varnishd/cache/cache_wrk.c
index 4d546ffd3..14bbfd4fd 100644
--- a/bin/varnishd/cache/cache_wrk.c
+++ b/bin/varnishd/cache/cache_wrk.c
@@ -58,12 +58,15 @@
 #include "cache_varnishd.h"
 #include "cache_pool.h"
 
+#include "vcli_serve.h"
 #include "vtim.h"
 
 #include "hash/hash_slinger.h"
 
 static void Pool_Work_Thread(struct pool *pp, struct worker *wrk);
 
+static uintmax_t reqpoolfail;
+
 /*--------------------------------------------------------------------
  * Create and start a back-ground thread which as its own worker and
  * session data structures;
@@ -261,6 +264,17 @@ Pool_Task(struct pool *pp, struct pool_task *task, enum task_prio prio)
 	AN(task->func);
 	assert(prio < TASK_QUEUE_END);
 
+	if (prio == TASK_QUEUE_REQ && reqpoolfail) {
+		retval = reqpoolfail & 1;
+		reqpoolfail >>= 1;
+		if (retval) {
+			VSL(SLT_Debug, 0,
+			    "Failing due to reqpoolfail (next= 0x%jx)",
+			    reqpoolfail);
+			return(retval);
+		}
+	}
+
 	Lck_Lock(&pp->mtx);
 
 	/* The common case first:  Take an idle thread, do it. */
@@ -610,3 +624,39 @@ pool_herder(void *priv)
 	}
 	return (NULL);
 }
+
+/*--------------------------------------------------------------------
+ * Debugging aids
+ */
+
+static void v_matchproto_(cli_func_t)
+debug_reqpoolfail(struct cli *cli, const char * const *av, void *priv)
+{
+	uintmax_t u = 1;
+	const char *p;
+
+        (void)priv;
+        (void)cli;
+	reqpoolfail = 0;
+	for (p = av[2]; *p != '\0'; p++) {
+		if (*p == 'F' || *p == 'f')
+			reqpoolfail |= u;
+		u <<= 1;
+	}
+}
+
+static struct cli_proto debug_cmds[] = {
+	{ CLICMD_DEBUG_REQPOOLFAIL,		"d", debug_reqpoolfail },
+	{ NULL }
+};
+
+/*--------------------------------------------------------------------
+ *
+ */
+
+void
+WRK_Init(void)
+{
+
+        CLI_AddFuncs(debug_cmds);
+}
diff --git a/include/tbl/cli_cmds.h b/include/tbl/cli_cmds.h
index 57efeaab6..732522736 100644
--- a/include/tbl/cli_cmds.h
+++ b/include/tbl/cli_cmds.h
@@ -278,6 +278,16 @@ CLI_CMD(DEBUG_FRAGFETCH,
 	1, 1
 )
 
+CLI_CMD(DEBUG_REQPOOLFAIL,
+	"debug.reqpool.fail",
+	"debug.reqpool.fail",
+	"Schedule req-pool failures.",
+	"The argument is read L-R and 'f' means fail:\n\n"
+	"\tparam.set debug.reqpoolfail F__F\n\n"
+	"Means that the frist and the third attempted allocation will fail",
+	1, 1
+)
+
 CLI_CMD(DEBUG_XID,
 	"debug.xid",
 	"debug.xid",


More information about the varnish-commit mailing list