[master] 0ad326227 Add a 'debug.reqpool.fail F__F____F_FFF' command

Poul-Henning Kamp phk at FreeBSD.org
Mon Mar 11 11:49:07 UTC 2019


commit 0ad32622710c1787d85333faea844d4ab4dd760d
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Mar 11 11:44:41 2019 +0000

    Add a 'debug.reqpool.fail F__F____F_FFF' command
    
    The argument is read LR and causes TASK_QUEUE_REQ allocs to fail.

diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c
index 4683a3f3e..02ae0df84 100644
--- a/bin/varnishd/cache/cache_main.c
+++ b/bin/varnishd/cache/cache_main.c
@@ -392,10 +392,13 @@ child_main(int sigmagic, size_t altstksz)
 
 	VMOD_Init();
 
+	WRK_Init();
+
 	BAN_Compile();
 
 	VRND_SeedAll();
 
+
 	CLI_AddFuncs(debug_cmds);
 
 #if WITH_PERSISTENT_STORAGE
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index a117d8b8d..f5c4bf656 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -452,6 +452,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 48672a9ea..ffa63deba 100644
--- a/bin/varnishd/cache/cache_wrk.c
+++ b/bin/varnishd/cache/cache_wrk.c
@@ -57,12 +57,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;
@@ -260,6 +263,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. */
@@ -609,3 +623,40 @@ 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 f886f94db..99193c6c7 100644
--- a/include/tbl/cli_cmds.h
+++ b/include/tbl/cli_cmds.h
@@ -321,6 +321,15 @@ 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