[master] 02671fe Fully convert obj->vxid to an obj_attr

Poul-Henning Kamp phk at FreeBSD.org
Wed Jul 30 13:23:35 CEST 2014


commit 02671fe4708e85df21f57a45533bc88ca2f80633
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Jul 30 11:23:19 2014 +0000

    Fully convert obj->vxid to an obj_attr

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 8ea97d8..b13e997 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -554,7 +554,7 @@ enum obj_attr {
 struct object {
 	unsigned		magic;
 #define OBJECT_MAGIC		0x32851d42
-	uint32_t		vxid;
+	char			oa_vxid[4];
 	struct storage		*objstore;
 	struct objcore		*objcore;
 
@@ -1059,6 +1059,8 @@ void ObjFreeObj(struct objcore *, struct dstat *);
 struct lru *ObjGetLRU(const struct objcore *);
 ssize_t ObjGetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr,
     void **ptr);
+void *ObjSetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr,
+    ssize_t len);
 
 /* cache_panic.c */
 void PAN_Init(void);
diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index e6c3ced..552b67a 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -967,7 +967,8 @@ BAN_CheckObject(struct worker *wrk, struct objcore *oc, struct req *req)
 		return (0);
 	} else {
 		oc->ban = NULL;
-		VSLb(vsl, SLT_ExpBan, "%u banned lookup", o->vxid);
+		VSLb(vsl, SLT_ExpBan, "%u banned lookup",
+		    VXID(ObjGetXID(oc, &wrk->stats)));
 		VSC_C_main->bans_obj_killed++;
 		EXP_Rearm(oc, oc->exp.t_origin, 0, 0, 0);	// XXX fake now
 		return (1);
@@ -1102,7 +1103,8 @@ ban_lurker_test_ban(struct worker *wrk, struct vsl_log *vsl, struct ban *bt,
 				break;
 		}
 		if (i) {
-			VSLb(vsl, SLT_ExpBan, "%u banned by lurker", o->vxid);
+			VSLb(vsl, SLT_ExpBan, "%u banned by lurker",
+			    VXID(ObjGetXID(oc, &wrk->stats)));
 			EXP_Rearm(oc, oc->exp.t_origin, 0, 0, 0); // XXX fake now
 			VSC_C_main->bans_lurker_obj_killed++;
 		}
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 2430b16..a169e38 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -35,6 +35,7 @@
 #include <stdlib.h>
 
 #include "cache.h"
+#include "vend.h"
 #include "hash/hash_slinger.h"
 #include "vcl.h"
 #include "vtim.h"
@@ -101,6 +102,7 @@ vbf_beresp2obj(struct busyobj *bo)
 	uint16_t nhttp;
 	struct object *obj;
 	struct http *hp, *hp2;
+	void *vp;
 
 	l = 0;
 
@@ -150,7 +152,8 @@ vbf_beresp2obj(struct busyobj *bo)
 		VSB_delete(vary);
 	}
 
-	obj->vxid = bo->vsl->wid;
+	vp = ObjSetattr(bo->fetch_objcore, bo->stats, OA_VXID, 4);
+	vbe32enc(vp, bo->vsl->wid);
 	WS_Assert(bo->ws_o);
 
 	/* Filter into object */
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index e9c0812..47fd31b 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -31,6 +31,7 @@
 #include <stdlib.h>
 
 #include "cache.h"
+#include "vend.h"
 #include "storage/storage.h"
 #include "hash/hash_slinger.h"
 
@@ -227,8 +228,8 @@ ObjGetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr, void **ptr)
 	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 	switch (attr) {
 	case OA_VXID:
-		*ptr = &o->vxid;
-		return (sizeof o->vxid);
+		*ptr = o->oa_vxid;
+		return (sizeof o->oa_vxid);
 	case OA_GZIPBITS:
 		*ptr = o->gzip_bits;
 		return (sizeof o->gzip_bits);
@@ -243,13 +244,31 @@ ObjGetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr, void **ptr)
 	WRONG("Unsupported OBJ_ATTR");
 }
 
+void *
+ObjSetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr,
+    ssize_t len)
+{
+	struct object *o;
+	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+	AN(ds);
+	o = ObjGetObj(oc, ds);
+	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
+	switch (attr) {
+	case OA_VXID:
+		assert(len == sizeof o->oa_vxid);
+		return (o->oa_vxid);
+	default:
+		break;
+	}
+	WRONG("Unsupported OBJ_ATTR");
+}
+
+
 unsigned
 ObjGetXID(struct objcore *oc, struct dstat *ds)
 {
 	void *p;
-	uint32_t u;
 
-	assert(ObjGetattr(oc, ds, OA_VXID, &p) == sizeof u);
-	memcpy(&u, p, sizeof u);
-	return (u);
+	assert(ObjGetattr(oc, ds, OA_VXID, &p) == 4);
+	return (vbe32dec(p));
 }
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 9b9a7a9..111e8c5 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -39,6 +39,7 @@
 #include <stdlib.h>
 
 #include "cache.h"
+#include "vend.h"
 #include "common/heritage.h"
 
 #include "cache_backend.h"
@@ -215,7 +216,7 @@ pan_object(const char *typ, const struct object *o)
 	const struct storage *st;
 
 	VSB_printf(pan_vsp, "  obj (%s) = %p {\n", typ, o);
-	VSB_printf(pan_vsp, "    vxid = %u,\n", VXID(o->vxid));
+	VSB_printf(pan_vsp, "    vxid = %u,\n", VXID(vbe32dec(o->oa_vxid)));
 	pan_http("obj", o->http, 4);
 	VSB_printf(pan_vsp, "    len = %jd,\n", (intmax_t)o->len);
 	VSB_printf(pan_vsp, "    store = {\n");
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 3e17779..7b4b2f5 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -109,7 +109,7 @@ cnt_deliver(struct worker *wrk, struct req *req)
 	if (req->wrk->stats.cache_hit)
 		http_PrintfHeader(req->resp,
 		    "X-Varnish: %u %u", VXID(req->vsl->wid),
-		    VXID(req->obj->vxid));
+		    VXID(ObjGetXID(req->obj->objcore, &wrk->stats)));
 	else
 		http_PrintfHeader(req->resp,
 		    "X-Varnish: %u", VXID(req->vsl->wid));
@@ -404,7 +404,8 @@ cnt_lookup(struct worker *wrk, struct req *req)
 	if (oc->flags & OC_F_PASS) {
 		/* Found a hit-for-pass */
 		VSLb(req->vsl, SLT_Debug, "XXXX HIT-FOR-PASS");
-		VSLb(req->vsl, SLT_HitPass, "%u", req->obj->vxid);
+		VSLb(req->vsl, SLT_HitPass, "%u",
+		    VXID(ObjGetXID(req->obj->objcore, &wrk->stats)));
 		AZ(boc);
 		(void)HSH_DerefObj(&wrk->stats, &req->obj);
 		req->objcore = NULL;
@@ -416,7 +417,8 @@ cnt_lookup(struct worker *wrk, struct req *req)
 	oh = oc->objhead;
 	CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
 
-	VSLb(req->vsl, SLT_Hit, "%u", req->obj->vxid);
+	VSLb(req->vsl, SLT_Hit, "%u",
+	    VXID(ObjGetXID(req->obj->objcore, &wrk->stats)));
 
 	VCL_hit_method(req->vcl, wrk, req, NULL, req->http->ws);
 



More information about the varnish-commit mailing list