[master] 5d19015 Push the last bit of struct object firmly into stevedore-space.

Poul-Henning Kamp phk at FreeBSD.org
Tue Aug 19 12:23:01 CEST 2014


commit 5d19015c9e2364ae79832f3083329ea12fd130a3
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Aug 19 10:22:36 2014 +0000

    Push the last bit of struct object firmly into stevedore-space.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 66712b8..c22bd14 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -950,7 +950,7 @@ void HTTP_Init(void);
 void http_PutResponse(struct http *to, const char *proto, uint16_t status,
     const char *response);
 void http_FilterReq(struct http *to, const struct http *fm, unsigned how);
-uint8_t *HTTP_Encode(const struct http *fm, struct ws *ws, unsigned how);
+void HTTP_Encode(const struct http *fm, uint8_t *, unsigned len, unsigned how);
 int HTTP_Decode(struct http *to, uint8_t *fm);
 void http_ForceHeader(struct http *to, const char *hdr, const char *val);
 void http_PrintfHeader(struct http *to, const char *fmt, ...)
@@ -1172,7 +1172,6 @@ void VSL_Flush(struct vsl_log *, int overflow);
 /* cache_vary.c */
 int VRY_Create(struct busyobj *bo, struct vsb **psb);
 int VRY_Match(struct req *, const uint8_t *vary);
-unsigned VRY_Validate(const uint8_t *vary);
 void VRY_Prep(struct req *);
 void VRY_Clear(struct req *);
 enum vry_finish_flag { KEEP, DISCARD };
@@ -1245,7 +1244,7 @@ void RFC2616_Weaken_Etag(struct http *hp);
 
 
 /* stevedore.c */
-struct object *STV_NewObject(struct busyobj *, const char *hint, unsigned len);
+int STV_NewObject(struct busyobj *, const char *hint, unsigned len);
 struct storage *STV_alloc(struct stevedore *, size_t size);
 void STV_trim(struct storage *st, size_t size, int move_ok);
 void STV_free(struct storage *st);
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 1abc7c0..a776730 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -46,10 +46,9 @@
  * XXX: Should this be merged over there ?
  */
 
-static struct object *
+static int
 vbf_allocobj(struct busyobj *bo, unsigned l)
 {
-	struct object *obj;
 	struct objcore *oc;
 	const char *storage_hint;
 	double lifetime;
@@ -67,13 +66,11 @@ vbf_allocobj(struct busyobj *bo, unsigned l)
 
 	bo->storage_hint = NULL;
 
-	obj = STV_NewObject(bo, storage_hint, l);
-
-	if (obj != NULL)
-		return (obj);
+	if (STV_NewObject(bo, storage_hint, l))
+		return (1);
 
 	if (storage_hint != NULL && !strcmp(storage_hint, TRANSIENT_STORAGE))
-		return (NULL);
+		return (0);
 
 	/*
 	 * Try to salvage the transaction by allocating a shortlived object
@@ -84,8 +81,7 @@ vbf_allocobj(struct busyobj *bo, unsigned l)
 		oc->exp.ttl = cache_param->shortlived;
 	oc->exp.grace = 0.0;
 	oc->exp.keep = 0.0;
-	obj = STV_NewObject(bo, TRANSIENT_STORAGE, l);
-	return (obj);
+	return (STV_NewObject(bo, TRANSIENT_STORAGE, l));
 }
 
 /*--------------------------------------------------------------------
@@ -95,11 +91,11 @@ vbf_allocobj(struct busyobj *bo, unsigned l)
 static int
 vbf_beresp2obj(struct busyobj *bo)
 {
-	unsigned l;
+	unsigned l, l2;
 	char *b;
+	uint8_t *bp;
 	struct vsb *vary = NULL;
 	int varyl = 0;
-	struct object *obj;
 
 	l = 0;
 
@@ -125,22 +121,18 @@ vbf_beresp2obj(struct busyobj *bo)
 			AZ(vary);
 	}
 
-	l += http_EstimateWS(bo->beresp,
+	l2 = http_EstimateWS(bo->beresp,
 	    bo->uncacheable ? HTTPH_R_PASS : HTTPH_A_INS);
+	l += l2;
 
 	if (bo->uncacheable)
 		bo->fetch_objcore->flags |= OC_F_PASS;
 
-	obj = vbf_allocobj(bo, l);
-
-	if (obj == NULL)
+	if (!vbf_allocobj(bo, l))
 		return (-1);
 
-	CHECK_OBJ_NOTNULL(obj, OBJECT_MAGIC);
-
 	if (vary != NULL) {
 		b = ObjSetattr(bo->vfc, OA_VARY, varyl, VSB_data(vary));
-		(void)VRY_Validate(obj->oa_vary);
 		VSB_delete(vary);
 	}
 
@@ -151,9 +143,10 @@ vbf_beresp2obj(struct busyobj *bo)
 	bo->beresp->logtag = SLT_ObjMethod;
 
 	/* Filter into object */
-	obj->oa_http = HTTP_Encode(bo->beresp, bo->ws_o,
+	bp = ObjSetattr(bo->vfc, OA_HEADERS, l2, NULL);
+	AN(bp);
+	HTTP_Encode(bo->beresp, bp, l2,
 	    bo->uncacheable ? HTTPH_R_PASS : HTTPH_A_INS);
-	AN(obj->oa_http);
 
 	if (http_GetHdr(bo->beresp, H_Last_Modified, &b))
 		AZ(ObjSetDouble(bo->vfc, OA_LASTMODIFIED, VTIM_parse(b)));
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 592d042..16c21bb 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -637,20 +637,18 @@ http_EstimateWS(const struct http *fm, unsigned how)
  * Encode http struct as byte string.
  */
 
-uint8_t *
-HTTP_Encode(const struct http *fm, struct ws *ws, unsigned how)
+void
+HTTP_Encode(const struct http *fm, uint8_t *p0, unsigned l, unsigned how)
 {
 	unsigned u, w;
 	uint16_t n;
 	uint8_t *p, *e;
 
-	u = WS_Reserve(ws, 0);
-	p = (uint8_t*)ws->f;
-	e = (uint8_t*)ws->f + u;
-	if (p + 5 > e) {
-		WS_Release(ws, 0);
-		return (NULL);
-	}
+	AN(p0);
+	AN(l);
+	p = p0;
+	e = p + l;
+	assert(p + 5 <= e);
 	assert(fm->nhd < fm->shd);
 	n = HTTP_HDR_FIRST - 3;
 	vbe16enc(p + 2, fm->status);
@@ -670,20 +668,14 @@ HTTP_Encode(const struct http *fm, struct ws *ws, unsigned how)
 #undef HTTPH
 		http_VSLH(fm, u);
 		w = Tlen(fm->hd[u]) + 1L;
-		if (p + w + 1 > e) {
-			WS_Release(ws, 0);
-			return (NULL);
-		}
+		assert(p + w + 1 <= e);
 		memcpy(p, fm->hd[u].b, w);
 		p += w;
 		n++;
 	}
 	*p++ = '\0';
 	assert(p <= e);
-	e = (uint8_t*)ws->f;
-	vbe16enc(e, n + 1);
-	WS_ReleaseP(ws, (void*)p);
-	return (e);
+	vbe16enc(p0, n + 1);
 }
 
 /*--------------------------------------------------------------------
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index a89a4ab..3a3913a 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -405,6 +405,11 @@ ObjSetattr(const struct vfp_ctx *vc, enum obj_attr attr, ssize_t len,
 		assert(len == sizeof o->oa_gzipbits);
 		retval = o->oa_gzipbits;
 		break;
+	case OA_HEADERS:
+		o->oa_http = (void*)WS_Alloc(vc->bo->ws_o, len);
+		AN(o->oa_http);
+		retval = o->oa_http;
+		break;
 	case OA_LASTMODIFIED:
 		assert(len == sizeof o->oa_lastmodified);
 		retval = o->oa_lastmodified;
diff --git a/bin/varnishd/cache/cache_vary.c b/bin/varnishd/cache/cache_vary.c
index e4a7628..7c783af 100644
--- a/bin/varnishd/cache/cache_vary.c
+++ b/bin/varnishd/cache/cache_vary.c
@@ -63,6 +63,8 @@
 #include "vct.h"
 #include "vend.h"
 
+static unsigned VRY_Validate(const uint8_t *vary);
+
 /**********************************************************************
  * Create a Vary matching string from a Vary header
  *
@@ -368,7 +370,7 @@ VRY_Match(struct req *req, const uint8_t *vary)
  * Check the validity of a Vary string and return its total length
  */
 
-unsigned
+static unsigned
 VRY_Validate(const uint8_t *vary)
 {
 	unsigned retval = 0;
diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index 4fd40a4..360d7b6 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -275,7 +275,7 @@ stv_default_allocobj(struct stevedore *stv, struct busyobj *bo,
  * XXX: for the body in the same allocation while we are at it.
  */
 
-struct object *
+int
 STV_NewObject(struct busyobj *bo, const char *hint, unsigned wsl)
 {
 	struct object *o;
@@ -315,14 +315,14 @@ STV_NewObject(struct busyobj *bo, const char *hint, unsigned wsl)
 	}
 
 	if (o == NULL)
-		return (NULL);
+		return (0);
 
 	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 	CHECK_OBJ_NOTNULL(o->objstore, STORAGE_MAGIC);
 	CHECK_OBJ_NOTNULL(o->objcore, OBJCORE_MAGIC);
 	assert(o->objcore->stevedore == stv);
 	AN(stv->methods);
-	return (o);
+	return (1);
 }
 
 /*-------------------------------------------------------------------*/



More information about the varnish-commit mailing list