[master] dd7083a Make generic functions for OA's in double format.
Poul-Henning Kamp
phk at FreeBSD.org
Wed Aug 6 10:49:23 CEST 2014
commit dd7083a2d192122d688c544506d0d1a23032d7d6
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Aug 6 08:49:02 2014 +0000
Make generic functions for OA's in double format.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 6c5251b..30bee0e 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -1065,8 +1065,9 @@ void *ObjSetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr,
ssize_t len);
int ObjCopyAttr(struct objcore *ocd, struct objcore *ocs, struct dstat *ds,
enum obj_attr attr);
-int ObjSetLastModified(struct objcore *oc, struct dstat *ds, double t);
-double ObjGetLastModified(struct objcore *oc, struct dstat *ds);
+
+int ObjSetDouble(struct objcore *, struct dstat *, enum obj_attr, double);
+int ObjGetDouble(struct objcore *, struct dstat *, enum obj_attr, double *);
/* cache_panic.c */
void PAN_Init(void);
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 70f467a..12faa3c 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -165,10 +165,10 @@ vbf_beresp2obj(struct busyobj *bo)
http_CopyHome(hp2);
if (http_GetHdr(hp, H_Last_Modified, &b))
- AZ(ObjSetLastModified(bo->fetch_objcore, bo->stats,
+ AZ(ObjSetDouble(bo->fetch_objcore, bo->stats, OA_LASTMODIFIED,
VTIM_parse(b)));
else
- AZ(ObjSetLastModified(bo->fetch_objcore, bo->stats,
+ AZ(ObjSetDouble(bo->fetch_objcore, bo->stats, OA_LASTMODIFIED,
floor(bo->fetch_objcore->exp.t_origin)));
/* Disassociate the obj from the bo's workspace */
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index 495599a..f43893d 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -307,36 +307,43 @@ ObjGetXID(struct objcore *oc, struct dstat *ds)
}
/*--------------------------------------------------------------------
- * NB: Copying double <--> uint64_t for endian encoding is unverified
+ * There is no well-defined byteorder for IEEE-754 double and the
+ * correct solution (frexp(3) and manual encoding) is more work
+ * than our (weak) goal of being endian-agnostic requires at this point.
+ * We give it a shot by memcpy'ing doubles over a uint64_t and then
+ * BE encode that.
*/
int
-ObjSetLastModified(struct objcore *oc, struct dstat *ds, double t)
+ObjSetDouble(struct objcore *oc, struct dstat *ds, enum obj_attr a, double t)
{
void *vp;
uint64_t u;
assert(sizeof t == sizeof u);
memcpy(&u, &t, sizeof u);
- vp = ObjSetattr(oc, ds, OA_LASTMODIFIED, sizeof u);
+ vp = ObjSetattr(oc, ds, a, sizeof u);
if (vp == NULL)
return (-1);
vbe64enc(vp, u);
return (0);
}
-double
-ObjGetLastModified(struct objcore *oc, struct dstat *ds)
+int
+ObjGetDouble(struct objcore *oc, struct dstat *ds, enum obj_attr a, double *d)
{
void *vp;
uint64_t u;
- double d;
ssize_t l;
- vp = ObjGetattr(oc, ds, OA_LASTMODIFIED, &l);
- AN(vp);
- assert(l == sizeof u);
- u = vbe64dec(vp);
- memcpy(&d, &u, sizeof d);
- return (d);
+ assert(sizeof *d == sizeof u);
+ vp = ObjGetattr(oc, ds, a, &l);
+ if (vp == NULL)
+ return (-1);
+ if (d != NULL) {
+ assert(l == sizeof u);
+ u = vbe64dec(vp);
+ memcpy(d, &u, sizeof *d);
+ }
+ return (0);
}
diff --git a/bin/varnishd/cache/cache_rfc2616.c b/bin/varnishd/cache/cache_rfc2616.c
index ab5edd7..6dc75ef 100644
--- a/bin/varnishd/cache/cache_rfc2616.c
+++ b/bin/varnishd/cache/cache_rfc2616.c
@@ -355,7 +355,8 @@ RFC2616_Do_Cond(const struct req *req)
ims = VTIM_parse(p);
if (ims > req->t_req) /* [RFC2616 14.25] */
return (0);
- lm = ObjGetLastModified(req->objcore, &req->wrk->stats);
+ AZ(ObjGetDouble(req->objcore, &req->wrk->stats,
+ OA_LASTMODIFIED, &lm));
if (lm > ims)
return (0);
do_cond = 1;
More information about the varnish-commit
mailing list