[master] fe8602b42 Return Flexelint to sanity wrt. Reserved WSs.
Poul-Henning Kamp
phk at FreeBSD.org
Mon Sep 7 06:22:08 UTC 2020
commit fe8602b42d98f56379b53eed6ab55ff53984ce10
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Sep 7 06:17:36 2020 +0000
Return Flexelint to sanity wrt. Reserved WSs.
Give WS_Reservation() the same "always return non-NULL or assert"
semantics WS_Front() had because literally every single caller which
uses the ->f pointer fails to check for NULL.
Introduce a new internal WS_IsReserved() for use in the asserts
which check if a reservation is active, but which doesn't otherwise
care for the ->f pointer, and the single instance of non-WS code
which (possibly) legitimatly does variant processing depending on
the reservation state.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index bd849d621..32c4972fa 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -814,7 +814,9 @@ WS_Reservation(const struct ws *ws)
{
WS_Assert(ws);
- return (ws->r != NULL ? ws->f : NULL);
+ AN(ws->r);
+ AN(ws->f);
+ return (ws->f);
}
static inline unsigned
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 6284b9f6b..c6e4218f4 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -1127,6 +1127,6 @@ CNT_Request(struct req *req)
VRB_Free(req);
req->wrk = NULL;
}
- assert(nxt == REQ_FSM_DISEMBARK || WS_Reservation(req->ws) == NULL);
+ assert(nxt == REQ_FSM_DISEMBARK || !WS_IsReserved(req->ws));
return (nxt);
}
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index 9d98778d3..ececc96aa 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -465,6 +465,12 @@ void WRK_Init(void);
/* cache_ws.c */
void WS_Panic(const struct ws *ws, struct vsb *vsb);
+static inline int
+WS_IsReserved(const struct ws *ws)
+{
+
+ return (ws->r != NULL);
+}
void WS_Rollback(struct ws *, uintptr_t);
void *WS_AtOffset(const struct ws *ws, unsigned off, unsigned len);
diff --git a/bin/varnishd/cache/cache_ws.c b/bin/varnishd/cache/cache_ws.c
index 4e09b59ae..338eac7f8 100644
--- a/bin/varnishd/cache/cache_ws.c
+++ b/bin/varnishd/cache/cache_ws.c
@@ -411,7 +411,7 @@ WS_VSB_finish(struct vsb *vsb, struct ws *ws, size_t *szp)
WS_Assert(ws);
if (!VSB_finish(vsb)) {
p = VSB_data(vsb);
- if (p == WS_Reservation(ws)) {
+ if (p == ws->f) {
WS_Release(ws, VSB_len(vsb) + 1);
if (szp != NULL)
*szp = VSB_len(vsb);
diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c
index 3bb6345e0..9625bed21 100644
--- a/bin/varnishd/http1/cache_http1_fsm.c
+++ b/bin/varnishd/http1/cache_http1_fsm.c
@@ -84,7 +84,7 @@ http1_req(struct worker *wrk, void *arg)
THR_SetRequest(req);
req->transport = &HTTP1_transport;
- AZ(WS_Reservation(wrk->aws));
+ assert(!WS_IsReserved(wrk->aws));
HTTP1_Session(wrk, req);
AZ(wrk->v1l);
WS_Assert(wrk->aws);
@@ -319,7 +319,7 @@ HTTP1_Session(struct worker *wrk, struct req *req)
sp->t_idle + SESS_TMO(sp, timeout_idle),
NAN,
cache_param->http_req_size);
- AZ(WS_Reservation(req->htc->ws));
+ assert(!WS_IsReserved(req->htc->ws));
if (hs < HTC_S_EMPTY) {
req->acct.req_hdrbytes +=
req->htc->rxbuf_e - req->htc->rxbuf_b;
@@ -354,8 +354,8 @@ HTTP1_Session(struct worker *wrk, struct req *req)
if (H2_prism_complete(req->htc) == HTC_S_COMPLETE) {
if (!FEATURE(FEATURE_HTTP2)) {
SES_Close(req->sp, SC_REQ_HTTP20);
- AZ(WS_Reservation(req->ws));
- AZ(WS_Reservation(wrk->aws));
+ assert(!WS_IsReserved(req->ws));
+ assert(!WS_IsReserved(wrk->aws));
http1_setstate(sp, H1CLEANUP);
continue;
}
@@ -370,8 +370,8 @@ HTTP1_Session(struct worker *wrk, struct req *req)
if (i) {
assert(req->doclose > 0);
SES_Close(req->sp, req->doclose);
- AZ(WS_Reservation(req->ws));
- AZ(WS_Reservation(wrk->aws));
+ assert(!WS_IsReserved(req->ws));
+ assert(!WS_IsReserved(wrk->aws));
http1_setstate(sp, H1CLEANUP);
continue;
}
@@ -405,13 +405,13 @@ HTTP1_Session(struct worker *wrk, struct req *req)
AZ(req->top->vcl0);
req->task->func = NULL;
req->task->priv = NULL;
- AZ(WS_Reservation(req->ws));
- AZ(WS_Reservation(wrk->aws));
+ assert(!WS_IsReserved(req->ws));
+ assert(!WS_IsReserved(wrk->aws));
http1_setstate(sp, H1CLEANUP);
} else if (st == H1CLEANUP) {
- AZ(WS_Reservation(wrk->aws));
- AZ(WS_Reservation(req->ws));
+ assert(!WS_IsReserved(wrk->aws));
+ assert(!WS_IsReserved(req->ws));
if (sp->fd >= 0 && req->doclose != SC_NULL)
SES_Close(sp, req->doclose);
diff --git a/bin/varnishd/http1/cache_http1_line.c b/bin/varnishd/http1/cache_http1_line.c
index 7ff71c151..7b595ca02 100644
--- a/bin/varnishd/http1/cache_http1_line.c
+++ b/bin/varnishd/http1/cache_http1_line.c
@@ -137,7 +137,7 @@ V1L_Close(struct worker *wrk, uint64_t *cnt)
wrk->v1l = NULL;
CHECK_OBJ_NOTNULL(v1l, V1L_MAGIC);
*cnt = v1l->cnt;
- if (WS_Reservation(v1l->ws))
+ if (WS_IsReserved(v1l->ws))
WS_Release(v1l->ws, 0);
WS_Rollback(v1l->ws, v1l->res);
ZERO_OBJ(v1l, sizeof *v1l);
diff --git a/bin/varnishd/http2/cache_http2_proto.c b/bin/varnishd/http2/cache_http2_proto.c
index edcf64c04..c079656b1 100644
--- a/bin/varnishd/http2/cache_http2_proto.c
+++ b/bin/varnishd/http2/cache_http2_proto.c
@@ -184,7 +184,7 @@ h2_del_req(struct worker *wrk, const struct h2_req *r2)
/* XXX: PRIORITY reshuffle */
VTAILQ_REMOVE(&h2->streams, r2, list);
Lck_Unlock(&sp->mtx);
- AZ(WS_Reservation(r2->req->ws));
+ assert(!WS_IsReserved(r2->req->ws));
Req_Cleanup(sp, wrk, r2->req);
Req_Release(r2->req);
}
@@ -532,7 +532,7 @@ h2_do_req(struct worker *wrk, void *priv)
wrk->stats->client_req++;
if (CNT_Request(req) != REQ_FSM_DISEMBARK) {
- AZ(WS_Reservation(req->ws));
+ assert(!WS_IsReserved(req->ws));
AZ(req->top->vcl0);
h2 = r2->h2sess;
CHECK_OBJ_NOTNULL(h2, H2_SESS_MAGIC);
@@ -563,7 +563,7 @@ h2_end_headers(struct worker *wrk, struct h2_sess *h2,
Lck_Lock(&h2->sess->mtx);
VSLb(h2->vsl, SLT_Debug, "HPACK/FINI %s", h2e->name);
Lck_Unlock(&h2->sess->mtx);
- AZ(WS_Reservation(r2->req->ws));
+ assert(!WS_IsReserved(r2->req->ws));
h2_del_req(wrk, r2);
return (h2e);
}
@@ -685,7 +685,7 @@ h2_rx_headers(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2)
VSLb(h2->vsl, SLT_Debug, "HPACK(hdr) %s", h2e->name);
Lck_Unlock(&h2->sess->mtx);
(void)h2h_decode_fini(h2);
- AZ(WS_Reservation(r2->req->ws));
+ assert(!WS_IsReserved(r2->req->ws));
h2_del_req(wrk, r2);
return (h2e);
}
@@ -720,7 +720,7 @@ h2_rx_continuation(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2)
VSLb(h2->vsl, SLT_Debug, "HPACK(cont) %s", h2e->name);
Lck_Unlock(&h2->sess->mtx);
(void)h2h_decode_fini(h2);
- AZ(WS_Reservation(r2->req->ws));
+ assert(!WS_IsReserved(r2->req->ws));
h2_del_req(wrk, r2);
return (h2e);
}
diff --git a/bin/varnishd/http2/cache_http2_session.c b/bin/varnishd/http2/cache_http2_session.c
index 15dd17b27..4b216f85c 100644
--- a/bin/varnishd/http2/cache_http2_session.c
+++ b/bin/varnishd/http2/cache_http2_session.c
@@ -148,7 +148,7 @@ h2_del_sess(struct worker *wrk, struct h2_sess *h2, enum sess_close reason)
VHT_Fini(h2->dectbl);
AZ(pthread_cond_destroy(h2->winupd_cond));
TAKE_OBJ_NOTNULL(req, &h2->srq, REQ_MAGIC);
- AZ(WS_Reservation(req->ws));
+ assert(!WS_IsReserved(req->ws));
sp = h2->sess;
Req_Cleanup(sp, wrk, req);
Req_Release(req);
More information about the varnish-commit
mailing list