[master] b2b35a5 Reorganize the OC_F and OC_EF flags to make space for a bitmap of OAs.

Poul-Henning Kamp phk at FreeBSD.org
Wed Feb 3 00:50:33 CET 2016


commit b2b35a52ea0608a8d9600f79e0c45a38b5527114
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Feb 2 23:49:32 2016 +0000

    Reorganize the OC_F and OC_EF flags to make space for a bitmap of OAs.
    
    Rename Obj[GS]etattr() to ..Attr
    
    Add ObjHasAttr() for cheap existence check on OAs.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 310d254..7dfb482 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -420,20 +420,22 @@ struct objcore {
 
 	struct exp		exp;
 
-	uint16_t		flags;
+	uint8_t			flags;
 #define OC_F_BUSY		(1<<1)
 #define OC_F_PASS		(1<<2)
 #define OC_F_INCOMPLETE		(1<<3)
 #define OC_F_ABANDON		(1<<4)
-#define OC_F_PRIVATE		(1<<8)
-#define OC_F_FAILED		(1<<9)
+#define OC_F_PRIVATE		(1<<5)
+#define OC_F_FAILED		(1<<6)
 
-	uint16_t		exp_flags;
-#define OC_EF_OFFLRU		(1<<4)
-#define OC_EF_MOVE		(1<<10)
-#define OC_EF_INSERT		(1<<11)
-#define OC_EF_EXP		(1<<12)
-#define OC_EF_DYING		(1<<7)
+	uint8_t			exp_flags;
+#define OC_EF_OFFLRU		(1<<1)
+#define OC_EF_MOVE		(1<<2)
+#define OC_EF_INSERT		(1<<3)
+#define OC_EF_EXP		(1<<4)
+#define OC_EF_DYING		(1<<5)
+
+	uint16_t		oa_present;
 
 	unsigned		timer_idx;
 	VTAILQ_ENTRY(objcore)	list;
@@ -860,9 +862,10 @@ void ObjUpdateMeta(struct worker *, struct objcore *);
 void ObjFreeObj(struct worker *, struct objcore *);
 void ObjSlim(struct worker *, struct objcore *oc);
 struct lru *ObjGetLRU(const struct objcore *);
-void *ObjGetattr(struct worker *wrk, struct objcore *oc, enum obj_attr attr,
+int ObjHasAttr(struct worker *, struct objcore *, enum obj_attr);
+void *ObjGetAttr(struct worker *, struct objcore *, enum obj_attr,
     ssize_t *len);
-void *ObjSetattr(struct worker *, struct objcore *, enum obj_attr attr,
+void *ObjSetAttr(struct worker *, struct objcore *, enum obj_attr,
     ssize_t len, const void *);
 int ObjCopyAttr(struct worker *, struct objcore *, struct objcore *,
     enum obj_attr attr);
diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index efa6fb2..88ab55c 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -254,7 +254,7 @@ VDP_ESI(struct req *req, enum vdp_action act, void **priv,
 	while (1) {
 		switch (ecx->state) {
 		case 0:
-			ecx->p = ObjGetattr(req->wrk, req->objcore,
+			ecx->p = ObjGetAttr(req->wrk, req->objcore,
 			    OA_ESIDATA, &l);
 			AN(ecx->p);
 			assert(l > 0);
@@ -699,7 +699,7 @@ ved_stripgzip(struct req *req, const struct boc *boc)
 	 * padding it, as necessary, to a byte boundary.
 	 */
 
-	p = ObjGetattr(req->wrk, req->objcore, OA_GZIPBITS, &l);
+	p = ObjGetAttr(req->wrk, req->objcore, OA_GZIPBITS, &l);
 	AN(p);
 	assert(l == 32);
 	foo.start = vbe64dec(p);
diff --git a/bin/varnishd/cache/cache_esi_fetch.c b/bin/varnishd/cache/cache_esi_fetch.c
index e3a50db..e1b9a56 100644
--- a/bin/varnishd/cache/cache_esi_fetch.c
+++ b/bin/varnishd/cache/cache_esi_fetch.c
@@ -123,7 +123,7 @@ vfp_esi_end(struct vfp_ctx *vc, struct vef_priv *vef,
 		if (retval == VFP_END) {
 			l = VSB_len(vsb);
 			assert(l > 0);
-			p = ObjSetattr(vc->wrk, vc->oc,
+			p = ObjSetAttr(vc->wrk, vc->oc,
 			    OA_ESIDATA, l, VSB_data(vsb));
 			if (p == NULL) {
 				retval = VFP_Error(vc,
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 5332e7c..99b283d 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -129,7 +129,7 @@ vbf_beresp2obj(struct busyobj *bo)
 		return (-1);
 
 	if (vary != NULL) {
-		b = ObjSetattr(bo->wrk, bo->fetch_objcore, OA_VARY, varyl,
+		b = ObjSetAttr(bo->wrk, bo->fetch_objcore, OA_VARY, varyl,
 		    VSB_data(vary));
 		VSB_delete(vary);
 	}
@@ -140,7 +140,7 @@ vbf_beresp2obj(struct busyobj *bo)
 	bo->beresp->logtag = SLT_ObjMethod;
 
 	/* Filter into object */
-	bp = ObjSetattr(bo->wrk, bo->fetch_objcore, OA_HEADERS, l2, NULL);
+	bp = ObjSetAttr(bo->wrk, bo->fetch_objcore, OA_HEADERS, l2, NULL);
 	AN(bp);
 	HTTP_Encode(bo->beresp, bp, l2,
 	    bo->uncacheable ? HTTPH_R_PASS : HTTPH_A_INS);
@@ -727,7 +727,7 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
 
 	AZ(vbf_beresp2obj(bo));
 
-	if (ObjGetattr(bo->wrk, bo->stale_oc, OA_ESIDATA, NULL) != NULL)
+	if (ObjHasAttr(bo->wrk, bo->stale_oc, OA_ESIDATA))
 		AZ(ObjCopyAttr(bo->wrk, bo->fetch_objcore, bo->stale_oc,
 		    OA_ESIDATA));
 
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index 917109a..0b8d3a7 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -310,7 +310,7 @@ VDP_gunzip(struct req *req, enum vdp_action act, void **priv,
 		if (req->objcore->flags & OC_F_INCOMPLETE)
 			return (0);	/* No idea about length */
 
-		p = ObjGetattr(req->wrk, req->objcore, OA_GZIPBITS, &dl);
+		p = ObjGetAttr(req->wrk, req->objcore, OA_GZIPBITS, &dl);
 		if (p == NULL || dl != 32)
 			return (0); /* No OA_GZIPBITS yet */
 
@@ -369,7 +369,7 @@ VGZ_UpdateObj(const struct vfp_ctx *vc, struct vgz *vg, enum vgz_ua_e e)
 	if (e == VUA_UPDATE && ii == vg->bits)
 		return;
 	vg->bits = ii;
-	p = ObjSetattr(vc->wrk, vc->oc, OA_GZIPBITS, 32, NULL);
+	p = ObjSetAttr(vc->wrk, vc->oc, OA_GZIPBITS, 32, NULL);
 	AN(p);
 	vbe64enc(p, vg->vz.start_bit);
 	vbe64enc(p + 8, vg->vz.last_bit);
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 7d22c25..fb1c5db 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -418,10 +418,11 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
 		if (BAN_CheckObject(wrk, oc, req))
 			continue;
 
-		vary = ObjGetattr(wrk, oc, OA_VARY, NULL);
-
-		if (vary != NULL && !VRY_Match(req, vary))
-			continue;
+		if (ObjHasAttr(wrk, oc, OA_VARY)) {
+			vary = ObjGetAttr(wrk, oc, OA_VARY, NULL);
+			if (!VRY_Match(req, vary))
+				continue;
+		}
 
 		if (EXP_Ttl(req, &oc->exp) >= req->t_req) {
 			/* If still valid, use it */
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 8e3fe0f..7caaafd 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -896,7 +896,7 @@ uint16_t
 HTTP_GetStatusPack(struct worker *wrk, struct objcore *oc)
 {
 	const char *ptr;
-	ptr = ObjGetattr(wrk, oc, OA_HEADERS, NULL);
+	ptr = ObjGetAttr(wrk, oc, OA_HEADERS, NULL);
 	AN(ptr);
 
 	return(vbe16dec(ptr + 2));
@@ -915,7 +915,7 @@ HTTP_IterHdrPack(struct worker *wrk, struct objcore *oc, const char **p)
 	AN(p);
 
 	if (*p == NULL) {
-		ptr = ObjGetattr(wrk, oc, OA_HEADERS, NULL);
+		ptr = ObjGetAttr(wrk, oc, OA_HEADERS, NULL);
 		AN(ptr);
 		ptr += 4;	/* Skip nhd and status */
 		ptr = strchr(ptr, '\0') + 1;	/* Skip :proto: */
@@ -948,7 +948,7 @@ HTTP_GetHdrPack(struct worker *wrk, struct objcore *oc, const char *hdr)
 
 	if (hdr[0] == ':') {
 		/* Special cases */
-		ptr = ObjGetattr(wrk, oc, OA_HEADERS, NULL);
+		ptr = ObjGetAttr(wrk, oc, OA_HEADERS, NULL);
 		AN(ptr);
 		ptr += 4;	/* Skip nhd and status */
 
@@ -991,7 +991,7 @@ HTTP_Merge(struct worker *wrk, struct objcore *oc, struct http *to)
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
 
-	ptr = ObjGetattr(wrk, oc, OA_HEADERS, NULL);
+	ptr = ObjGetAttr(wrk, oc, OA_HEADERS, NULL);
 	AN(ptr);
 
 	to->status = vbe16dec(ptr + 2);
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index b6a60c2..a1d2178 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -297,13 +297,33 @@ ObjGetLRU(const struct objcore *oc)
 }
 
 /*====================================================================
- * ObjGetattr()
+ * ObjHasAttr()
+ *
+ * Check if object has this attribute
+ */
+
+int
+ObjHasAttr(struct worker *wrk, struct objcore *oc, enum obj_attr attr)
+{
+
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+
+	if (oc->oa_present)
+		return (oc->oa_present & (1 << attr));
+
+	/* resurrected persistent objects don't have oa_present set */
+	return (ObjGetAttr(wrk, oc, attr, NULL) != NULL ? 1 : 0);
+}
+
+/*====================================================================
+ * ObjGetAttr()
  *
  * Get an attribute of the object.
  */
 
 void *
-ObjGetattr(struct worker *wrk, struct objcore *oc, enum obj_attr attr,
+ObjGetAttr(struct worker *wrk, struct objcore *oc, enum obj_attr attr,
    ssize_t *len)
 {
 	const struct obj_methods *om = obj_getmethods(oc);
@@ -315,14 +335,14 @@ ObjGetattr(struct worker *wrk, struct objcore *oc, enum obj_attr attr,
 }
 
 /*====================================================================
- * ObjSetattr()
+ * ObjSetAttr()
  *
  * If ptr is Non-NULL, it points to the new content which is copied into
  * the attribute.  Otherwise the caller will have to do the copying.
  */
 
 void *
-ObjSetattr(struct worker *wrk, struct objcore *oc, enum obj_attr attr,
+ObjSetAttr(struct worker *wrk, struct objcore *oc, enum obj_attr attr,
     ssize_t len, const void *ptr)
 {
 	const struct obj_methods *om = obj_getmethods(oc);
@@ -330,6 +350,8 @@ ObjSetattr(struct worker *wrk, struct objcore *oc, enum obj_attr attr,
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 
 	AN(om->objsetattr);
+	assert((int)attr < 16);
+	oc->oa_present |= (1 << attr);
 	return (om->objsetattr(wrk, oc, attr, len, ptr));
 }
 
@@ -362,11 +384,11 @@ ObjCopyAttr(struct worker *wrk, struct objcore *oc, struct objcore *ocs,
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	CHECK_OBJ_NOTNULL(ocs, OBJCORE_MAGIC);
 
-	vps = ObjGetattr(wrk, ocs, attr, &l);
+	vps = ObjGetAttr(wrk, ocs, attr, &l);
 	// XXX: later we want to have zero-length OA's too
 	if (vps == NULL || l <= 0)
 		return (-1);
-	vpd = ObjSetattr(wrk, oc, attr, l, vps);
+	vpd = ObjSetAttr(wrk, oc, attr, l, vps);
 	if (vpd == NULL)
 		return (-1);
 	return (0);
@@ -397,7 +419,7 @@ ObjSetDouble(struct worker *wrk, struct objcore *oc, enum obj_attr a, double t)
 
 	assert(sizeof t == sizeof u);
 	memcpy(&u, &t, sizeof u);
-	vp = ObjSetattr(wrk, oc, a, sizeof u, NULL);
+	vp = ObjSetAttr(wrk, oc, a, sizeof u, NULL);
 	if (vp == NULL)
 		return (-1);
 	vbe64enc(vp, u);
@@ -412,7 +434,7 @@ ObjGetDouble(struct worker *wrk, struct objcore *oc, enum obj_attr a, double *d)
 	ssize_t l;
 
 	assert(sizeof *d == sizeof u);
-	vp = ObjGetattr(wrk, oc, a, &l);
+	vp = ObjGetAttr(wrk, oc, a, &l);
 	if (vp == NULL)
 		return (-1);
 	if (d != NULL) {
@@ -431,7 +453,7 @@ ObjSetU64(struct worker *wrk, struct objcore *oc, enum obj_attr a, uint64_t t)
 {
 	void *vp;
 
-	vp = ObjSetattr(wrk, oc, a, sizeof t, NULL);
+	vp = ObjSetAttr(wrk, oc, a, sizeof t, NULL);
 	if (vp == NULL)
 		return (-1);
 	vbe64enc(vp, t);
@@ -444,7 +466,7 @@ ObjGetU64(struct worker *wrk, struct objcore *oc, enum obj_attr a, uint64_t *d)
 	void *vp;
 	ssize_t l;
 
-	vp = ObjGetattr(wrk, oc, a, &l);
+	vp = ObjGetAttr(wrk, oc, a, &l);
 	if (vp == NULL || l != sizeof *d)
 		return (-1);
 	if (d != NULL)
@@ -457,7 +479,7 @@ ObjSetU32(struct worker *wrk, struct objcore *oc, enum obj_attr a, uint32_t t)
 {
 	void *vp;
 
-	vp = ObjSetattr(wrk, oc, a, sizeof t, NULL);
+	vp = ObjSetAttr(wrk, oc, a, sizeof t, NULL);
 	if (vp == NULL)
 		return (-1);
 	vbe32enc(vp, t);
@@ -470,7 +492,7 @@ ObjGetU32(struct worker *wrk, struct objcore *oc, enum obj_attr a, uint32_t *d)
 	void *vp;
 	ssize_t l;
 
-	vp = ObjGetattr(wrk, oc, a, &l);
+	vp = ObjGetAttr(wrk, oc, a, &l);
 	if (vp == NULL || l != sizeof *d)
 		return (-1);
 	if (d != NULL)
@@ -486,7 +508,7 @@ ObjCheckFlag(struct worker *wrk, struct objcore *oc, enum obj_flags of)
 {
 	uint8_t *fp;
 
-	fp = ObjGetattr(wrk, oc, OA_FLAGS, NULL);
+	fp = ObjGetAttr(wrk, oc, OA_FLAGS, NULL);
 	AN(fp);
 	return ((*fp) & of);
 }
@@ -496,7 +518,7 @@ ObjSetFlag(struct worker *wrk, struct objcore *oc, enum obj_flags of, int val)
 {
 	uint8_t *fp;
 
-	fp = ObjSetattr(wrk, oc, OA_FLAGS, 1, NULL);
+	fp = ObjSetAttr(wrk, oc, OA_FLAGS, 1, NULL);
 	AN(fp);
 	if (val)
 		(*fp) |= of;
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 56ecaed..1926536 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -68,7 +68,7 @@ cnt_deliver(struct worker *wrk, struct req *req)
 
 	HTTP_Setup(req->resp, req->ws, req->vsl, SLT_RespMethod);
 	if (HTTP_Decode(req->resp,
-	    ObjGetattr(req->wrk, req->objcore, OA_HEADERS, NULL))) {
+	    ObjGetAttr(req->wrk, req->objcore, OA_HEADERS, NULL))) {
 		req->err_code = 500;
 		req->req_step = R_STP_SYNTH;
 		return (REQ_FSM_MORE);
@@ -267,7 +267,7 @@ cnt_transmit(struct worker *wrk, struct req *req)
 		sendbody = 1;
 
 	if (!req->disable_esi && req->resp_len != 0 &&
-	    ObjGetattr(req->wrk, req->objcore, OA_ESIDATA, NULL) != NULL)
+	    ObjHasAttr(wrk, req->objcore, OA_ESIDATA))
 		VDP_push(req, VDP_ESI, NULL, 0);
 
 	if (cache_param->http_gzip_support &&



More information about the varnish-commit mailing list