[6.2] c6df6a5fa Add WS_ReserveAll() to replace WS_Reserve(ws, 0)
Martin Blix Grydeland
martin at varnish-software.com
Tue Feb 4 10:03:07 UTC 2020
commit c6df6a5fa9e5575b079d602895eb429db417c5cd
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Mon Apr 8 15:19:30 2019 +0200
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 d001cdd2045aa484a968d09859cddf59dee372cb)
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 163c52948..cc2fc993d 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -765,6 +765,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);
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index f43e214ff..1395f7101 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -650,7 +650,7 @@ HSH_Purge(struct worker *wrk, struct objhead *oh, vtim_real ttl_now,
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
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 63d25799b..f77fcf30c 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -394,7 +394,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]);
@@ -1228,7 +1228,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);
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index 259110d7b..eac4773fc 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -203,7 +203,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) {
diff --git a/bin/varnishd/cache/cache_vary.c b/bin/varnishd/cache/cache_vary.c
index 46d6930fb..4af92f69c 100644
--- a/bin/varnishd/cache/cache_vary.c
+++ b/bin/varnishd/cache/cache_vary.c
@@ -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);
}
diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 2edfb85b6..bf1676653 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -261,7 +261,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;
@@ -385,7 +385,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') {
@@ -573,7 +573,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);
diff --git a/bin/varnishd/cache/cache_vrt_filter.c b/bin/varnishd/cache/cache_vrt_filter.c
index 271be6ccd..f192c3a7a 100644
--- a/bin/varnishd/cache/cache_vrt_filter.c
+++ b/bin/varnishd/cache/cache_vrt_filter.c
@@ -251,7 +251,7 @@ filter_on_ws(struct ws *ws, filter_list_t *func, void *arg)
AN(func);
AN(arg);
- u = WS_Reserve(ws, 0);
+ u = WS_ReserveAll(ws);
if (u == 0) {
WS_Release(ws, 0);
WS_MarkOverflow(ws);
diff --git a/bin/varnishd/cache/cache_vrt_re.c b/bin/varnishd/cache/cache_vrt_re.c
index 9cd0de3e7..ad1f44de8 100644
--- a/bin/varnishd/cache/cache_vrt_re.c
+++ b/bin/varnishd/cache/cache_vrt_re.c
@@ -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;
diff --git a/bin/varnishd/cache/cache_ws.c b/bin/varnishd/cache/cache_ws.c
index 3ec5ec017..e0a9b1d48 100644
--- a/bin/varnishd/cache/cache_ws.c
+++ b/bin/varnishd/cache/cache_ws.c
@@ -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
diff --git a/bin/varnishd/http2/cache_http2_deliver.c b/bin/varnishd/http2/cache_http2_deliver.c
index 7ee71ac99..26e4cc5da 100644
--- a/bin/varnishd/http2/cache_http2_deliver.c
+++ b/bin/varnishd/http2/cache_http2_deliver.c
@@ -225,9 +225,11 @@ h2_build_headers(struct vsb *resp, struct req *req)
uint8_t buf[6];
ssize_t sz, sz1;
- l = WS_Reserve(req->ws, 0);
- if (l < 10)
+ l = WS_ReserveAll(req->ws);
+ if (l < 10) {
+ WS_Release(req->ws, 0);
return (-1);
+ }
AN(VSB_new(resp, req->ws->f, l, VSB_FIXEDLEN));
diff --git a/bin/varnishd/http2/cache_http2_hpack.c b/bin/varnishd/http2/cache_http2_hpack.c
index 0524f3e32..d55c37614 100644
--- a/bin/varnishd/http2/cache_http2_hpack.c
+++ b/bin/varnishd/http2/cache_http2_hpack.c
@@ -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);
assert(d->out_l > 0); /* Can't do any work without any buffer
space. Require non-zero size. */
d->out = h2->new_req->http->ws->f;
diff --git a/lib/libvmod_blob/vmod_blob.c b/lib/libvmod_blob/vmod_blob.c
index 7820e810c..5fe6be553 100644
--- a/lib/libvmod_blob/vmod_blob.c
+++ b/lib/libvmod_blob/vmod_blob.c
@@ -339,7 +339,7 @@ vmod_decode(VRT_CTX, VCL_ENUM decs, VCL_INT length, VCL_STRANDS strings)
CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);
buf = WS_Front(ctx->ws);
- space = WS_Reserve(ctx->ws, 0);
+ space = WS_ReserveAll(ctx->ws);
if (length <= 0)
length = -1;
@@ -378,7 +378,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->blob, b->len);
diff --git a/lib/libvmod_std/vmod_std.c b/lib/libvmod_std/vmod_std.c
index d35d89f6c..11e5f8667 100644
--- a/lib/libvmod_std/vmod_std.c
+++ b/lib/libvmod_std/vmod_std.c
@@ -72,7 +72,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;
diff --git a/lib/libvmod_vtc/vmod_vtc.c b/lib/libvmod_vtc/vmod_vtc.c
index 72320ba94..ee9d23fa0 100644
--- a/lib/libvmod_vtc/vmod_vtc.c
+++ b/lib/libvmod_vtc/vmod_vtc.c
@@ -155,7 +155,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) {
@@ -182,7 +182,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);
}
More information about the varnish-commit
mailing list