[master] 4e56f03 Eliminate struct storage from VFP_GetStorage callers

Poul-Henning Kamp phk at FreeBSD.org
Thu Aug 21 11:50:48 CEST 2014


commit 4e56f03ff070be41d64f9d07e0f46091621b12a8
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Aug 21 09:50:32 2014 +0000

    Eliminate struct storage from VFP_GetStorage callers

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index c22bd14..1608454 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -908,7 +908,7 @@ void VBF_Fetch(struct worker *wrk, struct req *req,
     struct objcore *oc, struct objcore *oldoc, enum vbf_fetch_mode_e);
 
 /* cache_fetch_proc.c */
-struct storage *VFP_GetStorage(struct vfp_ctx *, ssize_t sz);
+enum vfp_status VFP_GetStorage(struct vfp_ctx *, ssize_t *sz, uint8_t **ptr);
 void VFP_Init(void);
 void VFP_Fetch_Body(struct busyobj *bo);
 
diff --git a/bin/varnishd/cache/cache_esi_fetch.c b/bin/varnishd/cache/cache_esi_fetch.c
index a0d10f8..5fa6835 100644
--- a/bin/varnishd/cache/cache_esi_fetch.c
+++ b/bin/varnishd/cache/cache_esi_fetch.c
@@ -59,9 +59,9 @@ static ssize_t
 vfp_vep_callback(struct vfp_ctx *vc, void *priv, ssize_t l, enum vgz_flag flg)
 {
 	struct vef_priv *vef;
-	size_t dl;
+	ssize_t dl;
 	const void *dp;
-	struct storage *st;
+	uint8_t *ptr;
 	int i;
 
 	CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC);
@@ -84,13 +84,13 @@ vfp_vep_callback(struct vfp_ctx *vc, void *priv, ssize_t l, enum vgz_flag flg)
 
 	VGZ_Ibuf(vef->vgz, vef->ibuf_o, l);
 	do {
-		st = VFP_GetStorage(vc, 0);
-		if (st == NULL) {
+		dl = 0;
+		if (VFP_GetStorage(vc, &dl, &ptr) != VFP_OK) {
 			vef->error = ENOMEM;
 			vef->tot += l;
 			return (vef->tot);
 		}
-		VGZ_Obuf(vef->vgz, st->ptr + st->len, st->space - st->len);
+		VGZ_Obuf(vef->vgz, ptr, dl);
 		i = VGZ_Gzip(vef->vgz, &dp, &dl, flg);
 		vef->tot += dl;
 		VBO_extend(vc->bo, dl);
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index a776730..001cd79 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -555,9 +555,9 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
 {
 	struct objiter *oi;
 	void *sp;
-	ssize_t sl, al, tl;
+	ssize_t sl, al, l;
+	uint8_t *ptr;
 	uint64_t ol;
-	struct storage *st;
 	enum objiter_status ois;
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
@@ -577,28 +577,22 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
 		VBO_setstate(bo, BOS_STREAM);
 	}
 
-	st = NULL;
 	al = 0;
-
 	ol = ObjGetLen(bo->ims_oc, bo->stats);
 	oi = ObjIterBegin(wrk, bo->ims_oc);
 	do {
 		ois = ObjIter(oi, &sp, &sl);
 		while (sl > 0) {
-			if (st == NULL)
-				st = VFP_GetStorage(bo->vfc, ol - al);
-			if (st == NULL)
+			l = ol - al;
+			if (VFP_GetStorage(bo->vfc, &l, &ptr) != VFP_OK)
 				break;
-			tl = sl;
-			if (tl > st->space - st->len)
-				tl = st->space - st->len;
-			memcpy(st->ptr + st->len, sp, tl);
-			al += tl;
-			sp = (char *)sp + tl;
-			sl -= tl;
-			VBO_extend(bo, tl);
-			if (st->len == st->space)
-				st = NULL;
+			if (sl < l)
+				l = sl;
+			memcpy(ptr, sp, l);
+			VBO_extend(bo, l);
+			al += l;
+			sp = (char *)sp + l;
+			sl -= l;
 		}
 	} while (!bo->vfc->failed && (ois == OIS_DATA || ois == OIS_STREAM));
 	ObjIterEnd(&oi);
@@ -631,9 +625,9 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
 static enum fetch_step
 vbf_stp_error(struct worker *wrk, struct busyobj *bo)
 {
-	struct storage *st;
-	ssize_t l;
+	ssize_t l, ll, o;
 	double now;
+	uint8_t *ptr;
 	char time_str[VTIM_FORMAT_SIZE];
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
@@ -687,19 +681,16 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo)
 	if (vbf_beresp2obj(bo))
 		return (F_STP_FAIL);
 
-
-	l = VSB_len(bo->synth_body);
-	if (l > 0) {
-		st = VFP_GetStorage(bo->vfc, l);
-		if (st != NULL) {
-			if (st->space < l) {
-				VSLb(bo->vsl, SLT_Error,
-				    "No space for %zd bytes of synth body", l);
-			} else {
-				memcpy(st->ptr, VSB_data(bo->synth_body), l);
-				VBO_extend(bo, l);
-			}
-		}
+	ll = VSB_len(bo->synth_body);
+	o = 0;
+	while (ll > 0) {
+		l = ll;
+		if (VFP_GetStorage(bo->vfc, &l, &ptr) != VFP_OK)
+			break;
+		memcpy(ptr, VSB_data(bo->synth_body) + o, l);
+		VBO_extend(bo, l);
+		ll -= l;
+		o += l;
 	}
 	VSB_delete(bo->synth_body);
 	bo->synth_body = NULL;
diff --git a/bin/varnishd/cache/cache_fetch_proc.c b/bin/varnishd/cache/cache_fetch_proc.c
index b4338a5..08c67c6 100644
--- a/bin/varnishd/cache/cache_fetch_proc.c
+++ b/bin/varnishd/cache/cache_fetch_proc.c
@@ -73,25 +73,34 @@ VFP_Error(struct vfp_ctx *vc, const char *fmt, ...)
  *
  */
 
-struct storage *
-VFP_GetStorage(struct vfp_ctx *vc, ssize_t sz)
+enum vfp_status
+VFP_GetStorage(struct vfp_ctx *vc, ssize_t *sz, uint8_t **ptr)
 {
 	ssize_t l;
 	struct storage *st;
 
 	CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC);
 	CHECK_OBJ_NOTNULL(vc->bo, BUSYOBJ_MAGIC);
+	AN(sz);
+	AN(ptr);
 
 	AN(vc->stats);
 	l = fetchfrag;
 	if (l == 0)
-		l = sz;
+		l = *sz;
 	if (l == 0)
 		l = cache_param->fetch_chunksize;
 	st = ObjGetSpace(vc->oc, vc->vsl, vc->stats, l);
-	if (st == NULL)
-		(void)VFP_Error(vc, "Could not get storage");
-	return (st);
+	if (st == NULL) {
+		*sz = 0;
+		*ptr = NULL;
+		return (VFP_Error(vc, "Could not get storage"));
+	}
+	*sz = st->space - st->len;
+	assert(*sz > 0);
+	*ptr = st->ptr + st->len;
+	AN(*ptr);
+	return (VFP_OK);
 }
 
 /**********************************************************************
@@ -182,8 +191,8 @@ void
 VFP_Fetch_Body(struct busyobj *bo)
 {
 	ssize_t l;
+	uint8_t *ptr;
 	enum vfp_status vfps = VFP_ERROR;
-	struct storage *st = NULL;
 	ssize_t est;
 
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
@@ -209,25 +218,19 @@ VFP_Fetch_Body(struct busyobj *bo)
 			break;
 		}
 		AZ(bo->vfc->failed);
-		if (st == NULL) {
-			st = VFP_GetStorage(bo->vfc, est);
-			est = 0;
-		}
-		if (st == NULL) {
+		l = est;
+		if (VFP_GetStorage(bo->vfc, &l, &ptr) != VFP_OK) {
 			bo->doclose = SC_RX_BODY;
-			(void)VFP_Error(bo->vfc, "Out of storage");
 			break;
 		}
 
-		CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC);
-		l = st->space - st->len;
 		AZ(bo->vfc->failed);
-		vfps = VFP_Suck(bo->vfc, st->ptr + st->len, &l);
+		vfps = VFP_Suck(bo->vfc, ptr, &l);
 		if (l > 0 && vfps != VFP_ERROR) {
 			VBO_extend(bo, l);
+			if (est > 0)
+				est -= l;
 		}
-		if (st->len == st->space)
-			st = NULL;
 	} while (vfps == VFP_OK);
 
 	if (vfps == VFP_ERROR) {
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index a41d089..edf16f3 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -26,16 +26,16 @@
  * SUCH DAMAGE.
  *
  * Primary API:
- * 	ObjNew		Associate stevedore with oc
- * 	ObjGetSpace	Add space
- * 	ObjExtend	Commit space
- * 	ObjDone		Object completed
- * 	ObjGetLen	Len of committed space
- * 	ObjIter		Iterate over committed space
- * 	ObjReserveAttr	Attr will be set later
- * 	ObjSetAttr	Set attr now
- * 	ObjGetAttr	Get attr no
- * 	ObjRelease	Done with attr ptr
+ *	ObjNew		Associate stevedore with oc
+ *	ObjGetSpace	Add space
+ *	ObjExtend	Commit space
+ *	ObjDone		Object completed
+ *	ObjGetLen	Len of committed space
+ *	ObjIter		Iterate over committed space
+ *	ObjReserveAttr	Attr will be set later
+ *	ObjSetAttr	Set attr now
+ *	ObjGetAttr	Get attr no
+ *	ObjRelease	Done with attr ptr
  */
 
 #include "config.h"



More information about the varnish-commit mailing list