[master] d1d7333 Make it possible to pass a pointer to the new value to ObjSetattr()
Poul-Henning Kamp
phk at FreeBSD.org
Tue Aug 19 08:58:28 CEST 2014
commit d1d73339f3fb1f5b44156911fda428eec8a10e86
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Aug 19 06:58:04 2014 +0000
Make it possible to pass a pointer to the new value to ObjSetattr()
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 66a21d5..cdfbcee 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -1067,7 +1067,8 @@ void ObjSlim(struct objcore *oc, struct dstat *ds);
struct lru *ObjGetLRU(const struct objcore *);
void *ObjGetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr,
ssize_t *len);
-void *ObjSetattr(const struct vfp_ctx *, enum obj_attr attr, ssize_t len);
+void *ObjSetattr(const struct vfp_ctx *, enum obj_attr attr, ssize_t len,
+ const void *);
int ObjCopyAttr(const struct vfp_ctx *, struct objcore *, enum obj_attr attr);
int ObjSetDouble(const struct vfp_ctx*, enum obj_attr, double);
diff --git a/bin/varnishd/cache/cache_esi_fetch.c b/bin/varnishd/cache/cache_esi_fetch.c
index 1608eff..db6da83 100644
--- a/bin/varnishd/cache/cache_esi_fetch.c
+++ b/bin/varnishd/cache/cache_esi_fetch.c
@@ -118,12 +118,10 @@ vfp_esi_end(struct vfp_ctx *vc, struct vef_priv *vef,
if (retval == VFP_END) {
l = VSB_len(vsb);
assert(l > 0);
- p = ObjSetattr(vc, OA_ESIDATA, l);
+ p = ObjSetattr(vc, OA_ESIDATA, l, VSB_data(vsb));
if (p == NULL) {
retval = VFP_Error(vc,
"Could not allocate storage for esidata");
- } else {
- memcpy(p, VSB_data(vsb), l);
}
}
VSB_delete(vsb);
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index b3adfa1..2c08ccd 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -139,8 +139,7 @@ vbf_beresp2obj(struct busyobj *bo)
CHECK_OBJ_NOTNULL(obj, OBJECT_MAGIC);
if (vary != NULL) {
- b = ObjSetattr(bo->vfc, OA_VARY, varyl);
- memcpy(b, VSB_data(vary), varyl);
+ b = ObjSetattr(bo->vfc, OA_VARY, varyl, VSB_data(vary));
(void)VRY_Validate(obj->oa_vary);
VSB_delete(vary);
}
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index 8cafe6b..96406ee 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -396,7 +396,7 @@ VGZ_UpdateObj(const struct vfp_ctx *vc, const struct vgz *vg)
char *p;
CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC);
- p = ObjSetattr(vc, OA_GZIPBITS, 24);
+ p = ObjSetattr(vc, OA_GZIPBITS, 24, NULL);
AN(p);
vbe64enc(p, vg->vz.start_bit);
vbe64enc(p + 8, vg->vz.last_bit);
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index d7312e3..93cba08 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -290,10 +290,11 @@ ObjGetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr,
}
void *
-ObjSetattr(const struct vfp_ctx *vc, enum obj_attr attr,
- ssize_t len)
+ObjSetattr(const struct vfp_ctx *vc, enum obj_attr attr, ssize_t len,
+ const void *ptr)
{
struct object *o;
+ void *retval = NULL;
CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC);
CHECK_OBJ_NOTNULL(vc->bo, BUSYOBJ_MAGIC);
@@ -306,27 +307,36 @@ ObjSetattr(const struct vfp_ctx *vc, enum obj_attr attr,
if (o->esidata == NULL)
return (NULL);
o->esidata->len = len;
- return (o->esidata->ptr);
+ retval = o->esidata->ptr;
+ break;
case OA_FLAGS:
assert(len == sizeof o->oa_flags);
- return (o->oa_flags);
+ retval = o->oa_flags;
+ break;
case OA_GZIPBITS:
assert(len == sizeof o->oa_gzipbits);
- return (o->oa_gzipbits);
+ retval = o->oa_gzipbits;
+ break;
case OA_LASTMODIFIED:
assert(len == sizeof o->oa_lastmodified);
- return (o->oa_lastmodified);
+ retval = o->oa_lastmodified;
+ break;
case OA_VARY:
o->oa_vary = (void*)WS_Alloc(vc->bo->ws_o, len);
AN(o->oa_vary);
- return (o->oa_vary);
+ retval = o->oa_vary;
+ break;
case OA_VXID:
assert(len == sizeof o->oa_vxid);
- return (o->oa_vxid);
+ retval = o->oa_vxid;
+ break;
default:
+ WRONG("Unsupported OBJ_ATTR");
break;
}
- WRONG("Unsupported OBJ_ATTR");
+ if (ptr != NULL)
+ memcpy(retval, ptr, len);
+ return (retval);
}
int
@@ -341,10 +351,9 @@ ObjCopyAttr(const struct vfp_ctx *vc, struct objcore *ocs, enum obj_attr attr)
// XXX: later we want to have zero-length OA's too
if (vps == NULL || l <= 0)
return (-1);
- vpd = ObjSetattr(vc, attr, l);
+ vpd = ObjSetattr(vc, attr, l, vps);
if (vpd == NULL)
return (-1);
- memcpy(vpd, vps, l);
return (0);
}
@@ -383,7 +392,7 @@ ObjSetDouble(const struct vfp_ctx *vc, enum obj_attr a, double t)
assert(sizeof t == sizeof u);
memcpy(&u, &t, sizeof u);
- vp = ObjSetattr(vc, a, sizeof u);
+ vp = ObjSetattr(vc, a, sizeof u, NULL);
if (vp == NULL)
return (-1);
vbe64enc(vp, u);
@@ -417,7 +426,7 @@ ObjSetU64(const struct vfp_ctx *vc, enum obj_attr a, uint64_t t)
{
void *vp;
- vp = ObjSetattr(vc, a, sizeof t);
+ vp = ObjSetattr(vc, a, sizeof t, NULL);
if (vp == NULL)
return (-1);
vbe64enc(vp, t);
@@ -443,7 +452,7 @@ ObjSetU32(const struct vfp_ctx *vc, enum obj_attr a, uint32_t t)
{
void *vp;
- vp = ObjSetattr(vc, a, sizeof t);
+ vp = ObjSetattr(vc, a, sizeof t, NULL);
if (vp == NULL)
return (-1);
vbe32enc(vp, t);
@@ -482,7 +491,7 @@ ObjSetFlag(const struct vfp_ctx *vc, enum obj_flags of, int val)
{
uint8_t *fp;
- fp = ObjSetattr(vc, OA_FLAGS, 1);
+ fp = ObjSetattr(vc, OA_FLAGS, 1, NULL);
AN(fp);
if (val)
(*fp) |= of;
More information about the varnish-commit
mailing list