Commit 2081eeb6 authored by Nils Goroll's avatar Nils Goroll Committed by Martin Blix Grydeland

Add WS_ReserveAll() to replace WS_Reserve(ws, 0)

... to un-confuse the interface

Notes on changes from WS_Reserve():

* Removed the first WS_Assert because all we change is ws->r and we got
  a specific assert on it.

* it follows from PAOK(ws->e) && PAOK(ws->f) in WS_Assert() that
  PAOK(ws->r) && PAOK(b), so we remove the PRNDDN()

Ref: varnishcache/varnish-cache#2967

(cherry picked from commit d001cdd2)
parent 183e032e
......@@ -762,6 +762,7 @@ void WRK_BgThread(pthread_t *thr, const char *name, bgthread_t *func,
void WS_Init(struct ws *ws, const char *id, void *space, unsigned len);
unsigned WS_Reserve(struct ws *ws, unsigned bytes);
unsigned WS_ReserveAll(struct ws *);
unsigned WS_ReserveLumps(struct ws *ws, size_t sz);
void WS_MarkOverflow(struct ws *ws);
void WS_Release(struct ws *ws, unsigned bytes);
......
......@@ -626,7 +626,7 @@ double grace, double keep)
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
ospc = WS_Reserve(wrk->aws, 0);
ospc = WS_ReserveAll(wrk->aws);
assert(ospc >= sizeof *ocp);
/*
* Because of "soft" purges, there might be oc's in the list that has
......
......@@ -374,7 +374,7 @@ http_CollectHdrSep(struct http *hp, const char *hdr, const char *sep)
}
if (b == NULL) {
/* Found second header, start our collection */
ml = WS_Reserve(hp->ws, 0);
ml = WS_ReserveAll(hp->ws);
b = hp->ws->f;
e = b + ml;
x = Tlen(hp->hd[f]);
......@@ -1208,7 +1208,7 @@ http_PrintfHeader(struct http *to, const char *fmt, ...)
unsigned l, n;
CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
l = WS_Reserve(to->ws, 0);
l = WS_ReserveAll(to->ws);
va_start(ap, fmt);
n = vsnprintf(to->ws->f, l, fmt, ap);
va_end(ap);
......
......@@ -204,7 +204,7 @@ HTC_RxInit(struct http_conn *htc, struct ws *ws)
CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
htc->ws = ws;
(void)WS_Reserve(htc->ws, 0);
(void)WS_ReserveAll(htc->ws);
htc->rxbuf_b = ws->f;
htc->rxbuf_e = ws->f;
if (htc->pipeline_b != NULL) {
......
......@@ -230,7 +230,7 @@ VRY_Prep(struct req *req)
AZ(req->vary_b);
AZ(req->vary_l);
AZ(req->vary_e);
(void)WS_Reserve(req->ws, 0);
(void)WS_ReserveAll(req->ws);
} else {
AN(req->ws->r);
}
......
......@@ -271,7 +271,7 @@ VRT_String(struct ws *ws, const char *h, const char *p, va_list ap)
unsigned u, x;
va_list aq;
u = WS_Reserve(ws, 0);
u = WS_ReserveAll(ws);
e = b = ws->f;
e += u;
......@@ -395,7 +395,7 @@ VRT_StrandsWS(struct ws *ws, const char *h, VCL_STRANDS s)
int i;
AN(s);
u = WS_Reserve(ws, 0);
u = WS_ReserveAll(ws);
for (i = 0; i < s->n; i++)
if (s->p[i] != NULL && *s->p[i] != '\0') {
......@@ -578,7 +578,7 @@ VRT_IP_string(VRT_CTX, VCL_IP ip)
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (ip == NULL)
return (NULL);
len = WS_Reserve(ctx->ws, 0);
len = WS_ReserveAll(ctx->ws);
if (len == 0) {
WS_Release(ctx->ws, 0);
return (NULL);
......
......@@ -127,7 +127,7 @@ VRT_regsub(VRT_CTX, int all, const char *str, void *re,
return(str);
}
u = WS_Reserve(ctx->ws, 0);
u = WS_ReserveAll(ctx->ws);
res_e = res_b = b0 = ctx->ws->f;
res_e += u;
......
......@@ -202,7 +202,7 @@ WS_Printf(struct ws *ws, const char *fmt, ...)
va_list ap;
char *p;
u = WS_Reserve(ws, 0);
u = WS_ReserveAll(ws);
p = ws->f;
va_start(ap, fmt);
v = vsnprintf(p, u, fmt, ap);
......@@ -227,6 +227,30 @@ WS_Snapshot(struct ws *ws)
return (ws->f == ws->s ? 0 : (uintptr_t)ws->f);
}
/*
* WS_Release() must be called in all cases
*/
unsigned
WS_ReserveAll(struct ws *ws)
{
unsigned b;
assert(ws->r == NULL);
ws->r = ws->e;
b = pdiff(ws->f, ws->r);
WS_Assert(ws);
DSL(DBG_WORKSPACE, 0, "WS_ReserveAll(%p) = %u", ws, b);
return (b);
}
/*
* bytes == 0 argument is deprecated - use WS_ReserveAll
*
* XXX rename to WS_ReserveSize and macro-wrap WS_Reserve to emit #warn ?
*/
unsigned
WS_Reserve(struct ws *ws, unsigned bytes)
{
......@@ -253,11 +277,7 @@ WS_Reserve(struct ws *ws, unsigned bytes)
unsigned
WS_ReserveLumps(struct ws *ws, size_t sz)
{
unsigned u;
u = WS_Reserve(ws, 0);
u /= sz;
return (u);
return (WS_ReserveAll(ws) / sz);
}
void
......
......@@ -229,7 +229,7 @@ h2_build_headers(struct vsb *resp, struct req *req)
uint8_t buf[6];
ssize_t sz, sz1;
l = WS_Reserve(req->ws, 0);
l = WS_ReserveAll(req->ws);
AN(VSB_new(resp, req->ws->f, l, VSB_FIXEDLEN));
if (l < 10) {
WS_Release(req->ws, 0);
......
......@@ -175,7 +175,7 @@ h2h_decode_init(const struct h2_sess *h2)
d = h2->decode;
INIT_OBJ(d, H2H_DECODE_MAGIC);
VHD_Init(d->vhd);
d->out_l = WS_Reserve(h2->new_req->http->ws, 0);
d->out_l = WS_ReserveAll(h2->new_req->http->ws);
/*
* Can't do any work without any buffer
* space. Require non-zero size.
......
......@@ -348,7 +348,7 @@ vmod_decode(VRT_CTX, VCL_ENUM decs, VCL_INT length, VCL_STRANDS strings)
}
buf = WS_Front(ctx->ws);
space = WS_Reserve(ctx->ws, 0);
space = WS_ReserveAll(ctx->ws);
if (length <= 0)
length = -1;
......@@ -389,7 +389,7 @@ encode(VRT_CTX, enum encoding enc, enum case_e kase, VCL_BLOB b)
CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);
snap = WS_Snapshot(ctx->ws);
buf = WS_Front(ctx->ws);
space = WS_Reserve(ctx->ws, 0);
space = WS_ReserveAll(ctx->ws);
len = func[enc].encode(enc, kase, buf, space, b->priv, b->len);
......
......@@ -74,7 +74,7 @@ vmod_updown(VRT_CTX, int up, const char *s, va_list ap)
const char *p;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
u = WS_Reserve(ctx->ws, 0);
u = WS_ReserveAll(ctx->ws);
e = b = ctx->ws->f;
e += u;
p = s;
......
......@@ -156,7 +156,7 @@ vmod_workspace_alloc(VRT_CTX, VCL_ENUM which, VCL_INT size)
WS_Assert(ws);
if (size < 0) {
size += WS_Reserve(ws, 0);
size += WS_ReserveAll(ws);
WS_Release(ws, 0);
}
if (size <= 0) {
......@@ -183,7 +183,7 @@ vmod_workspace_free(VRT_CTX, VCL_ENUM which)
return(-1);
WS_Assert(ws);
u = WS_Reserve(ws, 0);
u = WS_ReserveAll(ws);
WS_Release(ws, 0);
return (u);
}
......
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