[master] 4ee1b91 Wrap the gzip/changed_gzip flags into a more general object flag mechanism.
Poul-Henning Kamp
phk at FreeBSD.org
Mon Aug 11 13:45:17 CEST 2014
commit 4ee1b911bbf0b81542a4f013156810862d1d0d66
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Aug 11 11:44:00 2014 +0000
Wrap the gzip/changed_gzip flags into a more general object flag
mechanism.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 9a0d53d..12712b5 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -553,6 +553,12 @@ enum obj_attr {
#undef OBJ_ATTR
};
+enum obj_flags {
+#define OBJ_FLAG(U, l, v) OF_##U = v,
+#include "tbl/obj_attr.h"
+#undef OBJ_FLAG
+};
+
struct object {
unsigned magic;
#define OBJECT_MAGIC 0x32851d42
@@ -564,13 +570,12 @@ struct object {
uint8_t *oa_http;
- unsigned gziped:1;
- unsigned changed_gzip:1;
+
+ uint8_t oa_flags[1];
/* Bit positions in the gzip stream */
char oa_gzipbits[24];
-
/* VCL only variables */
char oa_lastmodified[8];
@@ -1077,6 +1082,9 @@ int ObjGetDouble(struct objcore *, struct dstat *, enum obj_attr, double *);
int ObjGetU32(struct objcore *, struct dstat *, enum obj_attr, uint32_t *);
int ObjGetU64(struct objcore *, struct dstat *, enum obj_attr, uint64_t *);
+int ObjCheckFlag(struct objcore *oc, struct dstat *ds, enum obj_flags of);
+void ObjSetFlag(const struct vfp_ctx *vc, enum obj_flags of, int val);
+
/* cache_panic.c */
void PAN_Init(void);
const char *body_status_2str(enum body_status e);
diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index 185378e..71313e3 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -516,7 +516,7 @@ ESI_DeliverChild(struct req *req)
obj = ObjGetObj(req->objcore, &req->wrk->stats);
CHECK_OBJ_NOTNULL(obj, OBJECT_MAGIC);
- if (!obj->gziped) {
+ if (!ObjCheckFlag(req->objcore, &req->wrk->stats, OF_GZIPED)) {
VTAILQ_FOREACH(st, &obj->body->list, list)
ved_pretend_gzip(req, st->ptr, st->len);
return;
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 3abd6ef..b657c03 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -352,7 +352,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
if (bo->ims_obj != NULL && http_IsStatus(bo->beresp, 304)) {
http_Merge(bo->ims_obj->http, bo->beresp,
- bo->ims_obj->changed_gzip);
+ ObjCheckFlag(bo->ims_oc, bo->stats, OF_CHGGZIP));
assert(http_IsStatus(bo->beresp, 200));
do_ims = 1;
} else
@@ -482,10 +482,10 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
bo->vfc->body = obj->body;
if (bo->do_gzip || (bo->is_gzip && !bo->do_gunzip))
- obj->gziped = 1;
+ ObjSetFlag(bo->vfc, OF_GZIPED, 1);
if (bo->do_gzip || bo->do_gunzip)
- obj->changed_gzip = 1;
+ ObjSetFlag(bo->vfc, OF_CHGGZIP, 1);
if (bo->htc.body_status != BS_NONE)
V1F_Setup_Fetch(bo);
@@ -566,7 +566,7 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
- if (bo->ims_obj->changed_gzip) {
+ if (ObjCheckFlag(bo->ims_oc, bo->stats, OF_CHGGZIP)) {
/*
* If we modified the gzip status of the IMS object, that
* must control the C-E header, if any.
@@ -584,8 +584,7 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
if (ObjGetattr(bo->ims_oc, bo->stats, OA_ESIDATA, NULL) != NULL)
AZ(ObjCopyAttr(bo->vfc, bo->ims_oc, OA_ESIDATA));
- obj->gziped = bo->ims_obj->gziped;
-
+ AZ(ObjCopyAttr(bo->vfc, bo->ims_oc, OA_FLAGS));
AZ(ObjCopyAttr(bo->vfc, bo->ims_oc, OA_GZIPBITS));
AZ(WS_Overflowed(bo->ws_o));
diff --git a/bin/varnishd/cache/cache_http1_deliver.c b/bin/varnishd/cache/cache_http1_deliver.c
index e3b392a..f27f1bd 100644
--- a/bin/varnishd/cache/cache_http1_deliver.c
+++ b/bin/varnishd/cache/cache_http1_deliver.c
@@ -266,7 +266,8 @@ V1D_Deliver(struct req *req, struct busyobj *bo)
req->res_mode |= RES_ESI_CHILD;
}
- if (cache_param->http_gzip_support && req->obj->gziped &&
+ if (cache_param->http_gzip_support &&
+ ObjCheckFlag(req->objcore, &req->wrk->stats, OF_GZIPED) &&
!RFC2616_Req_Gzip(req->http)) {
/*
* We don't know what it uncompresses to
@@ -344,7 +345,8 @@ V1D_Deliver(struct req *req, struct busyobj *bo)
ESI_DeliverChild(req);
} else if (req->res_mode & RES_GUNZIP ||
(req->res_mode & RES_ESI_CHILD &&
- !req->gzip_resp && req->obj->gziped)) {
+ !req->gzip_resp &&
+ ObjCheckFlag(req->objcore, &req->wrk->stats, OF_GZIPED))) {
VDP_push(req, VDP_gunzip);
req->vgz = VGZ_NewUngzip(req->vsl, "U D -");
AZ(VGZ_WrwInit(req->vgz));
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index e18169a..94dfb17 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -232,6 +232,9 @@ ObjGetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr,
return (NULL);
*len = o->esidata->len;
return (o->esidata->ptr);
+ case OA_FLAGS:
+ *len = sizeof o->oa_flags;
+ return (o->oa_flags);
case OA_GZIPBITS:
*len = sizeof o->oa_gzipbits;
return (o->oa_gzipbits);
@@ -271,6 +274,9 @@ ObjSetattr(const struct vfp_ctx *vc, enum obj_attr attr,
return (NULL);
o->esidata->len = len;
return (o->esidata->ptr);
+ case OA_FLAGS:
+ assert(len == sizeof o->oa_flags);
+ return (o->oa_flags);
case OA_GZIPBITS:
assert(len == sizeof o->oa_gzipbits);
return (o->oa_gzipbits);
@@ -420,3 +426,29 @@ ObjGetU32(struct objcore *oc, struct dstat *ds, enum obj_attr a, uint32_t *d)
*d = vbe32dec(vp);
return (0);
}
+
+/*--------------------------------------------------------------------
+ */
+
+int
+ObjCheckFlag(struct objcore *oc, struct dstat *ds, enum obj_flags of)
+{
+ uint8_t *fp;
+
+ fp = ObjGetattr(oc, ds, OA_FLAGS, NULL);
+ AN(fp);
+ return ((*fp) & of);
+}
+
+void
+ObjSetFlag(const struct vfp_ctx *vc, enum obj_flags of, int val)
+{
+ uint8_t *fp;
+
+ fp = ObjSetattr(vc, OA_FLAGS, 1);
+ AN(fp);
+ if (val)
+ (*fp) |= of;
+ else
+ (*fp) &= ~of;
+}
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 3405a1a..ecdbe15 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -128,7 +128,8 @@ cnt_deliver(struct worker *wrk, struct req *req)
http_SetHeader(req->resp, "Via: 1.1 varnish-v4");
- if (cache_param->http_gzip_support && req->obj->gziped &&
+ if (cache_param->http_gzip_support &&
+ ObjCheckFlag(req->objcore, &req->wrk->stats, OF_GZIPED) &&
!RFC2616_Req_Gzip(req->http))
RFC2616_Weaken_Etag(req->resp);
diff --git a/include/tbl/obj_attr.h b/include/tbl/obj_attr.h
index 860fc5c..42e58e7 100644
--- a/include/tbl/obj_attr.h
+++ b/include/tbl/obj_attr.h
@@ -30,13 +30,21 @@
/*lint -save -e525 -e539 */
/* upper, lower */
+#ifdef OBJ_ATTR
OBJ_ATTR(VXID, vxid)
OBJ_ATTR(EXP, exp)
OBJ_ATTR(VARY, vary)
OBJ_ATTR(HEADERS, headers)
-OBJ_ATTR(GZIPFLAGS, gzipflags)
+OBJ_ATTR(FLAGS, flags)
OBJ_ATTR(GZIPBITS, gzipbits)
OBJ_ATTR(ESIDATA, esidata)
OBJ_ATTR(LASTMODIFIED, lastmodified)
+#endif
+
+#ifdef OBJ_FLAG
+/* upper, lower, val */
+OBJ_FLAG(GZIPED, gziped, (1<<1))
+OBJ_FLAG(CHGGZIP, chggzip, (1<<2))
+#endif
/*lint -restore */
More information about the varnish-commit
mailing list