[master] f36b476 Make vcl_hit{}'s access to obj.* happen through the packed string.

Poul-Henning Kamp phk at FreeBSD.org
Mon Aug 18 23:34:25 CEST 2014


commit f36b47641fad8f6b6bd0f9841e3e3ee16cf6fdeb
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Aug 18 21:33:50 2014 +0000

    Make vcl_hit{}'s access to obj.* happen through the packed string.
    
    This bumps the vrt.h major version.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 42c40d3..44dea14 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -979,6 +979,7 @@ void http_MarkHeader(const struct http *, const char *hdr, unsigned hdrlen,
 void http_CollectHdr(struct http *hp, const char *hdr);
 void http_VSL_log(const struct http *hp);
 void HTTP_Merge(struct objcore *, struct dstat *, struct http *to);
+uint16_t HTTP_GetStatusPack(struct objcore *oc, struct dstat *ds);
 const char *HTTP_GetHdrPack(struct objcore *, struct dstat *,
     const char *hdr);
 
@@ -1062,7 +1063,6 @@ void ObjIterEnd(struct objiter **);
 void ObjTrimStore(struct objcore *, struct dstat *);
 unsigned ObjGetXID(struct objcore *, struct dstat *);
 uint64_t ObjGetLen(struct objcore *oc, struct dstat *ds);
-struct object *ObjGetObj(struct objcore *, struct dstat *);
 void ObjUpdateMeta(struct objcore *, struct dstat *);
 void ObjFreeObj(struct objcore *, struct dstat *);
 void ObjSlim(struct objcore *oc, struct dstat *ds);
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 83f4aa2..f79d173 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -723,6 +723,18 @@ HTTP_Decode(struct http *to, uint8_t *fm)
 
 /*--------------------------------------------------------------------*/
 
+uint16_t
+HTTP_GetStatusPack(struct objcore *oc, struct dstat *ds)
+{
+	const char *ptr;
+	ptr = ObjGetattr(oc, ds, OA_HEADERS, NULL);
+	AN(ptr);
+
+	return(vbe16dec(ptr + 2));
+}
+
+/*--------------------------------------------------------------------*/
+
 const char *
 HTTP_GetHdrPack(struct objcore *oc, struct dstat *ds, const char *hdr)
 {
@@ -741,10 +753,14 @@ HTTP_GetHdrPack(struct objcore *oc, struct dstat *ds, const char *hdr)
 	VSL(SLT_Debug, 0, "%d %s", __LINE__, ptr);
 
 	/* Skip PROTO, STATUS and REASON */
+	if (!strcmp(hdr, ":proto"))
+		return (ptr);
 	ptr = strchr(ptr, '\0') + 1;
 	if (!strcmp(hdr, ":status"))
 		return (ptr);
 	ptr = strchr(ptr, '\0') + 1;
+	if (!strcmp(hdr, ":reason"))
+		return (ptr);
 	ptr = strchr(ptr, '\0') + 1;
 
 	l = hdr[0];
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index ca028bc..158fedb 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -35,6 +35,30 @@
 #include "storage/storage.h"
 #include "hash/hash_slinger.h"
 
+
+static const struct objcore_methods *
+obj_getmethods(const struct objcore *oc)
+{
+
+	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+	CHECK_OBJ_NOTNULL(oc->stevedore, STEVEDORE_MAGIC);
+	AN(oc->stevedore->methods);
+	return (oc->stevedore->methods);
+}
+
+static struct object *
+obj_getobj(struct objcore *oc, struct dstat *ds)
+{
+	const struct objcore_methods *m = obj_getmethods(oc);
+
+	AN(ds);
+	AN(m->getobj);
+	return (m->getobj(ds, oc));
+}
+
+/*--------------------------------------------------------------------
+ */
+
 struct objiter {
 	unsigned			magic;
 #define OBJITER_MAGIC			0x745fb151
@@ -52,7 +76,7 @@ ObjIterBegin(struct worker *wrk, struct objcore *oc)
 	struct object *obj;
 
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
-	obj = ObjGetObj(oc, &wrk->stats);
+	obj = obj_getobj(oc, &wrk->stats);
 	CHECK_OBJ_NOTNULL(obj, OBJECT_MAGIC);
 	ALLOC_OBJ(oi, OBJITER_MAGIC);
 	if (oi == NULL)
@@ -142,16 +166,6 @@ ObjIterEnd(struct objiter **oi)
 	*oi = NULL;
 }
 
-static const struct objcore_methods *
-obj_getmethods(const struct objcore *oc)
-{
-
-	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
-	CHECK_OBJ_NOTNULL(oc->stevedore, STEVEDORE_MAGIC);
-	AN(oc->stevedore->methods);
-	return (oc->stevedore->methods);
-}
-
 void
 ObjTrimStore(struct objcore *oc, struct dstat *ds)
 {
@@ -163,7 +177,7 @@ ObjTrimStore(struct objcore *oc, struct dstat *ds)
 	AN(ds);
 	stv = oc->stevedore;
 	CHECK_OBJ_NOTNULL(stv, STEVEDORE_MAGIC);
-	o = ObjGetObj(oc, ds);
+	o = obj_getobj(oc, ds);
 	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 	st = VTAILQ_LAST(&o->body->list, storagehead);
 	if (st == NULL)
@@ -188,7 +202,7 @@ ObjSlim(struct objcore *oc, struct dstat *ds)
 
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	AN(ds);
-	o = ObjGetObj(oc, ds);
+	o = obj_getobj(oc, ds);
 	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 
 	if (o->esidata != NULL) {
@@ -202,16 +216,6 @@ ObjSlim(struct objcore *oc, struct dstat *ds)
 	}
 }
 
-struct object *
-ObjGetObj(struct objcore *oc, struct dstat *ds)
-{
-	const struct objcore_methods *m = obj_getmethods(oc);
-
-	AN(ds);
-	AN(m->getobj);
-	return (m->getobj(ds, oc));
-}
-
 void
 ObjUpdateMeta(struct objcore *oc, struct dstat *ds)
 {
@@ -253,7 +257,7 @@ ObjGetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr,
 	AN(ds);
 	if (len == NULL)
 		len = &dummy;
-	o = ObjGetObj(oc, ds);
+	o = obj_getobj(oc, ds);
 	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 	switch (attr) {
 	case OA_ESIDATA:
@@ -294,7 +298,7 @@ ObjSetattr(const struct vfp_ctx *vc, enum obj_attr attr,
 	CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC);
 	CHECK_OBJ_NOTNULL(vc->bo, BUSYOBJ_MAGIC);
 	CHECK_OBJ_NOTNULL(vc->bo->fetch_objcore, OBJCORE_MAGIC);
-	o = ObjGetObj(vc->bo->fetch_objcore, vc->bo->stats);
+	o = obj_getobj(vc->bo->fetch_objcore, vc->bo->stats);
 	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 	switch (attr) {
 	case OA_ESIDATA:
@@ -358,7 +362,7 @@ ObjGetLen(struct objcore *oc, struct dstat *ds)
 {
 	struct object *o;
 
-	o = ObjGetObj(oc, ds);
+	o = obj_getobj(oc, ds);
 	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 	return (o->body->len);
 }
diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index db1feb3..345696e 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -432,9 +432,6 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
 		ctx.http_req = req->http;
 		ctx.http_resp = req->resp;
 		ctx.req = req;
-		if (method == VCL_MET_HIT)
-			ctx.http_obj =
-			    ObjGetObj(req->objcore, &wrk->stats)->http;
 	}
 	if (bo != NULL) {
 		CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 46f3e02..f2c2065 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -109,9 +109,6 @@ vrt_selecthttp(const struct vrt_ctx *ctx, enum gethdr_e where)
 	case HDR_RESP:
 		hp = ctx->http_resp;
 		break;
-	case HDR_OBJ:
-		hp = ctx->http_obj;
-		break;
 	default:
 		WRONG("vrt_selecthttp 'where' invalid");
 	}
@@ -120,13 +117,19 @@ vrt_selecthttp(const struct vrt_ctx *ctx, enum gethdr_e where)
 
 /*--------------------------------------------------------------------*/
 
-char *
+const char *
 VRT_GetHdr(const struct vrt_ctx *ctx, const struct gethdr_s *hs)
 {
 	char *p;
 	struct http *hp;
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	if (hs->where == HDR_OBJ) {
+		CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
+		CHECK_OBJ_NOTNULL(ctx->req->objcore, OBJCORE_MAGIC);
+		return(HTTP_GetHdrPack(ctx->req->objcore,
+		    &ctx->req->wrk->stats, hs->what));
+	}
 	hp = vrt_selecthttp(ctx, hs->where);
 	CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
 	if (!http_GetHdr(hp, hs->what, &p))
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 3f50a4b..0d639a7 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -124,10 +124,6 @@ VRT_HDR_LR(req,    method,	HTTP_HDR_METHOD)
 VRT_HDR_LR(req,    url,		HTTP_HDR_URL)
 VRT_HDR_LR(req,    proto,	HTTP_HDR_PROTO)
 
-VRT_HDR_R(obj,    proto,	HTTP_HDR_PROTO)
-VRT_HDR_R(obj,    reason,	HTTP_HDR_REASON)
-VRT_STATUS_R(obj)
-
 VRT_HDR_LR(resp,   proto,	HTTP_HDR_PROTO)
 VRT_HDR_LR(resp,   reason,	HTTP_HDR_REASON)
 VRT_STATUS_L(resp)
@@ -142,6 +138,42 @@ VRT_STATUS_L(beresp)
 VRT_STATUS_R(beresp)
 
 /*--------------------------------------------------------------------
+ * Pulling things out of the packed object->http
+ */
+
+long
+VRT_r_obj_status(const struct vrt_ctx *ctx)
+{
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx->req->objcore, OBJCORE_MAGIC);
+
+	return (HTTP_GetStatusPack(ctx->req->objcore, &ctx->req->wrk->stats));
+}
+
+const char *
+VRT_r_obj_proto(const struct vrt_ctx *ctx)
+{
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx->req->objcore, OBJCORE_MAGIC);
+
+	return (HTTP_GetHdrPack(ctx->req->objcore,
+	    &ctx->req->wrk->stats, ":proto"));
+}
+
+const char *
+VRT_r_obj_reason(const struct vrt_ctx *ctx)
+{
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx->req->objcore, OBJCORE_MAGIC);
+
+	return (HTTP_GetHdrPack(ctx->req->objcore,
+	    &ctx->req->wrk->stats, ":reason"));
+}
+
+/*--------------------------------------------------------------------
  * bool-fields (.do_*)
  */
 
diff --git a/include/vrt.h b/include/vrt.h
index ead55d3..cb47db9 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -39,9 +39,9 @@
  * binary/load-time compatible, increment MAJOR version
  */
 
-#define VRT_MAJOR_VERSION	1U
+#define VRT_MAJOR_VERSION	2U
 
-#define VRT_MINOR_VERSION	2U
+#define VRT_MINOR_VERSION	0U
 
 
 /***********************************************************************/
@@ -95,7 +95,6 @@ struct vrt_ctx {
 
 	struct req			*req;
 	struct http			*http_req;
-	struct http			*http_obj;
 	struct http			*http_resp;
 
 	struct busyobj			*bo;
@@ -238,7 +237,7 @@ int VRT_rewrite(const char *, const char *);
 void VRT_error(const struct vrt_ctx *, unsigned, const char *);
 int VRT_switch_config(const char *);
 
-char *VRT_GetHdr(const struct vrt_ctx *, const struct gethdr_s *);
+const char *VRT_GetHdr(const struct vrt_ctx *, const struct gethdr_s *);
 void VRT_SetHdr(const struct vrt_ctx *, const struct gethdr_s *,
     const char *, ...);
 void VRT_handling(const struct vrt_ctx *, unsigned hand);



More information about the varnish-commit mailing list