[master] 4aeb4f6 Simplify the mgt->child handover of CLI setup
Poul-Henning Kamp
phk at FreeBSD.org
Mon Nov 6 11:13:06 UTC 2017
commit 4aeb4f63aec4525d1d5f00c4eae3da72801a3bfa
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Nov 6 11:12:17 2017 +0000
Simplify the mgt->child handover of CLI setup
diff --git a/bin/varnishd/cache/cache_cli.c b/bin/varnishd/cache/cache_cli.c
index 343a576..b674147 100644
--- a/bin/varnishd/cache/cache_cli.c
+++ b/bin/varnishd/cache/cache_cli.c
@@ -44,7 +44,7 @@
pthread_t cli_thread;
static struct lock cli_mtx;
static int add_check;
-static struct VCLS *cls;
+static struct VCLS *cache_cls;
/*
* The CLI commandlist is split in three:
@@ -64,7 +64,7 @@ CLI_AddFuncs(struct cli_proto *p)
AZ(add_check);
Lck_Lock(&cli_mtx);
- VCLS_AddFunc(cls, 0, p);
+ VCLS_AddFunc(cache_cls, 0, p);
Lck_Unlock(&cli_mtx);
}
@@ -96,10 +96,10 @@ CLI_Run(void)
add_check = 1;
- AN(VCLS_AddFd(cls, heritage.cli_in, heritage.cli_out, NULL, NULL));
+ AN(VCLS_AddFd(cache_cls, heritage.cli_in, heritage.cli_out, NULL, NULL));
do {
- i = VCLS_PollFd(cls, heritage.cli_in, -1);
+ i = VCLS_PollFd(cache_cls, heritage.cli_in, -1);
} while (i == 0);
VSL(SLT_CLI, 0, "EOF on CLI connection, worker stops");
}
@@ -123,10 +123,9 @@ CLI_Init(void)
Lck_New(&cli_mtx, lck_cli);
cli_thread = pthread_self();
- cls = VCLS_New(cli_cb_before, cli_cb_after,
- &cache_param->cli_buffer, &cache_param->cli_limit);
- AN(cls);
- VCLS_Clone(cls, heritage.cls);
+ cache_cls = heritage.cls;
+ AN(cache_cls);
+ VCLS_SetHooks(cache_cls, cli_cb_before, cli_cb_after);
CLI_AddFuncs(cli_cmds);
}
diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c
index dd031ed..720bfea 100644
--- a/bin/varnishd/mgt/mgt_cli.c
+++ b/bin/varnishd/mgt/mgt_cli.c
@@ -364,9 +364,9 @@ void
mgt_cli_init_cls(void)
{
- mgt_cls = VCLS_New(mgt_cli_cb_before, mgt_cli_cb_after,
- &mgt_param.cli_buffer, &mgt_param.cli_limit);
+ mgt_cls = VCLS_New(&mgt_param.cli_buffer, &mgt_param.cli_limit);
AN(mgt_cls);
+ VCLS_SetHooks(mgt_cls, mgt_cli_cb_before, mgt_cli_cb_after);
VCLS_AddFunc(mgt_cls, MCF_NOAUTH, cli_auth);
VCLS_AddFunc(mgt_cls, MCF_AUTH, cli_proto);
VCLS_AddFunc(mgt_cls, MCF_AUTH, cli_debug);
diff --git a/include/vcli_serve.h b/include/vcli_serve.h
index ddaaa61..a1e6bb3 100644
--- a/include/vcli_serve.h
+++ b/include/vcli_serve.h
@@ -92,14 +92,13 @@ void VCLI_SetResult(struct cli *cli, unsigned r);
typedef void cls_cb_f(void *priv);
typedef void cls_cbc_f(const struct cli*);
-struct VCLS *VCLS_New(cls_cbc_f *before, cls_cbc_f *after,
- volatile unsigned *maxlen, volatile unsigned *limit);
+struct VCLS *VCLS_New(volatile unsigned *maxlen, volatile unsigned *limit);
+void VCLS_SetHooks(struct VCLS *, cls_cbc_f *, cls_cbc_f *);
struct cli *VCLS_AddFd(struct VCLS *cs, int fdi, int fdo, cls_cb_f *closefunc,
void *priv);
void VCLS_AddFunc(struct VCLS *cs, unsigned auth, struct cli_proto *clp);
int VCLS_PollFd(struct VCLS *cs, int fd, int timeout);
void VCLS_Destroy(struct VCLS **);
-void VCLS_Clone(struct VCLS *cs, struct VCLS *cso);
/* From libvarnish/cli.c */
cli_func_t VCLS_func_close;
diff --git a/lib/libvarnish/vcli_serve.c b/lib/libvarnish/vcli_serve.c
index a26c50b..626ec3a 100644
--- a/lib/libvarnish/vcli_serve.c
+++ b/lib/libvarnish/vcli_serve.c
@@ -400,8 +400,7 @@ cls_vlu(void *priv, const char *p)
}
struct VCLS *
-VCLS_New(cls_cbc_f *before, cls_cbc_f *after, volatile unsigned *maxlen,
- volatile unsigned *limit)
+VCLS_New(volatile unsigned *maxlen, volatile unsigned *limit)
{
struct VCLS *cs;
@@ -409,13 +408,20 @@ VCLS_New(cls_cbc_f *before, cls_cbc_f *after, volatile unsigned *maxlen,
AN(cs);
VTAILQ_INIT(&cs->fds);
VTAILQ_INIT(&cs->funcs);
- cs->before = before;
- cs->after = after;
cs->maxlen = maxlen;
cs->limit = limit;
return (cs);
}
+void
+VCLS_SetHooks(struct VCLS *cs, cls_cbc_f *before, cls_cbc_f *after)
+{
+
+ CHECK_OBJ_NOTNULL(cs, VCLS_MAGIC);
+ cs->before = before;
+ cs->after = after;
+}
+
struct cli *
VCLS_AddFd(struct VCLS *cs, int fdi, int fdo, cls_cb_f *closefunc, void *priv)
{
@@ -499,26 +505,6 @@ VCLS_AddFunc(struct VCLS *cs, unsigned auth, struct cli_proto *clp)
}
}
-/*
- * This function has *very* special semantics, related to the mgt/worker
- * process Copy-On-Write memory relationship.
- */
-
-void
-VCLS_Clone(struct VCLS *cs, struct VCLS *cso)
-{
- struct cli_proto *clp, *clp2;
-
- CHECK_OBJ_NOTNULL(cs, VCLS_MAGIC);
- CHECK_OBJ_NOTNULL(cso, VCLS_MAGIC);
- VTAILQ_FOREACH_SAFE(clp, &cso->funcs, list, clp2) {
- VTAILQ_REMOVE(&cso->funcs, clp, list);
- VTAILQ_INSERT_TAIL(&cs->funcs, clp, list);
- clp->auth = 0;
- clp->func = NULL;
- }
-}
-
int
VCLS_PollFd(struct VCLS *cs, int fd, int timeout)
{
More information about the varnish-commit
mailing list