[master] ed3b095c0 add a facility to test WS_ReserveSize()

Dridi Boukelmoune dridi at varni.sh
Tue Nov 26 13:10:21 UTC 2019


On Tue, Nov 26, 2019 at 12:44 PM Nils Goroll <nils.goroll at uplex.de> wrote:
>
>
> commit ed3b095c0414af453493580a654f63a02d22e0e8
> Author: Nils Goroll <nils.goroll at uplex.de>
> Date:   Tue Nov 26 13:21:37 2019 +0100
>
>     add a facility to test WS_ReserveSize()
>
> diff --git a/lib/libvmod_vtc/vmod.vcc b/lib/libvmod_vtc/vmod.vcc
> index 51154f366..4f15d0d07 100644
> --- a/lib/libvmod_vtc/vmod.vcc
> +++ b/lib/libvmod_vtc/vmod.vcc
> @@ -96,6 +96,14 @@ as much as needed to leave that many bytes free. The actual allocation size
>  may be higher to comply with memory alignment requirements of the CPU
>  architecture. A failed allocation fails the transaction.
>
> +$Function BYTES workspace_reserve(ENUM { client, backend, session, thread },
> +       INT size)
> +
> +Attempt to reserve *size* bytes and release the reservation right
> +away. Return the size of the reservation.
> +
> +See `vtc.workspace_alloc`_ for semantics of the *size* argument.
> +
>  $Function INT workspace_free(ENUM { client, backend, session, thread })
>
>  Find how much unallocated space there is left in a workspace.
> diff --git a/lib/libvmod_vtc/vmod_vtc.c b/lib/libvmod_vtc/vmod_vtc.c
> index f7e58db5c..e52c40d5a 100644
> --- a/lib/libvmod_vtc/vmod_vtc.c
> +++ b/lib/libvmod_vtc/vmod_vtc.c
> @@ -167,6 +167,34 @@ vmod_workspace_alloc(VRT_CTX, VCL_ENUM which, VCL_INT size)
>                 memset(p, '\0', size);
>  }
>
> +VCL_BYTES v_matchproto_(td_vtc_workspace_reserve)
> +vmod_workspace_reserve(VRT_CTX, VCL_ENUM which, VCL_INT size)
> +{
> +       struct ws *ws;
> +       unsigned r;
> +
> +       CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
> +
> +       ws = vtc_ws_find(ctx, which);
> +       if (ws == NULL)
> +               return (0);
> +       WS_Assert(ws);
> +
> +       if (size < 0) {
> +               size += WS_ReserveAll(ws);
> +               WS_Release(ws, 0);
> +       }
> +       if (size <= 0) {
> +               VRT_fail(ctx, "Attempted negative WS reservation");
> +               return (0);
> +       }

I'm not sure to follow the logic above. If we want to allow a negative
size it should be handled separately from the "normal" case.

> +       r = WS_ReserveSize(ws, size);
> +       if (r == 0)
> +               return (0);
> +       WS_Release(ws, 0);
> +       return (1);
> +}
> +
>  VCL_INT v_matchproto_(td_vtc_workspace_free)
>  vmod_workspace_free(VRT_CTX, VCL_ENUM which)
>  {
> _______________________________________________
> varnish-commit mailing list
> varnish-commit at varnish-cache.org
> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit


More information about the varnish-commit mailing list