Commit 7532c3a7 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Eliminate a level of structure on vrt_privs, the extra 'magic' does

not buy us anything because the compiler can see at all times what
goes on.
parent d9195348
...@@ -199,13 +199,7 @@ struct vxid_pool { ...@@ -199,13 +199,7 @@ struct vxid_pool {
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
VRBT_HEAD(vrt_priv_tree,vrt_priv); VRBT_HEAD(vrt_privs, vrt_priv);
struct vrt_privs {
unsigned magic;
#define VRT_PRIVS_MAGIC 0x03ba7502
struct vrt_priv_tree privs;
};
/* Worker pool stuff -------------------------------------------------*/ /* Worker pool stuff -------------------------------------------------*/
......
...@@ -153,8 +153,6 @@ VBO_ReleaseBusyObj(struct worker *wrk, struct busyobj **pbo) ...@@ -153,8 +153,6 @@ VBO_ReleaseBusyObj(struct worker *wrk, struct busyobj **pbo)
AZ(bo->htc); AZ(bo->htc);
AZ(bo->stale_oc); AZ(bo->stale_oc);
AZ(bo->privs->magic);
VSLb(bo->vsl, SLT_BereqAcct, "%ju %ju %ju %ju %ju %ju", VSLb(bo->vsl, SLT_BereqAcct, "%ju %ju %ju %ju %ju %ju",
(uintmax_t)bo->acct.bereq_hdrbytes, (uintmax_t)bo->acct.bereq_hdrbytes,
(uintmax_t)bo->acct.bereq_bodybytes, (uintmax_t)bo->acct.bereq_bodybytes,
......
...@@ -212,8 +212,6 @@ Req_Cleanup(struct sess *sp, struct worker *wrk, struct req *req) ...@@ -212,8 +212,6 @@ Req_Cleanup(struct sess *sp, struct worker *wrk, struct req *req)
req->director_hint = NULL; req->director_hint = NULL;
req->restarts = 0; req->restarts = 0;
AZ(req->privs->magic);
if (req->vcl != NULL) if (req->vcl != NULL)
VCL_Recache(wrk, &req->vcl); VCL_Recache(wrk, &req->vcl);
......
...@@ -1082,7 +1082,6 @@ CNT_Request(struct req *req) ...@@ -1082,7 +1082,6 @@ CNT_Request(struct req *req)
AN(req->vsl->wid & VSL_CLIENTMARKER); AN(req->vsl->wid & VSL_CLIENTMARKER);
AN(req->vcl); AN(req->vcl);
CHECK_OBJ(req->privs, VRT_PRIVS_MAGIC);
for (nxt = REQ_FSM_MORE; nxt == REQ_FSM_MORE; ) { for (nxt = REQ_FSM_MORE; nxt == REQ_FSM_MORE; ) {
/* /*
......
...@@ -50,7 +50,8 @@ struct vrt_privs cli_task_privs[1]; ...@@ -50,7 +50,8 @@ struct vrt_privs cli_task_privs[1];
static inline int vrt_priv_dyncmp(const struct vrt_priv *, static inline int vrt_priv_dyncmp(const struct vrt_priv *,
const struct vrt_priv *); const struct vrt_priv *);
VRBT_PROTOTYPE_STATIC(vrt_priv_tree, vrt_priv, entry, vrt_priv_dyncmp)
VRBT_PROTOTYPE_STATIC(vrt_privs, vrt_priv, entry, vrt_priv_dyncmp)
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
*/ */
...@@ -64,9 +65,8 @@ pan_privs(struct vsb *vsb, const struct vrt_privs *privs) ...@@ -64,9 +65,8 @@ pan_privs(struct vsb *vsb, const struct vrt_privs *privs)
if (PAN_already(vsb, privs)) if (PAN_already(vsb, privs))
return; return;
VSB_indent(vsb, 2); VSB_indent(vsb, 2);
PAN_CheckMagic(vsb, privs, VRT_PRIVS_MAGIC); if (privs != NULL) {
if (privs->magic == VRT_PRIVS_MAGIC) { VRBT_FOREACH(vp, vrt_privs, privs) {
VRBT_FOREACH(vp, vrt_priv_tree, &privs->privs) {
PAN_CheckMagic(vsb, vp, VRT_PRIV_MAGIC); PAN_CheckMagic(vsb, vp, VRT_PRIV_MAGIC);
VSB_printf(vsb, VSB_printf(vsb,
"priv {p %p l %ld f %p} vmod %jx\n", "priv {p %p l %ld f %p} vmod %jx\n",
...@@ -89,8 +89,7 @@ static void ...@@ -89,8 +89,7 @@ static void
VRTPRIV_init(struct vrt_privs *privs) VRTPRIV_init(struct vrt_privs *privs)
{ {
INIT_OBJ(privs, VRT_PRIVS_MAGIC); VRBT_INIT(privs);
VRBT_INIT(&privs->privs);
} }
static inline int static inline int
...@@ -103,10 +102,10 @@ vrt_priv_dyncmp(const struct vrt_priv *vp1, const struct vrt_priv *vp2) ...@@ -103,10 +102,10 @@ vrt_priv_dyncmp(const struct vrt_priv *vp1, const struct vrt_priv *vp2)
return (0); return (0);
} }
VRBT_GENERATE_STATIC(vrt_priv_tree, vrt_priv, entry, vrt_priv_dyncmp) VRBT_GENERATE_STATIC(vrt_privs, vrt_priv, entry, vrt_priv_dyncmp)
static struct vmod_priv * static struct vmod_priv *
vrt_priv_dynamic(struct ws *ws, struct vrt_privs *vps, uintptr_t id, vrt_priv_dynamic(struct ws *ws, struct vrt_privs *privs, uintptr_t id,
uintptr_t vmod_id) uintptr_t vmod_id)
{ {
struct vrt_priv *vp; struct vrt_priv *vp;
...@@ -115,11 +114,10 @@ vrt_priv_dynamic(struct ws *ws, struct vrt_privs *vps, uintptr_t id, ...@@ -115,11 +114,10 @@ vrt_priv_dynamic(struct ws *ws, struct vrt_privs *vps, uintptr_t id,
.vmod_id = vmod_id, .vmod_id = vmod_id,
}; };
CHECK_OBJ_NOTNULL(vps, VRT_PRIVS_MAGIC);
AN(id); AN(id);
AN(vmod_id); AN(vmod_id);
vp = VRBT_FIND(vrt_priv_tree, &vps->privs, &needle); vp = VRBT_FIND(vrt_privs, privs, &needle);
if (vp) { if (vp) {
CHECK_OBJ(vp, VRT_PRIV_MAGIC); CHECK_OBJ(vp, VRT_PRIV_MAGIC);
assert(vp->id == id); assert(vp->id == id);
...@@ -133,16 +131,13 @@ vrt_priv_dynamic(struct ws *ws, struct vrt_privs *vps, uintptr_t id, ...@@ -133,16 +131,13 @@ vrt_priv_dynamic(struct ws *ws, struct vrt_privs *vps, uintptr_t id,
INIT_OBJ(vp, VRT_PRIV_MAGIC); INIT_OBJ(vp, VRT_PRIV_MAGIC);
vp->id = id; vp->id = id;
vp->vmod_id = vmod_id; vp->vmod_id = vmod_id;
VRBT_INSERT(vrt_priv_tree, &vps->privs, vp); VRBT_INSERT(vrt_privs, privs, vp);
return (vp->priv); return (vp->priv);
} }
struct vmod_priv * struct vmod_priv *
VRT_priv_task(VRT_CTX, const void *vmod_id) VRT_priv_task(VRT_CTX, const void *vmod_id)
{ {
uintptr_t id;
struct vrt_privs *vps;
struct vmod_priv *vp;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
assert(ctx->req == NULL || ctx->bo == NULL || assert(ctx->req == NULL || ctx->bo == NULL ||
...@@ -150,27 +145,35 @@ VRT_priv_task(VRT_CTX, const void *vmod_id) ...@@ -150,27 +145,35 @@ VRT_priv_task(VRT_CTX, const void *vmod_id)
if (ctx->req) { if (ctx->req) {
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
id = (uintptr_t)ctx->req; return (vrt_priv_dynamic(
CAST_OBJ_NOTNULL(vps, ctx->req->privs, VRT_PRIVS_MAGIC); ctx->ws,
} else if (ctx->bo) { ctx->req->privs,
(uintptr_t)ctx->req,
(uintptr_t)vmod_id
));
}
if (ctx->bo) {
CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC); CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
id = (uintptr_t)ctx->bo; return (vrt_priv_dynamic(
CAST_OBJ_NOTNULL(vps, ctx->bo->privs, VRT_PRIVS_MAGIC); ctx->ws,
} else { ctx->bo->privs,
ASSERT_CLI(); (uintptr_t)ctx->bo,
id = (uintptr_t)cli_task_privs; (uintptr_t)vmod_id
CAST_OBJ_NOTNULL(vps, cli_task_privs, VRT_PRIVS_MAGIC); ));
} }
ASSERT_CLI();
vp = vrt_priv_dynamic(ctx->ws, vps, id, (uintptr_t)vmod_id);
return (vp); return (vrt_priv_dynamic(
ctx->ws,
cli_task_privs,
(uintptr_t)cli_task_privs,
(uintptr_t)vmod_id
));
} }
struct vmod_priv * struct vmod_priv *
VRT_priv_top(VRT_CTX, const void *vmod_id) VRT_priv_top(VRT_CTX, const void *vmod_id)
{ {
uintptr_t id;
struct vrt_privs *vps;
struct req *req; struct req *req;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
...@@ -181,9 +184,12 @@ VRT_priv_top(VRT_CTX, const void *vmod_id) ...@@ -181,9 +184,12 @@ VRT_priv_top(VRT_CTX, const void *vmod_id)
} }
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
req = ctx->req->topreq; req = ctx->req->topreq;
id = (uintptr_t)&req->topreq; return (vrt_priv_dynamic(
CAST_OBJ_NOTNULL(vps, req->privs, VRT_PRIVS_MAGIC); req->ws,
return (vrt_priv_dynamic(req->ws, vps, id, (uintptr_t)vmod_id)); req->privs,
(uintptr_t)&req->topreq,
(uintptr_t)vmod_id
));
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
...@@ -204,7 +210,6 @@ VCL_TaskEnter(const struct vcl *vcl, struct vrt_privs *privs) ...@@ -204,7 +210,6 @@ VCL_TaskEnter(const struct vcl *vcl, struct vrt_privs *privs)
{ {
AN(vcl); AN(vcl);
AZ(privs->magic);
VRTPRIV_init(privs); VRTPRIV_init(privs);
} }
...@@ -214,12 +219,12 @@ VCL_TaskLeave(const struct vcl *vcl, struct vrt_privs *privs) ...@@ -214,12 +219,12 @@ VCL_TaskLeave(const struct vcl *vcl, struct vrt_privs *privs)
struct vrt_priv *vp, *vp1; struct vrt_priv *vp, *vp1;
AN(vcl); AN(vcl);
CHECK_OBJ_NOTNULL(privs, VRT_PRIVS_MAGIC); /*
/* NB: We don't bother removing entries as we finish them because it's * NB: We don't bother removing entries as we finish them because it's
* a costly operation. Instead we safely walk the whole tree and clear * a costly operation. Instead we safely walk the whole tree and clear
* the head at the very end. * the head at the very end.
*/ */
VRBT_FOREACH_SAFE(vp, vrt_priv_tree, &privs->privs, vp1) VRBT_FOREACH_SAFE(vp, vrt_privs, privs, vp1)
VRT_priv_fini(vp->priv); VRT_priv_fini(vp->priv);
ZERO_OBJ(privs, sizeof *privs); ZERO_OBJ(privs, sizeof *privs);
} }
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