Mailing List Archive

[master] 0ac6be1bf Make the internal steps of the request-handling a (much more) private matter
commit 0ac6be1bf2b4d5ace463ca4287158fb220c5cc5a
Author: Poul-Henning Kamp <phk@FreeBSD.org>
Date: Mon Oct 26 09:53:43 2020 +0000

Make the internal steps of the request-handling a (much more) private matter

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index f763a9fa6..dbeabe7b1 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -103,6 +103,7 @@ struct transport;
struct worker;
struct listen_sock;
struct vcf;
+struct req_step;

#define DIGEST_LEN 32

@@ -115,14 +116,6 @@ typedef struct {

/*--------------------------------------------------------------------*/

-enum req_step {
- R_STP_NONE = 0,
-#define REQ_STEP(l, u, arg) R_STP_##u,
-#include "tbl/steps.h"
-};
-
-/*--------------------------------------------------------------------*/
-
struct lock { void *priv; }; // Opaque

/*--------------------------------------------------------------------
@@ -451,13 +444,19 @@ struct reqtop {

struct req {
unsigned magic;
-#define REQ_MAGIC 0x2751aaa1
+#define REQ_MAGIC 0xfb4abf6d

- enum req_step req_step;
body_status_t req_body_status;
enum sess_close doclose;
unsigned restarts;
unsigned esi_level;
+
+ /* Delivery mode */
+ unsigned res_mode;
+#define RES_ESI (1<<4)
+#define RES_PIPE (1<<7)
+
+ const struct req_step *req_step;
struct reqtop *top; /* esi_level == 0 request */

#define REQ_FLAG(l, r, w, d) unsigned l:1;
@@ -522,11 +521,6 @@ struct req {
struct vdp_ctx *vdc;
const char *filter_list;

- /* Delivery mode */
- unsigned res_mode;
-#define RES_ESI (1<<4)
-#define RES_PIPE (1<<7)
-
/* Transaction VSL buffer */
struct vsl_log vsl[1];

diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 253fa674a..a0292e023 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -454,7 +454,6 @@ pan_top(struct vsb *vsb, const struct reqtop *top)
static void
pan_req(struct vsb *vsb, const struct req *req)
{
- const char *stp;
const struct transport *xp;

VSB_printf(vsb, "req = %p {\n", req);
@@ -474,15 +473,10 @@ pan_req(struct vsb *vsb, const struct req *req)
VSB_cat(vsb, "}");
}
VSB_cat(vsb, "\n");
- switch (req->req_step) {
-#define REQ_STEP(l, u, arg) case R_STP_##u: stp = "R_STP_" #u; break;
-#include "tbl/steps.h"
- default: stp = NULL;
- }
- if (stp != NULL)
- VSB_printf(vsb, "step = %s,\n", stp);
+ if (req->req_step == NULL)
+ VSB_cat(vsb, "step = R_STP_TRANSPORT\n");
else
- VSB_printf(vsb, "step = 0x%x,\n", req->req_step);
+ VSB_printf(vsb, "step = %s\n", req->req_step->name);

VSB_printf(vsb, "req_body = %s,\n",
req->req_body_status ? req->req_body_status->name : "NULL");
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 47ed06b31..b84591bb8 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -53,11 +53,35 @@
#include "vsha256.h"
#include "vtim.h"

+#define REQ_STEPS \
+ REQ_STEP(transport, TRANSPORT, ) \
+ REQ_STEP(restart, RESTART, static) \
+ REQ_STEP(recv, RECV, ) \
+ REQ_STEP(pipe, PIPE, static) \
+ REQ_STEP(pass, PASS, static) \
+ REQ_STEP(lookup, LOOKUP, static) \
+ REQ_STEP(purge, PURGE, static) \
+ REQ_STEP(miss, MISS, static) \
+ REQ_STEP(fetch, FETCH, static) \
+ REQ_STEP(deliver, DELIVER, static) \
+ REQ_STEP(vclfail, VCLFAIL, static) \
+ REQ_STEP(synth, SYNTH, static) \
+ REQ_STEP(transmit, TRANSMIT, static)
+
+#define REQ_STEP(l, U, priv) \
+ static req_state_f cnt_##l; \
+ priv const struct req_step R_STP_##U[1] = {{ \
+ .name = "Fetch Step" #l, \
+ .func = cnt_##l, \
+ }};
+REQ_STEPS
+#undef REQ_STEP
+
/*--------------------------------------------------------------------
* Handle "Expect:" and "Connection:" on incoming request
*/

-static enum req_fsm_nxt
+static enum req_fsm_nxt v_matchproto_(req_state_f)
cnt_transport(struct worker *wrk, struct req *req)
{
const char *p;
@@ -177,7 +201,7 @@ Resp_Setup_Synth(struct req *req)
http_SetHeader(h, "Connection: close");
}

-static enum req_fsm_nxt
+static enum req_fsm_nxt v_matchproto_(req_state_f)
cnt_deliver(struct worker *wrk, struct req *req)
{

@@ -239,8 +263,8 @@ cnt_deliver(struct worker *wrk, struct req *req)
* VCL failed, die horribly
*/

-static enum req_fsm_nxt
-cnt_vclfail(const struct worker *wrk, struct req *req)
+static enum req_fsm_nxt v_matchproto_(req_state_f)
+cnt_vclfail(struct worker *wrk, struct req *req)
{

CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
@@ -263,7 +287,7 @@ cnt_vclfail(const struct worker *wrk, struct req *req)
* Emit a synthetic response
*/

-static enum req_fsm_nxt
+static enum req_fsm_nxt v_matchproto_(req_state_f)
cnt_synth(struct worker *wrk, struct req *req)
{
struct vsb *synth_body;
@@ -365,7 +389,7 @@ cnt_synth(struct worker *wrk, struct req *req)
* The mechanics of sending a response (from deliver or synth)
*/

-static enum req_fsm_nxt
+static enum req_fsm_nxt v_matchproto_(req_state_f)
cnt_transmit(struct worker *wrk, struct req *req)
{
struct boc *boc;
@@ -458,7 +482,7 @@ cnt_transmit(struct worker *wrk, struct req *req)
* Initiated a fetch (pass/miss) which we intend to deliver
*/

-static enum req_fsm_nxt
+static enum req_fsm_nxt v_matchproto_(req_state_f)
cnt_fetch(struct worker *wrk, struct req *req)
{

@@ -487,7 +511,7 @@ cnt_fetch(struct worker *wrk, struct req *req)
* this state if we get suspended on a busy objhdr.
*/

-static enum req_fsm_nxt
+static enum req_fsm_nxt v_matchproto_(req_state_f)
cnt_lookup(struct worker *wrk, struct req *req)
{
struct objcore *oc, *busy;
@@ -614,7 +638,7 @@ cnt_lookup(struct worker *wrk, struct req *req)
* Cache miss.
*/

-static enum req_fsm_nxt
+static enum req_fsm_nxt v_matchproto_(req_state_f)
cnt_miss(struct worker *wrk, struct req *req)
{

@@ -659,7 +683,7 @@ cnt_miss(struct worker *wrk, struct req *req)
* Pass processing
*/

-static enum req_fsm_nxt
+static enum req_fsm_nxt v_matchproto_(req_state_f)
cnt_pass(struct worker *wrk, struct req *req)
{

@@ -697,7 +721,7 @@ cnt_pass(struct worker *wrk, struct req *req)
* Pipe mode
*/

-static enum req_fsm_nxt
+static enum req_fsm_nxt v_matchproto_(req_state_f)
cnt_pipe(struct worker *wrk, struct req *req)
{
struct busyobj *bo;
@@ -769,7 +793,7 @@ cnt_pipe(struct worker *wrk, struct req *req)
* Handle restart events
*/

-static enum req_fsm_nxt
+static enum req_fsm_nxt v_matchproto_(req_state_f)
cnt_restart(struct worker *wrk, struct req *req)
{

@@ -803,7 +827,7 @@ cnt_restart(struct worker *wrk, struct req *req)
* - remove duplicatation with Req_Cleanup()
*/

-static void
+static void v_matchproto_(req_state_f)
cnt_recv_prep(struct req *req, const char *ci)
{
const char *xff;
@@ -849,7 +873,7 @@ cnt_recv_prep(struct req *req, const char *ci)
* a interior request during ESI delivery.
*/

-static enum req_fsm_nxt
+static enum req_fsm_nxt v_matchproto_(req_state_f)
cnt_recv(struct worker *wrk, struct req *req)
{
unsigned recv_handling;
@@ -986,7 +1010,7 @@ cnt_recv(struct worker *wrk, struct req *req)
* In VCL, a restart is necessary to get a new object
*/

-static enum req_fsm_nxt
+static enum req_fsm_nxt v_matchproto_(req_state_f)
cnt_purge(struct worker *wrk, struct req *req)
{
struct objcore *oc, *boc;
@@ -1037,7 +1061,7 @@ cnt_purge(struct worker *wrk, struct req *req)
*
*/

-static void
+static void v_matchproto_(req_state_f)
cnt_diag(struct req *req, const char *state)
{

@@ -1102,17 +1126,12 @@ CNT_Request(struct req *req)
CHECK_OBJ_ORNULL(wrk->nobjhead, OBJHEAD_MAGIC);
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);

- switch (req->req_step) {
-#define REQ_STEP(l,u,arg) \
- case R_STP_##u: \
- if (DO_DEBUG(DBG_REQ_STATE)) \
- cnt_diag(req, #u); \
- nxt = cnt_##l arg; \
- break;
-#include "tbl/steps.h"
- default:
- WRONG("State engine misfire");
- }
+ AN(req->req_step);
+ AN(req->req_step->name);
+ AN(req->req_step->func);
+ if (DO_DEBUG(DBG_REQ_STATE))
+ cnt_diag(req, req->req_step->name);
+ nxt = req->req_step->func(wrk, req);
CHECK_OBJ_ORNULL(wrk->nobjhead, OBJHEAD_MAGIC);
}
wrk->vsl = NULL;
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index f95f3c773..bc9750910 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -47,12 +47,23 @@
# include "VSC_main.h"
#endif

-/* -------------------------------------------------------------------*/
+/*--------------------------------------------------------------------*/

struct vfp;
struct cli_proto;
struct poolparam;

+/*--------------------------------------------------------------------*/
+
+typedef enum req_fsm_nxt req_state_f(struct worker *, struct req *);
+struct req_step {
+ const char *name;
+ req_state_f *func;
+};
+
+extern const struct req_step R_STP_TRANSPORT[1];
+extern const struct req_step R_STP_RECV[1];
+
/*--------------------------------------------------------------------
* HTTP Protocol connection structure
*
diff --git a/include/Makefile.am b/include/Makefile.am
index 869ac7684..818011d3d 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -30,7 +30,6 @@ nobase_pkginclude_HEADERS = \
tbl/req_flags.h \
tbl/sess_attr.h \
tbl/sess_close.h \
- tbl/steps.h \
tbl/symbol_kind.h \
tbl/vcl_returns.h \
tbl/vcl_states.h \
diff --git a/include/tbl/steps.h b/include/tbl/steps.h
deleted file mode 100644
index b16a65bfc..000000000
--- a/include/tbl/steps.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*-
- * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2015 Varnish Software AS
- * All rights reserved.
- *
- * Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
-
-/*lint -save -e525 -e539 */
-
-#ifdef REQ_STEP
- REQ_STEP(transport, TRANSPORT, (wrk, req))
- REQ_STEP(restart, RESTART, (wrk, req))
- REQ_STEP(recv, RECV, (wrk, req))
- REQ_STEP(pipe, PIPE, (wrk, req))
- REQ_STEP(pass, PASS, (wrk, req))
- REQ_STEP(lookup, LOOKUP, (wrk, req))
- REQ_STEP(purge, PURGE, (wrk, req))
- REQ_STEP(miss, MISS, (wrk, req))
- REQ_STEP(fetch, FETCH, (wrk, req))
- REQ_STEP(deliver, DELIVER, (wrk, req))
- REQ_STEP(vclfail, VCLFAIL, (wrk, req))
- REQ_STEP(synth, SYNTH, (wrk, req))
- REQ_STEP(transmit, TRANSMIT, (wrk, req))
- #undef REQ_STEP
-#endif
-
-/*lint -restore */
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit