[master] 0020803 More polishing of the stevedore code, to try to find out what FlexeLint is getting its knickers in a twist about.
Poul-Henning Kamp
phk at FreeBSD.org
Tue Nov 1 20:45:05 CET 2016
commit 0020803ef0685089d3371c33ace9423d28a290f1
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Nov 1 19:43:58 2016 +0000
More polishing of the stevedore code, to try to find out what
FlexeLint is getting its knickers in a twist about.
diff --git a/bin/varnishd/storage/mgt_stevedore.c b/bin/varnishd/storage/mgt_stevedore.c
index 89399f1..b199ce6 100644
--- a/bin/varnishd/storage/mgt_stevedore.c
+++ b/bin/varnishd/storage/mgt_stevedore.c
@@ -44,17 +44,19 @@
#include "storage/storage.h"
#include "vav.h"
-struct stevedore_head stv_stevedores =
- VTAILQ_HEAD_INITIALIZER(stv_stevedores);
+static VTAILQ_HEAD(, stevedore) stevedores =
+ VTAILQ_HEAD_INITIALIZER(stevedores);
struct stevedore *stv_transient;
/*--------------------------------------------------------------------*/
int
-STV__iter(struct stevedore **pp)
+STV__iter(struct stevedore ** const pp)
{
+ AN(pp);
+ CHECK_OBJ_ORNULL(*pp, STEVEDORE_MAGIC);
if (*pp == stv_transient) {
*pp = NULL;
return (0);
@@ -62,7 +64,7 @@ STV__iter(struct stevedore **pp)
if (*pp != NULL)
*pp = VTAILQ_NEXT(*pp, list);
else
- *pp = VTAILQ_FIRST(&stv_stevedores);
+ *pp = VTAILQ_FIRST(&stevedores);
if (*pp == NULL)
*pp = stv_transient;
return (1);
@@ -79,9 +81,7 @@ stv_cli_list(struct cli *cli, const char * const *av, void *priv)
(void)av;
(void)priv;
VCLI_Out(cli, "Storage devices:\n");
- stv = stv_transient;
- VCLI_Out(cli, "\tstorage.%s = %s\n", stv->ident, stv->name);
- VTAILQ_FOREACH(stv, &stv_stevedores, list)
+ STV_Foreach(stv)
VCLI_Out(cli, "\tstorage.%s = %s\n", stv->ident, stv->name);
}
@@ -138,6 +138,7 @@ STV_Config(const char *spec)
const char *p, *q;
struct stevedore *stv;
const struct stevedore *stv2;
+ struct stevedore *stv3;
int ac, l;
static unsigned seq = 0;
@@ -185,12 +186,10 @@ STV_Config(const char *spec)
bprintf(stv->ident, "%.*s", l, spec);
}
- VTAILQ_FOREACH(stv2, &stv_stevedores, list) {
- if (strcmp(stv2->ident, stv->ident))
- continue;
- ARGV_ERR("(-s%s=%s) already defined once\n",
- stv->ident, stv->name);
- }
+ STV_Foreach(stv3)
+ if (!strcmp(stv3->ident, stv->ident))
+ ARGV_ERR("(-s%s=%s) already defined once\n",
+ stv->ident, stv->name);
if (stv->init != NULL)
stv->init(stv, ac, av);
@@ -204,7 +203,7 @@ STV_Config(const char *spec)
AZ(stv_transient);
stv_transient = stv;
} else {
- VTAILQ_INSERT_TAIL(&stv_stevedores, stv, list);
+ VTAILQ_INSERT_TAIL(&stevedores, stv, list);
}
/* NB: Do not free av, stevedore gets to keep it */
}
diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index c32105a..ef90263 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -43,7 +43,6 @@
#include "vrt.h"
#include "vrt_obj.h"
-static const struct stevedore * volatile stv_next;
/*--------------------------------------------------------------------
* XXX: trust pointer writes to be atomic
@@ -52,16 +51,15 @@ static const struct stevedore * volatile stv_next;
const struct stevedore *
STV_next()
{
- struct stevedore *stv;
- if (stv_next == NULL)
- return (stv_transient);
- /* pick a stevedore and bump the head along */
- stv = VTAILQ_NEXT(stv_next, list);
- if (stv == NULL)
- stv = VTAILQ_FIRST(&stv_stevedores);
+ static struct stevedore *stv;
+
+ if (!STV__iter(&stv))
+ AN(STV__iter(&stv));
+ if (stv == stv_transient) {
+ stv = NULL;
+ AN(STV__iter(&stv));
+ }
AN(stv);
- AN(stv->name);
- stv_next = stv;
return (stv);
}
@@ -106,7 +104,6 @@ STV_open(void)
if (stv->open != NULL)
stv->open(stv);
}
- stv_next = VTAILQ_FIRST(&stv_stevedores);
}
void
diff --git a/bin/varnishd/storage/storage.h b/bin/varnishd/storage/storage.h
index c87c5e9..849e442 100644
--- a/bin/varnishd/storage/storage.h
+++ b/bin/varnishd/storage/storage.h
@@ -125,14 +125,13 @@ struct stevedore {
char *vclname;
};
-VTAILQ_HEAD(stevedore_head, stevedore);
-
-extern struct stevedore_head stv_stevedores;
extern struct stevedore *stv_transient;
/*--------------------------------------------------------------------*/
+
#define STV_Foreach(arg) for(arg = NULL; STV__iter(&arg);)
-int STV__iter(struct stevedore **);
+
+int STV__iter(struct stevedore ** const );
/*--------------------------------------------------------------------*/
int STV_GetFile(const char *fn, int *fdp, const char **fnp, const char *ctx);
diff --git a/bin/varnishd/storage/storage_simple.c b/bin/varnishd/storage/storage_simple.c
index bf0834c..957c8f4 100644
--- a/bin/varnishd/storage/storage_simple.c
+++ b/bin/varnishd/storage/storage_simple.c
@@ -134,7 +134,7 @@ SML_allocobj(struct worker *wrk, const struct stevedore *stv,
struct objcore *oc, unsigned wsl, int nuke_limit)
{
struct object *o;
- struct storage *st;
+ struct storage *st = NULL;
unsigned ltot;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
diff --git a/bin/varnishtest/tests/c00044.vtc b/bin/varnishtest/tests/c00044.vtc
index 46bd2b3..2c0cf66 100644
--- a/bin/varnishtest/tests/c00044.vtc
+++ b/bin/varnishtest/tests/c00044.vtc
@@ -18,9 +18,9 @@ server s1 {
} -start
varnish v1 \
- -arg "-smalloc,1m" \
- -arg "-smalloc,1m" \
- -arg "-smalloc,1m" \
+ -arg "-ss1=malloc,1m" \
+ -arg "-ss2=malloc,1m" \
+ -arg "-ss0=malloc,1m" \
-vcl+backend {
sub vcl_backend_response {
set beresp.do_stream = false;
diff --git a/bin/varnishtest/tests/c00078.vtc b/bin/varnishtest/tests/c00078.vtc
index e7047ff..3a33888 100644
--- a/bin/varnishtest/tests/c00078.vtc
+++ b/bin/varnishtest/tests/c00078.vtc
@@ -5,8 +5,11 @@ server s1 -repeat 6 {
txresp
} -start
-varnish v1 -arg "-smalloc,1m" -arg "-smalloc,1m" \
- -arg "-smalloc,1m" -vcl+backend {
+varnish v1 \
+ -arg "-ss1=malloc,1m" \
+ -arg "-ss2=malloc,1m" \
+ -arg "-ss0=malloc,1m" \
+ -vcl+backend {
import debug;
sub vcl_backend_response {
if (bereq.url == "/1") {
More information about the varnish-commit
mailing list