[master] f9f2a8655 wrk: Opportunistic logging in a worker's VSL buffer

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Dec 1 15:04:05 UTC 2021


commit f9f2a8655211412937cf161802b490bf9735f78b
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Wed Sep 8 10:21:26 2021 +0200

    wrk: Opportunistic logging in a worker's VSL buffer
    
    Since its primary usage will be workspace logs, workers can be
    initialized earlier to offer even more opportunity for logging.

diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c
index 095279dc3..2a102940e 100644
--- a/bin/varnishd/cache/cache_main.c
+++ b/bin/varnishd/cache/cache_main.c
@@ -408,6 +408,8 @@ child_main(int sigmagic, size_t altstksz)
 
 	ObjInit();
 
+	WRK_Init();
+
 	VCL_Init();
 	VCL_VRT_Init();
 
@@ -432,8 +434,6 @@ 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 a4192018f..59ea9b1cb 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -524,6 +524,7 @@ void VMOD_Panic(struct vsb *);
 /* cache_wrk.c */
 void WRK_Init(void);
 void WRK_AddStat(const struct worker *);
+void WRK_Log(enum VSL_tag_e, const char *, ...);
 
 /* cache_ws.c */
 void WS_Panic(struct vsb *, const struct ws *);
@@ -577,3 +578,9 @@ void SMP_Ready(void);
 		if (DO_DEBUG(debug_bit))			\
 			VSL(SLT_Debug, (id), __VA_ARGS__);	\
 	} while (0)
+
+#define DSLb(debug_bit, ...)					\
+	do {							\
+		if (DO_DEBUG(debug_bit))			\
+			WRK_Log(SLT_Debug, __VA_ARGS__);	\
+	} while (0)
diff --git a/bin/varnishd/cache/cache_wrk.c b/bin/varnishd/cache/cache_wrk.c
index 3cbb99fe2..e8e6f6154 100644
--- a/bin/varnishd/cache/cache_wrk.c
+++ b/bin/varnishd/cache/cache_wrk.c
@@ -738,6 +738,25 @@ static struct cli_proto debug_cmds[] = {
 	{ NULL }
 };
 
+void
+WRK_Log(enum VSL_tag_e tag, const char *fmt, ...)
+{
+	struct worker *wrk;
+	va_list ap;
+
+	AN(fmt);
+
+	wrk = THR_GetWorker();
+	CHECK_OBJ_ORNULL(wrk, WORKER_MAGIC);
+
+	va_start(ap, fmt);
+	if (wrk != NULL && wrk->vsl != NULL)
+		VSLbv(wrk->vsl, tag, fmt, ap);
+	else
+		VSLv(tag, 0, fmt, ap);
+	va_end(ap);
+}
+
 /*--------------------------------------------------------------------
  *
  */


More information about the varnish-commit mailing list