[master] 0b7c06f Start injecting the fetch state-engine into the fetch-code
Poul-Henning Kamp
phk at varnish-cache.org
Sun Jun 16 11:58:48 CEST 2013
commit 0b7c06fb13620ccc974ed6cadcc8d60815115453
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Sun Jun 16 09:58:14 2013 +0000
Start injecting the fetch state-engine into the fetch-code
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 77ef0d5..53a397f 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -153,6 +153,12 @@ enum req_step {
#undef REQ_STEP
};
+enum fetch_step {
+#define FETCH_STEP(l, U, arg) F_STP_##U,
+#include "tbl/steps.h"
+#undef FETCH_STEP
+};
+
/*--------------------------------------------------------------------*/
struct lock { void *priv; }; // Opaque
@@ -495,6 +501,7 @@ struct busyobj {
#define BUSYOBJ_MAGIC 0x23b95567
struct lock mtx;
char *end;
+ enum fetch_step step;
/*
* All fields from refcount and down are zeroed when the busyobj
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 9acea11..ae74bd9 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -771,21 +771,15 @@ vbf_proc_resp(struct worker *wrk, struct busyobj *bo)
}
-struct vbf_secret_handshake {
- unsigned magic;
-#define VBF_SECRET_HANDSHAKE_MAGIC 0x98c95172
- struct busyobj *bo;
- struct req **reqp;
-};
+/*--------------------------------------------------------------------
+ */
-static void
-vbf_fetch_thread(struct worker *wrk, void *priv)
+static enum fetch_step
+vbf_stp_fetch(struct worker *wrk, struct busyobj *bo, struct req **reqp)
{
- struct vbf_secret_handshake *vsh;
- struct busyobj *bo;
- struct req *req;
int i;
struct http *hp, *hp2;
+ struct req *req;
char *b;
uint16_t nhttp;
unsigned l;
@@ -795,13 +789,10 @@ vbf_fetch_thread(struct worker *wrk, void *priv)
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
- CAST_OBJ_NOTNULL(vsh, priv, VBF_SECRET_HANDSHAKE_MAGIC);
- AN(vsh->reqp);
- req = *vsh->reqp;
+ AN(reqp);
+ req = *reqp;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
-
- bo = vsh->bo;
- THR_SetBusyobj(bo);
+ CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
vbf_make_bereq(wrk, req, bo);
xxxassert (wrk->handling == VCL_RET_FETCH);
@@ -810,10 +801,8 @@ vbf_fetch_thread(struct worker *wrk, void *priv)
if (!bo->do_pass) {
AN(req);
- AN(vsh);
req = NULL;
- *vsh->reqp = NULL;
- vsh = NULL;
+ *reqp = NULL;
}
i = vbf_fetch_hdr(wrk, bo, req);
@@ -829,13 +818,10 @@ vbf_fetch_thread(struct worker *wrk, void *priv)
if (bo->do_pass) {
AN(req);
- AN(vsh);
req = NULL;
- *vsh->reqp = NULL;
- vsh = NULL;
+ *reqp = NULL;
}
AZ(req);
- AZ(vsh);
if (i) {
wrk->handling = VCL_RET_ERROR;
@@ -865,8 +851,7 @@ vbf_fetch_thread(struct worker *wrk, void *priv)
case VCL_RET_ERROR:
bo->state = BOS_FAILED;
VBO_DerefBusyObj(wrk, &bo); // XXX ?
- THR_SetBusyobj(NULL);
- return;
+ return (F_STP_DONE);
case VCL_RET_RESTART:
INCOMPL();
default:
@@ -897,10 +882,7 @@ vbf_fetch_thread(struct worker *wrk, void *priv)
AZ(HSH_Deref(&wrk->stats, bo->fetch_objcore, NULL));
bo->fetch_objcore = NULL;
VDI_CloseFd(&bo->vbc);
- bo->state = BOS_FAILED;
-VSL_Flush(bo->vsl, 0);
- THR_SetBusyobj(NULL);
- return;
+ return (F_STP_ABANDON);
} else
/* No vary */
AZ(vary);
@@ -934,10 +916,7 @@ VSL_Flush(bo->vsl, 0);
AZ(HSH_Deref(&wrk->stats, bo->fetch_objcore, NULL));
bo->fetch_objcore = NULL;
VDI_CloseFd(&bo->vbc);
- bo->state = BOS_FAILED;
- VBO_DerefBusyObj(wrk, &bo); // XXX ?
- THR_SetBusyobj(NULL);
- return;
+ return (F_STP_ABANDON);
}
CHECK_OBJ_NOTNULL(obj, OBJECT_MAGIC);
@@ -998,17 +977,83 @@ VSL_Flush(bo->vsl, 0);
if (bo->state == BOS_FAILED) {
/* handle early failures */
- VBO_DerefBusyObj(wrk, &bo); // XXX ?
(void)HSH_Deref(&wrk->stats, NULL, &obj);
- THR_SetBusyobj(NULL);
- return;
+ return (F_STP_ABANDON);
}
VBO_DerefBusyObj(wrk, &bo); // XXX ?
+ return (F_STP_DONE);
+}
+
+/*--------------------------------------------------------------------
+ */
+
+static enum fetch_step
+vbf_stp_abandon(struct worker *wrk, struct busyobj *bo)
+{
+ CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+ CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+
+ bo->state = BOS_FAILED;
+ VBO_DerefBusyObj(wrk, &bo); // XXX ?
+ return (F_STP_DONE);
+}
+
+/*--------------------------------------------------------------------
+ */
+
+static enum fetch_step
+vbf_stp_done(void)
+{
+ WRONG("Just plain wrong");
+}
+
+/*--------------------------------------------------------------------
+ */
+
+struct vbf_secret_handshake {
+ unsigned magic;
+#define VBF_SECRET_HANDSHAKE_MAGIC 0x98c95172
+ struct busyobj *bo;
+ struct req **reqp;
+};
+
+static void
+vbf_fetch_thread(struct worker *wrk, void *priv)
+{
+ struct vbf_secret_handshake *vsh;
+ struct busyobj *bo;
+ struct req **reqp;
+
+ CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+ CAST_OBJ_NOTNULL(vsh, priv, VBF_SECRET_HANDSHAKE_MAGIC);
+ AN(vsh->reqp);
+ reqp = vsh->reqp;
+ CHECK_OBJ_NOTNULL((*vsh->reqp), REQ_MAGIC);
+
+ bo = vsh->bo;
+ THR_SetBusyobj(bo);
+ bo->step = F_STP_FETCH;
+
+ while (bo->step != F_STP_DONE) {
+ switch(bo->step) {
+#define FETCH_STEP(l, U, arg) \
+ case F_STP_##U: \
+ bo->step = vbf_stp_##l arg; \
+ break;
+#include "tbl/steps.h"
+#undef FETCH_STEP
+ default:
+ WRONG("Illegal fetch_step");
+ }
+ }
assert(WRW_IsReleased(wrk));
THR_SetBusyobj(NULL);
}
+/*--------------------------------------------------------------------
+ */
+
void
VBF_Fetch(struct worker *wrk, struct req *req)
{
diff --git a/include/tbl/steps.h b/include/tbl/steps.h
index 6c3f3f6..32af092 100644
--- a/include/tbl/steps.h
+++ b/include/tbl/steps.h
@@ -48,4 +48,11 @@ REQ_STEP(prepresp, PREPRESP, (wrk, req))
REQ_STEP(deliver, DELIVER, (wrk, req))
REQ_STEP(error, ERROR, (wrk, req))
#endif
+
+#ifdef FETCH_STEP
+FETCH_STEP(fetch, FETCH, (wrk, bo, reqp))
+FETCH_STEP(abandon, ABANDON, (wrk, bo))
+FETCH_STEP(done, DONE, ())
+#endif
+
/*lint -restore */
More information about the varnish-commit
mailing list