[master] 58db58b Final refactoring of struct worker as context for Obj*()

Poul-Henning Kamp phk at FreeBSD.org
Tue Sep 16 13:49:39 CEST 2014


commit 58db58bed260ea52342e5456f7772668f8e73781
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Sep 16 11:49:14 2014 +0000

    Final refactoring of struct worker as context for Obj*()

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 74f2d9f..b4e79c4 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -992,20 +992,21 @@ 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,
     ssize_t *len);
-void *ObjSetattr(const struct vfp_ctx *, enum obj_attr attr, ssize_t len,
-    const void *);
-int ObjCopyAttr(const struct vfp_ctx *, struct objcore *, enum obj_attr attr);
+void *ObjSetattr(struct worker *, struct objcore *, enum obj_attr attr,
+    ssize_t len, const void *);
+int ObjCopyAttr(struct worker *, struct objcore *, struct objcore *,
+    enum obj_attr attr);
 
-int ObjSetDouble(const struct vfp_ctx*, enum obj_attr, double);
-int ObjSetU32(const struct vfp_ctx *, enum obj_attr, uint32_t);
-int ObjSetU64(const struct vfp_ctx *, enum obj_attr, uint64_t);
+int ObjSetDouble(struct worker *, struct objcore *, enum obj_attr, double);
+int ObjSetU32(struct worker *, struct objcore *, enum obj_attr, uint32_t);
+int ObjSetU64(struct worker *, struct objcore *, enum obj_attr, uint64_t);
 
 int ObjGetDouble(struct worker *, struct objcore *, enum obj_attr, double *);
 int ObjGetU32(struct worker *, struct objcore *, enum obj_attr, uint32_t *);
 int ObjGetU64(struct worker *, struct objcore *, enum obj_attr, uint64_t *);
 
 int ObjCheckFlag(struct worker *, struct objcore *oc, enum obj_flags of);
-void ObjSetFlag(const struct vfp_ctx *vc, enum obj_flags of, int val);
+void ObjSetFlag(struct worker *, struct objcore *, enum obj_flags of, int val);
 
 /* cache_panic.c */
 void PAN_Init(void);
diff --git a/bin/varnishd/cache/cache_esi_fetch.c b/bin/varnishd/cache/cache_esi_fetch.c
index 8a73566..a2aadb7 100644
--- a/bin/varnishd/cache/cache_esi_fetch.c
+++ b/bin/varnishd/cache/cache_esi_fetch.c
@@ -118,7 +118,8 @@ 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, OA_ESIDATA, l, VSB_data(vsb));
+			p = ObjSetattr(vc->wrk, vc->oc,
+			    OA_ESIDATA, l, VSB_data(vsb));
 			if (p == NULL) {
 				retval = VFP_Error(vc,
 				    "Could not allocate storage for esidata");
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index caa74c3..3dbd83a 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -133,25 +133,25 @@ vbf_beresp2obj(struct busyobj *bo)
 		return (-1);
 
 	if (vary != NULL) {
-		b = ObjSetattr(bo->vfc, OA_VARY, varyl, VSB_data(vary));
+		b = ObjSetattr(bo->wrk, bo->fetch_objcore, OA_VARY, varyl, VSB_data(vary));
 		VSB_delete(vary);
 	}
 
-	AZ(ObjSetU32(bo->vfc, OA_VXID, VXID(bo->vsl->wid)));
+	AZ(ObjSetU32(bo->wrk, bo->fetch_objcore, OA_VXID, VXID(bo->vsl->wid)));
 
 	/* for HTTP_Encode() VSLH call */
 	bo->beresp->logtag = SLT_ObjMethod;
 
 	/* Filter into object */
-	bp = ObjSetattr(bo->vfc, 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);
 
 	if (http_GetHdr(bo->beresp, H_Last_Modified, &b))
-		AZ(ObjSetDouble(bo->vfc, OA_LASTMODIFIED, VTIM_parse(b)));
+		AZ(ObjSetDouble(bo->wrk, bo->fetch_objcore, OA_LASTMODIFIED, VTIM_parse(b)));
 	else
-		AZ(ObjSetDouble(bo->vfc, OA_LASTMODIFIED,
+		AZ(ObjSetDouble(bo->wrk, bo->fetch_objcore, OA_LASTMODIFIED,
 		    floor(bo->fetch_objcore->exp.t_origin)));
 
 	return (0);
@@ -587,15 +587,15 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 
 
 	if (bo->do_gzip || (bo->is_gzip && !bo->do_gunzip))
-		ObjSetFlag(bo->vfc, OF_GZIPED, 1);
+		ObjSetFlag(bo->wrk, bo->fetch_objcore, OF_GZIPED, 1);
 
 	if (bo->do_gzip || bo->do_gunzip)
-		ObjSetFlag(bo->vfc, OF_CHGGZIP, 1);
+		ObjSetFlag(bo->wrk, bo->fetch_objcore, OF_CHGGZIP, 1);
 
 	if (http_IsStatus(bo->beresp, 200) && (
 	    http_GetHdr(bo->beresp, H_Last_Modified, &p) ||
 	    http_GetHdr(bo->beresp, H_ETag, &p)))
-		ObjSetFlag(bo->vfc, OF_IMSCAND, 1);
+		ObjSetFlag(bo->wrk, bo->fetch_objcore, OF_IMSCAND, 1);
 
 	if (bo->htc->body_status != BS_NONE)
 		V1F_Setup_Fetch(bo->vfc, bo->htc);
@@ -672,10 +672,11 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
 	AZ(vbf_beresp2obj(bo));
 
 	if (ObjGetattr(bo->wrk, bo->ims_oc, OA_ESIDATA, NULL) != NULL)
-		AZ(ObjCopyAttr(bo->vfc, bo->ims_oc, OA_ESIDATA));
+		AZ(ObjCopyAttr(bo->wrk, bo->fetch_objcore, bo->ims_oc,
+		    OA_ESIDATA));
 
-	AZ(ObjCopyAttr(bo->vfc, bo->ims_oc, OA_FLAGS));
-	AZ(ObjCopyAttr(bo->vfc, bo->ims_oc, OA_GZIPBITS));
+	AZ(ObjCopyAttr(bo->wrk, bo->fetch_objcore, bo->ims_oc, OA_FLAGS));
+	AZ(ObjCopyAttr(bo->wrk, bo->fetch_objcore, bo->ims_oc, OA_GZIPBITS));
 
 	if (bo->do_stream) {
 		HSH_Unbusy(wrk, bo->fetch_objcore);
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index a4b3034..5e2125b 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -396,7 +396,7 @@ VGZ_UpdateObj(const struct vfp_ctx *vc, const struct vgz *vg)
 	char *p;
 
 	CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC);
-	p = ObjSetattr(vc, OA_GZIPBITS, 24, NULL);
+	p = ObjSetattr(vc->wrk, vc->oc, OA_GZIPBITS, 24, NULL);
 	AN(p);
 	vbe64enc(p, vg->vz.start_bit);
 	vbe64enc(p + 8, vg->vz.last_bit);
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index 4db9524..73eff9c 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -515,27 +515,25 @@ ObjGetattr(struct worker *wrk, struct objcore *oc, enum obj_attr attr,
  */
 
 void *
-ObjSetattr(const struct vfp_ctx *vc, enum obj_attr attr, ssize_t len,
-    const void *ptr)
+ObjSetattr(struct worker *wrk, struct objcore *oc, enum obj_attr attr,
+    ssize_t len, const void *ptr)
 {
 	struct object *o;
 	void *retval = NULL;
 	struct storage *st;
-	const struct storeobj_methods *om = obj_getmethods(vc->oc);
+	const struct storeobj_methods *om = obj_getmethods(oc);
 
 	if (om->objsetattr != NULL)
-		return (om->objsetattr(vc, attr, len, ptr));
+		return (om->objsetattr(wrk, oc, attr, len, ptr));
 
-	CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC);
-	CHECK_OBJ_NOTNULL(vc->bo, BUSYOBJ_MAGIC);
-	CHECK_OBJ_NOTNULL(vc->oc, OBJCORE_MAGIC);
-	o = obj_getobj(vc->wrk, vc->oc);
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+	o = obj_getobj(wrk, oc);
 	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 	st = o->objstore;
 	switch (attr) {
 	case OA_ESIDATA:
-		o->esidata = objallocwithnuke(vc->oc->stobj->stevedore,
-		    vc->wrk, len);
+		o->esidata = objallocwithnuke(oc->stobj->stevedore, wrk, len);
 		if (o->esidata == NULL)
 			return (NULL);
 		o->esidata->len = len;
@@ -585,18 +583,20 @@ ObjSetattr(const struct vfp_ctx *vc, enum obj_attr attr, ssize_t len,
  */
 
 int
-ObjCopyAttr(const struct vfp_ctx *vc, struct objcore *ocs, enum obj_attr attr)
+ObjCopyAttr(struct worker *wrk, struct objcore *oc, struct objcore *ocs,
+    enum obj_attr attr)
 {
 	void *vps, *vpd;
 	ssize_t l;
 
-	CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 
-	vps = ObjGetattr(vc->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(vc, attr, l, vps);
+	vpd = ObjSetattr(wrk, oc, attr, l, vps);
 	if (vpd == NULL)
 		return (-1);
 	return (0);
@@ -620,14 +620,14 @@ ObjGetXID(struct worker *wrk, struct objcore *oc)
  */
 
 int
-ObjSetDouble(const struct vfp_ctx *vc, enum obj_attr a, double t)
+ObjSetDouble(struct worker *wrk, struct objcore *oc, enum obj_attr a, double t)
 {
 	void *vp;
 	uint64_t u;
 
 	assert(sizeof t == sizeof u);
 	memcpy(&u, &t, sizeof u);
-	vp = ObjSetattr(vc, a, sizeof u, NULL);
+	vp = ObjSetattr(wrk, oc, a, sizeof u, NULL);
 	if (vp == NULL)
 		return (-1);
 	vbe64enc(vp, u);
@@ -657,11 +657,11 @@ ObjGetDouble(struct worker *wrk, struct objcore *oc, enum obj_attr a, double *d)
  */
 
 int
-ObjSetU64(const struct vfp_ctx *vc, enum obj_attr a, uint64_t t)
+ObjSetU64(struct worker *wrk, struct objcore *oc, enum obj_attr a, uint64_t t)
 {
 	void *vp;
 
-	vp = ObjSetattr(vc, a, sizeof t, NULL);
+	vp = ObjSetattr(wrk, oc, a, sizeof t, NULL);
 	if (vp == NULL)
 		return (-1);
 	vbe64enc(vp, t);
@@ -683,11 +683,11 @@ ObjGetU64(struct worker *wrk, struct objcore *oc, enum obj_attr a, uint64_t *d)
 }
 
 int
-ObjSetU32(const struct vfp_ctx *vc, enum obj_attr a, uint32_t t)
+ObjSetU32(struct worker *wrk, struct objcore *oc, enum obj_attr a, uint32_t t)
 {
 	void *vp;
 
-	vp = ObjSetattr(vc, a, sizeof t, NULL);
+	vp = ObjSetattr(wrk, oc, a, sizeof t, NULL);
 	if (vp == NULL)
 		return (-1);
 	vbe32enc(vp, t);
@@ -722,11 +722,11 @@ ObjCheckFlag(struct worker *wrk, struct objcore *oc, enum obj_flags of)
 }
 
 void
-ObjSetFlag(const struct vfp_ctx *vc, enum obj_flags of, int val)
+ObjSetFlag(struct worker *wrk, struct objcore *oc, enum obj_flags of, int val)
 {
 	uint8_t *fp;
 
-	fp = ObjSetattr(vc, OA_FLAGS, 1, NULL);
+	fp = ObjSetattr(wrk, oc, OA_FLAGS, 1, NULL);
 	AN(fp);
 	if (val)
 		(*fp) |= of;
diff --git a/bin/varnishd/storage/storage.h b/bin/varnishd/storage/storage.h
index c3d6158..0d162ca 100644
--- a/bin/varnishd/storage/storage.h
+++ b/bin/varnishd/storage/storage.h
@@ -33,7 +33,6 @@
 
 struct stevedore;
 struct sess;
-struct dstat;
 struct busyobj;
 struct objcore;
 struct worker;
@@ -106,8 +105,8 @@ typedef void objtrimstore_f(struct worker *, struct objcore *);
 typedef void objslim_f(struct worker *, struct objcore *);
 typedef void *objgetattr_f(struct worker *, struct objcore *,
     enum obj_attr attr, ssize_t *len);
-typedef void *objsetattr_f(const struct vfp_ctx *, enum obj_attr attr,
-    ssize_t len, const void *ptr);
+typedef void *objsetattr_f(struct worker *, struct objcore *,
+    enum obj_attr attr, ssize_t len, const void *ptr);
 typedef uint64_t objgetlen_f(struct worker *, struct objcore *);
 
 struct storeobj_methods {



More information about the varnish-commit mailing list