[master] 0e4174c Fail name checks early in varnishtest
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Thu Mar 9 17:35:07 CET 2017
commit 0e4174c0d3187e126494443a9588ef3a6e5f2b1d
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Thu Mar 9 17:30:56 2017 +0100
Fail name checks early in varnishtest
It closes a race for barriers because the list could be updated by the
top thread while walked by another thread. It also saves useless lookups
by rejecting names earlier.
This is not the case for servers because a) they have proper locking of
the servers list and b) there is the dispatch special case. It would
otherwise be harmless to do it for the server too because dispatched
servers don't depend on user input.
diff --git a/bin/varnishtest/vtc_barrier.c b/bin/varnishtest/vtc_barrier.c
index 6a131a0..8cd80d9 100644
--- a/bin/varnishtest/vtc_barrier.c
+++ b/bin/varnishtest/vtc_barrier.c
@@ -74,7 +74,6 @@ barrier_new(const char *name, struct vtclog *vl)
{
struct barrier *b;
- VTC_CHECK_NAME(vl, name, "Barrier", 'b');
ALLOC_OBJ(b, BARRIER_MAGIC);
AN(b);
if (pthread_self() != vtc_thread)
@@ -436,6 +435,7 @@ cmd_barrier(CMD_ARGS)
AZ(strcmp(av[0], "barrier"));
av++;
+ VTC_CHECK_NAME(vl, av[0], "Barrier", 'b');
VTAILQ_FOREACH(b, &barriers, list)
if (!strcmp(b->name, av[0]))
break;
diff --git a/bin/varnishtest/vtc_client.c b/bin/varnishtest/vtc_client.c
index 24296ba..7f317ac 100644
--- a/bin/varnishtest/vtc_client.c
+++ b/bin/varnishtest/vtc_client.c
@@ -165,11 +165,10 @@ client_thread(void *priv)
*/
static struct client *
-client_new(const char *name, struct vtclog *vl)
+client_new(const char *name)
{
struct client *c;
- VTC_CHECK_NAME(vl, name, "Client", 'c');
ALLOC_OBJ(c, CLIENT_MAGIC);
AN(c);
REPLACE(c->name, name);
@@ -269,11 +268,12 @@ cmd_client(CMD_ARGS)
AZ(strcmp(av[0], "client"));
av++;
+ VTC_CHECK_NAME(vl, av[0], "Client", 'c');
VTAILQ_FOREACH(c, &clients, list)
if (!strcmp(c->name, av[0]))
break;
if (c == NULL)
- c = client_new(av[0], vl);
+ c = client_new(av[0]);
av++;
for (; *av != NULL; av++) {
diff --git a/bin/varnishtest/vtc_logexp.c b/bin/varnishtest/vtc_logexp.c
index 4bed257..45e856e 100644
--- a/bin/varnishtest/vtc_logexp.c
+++ b/bin/varnishtest/vtc_logexp.c
@@ -199,11 +199,10 @@ logexp_delete(struct logexp *le)
}
static struct logexp *
-logexp_new(const char *name, struct vtclog *vl)
+logexp_new(const char *name)
{
struct logexp *le;
- VTC_CHECK_NAME(vl, name, "Logexpect", 'l');
ALLOC_OBJ(le, LOGEXP_MAGIC);
AN(le);
REPLACE(le->name, name);
@@ -528,12 +527,13 @@ cmd_logexpect(CMD_ARGS)
AZ(strcmp(av[0], "logexpect"));
av++;
+ VTC_CHECK_NAME(vl, av[0], "Logexpect", 'l');
VTAILQ_FOREACH(le, &logexps, list) {
if (!strcmp(le->name, av[0]))
break;
}
if (le == NULL)
- le = logexp_new(av[0], vl);
+ le = logexp_new(av[0]);
av++;
for (; *av != NULL; av++) {
diff --git a/bin/varnishtest/vtc_process.c b/bin/varnishtest/vtc_process.c
index 46d97ae..8960692 100644
--- a/bin/varnishtest/vtc_process.c
+++ b/bin/varnishtest/vtc_process.c
@@ -85,13 +85,12 @@ static VTAILQ_HEAD(, process) processes =
} while (0)
static struct process *
-process_new(const char *name, struct vtclog *vl)
+process_new(const char *name)
{
struct process *p;
struct vsb *vsb;
char buf[1024];
- VTC_CHECK_NAME(vl, name, "Process", 'p');
ALLOC_OBJ(p, PROCESS_MAGIC);
AN(p);
REPLACE(p->name, name);
@@ -455,11 +454,12 @@ cmd_process(CMD_ARGS)
AZ(strcmp(av[0], "process"));
av++;
+ VTC_CHECK_NAME(vl, av[0], "Process", 'p');
VTAILQ_FOREACH(p, &processes, list)
if (!strcmp(p->name, av[0]))
break;
if (p == NULL)
- p = process_new(av[0], vl);
+ p = process_new(av[0]);
av++;
for (; *av != NULL; av++) {
diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c
index 26d478d..5941848 100644
--- a/bin/varnishtest/vtc_varnish.c
+++ b/bin/varnishtest/vtc_varnish.c
@@ -268,13 +268,12 @@ varnishlog_thread(void *priv)
*/
static struct varnish *
-varnish_new(const char *name, struct vtclog *vl)
+varnish_new(const char *name)
{
struct varnish *v;
struct vsb *vsb;
char buf[1024];
- VTC_CHECK_NAME(vl, name, "Varnish", 'v');
ALLOC_OBJ(v, VARNISH_MAGIC);
AN(v);
REPLACE(v->name, name);
@@ -1075,11 +1074,12 @@ cmd_varnish(CMD_ARGS)
AZ(strcmp(av[0], "varnish"));
av++;
+ VTC_CHECK_NAME(vl, av[0], "Varnish", 'v');
VTAILQ_FOREACH(v, &varnishes, list)
if (!strcmp(v->name, av[0]))
break;
if (v == NULL)
- v = varnish_new(av[0], vl);
+ v = varnish_new(av[0]);
av++;
for (; *av != NULL; av++) {
More information about the varnish-commit
mailing list