[master] 7d0216d Use a bit field for request flags
Nils Goroll
nils.goroll at uplex.de
Tue Jan 6 20:39:06 CET 2015
commit 7d0216de575ac47b03510590d08be1894445bc6c
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Tue Jan 6 20:36:57 2015 +0100
Use a bit field for request flags
... by example of the backend object flags
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 20b6022..2e7fa47 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -539,10 +539,10 @@ struct req {
int restarts;
int esi_level;
- int disable_esi;
- uint8_t hash_ignore_busy;
- uint8_t hash_always_miss;
- uint8_t hit;
+
+#define REQ_FLAG(l, r, w, d) unsigned l:1;
+#include "tbl/req_flags.h"
+#undef REQ_FLAG
struct sess *sp;
struct worker *wrk;
@@ -565,7 +565,6 @@ struct req {
enum sess_close doclose;
double d_ttl;
- unsigned char wantbody;
uint64_t req_bodybytes; /* Parsed req bodybytes */
uint16_t err_code;
@@ -596,7 +595,6 @@ struct req {
struct SHA256Context *sha256ctx;
/* ESI delivery stuff */
- int gzip_resp;
ssize_t l_crc;
uint32_t crc;
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 476b252..7c8ec65 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -412,6 +412,12 @@ pan_req(const struct req *req)
pan_busyobj(req->objcore->busyobj);
}
+ VSB_printf(pan_vsp, " flags = {\n");
+#define REQ_FLAG(l, r, w, d) if(req->l) VSB_printf(pan_vsp, " " #l ",\n");
+#include "tbl/req_flags.h"
+#undef REQ_FLAG
+ VSB_printf(pan_vsp, " }\n");
+
VSB_printf(pan_vsp, "},\n");
}
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 9255bbd..c434253 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -74,7 +74,7 @@ cnt_deliver(struct worker *wrk, struct req *req)
ObjGetattr(req->wrk, req->objcore, OA_HEADERS, NULL)));
http_ForceField(req->resp, HTTP_HDR_PROTO, "HTTP/1.1");
- if (req->hit)
+ if (req->is_hit)
http_PrintfHeader(req->resp,
"X-Varnish: %u %u", VXID(req->vsl->wid),
ObjGetXID(wrk, req->objcore));
@@ -364,7 +364,7 @@ cnt_lookup(struct worker *wrk, struct req *req)
(void)VRB_Ignore(req);// XXX: handle err
}
wrk->stats->cache_hit++;
- req->hit = 1;
+ req->is_hit = 1;
req->req_step = R_STP_DELIVER;
return (REQ_FSM_MORE);
case VCL_RET_FETCH:
@@ -392,7 +392,7 @@ cnt_lookup(struct worker *wrk, struct req *req)
break;
case VCL_RET_PASS:
wrk->stats->cache_hit++;
- req->hit = 1;
+ req->is_hit = 1;
req->req_step = R_STP_PASS;
break;
default:
@@ -548,7 +548,7 @@ cnt_restart(struct worker *wrk, struct req *req)
req->err_code = 0;
req->req_step = R_STP_RECV;
}
- req->hit = 0;
+ req->is_hit = 0;
return (REQ_FSM_MORE);
}
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index fe4fea8..b57c4b7 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -562,29 +562,35 @@ VRT_r_bereq_xid(VRT_CTX)
return (WS_Printf(ctx->bo->bereq->ws, "%u", VXID(ctx->bo->vsl->wid)));
}
-/*--------------------------------------------------------------------*/
+/*--------------------------------------------------------------------
+ * req fields
+ */
-#define REQ_BOOL(hash_var) \
-void \
-VRT_l_req_##hash_var(VRT_CTX, unsigned val) \
-{ \
- \
- CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
+#define VREQW0(field)
+#define VREQW1(field) \
+void \
+VRT_l_req_##field(VRT_CTX, unsigned a) \
+{ \
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); \
- ctx->req->hash_var = val ? 1 : 0; \
-} \
- \
-unsigned \
-VRT_r_req_##hash_var(VRT_CTX) \
-{ \
- \
- CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
+ ctx->req->field = a ? 1 : 0; \
+}
+
+#define VREQR0(field)
+#define VREQR1(field) \
+unsigned \
+VRT_r_req_##field(VRT_CTX) \
+{ \
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); \
- return(ctx->req->hash_var); \
+ return (ctx->req->field); \
}
-REQ_BOOL(hash_ignore_busy)
-REQ_BOOL(hash_always_miss)
+#define REQ_FLAG(l, r, w, d) \
+ VREQR##r(l) \
+ VREQW##r(l)
+#include "tbl/req_flags.h"
+#undef REQ_FLAG
/*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c
index f8814a1..62cfcf1 100644
--- a/bin/varnishd/http1/cache_http1_fsm.c
+++ b/bin/varnishd/http1/cache_http1_fsm.c
@@ -186,7 +186,7 @@ http1_cleanup(struct sess *sp, struct worker *wrk, struct req *req)
req->hash_always_miss = 0;
req->hash_ignore_busy = 0;
- req->hit = 0;
+ req->is_hit = 0;
if (sp->fd >= 0 && req->doclose != SC_NULL)
SES_Close(sp, req->doclose);
diff --git a/include/tbl/req_flags.h b/include/tbl/req_flags.h
new file mode 100644
index 0000000..6757d90
--- /dev/null
+++ b/include/tbl/req_flags.h
@@ -0,0 +1,39 @@
+/*-
+ * Copyright (c) 2014 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * 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 */
+
+/* lower, vcl_r, vcl_w, doc */
+REQ_FLAG(disable_esi, 0, 0, "")
+REQ_FLAG(hash_ignore_busy, 1, 1, "")
+REQ_FLAG(hash_always_miss, 1, 1, "")
+REQ_FLAG(is_hit, 0, 0, "")
+REQ_FLAG(wantbody, 0, 0, "")
+REQ_FLAG(gzip_resp, 0, 0, "")
+/*lint -restore */
More information about the varnish-commit
mailing list