[master] ed7616419 Do not truncate 64bit XID's in storage_simple.

Poul-Henning Kamp phk at FreeBSD.org
Tue Apr 11 15:26:08 UTC 2023


commit ed7616419cb33fb856992e3ec07c9eb53160a870
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Apr 11 15:23:48 2023 +0000

    Do not truncate 64bit XID's in storage_simple.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 55a86960a..21b44fbf2 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -752,10 +752,9 @@ typedef int objiterate_f(void *priv, unsigned flush,
 int ObjIterate(struct worker *, struct objcore *,
     void *priv, objiterate_f *func, int final);
 
-unsigned ObjGetXID(struct worker *, struct objcore *);
+vxid_t ObjGetXID(struct worker *, struct objcore *);
 uint64_t ObjGetLen(struct worker *, struct objcore *);
 int ObjGetDouble(struct worker *, struct objcore *, enum obj_attr, double *);
-int ObjGetU32(struct worker *, struct objcore *, enum obj_attr, uint32_t *);
 int ObjGetU64(struct worker *, struct objcore *, enum obj_attr, uint64_t *);
 int ObjCheckFlag(struct worker *, struct objcore *, enum obj_flags of);
 
diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index ab523cd6e..e13380e7d 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -706,7 +706,8 @@ BAN_CheckObject(struct worker *wrk, struct objcore *oc, struct req *req)
 		ObjSendEvent(wrk, oc, OEV_BANCHG);
 		return (0);
 	} else {
-		VSLb(vsl, SLT_ExpBan, "%u banned lookup", ObjGetXID(wrk, oc));
+		VSLb(vsl, SLT_ExpBan,
+		    "%ju banned lookup", VXID(ObjGetXID(wrk, oc)));
 		return (1);
 	}
 }
diff --git a/bin/varnishd/cache/cache_ban_lurker.c b/bin/varnishd/cache/cache_ban_lurker.c
index ab5280e88..1c3b4088d 100644
--- a/bin/varnishd/cache/cache_ban_lurker.c
+++ b/bin/varnishd/cache/cache_ban_lurker.c
@@ -300,13 +300,13 @@ ban_lurker_test_ban(struct worker *wrk, struct vsl_log *vsl, struct ban *bt,
 			if (i) {
 				if (kill) {
 					VSLb(vsl, SLT_ExpBan,
-					    "%u killed for lurker cutoff",
-					    ObjGetXID(wrk, oc));
+					    "%ju killed for lurker cutoff",
+					    VXID(ObjGetXID(wrk, oc)));
 					lokc++;
 				} else {
 					VSLb(vsl, SLT_ExpBan,
-					    "%u banned by lurker",
-					    ObjGetXID(wrk, oc));
+					    "%ju banned by lurker",
+					    VXID(ObjGetXID(wrk, oc)));
 					lok++;
 				}
 				HSH_Kill(oc);
diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index 21a40a05f..33345ac86 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -354,8 +354,8 @@ exp_expire(struct exp_priv *ep, vtim_real now)
 		assert(oc->timer_idx == VBH_NOIDX);
 
 		CHECK_OBJ_NOTNULL(oc->objhead, OBJHEAD_MAGIC);
-		VSLb(&ep->vsl, SLT_ExpKill, "EXP_Expired x=%u t=%.0f",
-		    ObjGetXID(ep->wrk, oc), EXP_Ttl(NULL, oc) - now);
+		VSLb(&ep->vsl, SLT_ExpKill, "EXP_Expired xid=%ju t=%.0f",
+		    VXID(ObjGetXID(ep->wrk, oc)), EXP_Ttl(NULL, oc) - now);
 		ObjSendEvent(ep->wrk, oc, OEV_EXPIRE);
 		(void)HSH_DerefObjCore(ep->wrk, &oc, 0);
 	}
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 0af5c0d54..027b617f5 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -218,7 +218,7 @@ vbf_beresp2obj(struct busyobj *bo)
 		VSB_destroy(&vary);
 	}
 
-	AZ(ObjSetU32(bo->wrk, oc, OA_VXID, VXID(bo->vsl->wid)));
+	AZ(ObjSetXID(bo->wrk, oc, bo->vsl->wid));
 
 	/* for HTTP_Encode() VSLH call */
 	bo->beresp->logtag = SLT_ObjMethod;
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 4a77e7ffd..4b3799888 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -499,7 +499,7 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp)
 		(void)req->vcf->func(req, &oc, &exp_oc, 1);
 
 	if (oc != NULL && oc->flags & OC_F_HFP) {
-		xid = ObjGetXID(wrk, oc);
+		xid = VXID(ObjGetXID(wrk, oc));
 		dttl = EXP_Dttl(req, oc);
 		AN(hsh_deref_objhead_unlock(wrk, &oh, HSH_RUSH_POLICY));
 		wrk->stats->cache_hitpass++;
@@ -511,7 +511,7 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp)
 		*ocp = oc;
 		oc->refcnt++;
 		if (oc->flags & OC_F_HFM) {
-			xid = ObjGetXID(wrk, oc);
+			xid = VXID(ObjGetXID(wrk, oc));
 			dttl = EXP_Dttl(req, oc);
 			*bocp = hsh_insert_busyobj(wrk, oh);
 			Lck_Unlock(&oh->mtx);
@@ -533,7 +533,7 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp)
 		 * XXX should HFM objects actually have grace/keep ?
 		 * XXX also:  why isn't *ocp = exp_oc ?
 		 */
-		xid = ObjGetXID(wrk, exp_oc);
+		xid = VXID(ObjGetXID(wrk, exp_oc));
 		dttl = EXP_Dttl(req, exp_oc);
 		*bocp = hsh_insert_busyobj(wrk, oh);
 		Lck_Unlock(&oh->mtx);
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index b862d2c44..35a9635dd 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -536,12 +536,23 @@ ObjCopyAttr(struct worker *wrk, struct objcore *oc, struct objcore *ocs,
 	return (0);
 }
 
-unsigned
+int
+ObjSetXID(struct worker *wrk, struct objcore *oc, vxid_t xid)
+{
+	uint64_t u;
+
+	u = VXID(xid);
+	AZ(ObjSetU64(wrk, oc, OA_VXID, u));
+	return (0);
+}
+
+
+vxid_t
 ObjGetXID(struct worker *wrk, struct objcore *oc)
 {
-	uint32_t u;
+	vxid_t u;
 
-	AZ(ObjGetU32(wrk, oc, OA_VXID, &u));
+	AZ(ObjGetU64(wrk, oc, OA_VXID, &u.vxid));
 	return (u);
 }
 
@@ -616,32 +627,6 @@ ObjGetU64(struct worker *wrk, struct objcore *oc, enum obj_attr a, uint64_t *d)
 	return (0);
 }
 
-int
-ObjSetU32(struct worker *wrk, struct objcore *oc, enum obj_attr a, uint32_t t)
-{
-	void *vp;
-
-	vp = ObjSetAttr(wrk, oc, a, sizeof t, NULL);
-	if (vp == NULL)
-		return (-1);
-	vbe32enc(vp, t);
-	return (0);
-}
-
-int
-ObjGetU32(struct worker *wrk, struct objcore *oc, enum obj_attr a, uint32_t *d)
-{
-	const void *vp;
-	ssize_t l;
-
-	vp = ObjGetAttr(wrk, oc, a, &l);
-	if (vp == NULL || l != sizeof *d)
-		return (-1);
-	if (d != NULL)
-		*d = vbe32dec(vp);
-	return (0);
-}
-
 /*--------------------------------------------------------------------
  */
 
diff --git a/bin/varnishd/cache/cache_req.c b/bin/varnishd/cache/cache_req.c
index 113f3a987..eb1700df1 100644
--- a/bin/varnishd/cache/cache_req.c
+++ b/bin/varnishd/cache/cache_req.c
@@ -88,13 +88,13 @@ Req_LogHit(struct worker *wrk, struct req *req, struct objcore *oc,
 			clen = sep = "";
 		else
 			sep = " ";
-		VSLb(req->vsl, SLT_Hit, "%u %.6f %.6f %.6f %jd%s%s",
-		    ObjGetXID(wrk, oc), EXP_Dttl(req, oc),
+		VSLb(req->vsl, SLT_Hit, "%ju %.6f %.6f %.6f %jd%s%s",
+		    VXID(ObjGetXID(wrk, oc)), EXP_Dttl(req, oc),
 		    oc->grace, oc->keep,
 		    fetch_progress, sep, clen);
 	} else {
-		VSLb(req->vsl, SLT_Hit, "%u %.6f %.6f %.6f",
-		    ObjGetXID(wrk, oc), EXP_Dttl(req, oc),
+		VSLb(req->vsl, SLT_Hit, "%ju %.6f %.6f %.6f",
+		    VXID(ObjGetXID(wrk, oc)), EXP_Dttl(req, oc),
 		    oc->grace, oc->keep);
 	}
 }
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 3deb70e5a..f9c23d745 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -152,8 +152,8 @@ Resp_Setup_Deliver(struct req *req)
 	http_ForceField(h, HTTP_HDR_PROTO, "HTTP/1.1");
 
 	if (req->is_hit)
-		http_PrintfHeader(h, "X-Varnish: %ju %u", VXID(req->vsl->wid),
-		    ObjGetXID(req->wrk, oc));
+		http_PrintfHeader(h, "X-Varnish: %ju %ju", VXID(req->vsl->wid),
+		    VXID(ObjGetXID(req->wrk, oc)));
 	else
 		http_PrintfHeader(h, "X-Varnish: %ju", VXID(req->vsl->wid));
 
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index e6dc7e697..08763874c 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -347,8 +347,8 @@ int ObjCopyAttr(struct worker *, struct objcore *, struct objcore *,
 void ObjBocDone(struct worker *, struct objcore *, struct boc **);
 
 int ObjSetDouble(struct worker *, struct objcore *, enum obj_attr, double);
-int ObjSetU32(struct worker *, struct objcore *, enum obj_attr, uint32_t);
 int ObjSetU64(struct worker *, struct objcore *, enum obj_attr, uint64_t);
+int ObjSetXID(struct worker *, struct objcore *, vxid_t);
 
 void ObjSetFlag(struct worker *, struct objcore *, enum obj_flags of, int val);
 
diff --git a/bin/varnishd/storage/storage_lru.c b/bin/varnishd/storage/storage_lru.c
index e14782e56..5e046e794 100644
--- a/bin/varnishd/storage/storage_lru.c
+++ b/bin/varnishd/storage/storage_lru.c
@@ -204,7 +204,7 @@ LRU_NukeOne(struct worker *wrk, struct lru *lru)
 	/* XXX: We could grab and return one storage segment to our caller */
 	ObjSlim(wrk, oc);
 
-	VSLb(wrk->vsl, SLT_ExpKill, "LRU x=%u", ObjGetXID(wrk, oc));
+	VSLb(wrk->vsl, SLT_ExpKill, "LRU xid=%ju", VXID(ObjGetXID(wrk, oc)));
 	(void)HSH_DerefObjCore(wrk, &oc, 0);	// Ref from HSH_Snipe
 	return (1);
 }
diff --git a/bin/varnishtest/tests/p00000.vtc b/bin/varnishtest/tests/p00000.vtc
index ea803b524..874adcd96 100644
--- a/bin/varnishtest/tests/p00000.vtc
+++ b/bin/varnishtest/tests/p00000.vtc
@@ -13,7 +13,7 @@ process p1 -wait
 
 server s1 {
 	rxreq
-	txresp
+	txresp -body FOO
 	accept
 	rxreq
 	txresp -status 700
diff --git a/bin/varnishtest/tests/r01140.vtc b/bin/varnishtest/tests/r01140.vtc
index 1c9bd4973..2c61bff60 100644
--- a/bin/varnishtest/tests/r01140.vtc
+++ b/bin/varnishtest/tests/r01140.vtc
@@ -4,7 +4,7 @@ server s1 {
 	# This response should almost completely fill the storage
 	rxreq
 	expect req.url == /url1
-	txresp -bodylen 1048408
+	txresp -bodylen 1048400
 
 	# The next one should not fit in the storage, ending up in transient
 	# with zero ttl (=shortlived)
@@ -31,7 +31,7 @@ client c1 {
 	txreq -url /url1
 	rxresp
 	expect resp.status == 200
-	expect resp.bodylen == 1048408
+	expect resp.bodylen == 1048400
 } -run
 
 delay .1
diff --git a/bin/varnishtest/tests/r02339.vtc b/bin/varnishtest/tests/r02339.vtc
index 11f84fb27..d4d06e859 100644
--- a/bin/varnishtest/tests/r02339.vtc
+++ b/bin/varnishtest/tests/r02339.vtc
@@ -55,7 +55,7 @@ varnish v1 -vcl+backend {
 varnish v1 -cliok "param.set timeout_idle 2"
 
 logexpect l0 -v v1 -g raw {
-	expect * 0 ExpKill	"EXP_Expired x=1002"
+	expect * 0 ExpKill	"EXP_Expired xid=1002"
 } -start
 
 logexpect l2 -v v1 -g raw {
diff --git a/bin/varnishtest/tests/t02022.vtc b/bin/varnishtest/tests/t02022.vtc
index a646893be..e4cc543d1 100644
--- a/bin/varnishtest/tests/t02022.vtc
+++ b/bin/varnishtest/tests/t02022.vtc
@@ -72,7 +72,7 @@ varnish v1 -expect SM?.rxbuf.g_bytes >= 1048000
 varnish v1 -expect MAIN.n_lru_nuked == 0
 
 logexpect l1 -v v1 -g raw -q "Expkill ~ LRU" {
-	expect * * Expkill x=1005
+	expect * * Expkill xid=1005
 } -start
 
 client c3 {
diff --git a/bin/varnishtest/tests/v00064.vtc b/bin/varnishtest/tests/v00064.vtc
index 19544d686..63568bd62 100644
--- a/bin/varnishtest/tests/v00064.vtc
+++ b/bin/varnishtest/tests/v00064.vtc
@@ -7,7 +7,7 @@ server s1 {
 
     rxreq
     expect req.url == "/malloc"
-    txresp -hdr "Cache-Control: max-age=2" -hdr "Last-Modified: Fri, 03 Apr 2020 13:00:01 GMT" -bodylen 1048300
+    txresp -hdr "Cache-Control: max-age=2" -hdr "Last-Modified: Fri, 03 Apr 2020 13:00:01 GMT" -bodylen 1048292
 
     rxreq
     expect req.http.If-Modified-Since == "Fri, 03 Apr 2020 13:00:01 GMT"
diff --git a/include/tbl/obj_attr.h b/include/tbl/obj_attr.h
index 65c3ac0cc..f9441b17a 100644
--- a/include/tbl/obj_attr.h
+++ b/include/tbl/obj_attr.h
@@ -33,11 +33,11 @@
 
 /* upper, lower, size */
 #ifdef OBJ_FIXATTR
-  OBJ_FIXATTR(LEN, len, 8)
-  OBJ_FIXATTR(VXID, vxid, 4)
+  OBJ_FIXATTR(LEN, len, sizeof(uint64_t))
+  OBJ_FIXATTR(VXID, vxid, sizeof(uint64_t))
   OBJ_FIXATTR(FLAGS, flags, 1)
   OBJ_FIXATTR(GZIPBITS, gzipbits, 32)
-  OBJ_FIXATTR(LASTMODIFIED, lastmodified, 8)
+  OBJ_FIXATTR(LASTMODIFIED, lastmodified, sizeof(double))
   #undef OBJ_FIXATTR
 #endif
 
diff --git a/vmod/tests/purge_c00000.vtc b/vmod/tests/purge_c00000.vtc
index 267f4b882..8cf199a12 100644
--- a/vmod/tests/purge_c00000.vtc
+++ b/vmod/tests/purge_c00000.vtc
@@ -68,7 +68,7 @@ logexpect l2 -v v1 -q "Begin ~ bgfetch" {
 } -start
 
 logexpect l3 -v v1 -g raw -q "vxid == 0" {
-	expect * * ExpKill x=1008
+	expect * * ExpKill xid=1008
 } -start
 
 client c1 {


More information about the varnish-commit mailing list