[master] 722f654 Add a STV_Foreach() iterator, to isolate the clue to Transients special treatment.
Poul-Henning Kamp
phk at FreeBSD.org
Tue Nov 1 13:23:05 CET 2016
commit 722f654feede371ab9c98dd240d458b8e6954844
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Nov 1 12:22:28 2016 +0000
Add a STV_Foreach() iterator, to isolate the clue to Transients
special treatment.
diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c
index f8d6224..2cbaaeb 100644
--- a/bin/varnishd/mgt/mgt_vcc.c
+++ b/bin/varnishd/mgt/mgt_vcc.c
@@ -104,10 +104,9 @@ run_vcc(void *priv)
VCC_Err_Unref(vcc, mgt_vcc_err_unref);
VCC_Allow_InlineC(vcc, mgt_vcc_allow_inline_c);
VCC_Unsafe_Path(vcc, mgt_vcc_unsafe_path);
- VTAILQ_FOREACH(stv, &stv_stevedores, list)
+ STV_Foreach(stv)
VCC_Predef(vcc, "VCL_STEVEDORE", stv->ident);
mgt_vcl_export_labels(vcc);
- VCC_Predef(vcc, "VCL_STEVEDORE", stv_transient->ident);
csrc = VCC_Compile(vcc, &sb, vp->vclsrc, vp->vclsrcfile);
AZ(VSB_finish(sb));
if (VSB_len(sb))
diff --git a/bin/varnishd/storage/mgt_stevedore.c b/bin/varnishd/storage/mgt_stevedore.c
index dff69fd..89399f1 100644
--- a/bin/varnishd/storage/mgt_stevedore.c
+++ b/bin/varnishd/storage/mgt_stevedore.c
@@ -51,6 +51,25 @@ struct stevedore *stv_transient;
/*--------------------------------------------------------------------*/
+int
+STV__iter(struct stevedore **pp)
+{
+
+ if (*pp == stv_transient) {
+ *pp = NULL;
+ return (0);
+ }
+ if (*pp != NULL)
+ *pp = VTAILQ_NEXT(*pp, list);
+ else
+ *pp = VTAILQ_FIRST(&stv_stevedores);
+ if (*pp == NULL)
+ *pp = stv_transient;
+ return (1);
+}
+
+/*--------------------------------------------------------------------*/
+
static void __match_proto__(cli_func_t)
stv_cli_list(struct cli *cli, const char * const *av, void *priv)
{
diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index 072ba26..300faca 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -99,19 +99,13 @@ STV_open(void)
char buf[1024];
ASSERT_CLI();
- VTAILQ_FOREACH(stv, &stv_stevedores, list) {
+ STV_Foreach(stv) {
bprintf(buf, "storage.%s", stv->ident);
stv->vclname = strdup(buf);
AN(stv->vclname);
if (stv->open != NULL)
stv->open(stv);
}
- stv = stv_transient;
- bprintf(buf, "storage.%s", stv->ident);
- stv->vclname = strdup(buf);
- AN(stv->vclname);
- if (stv->open != NULL)
- stv->open(stv);
stv_next = VTAILQ_FIRST(&stv_stevedores);
}
@@ -124,11 +118,7 @@ STV_close(void)
ASSERT_CLI();
for (i = 1; i >= 0; i--) {
/* First send close warning */
- VTAILQ_FOREACH(stv, &stv_stevedores, list)
- if (stv->close != NULL)
- stv->close(stv, i);
- stv = stv_transient;
- if (stv->close != NULL)
+ STV_Foreach(stv)
if (stv->close != NULL)
stv->close(stv, i);
}
diff --git a/bin/varnishd/storage/storage.h b/bin/varnishd/storage/storage.h
index db8856b..c87c5e9 100644
--- a/bin/varnishd/storage/storage.h
+++ b/bin/varnishd/storage/storage.h
@@ -131,6 +131,10 @@ 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_GetFile(const char *fn, int *fdp, const char **fnp, const char *ctx);
uintmax_t STV_FileSize(int fd, const char *size, unsigned *granularity,
const char *ctx);
More information about the varnish-commit
mailing list