[master] 1e2e40ce6 vtc: Allow a tunnel to start already paused

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Fri May 28 08:59:05 UTC 2021


commit 1e2e40ce6488910411fc674aa9cb40d615e6bf97
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Fri May 28 09:46:02 2021 +0200

    vtc: Allow a tunnel to start already paused
    
    To cut down synchronization needs for the very beginning of a session.

diff --git a/bin/varnishtest/tests/a00021.vtc b/bin/varnishtest/tests/a00021.vtc
index c7c175e79..9eb158582 100644
--- a/bin/varnishtest/tests/a00021.vtc
+++ b/bin/varnishtest/tests/a00021.vtc
@@ -30,3 +30,17 @@ client c1 -connect "${t1_sock}" {
 } -run
 
 tunnel t1 -wait
+
+server s2 {
+	rxreq
+	txresp
+} -start
+
+tunnel t2 -connect "${s2_sock}" {
+	resume
+} -start+pause
+
+client c2 -connect "${t2_sock}" {
+	txreq
+	rxresp
+} -run
diff --git a/bin/varnishtest/vtc_tunnel.c b/bin/varnishtest/vtc_tunnel.c
index 41ce3c775..4f6f24c7b 100644
--- a/bin/varnishtest/vtc_tunnel.c
+++ b/bin/varnishtest/vtc_tunnel.c
@@ -64,6 +64,9 @@
  *        Start the tunnel in background, processing the last given
  *        specification.
  *
+ * \-start+pause
+ *        Start the tunnel, but already paused.
+ *
  * \-wait
  *        Block until the thread finishes.
  *
@@ -122,6 +125,7 @@ struct tunnel {
 	struct vtclog		*vl;
 	VTAILQ_ENTRY(tunnel)	list;
 	enum tunnel_state_e	state;
+	unsigned		start_paused;
 
 	char			*spec;
 
@@ -474,7 +478,11 @@ tunnel_accept(struct tunnel *t, struct vtclog *vl)
 	t->send_lane->wrk_len = 0;
 	t->recv_lane->buf_len = 0;
 	t->recv_lane->wrk_len = 0;
-	t->state = TUNNEL_RUNNING;
+	if (t->start_paused) {
+		t->state = TUNNEL_PAUSED;
+		t->start_paused = 0;
+	} else
+		t->state = TUNNEL_RUNNING;
 	AZ(pthread_cond_signal(&t->cond));
 	AZ(pthread_mutex_unlock(&t->mtx));
 }
@@ -614,6 +622,15 @@ tunnel_start(struct tunnel *t)
 	AZ(pthread_create(&t->tspec, NULL, tunnel_spec_thread, t));
 }
 
+static void
+tunnel_start_pause(struct tunnel *t)
+{
+
+	CHECK_OBJ_NOTNULL(t, TUNNEL_MAGIC);
+	t->start_paused = 1;
+	tunnel_start(t);
+}
+
 /**********************************************************************
  * Wait for tunnel thread to stop
  */
@@ -744,6 +761,10 @@ cmd_tunnel(CMD_ARGS)
 			tunnel_start(t);
 			continue;
 		}
+		if (!strcmp(*av, "-start+pause")) {
+			tunnel_start_pause(t);
+			continue;
+		}
 		if (**av == '-')
 			vtc_fatal(t->vl, "Unknown tunnel argument: %s", *av);
 		t->spec = *av;


More information about the varnish-commit mailing list