Commit be938d34 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Wrap obj->len in an accessor function

parent 4d5a73ba
......@@ -1059,6 +1059,7 @@ enum objiter_status ObjIter(struct objiter *, void **, ssize_t *);
void ObjIterEnd(struct objiter **);
void ObjTrimStore(struct objcore *, struct dstat *);
unsigned ObjGetXID(struct objcore *, struct dstat *);
uint64_t ObjGetLen(struct objcore *oc, struct dstat *ds);
struct object *ObjGetObj(struct objcore *, struct dstat *);
void ObjUpdateMeta(struct objcore *);
void ObjFreeObj(struct objcore *, struct dstat *);
......
......@@ -505,6 +505,7 @@ ESI_DeliverChild(struct req *req)
u_char cc;
uint32_t icrc;
uint32_t ilen;
uint64_t olen;
uint8_t *dbits;
int i, j;
uint8_t tailbuf[8];
......@@ -534,9 +535,10 @@ ESI_DeliverChild(struct req *req)
start = vbe64dec(p);
last = vbe64dec(p + 8);
stop = vbe64dec(p + 16);
assert(start > 0 && start < obj->len * 8);
assert(last > 0 && last < obj->len * 8);
assert(stop > 0 && stop < obj->len * 8);
olen = ObjGetLen(obj->objcore, &req->wrk->stats);
assert(start > 0 && start < olen * 8);
assert(last > 0 && last < olen * 8);
assert(stop > 0 && stop < olen * 8);
assert(last >= start);
assert(last < stop);
......
......@@ -559,6 +559,7 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
struct objiter *oi;
void *sp;
ssize_t sl, al, tl;
uint64_t ol;
struct storage *st;
enum objiter_status ois;
char *p;
......@@ -606,13 +607,13 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
st = NULL;
al = 0;
ol = ObjGetLen(bo->ims_oc, bo->stats);
oi = ObjIterBegin(wrk, bo->ims_obj);
do {
ois = ObjIter(oi, &sp, &sl);
while (sl > 0) {
if (st == NULL)
st = VFP_GetStorage(bo->vfc,
bo->ims_obj->len - al);
st = VFP_GetStorage(bo->vfc, ol - al);
if (st == NULL)
break;
tl = sl;
......@@ -634,8 +635,8 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
if (!bo->do_stream)
HSH_Unbusy(&wrk->stats, obj->objcore);
assert(al == bo->ims_obj->len);
assert(obj->len == al);
assert(al == ol);
assert(ObjGetLen(bo->fetch_objcore, bo->stats) == al);
EXP_Rearm(bo->ims_oc, bo->ims_oc->exp.t_origin, 0, 0, 0);
/* Recycle the backend connection before setting BOS_FINISHED to
......@@ -802,8 +803,6 @@ vbf_fetch_thread(struct worker *wrk, void *priv)
}
assert(WRW_IsReleased(wrk));
bo->stats = NULL;
if (bo->vbc != NULL) {
if (bo->doclose != SC_NULL)
VDI_CloseFd(&bo->vbc, &bo->acct);
......@@ -818,22 +817,8 @@ vbf_fetch_thread(struct worker *wrk, void *priv)
if (bo->state == BOS_FINISHED) {
AZ(bo->fetch_objcore->flags & OC_F_FAILED);
HSH_Complete(bo->fetch_objcore);
VSLb(bo->vsl, SLT_Length, "%zd", bo->fetch_obj->len);
{
/* Sanity check fetch methods accounting */
ssize_t uu;
struct storage *st;
uu = 0;
VTAILQ_FOREACH(st, &bo->fetch_obj->body->list, list)
uu += st->len;
if (bo->do_stream)
/* Streaming might have started freeing stuff */
assert(uu <= bo->fetch_obj->len);
else
assert(uu == bo->fetch_obj->len);
}
VSLb(bo->vsl, SLT_Length, "%zd",
ObjGetLen(bo->fetch_objcore, bo->stats));
}
AZ(bo->fetch_objcore->busyobj);
......@@ -842,6 +827,8 @@ vbf_fetch_thread(struct worker *wrk, void *priv)
bo->ims_obj = NULL;
}
bo->stats = NULL;
VBO_DerefBusyObj(wrk, &bo);
THR_SetBusyobj(NULL);
}
......
......@@ -99,7 +99,7 @@ v1d_dorange(struct req *req, struct busyobj *bo, const char *r)
if (bo != NULL)
len = VBO_waitlen(bo, -1);
else
len = req->obj->len;
len = ObjGetLen(req->objcore, &req->wrk->stats);
if (strncmp(r, "bytes=", 6))
return;
......@@ -252,10 +252,11 @@ V1D_Deliver(struct req *req, struct busyobj *bo)
/* XXX: Not happy with this convoluted test */
req->res_mode |= RES_LEN;
if (!(req->objcore->flags & OC_F_PASS) ||
req->obj->len != 0) {
ObjGetLen(req->objcore, &req->wrk->stats) != 0) {
http_Unset(req->resp, H_Content_Length);
http_PrintfHeader(req->resp,
"Content-Length: %zd", req->obj->len);
"Content-Length: %ju", (uintmax_t)ObjGetLen(
req->objcore, &req->wrk->stats));
}
}
......
......@@ -303,6 +303,16 @@ ObjGetXID(struct objcore *oc, struct dstat *ds)
return (u);
}
uint64_t
ObjGetLen(struct objcore *oc, struct dstat *ds)
{
struct object *o;
o = ObjGetObj(oc, ds);
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
return (o->len);
}
/*--------------------------------------------------------------------
* There is no well-defined byteorder for IEEE-754 double and the
* correct solution (frexp(3) and manual encoding) is more work
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment