[master] 6ce5b1e Add generic uint{32, 64} OA_ accessor functions, use for VXID.

Poul-Henning Kamp phk at FreeBSD.org
Wed Aug 6 11:10:38 CEST 2014


commit 6ce5b1ef31a622c78283b9b6960cfe38ca90f899
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Aug 6 09:10:11 2014 +0000

    Add generic uint{32,64} OA_ accessor functions, use for VXID.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 30bee0e..856d5cd 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -1068,6 +1068,10 @@ int ObjCopyAttr(struct objcore *ocd, struct objcore *ocs, struct dstat *ds,
 
 int ObjSetDouble(struct objcore *, struct dstat *, enum obj_attr, double);
 int ObjGetDouble(struct objcore *, struct dstat *, enum obj_attr, double *);
+int ObjSetU32(struct objcore *, struct dstat *, enum obj_attr, uint32_t);
+int ObjGetU32(struct objcore *, struct dstat *, enum obj_attr, uint32_t *);
+int ObjSetU64(struct objcore *, struct dstat *, enum obj_attr, uint64_t);
+int ObjGetU64(struct objcore *, struct dstat *, enum obj_attr, uint64_t *);
 
 /* cache_panic.c */
 void PAN_Init(void);
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 12faa3c..5b66145 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -102,7 +102,6 @@ vbf_beresp2obj(struct busyobj *bo)
 	uint16_t nhttp;
 	struct object *obj;
 	struct http *hp, *hp2;
-	void *vp;
 
 	l = 0;
 
@@ -152,8 +151,7 @@ vbf_beresp2obj(struct busyobj *bo)
 		VSB_delete(vary);
 	}
 
-	vp = ObjSetattr(bo->fetch_objcore, bo->stats, OA_VXID, 4);
-	vbe32enc(vp, bo->vsl->wid);
+	AZ(ObjSetU32(bo->fetch_objcore, bo->stats, OA_VXID, 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 f43893d..d5b7390 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -297,13 +297,10 @@ ObjCopyAttr(struct objcore *ocd, struct objcore *ocs, struct dstat *ds,
 unsigned
 ObjGetXID(struct objcore *oc, struct dstat *ds)
 {
-	ssize_t l;
-	void *p;
+	uint32_t u;
 
-	p = ObjGetattr(oc, ds, OA_VXID, &l);
-	AN(p);
-	assert(l == 4);
-	return (vbe32dec(p));
+	AZ(ObjGetU32(oc, ds, OA_VXID, &u));
+	return (u);
 }
 
 /*--------------------------------------------------------------------
@@ -347,3 +344,58 @@ ObjGetDouble(struct objcore *oc, struct dstat *ds, enum obj_attr a, double *d)
 	}
 	return (0);
 }
+
+/*--------------------------------------------------------------------
+ */
+
+int
+ObjSetU64(struct objcore *oc, struct dstat *ds, enum obj_attr a, uint64_t t)
+{
+	void *vp;
+
+	vp = ObjSetattr(oc, ds, a, sizeof t);
+	if (vp == NULL)
+		return (-1);
+	vbe64enc(vp, t);
+	return (0);
+}
+
+int
+ObjGetU64(struct objcore *oc, struct dstat *ds, enum obj_attr a, uint64_t *d)
+{
+	void *vp;
+	ssize_t l;
+
+	vp = ObjGetattr(oc, ds, a, &l);
+	if (vp == NULL || l != sizeof *d)
+		return (-1);
+	if (d != NULL)
+		*d = vbe64dec(vp);
+	return (0);
+}
+
+int
+ObjSetU32(struct objcore *oc, struct dstat *ds, enum obj_attr a, uint32_t t)
+{
+	void *vp;
+
+	vp = ObjSetattr(oc, ds, a, sizeof t);
+	if (vp == NULL)
+		return (-1);
+	vbe32enc(vp, t);
+	return (0);
+}
+
+int
+ObjGetU32(struct objcore *oc, struct dstat *ds, enum obj_attr a, uint32_t *d)
+{
+	void *vp;
+	ssize_t l;
+
+	vp = ObjGetattr(oc, ds, a, &l);
+	if (vp == NULL || l != sizeof *d)
+		return (-1);
+	if (d != NULL)
+		*d = vbe32dec(vp);
+	return (0);
+}



More information about the varnish-commit mailing list