[master] 24303d3 Make obj->last_modified an object_attribute
Poul-Henning Kamp
phk at FreeBSD.org
Wed Jul 30 14:44:39 CEST 2014
commit 24303d3adaf38a17541f6cd502e003b896db3ba8
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Jul 30 12:44:19 2014 +0000
Make obj->last_modified an object_attribute
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 6674100..f21c57d 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -569,7 +569,7 @@ struct object {
ssize_t len;
/* VCL only variables */
- double last_modified;
+ char oa_lastmodified[8];
struct http *http;
@@ -1063,6 +1063,8 @@ 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);
/* cache_panic.c */
void PAN_Init(void);
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 44bd58e..1e45392 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -165,9 +165,11 @@ vbf_beresp2obj(struct busyobj *bo)
http_CopyHome(hp2);
if (http_GetHdr(hp, H_Last_Modified, &b))
- obj->last_modified = VTIM_parse(b);
+ AZ(ObjSetLastModified(bo->fetch_objcore, bo->stats,
+ VTIM_parse(b)));
else
- obj->last_modified = floor(bo->fetch_objcore->exp.t_origin);
+ AZ(ObjSetLastModified(bo->fetch_objcore, bo->stats,
+ floor(bo->fetch_objcore->exp.t_origin)));
/* Disassociate the obj from the bo's workspace */
hp2->ws = NULL;
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index 5ad3e4c..b5a0faa 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -229,6 +229,9 @@ ObjGetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr,
case OA_VXID:
*len = sizeof o->oa_vxid;
return (o->oa_vxid);
+ case OA_LASTMODIFIED:
+ *len = sizeof o->oa_lastmodified;
+ return (o->oa_lastmodified);
case OA_GZIPBITS:
*len = sizeof o->oa_gzipbits;
return (o->oa_gzipbits);
@@ -259,6 +262,9 @@ ObjSetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr,
case OA_GZIPBITS:
assert(len == sizeof o->oa_gzipbits);
return (o->oa_gzipbits);
+ case OA_LASTMODIFIED:
+ assert(len == sizeof o->oa_lastmodified);
+ return (o->oa_lastmodified);
default:
break;
}
@@ -294,3 +300,38 @@ ObjGetXID(struct objcore *oc, struct dstat *ds)
assert(l == 4);
return (vbe32dec(p));
}
+
+/*--------------------------------------------------------------------
+ * NB: Copying double <--> uint64_t for endian encoding is unverified
+ */
+
+int
+ObjSetLastModified(struct objcore *oc, struct dstat *ds, 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);
+ if (vp == NULL)
+ return (-1);
+ vbe64enc(vp, u);
+ return (0);
+}
+
+double
+ObjGetLastModified(struct objcore *oc, struct dstat *ds)
+{
+ 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);
+}
diff --git a/bin/varnishd/cache/cache_rfc2616.c b/bin/varnishd/cache/cache_rfc2616.c
index a58f282..1c26641 100644
--- a/bin/varnishd/cache/cache_rfc2616.c
+++ b/bin/varnishd/cache/cache_rfc2616.c
@@ -345,19 +345,18 @@ int
RFC2616_Do_Cond(const struct req *req)
{
char *p, *e;
- double ims;
+ double ims, lm;
int do_cond = 0;
/* RFC 2616 13.3.4 states we need to match both ETag
and If-Modified-Since if present*/
if (http_GetHdr(req->http, H_If_Modified_Since, &p) ) {
- if (!req->obj->last_modified)
- return (0);
ims = VTIM_parse(p);
if (ims > req->t_req) /* [RFC2616 14.25] */
return (0);
- if (req->obj->last_modified > ims)
+ lm = ObjGetLastModified(req->obj->objcore, &req->wrk->stats);
+ if (lm > ims)
return (0);
do_cond = 1;
}
diff --git a/include/tbl/obj_attr.h b/include/tbl/obj_attr.h
index c1f2d10..860fc5c 100644
--- a/include/tbl/obj_attr.h
+++ b/include/tbl/obj_attr.h
@@ -34,9 +34,9 @@ OBJ_ATTR(VXID, vxid)
OBJ_ATTR(EXP, exp)
OBJ_ATTR(VARY, vary)
OBJ_ATTR(HEADERS, headers)
-OBJ_ATTR(GZIPED, gziped)
-OBJ_ATTR(CHGGZIPED, chggziped)
+OBJ_ATTR(GZIPFLAGS, gzipflags)
OBJ_ATTR(GZIPBITS, gzipbits)
OBJ_ATTR(ESIDATA, esidata)
+OBJ_ATTR(LASTMODIFIED, lastmodified)
/*lint -restore */
More information about the varnish-commit
mailing list