[master] 115742b07 Merge ObjTrimStore into ObjExtend, as aid to #3298

Poul-Henning Kamp phk at FreeBSD.org
Wed Oct 7 19:23:06 UTC 2020


commit 115742b07c8bad6d465f1c981ee264f934a4492b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Oct 7 19:21:19 2020 +0000

    Merge ObjTrimStore into ObjExtend, as aid to #3298

diff --git a/bin/varnishd/cache/cache_esi_fetch.c b/bin/varnishd/cache/cache_esi_fetch.c
index 221822059..0a0d1e2aa 100644
--- a/bin/varnishd/cache/cache_esi_fetch.c
+++ b/bin/varnishd/cache/cache_esi_fetch.c
@@ -100,7 +100,7 @@ vfp_vep_callback(struct vfp_ctx *vc, void *priv, ssize_t l, enum vgz_flag flg)
 		VGZ_UpdateObj(vc, vef->vgz, VUA_UPDATE);
 		if (dl > 0) {
 			vef->tot += dl;
-			VFP_Extend(vc, dl);
+			VFP_Extend(vc, dl, VFP_OK);
 		}
 	} while (i != VGZ_ERROR &&
 	    (!VGZ_IbufEmpty(vef->vgz) || VGZ_ObufFull(vef->vgz)));
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 3f848db63..c8958dfb4 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -517,7 +517,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
  */
 
 static enum fetch_step
-vbf_stp_fetchbody(struct worker *wrk, struct busyobj *bo)
+vbf_stp_fetchbody(const struct worker *wrk, struct busyobj *bo)
 {
 	ssize_t l;
 	uint8_t *ptr;
@@ -561,8 +561,8 @@ vbf_stp_fetchbody(struct worker *wrk, struct busyobj *bo)
 
 		AZ(vfc->failed);
 		vfps = VFP_Suck(vfc, ptr, &l);
-		if (l > 0 && vfps != VFP_ERROR) {
-			VFP_Extend(vfc, l);
+		if (l >= 0 && vfps != VFP_ERROR) {
+			VFP_Extend(vfc, l, vfps);
 			if (est >= l)
 				est -= l;
 			else
@@ -584,7 +584,6 @@ vbf_stp_fetchbody(struct worker *wrk, struct busyobj *bo)
 		}
 	}
 
-	ObjTrimStore(wrk, oc);
 	return (F_STP_FETCHEND);
 }
 
@@ -729,7 +728,7 @@ vbf_objiterator(void *priv, unsigned flush, const void *ptr, ssize_t len)
 		if (len < l)
 			l = len;
 		memcpy(pd, ps, l);
-		VFP_Extend(bo->vfc, l);
+		VFP_Extend(bo->vfc, l, l == len ? VFP_END : VFP_OK);
 		ps += l;
 		len -= l;
 	}
@@ -929,7 +928,7 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo)
 		if (l > ll)
 			l = ll;
 		memcpy(ptr, VSB_data(synth_body) + o, l);
-		VFP_Extend(bo->vfc, l);
+		VFP_Extend(bo->vfc, l, l == ll ? VFP_END : VFP_OK);
 		ll -= l;
 		o += l;
 	}
diff --git a/bin/varnishd/cache/cache_fetch_proc.c b/bin/varnishd/cache/cache_fetch_proc.c
index d9fa10716..0b7c69913 100644
--- a/bin/varnishd/cache/cache_fetch_proc.c
+++ b/bin/varnishd/cache/cache_fetch_proc.c
@@ -95,11 +95,11 @@ VFP_GetStorage(struct vfp_ctx *vc, ssize_t *sz, uint8_t **ptr)
 }
 
 void
-VFP_Extend(const struct vfp_ctx *vc, ssize_t sz)
+VFP_Extend(const struct vfp_ctx *vc, ssize_t sz, enum vfp_status flg)
 {
 	CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC);
 
-	ObjExtend(vc->wrk, vc->oc, sz);
+	ObjExtend(vc->wrk, vc->oc, sz, flg == VFP_END);
 }
 
 /**********************************************************************
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index ef10c10b7..76a90f9cf 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -47,7 +47,6 @@
  * 2	ObjGetSpace()	allocates space
  * 2	ObjExtend()	commits content
  * 2	ObjWaitExtend()	waits for content - used to implement ObjIterate())
- * 2	ObjTrimStore()	signals end of content addition
  *
  * 2	ObjSetAttr()
  * 2	  ObjCopyAttr()
@@ -212,23 +211,33 @@ ObjGetSpace(struct worker *wrk, struct objcore *oc, ssize_t *sz, uint8_t **ptr)
  *
  * This function extends the used part of the object a number of bytes
  * into the last space returned by ObjGetSpace()
+ *
+ * The final flag must be set on the last call, and it will release any
+ * surplus space allocated.
  */
 
 void
-ObjExtend(struct worker *wrk, struct objcore *oc, ssize_t l)
+ObjExtend(struct worker *wrk, struct objcore *oc, ssize_t l, int final)
 {
 	const struct obj_methods *om = obj_getmethods(oc);
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(oc->boc, BOC_MAGIC);
-	assert(l > 0);
+	(void)final;
+	assert(l >= 0);
 
 	Lck_Lock(&oc->boc->mtx);
 	AN(om->objextend);
-	om->objextend(wrk, oc, l);
-	oc->boc->len_so_far += l;
+	if (l > 0) {
+		om->objextend(wrk, oc, l);
+		oc->boc->len_so_far += l;
+		AZ(pthread_cond_broadcast(&oc->boc->cond));
+	}
 	Lck_Unlock(&oc->boc->mtx);
-	AZ(pthread_cond_broadcast(&oc->boc->cond));
+
+	assert(oc->boc == NULL || oc->boc->state < BOS_FINISHED);
+	if (final && om->objtrimstore != NULL)
+		om->objtrimstore(wrk, oc);
 }
 
 /*====================================================================
@@ -320,26 +329,6 @@ ObjGetLen(struct worker *wrk, struct objcore *oc)
 	return (len);
 }
 
-/*====================================================================
- * ObjTrimStore()
- *
- * Release any surplus space allocated, we promise not to call ObjExtend()
- * any more.
- */
-
-void
-ObjTrimStore(struct worker *wrk, struct objcore *oc)
-{
-	const struct obj_methods *om = obj_getmethods(oc);
-
-	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
-
-	assert(oc->boc == NULL || oc->boc->state < BOS_FINISHED);
-
-	if (om->objtrimstore != NULL)
-		om->objtrimstore(wrk, oc);
-}
-
 /*====================================================================
  * ObjSlim()
  *
diff --git a/bin/varnishd/cache/cache_req_body.c b/bin/varnishd/cache/cache_req_body.c
index 0d417ab6c..a3a771163 100644
--- a/bin/varnishd/cache/cache_req_body.c
+++ b/bin/varnishd/cache/cache_req_body.c
@@ -124,7 +124,7 @@ vrb_pull(struct req *req, ssize_t maxsize, objiterate_f *func, void *priv)
 				if (r)
 					break;
 			} else {
-				ObjExtend(req->wrk, req->body_oc, l);
+				ObjExtend(req->wrk, req->body_oc, l, vfps == VFP_END);
 			}
 		}
 
@@ -142,7 +142,6 @@ vrb_pull(struct req *req, ssize_t maxsize, objiterate_f *func, void *priv)
 		return (r);
 	}
 
-	ObjTrimStore(req->wrk, req->body_oc);
 	AZ(ObjSetU64(req->wrk, req->body_oc, OA_LEN, req_bodybytes));
 	HSH_DerefBoc(req->wrk, req->body_oc);
 
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 919a34d15..6cb1f7a67 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -337,7 +337,7 @@ cnt_synth(struct worker *wrk, struct req *req)
 		if (sz > 0 &&
 		    ObjGetSpace(wrk, req->objcore, &sz, &ptr) && sz >= szl) {
 			memcpy(ptr, VSB_data(synth_body), szl);
-			ObjExtend(wrk, req->objcore, szl);
+			ObjExtend(wrk, req->objcore, szl, 1);
 		} else if (sz > 0) {
 			szl = -1;
 		}
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index c365ce057..f95f3c773 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -248,7 +248,7 @@ void Bereq_Rollback(struct busyobj *);
 /* cache_fetch_proc.c */
 void VFP_Init(void);
 enum vfp_status VFP_GetStorage(struct vfp_ctx *, ssize_t *sz, uint8_t **ptr);
-void VFP_Extend(const struct vfp_ctx *, ssize_t sz);
+void VFP_Extend(const struct vfp_ctx *, ssize_t sz, enum vfp_status);
 void VFP_Setup(struct vfp_ctx *vc, struct worker *wrk);
 int VFP_Open(struct vfp_ctx *bo);
 uint64_t VFP_Close(struct vfp_ctx *bo);
@@ -295,13 +295,12 @@ void ObjInit(void);
 struct objcore * ObjNew(const struct worker *);
 void ObjDestroy(const struct worker *, struct objcore **);
 int ObjGetSpace(struct worker *, struct objcore *, ssize_t *sz, uint8_t **ptr);
-void ObjExtend(struct worker *, struct objcore *, ssize_t l);
+void ObjExtend(struct worker *, struct objcore *, ssize_t l, int final);
 uint64_t ObjWaitExtend(const struct worker *, const struct objcore *,
     uint64_t l);
 void ObjSetState(struct worker *, const struct objcore *,
     enum boc_state_e next);
 void ObjWaitState(const struct objcore *, enum boc_state_e want);
-void ObjTrimStore(struct worker *, struct objcore *);
 void ObjTouch(struct worker *, struct objcore *, vtim_real now);
 void ObjFreeObj(struct worker *, struct objcore *);
 void ObjSlim(struct worker *, struct objcore *);


More information about the varnish-commit mailing list