Converting a Varnish 3.0 VMOD to 4.0

So we’re getting closer to releasing the first proper 4.0 version of Varnish Cache. One of the things we need to fix is to get all the vmod writers to make sure their vmod works with the new version.

Here are my notes from doing just that, in the hope to make it simpler for others.

In 4.0, you don’t need the source tree of Varnish any more. The include files will be enough, and pkg-config will find them for you.

Make sure that /usr/lib/pkgconfig/varnishapi.pc and /usr/share/aclocal/varnish.m4 exists. If you installed Varnish in the standard path/prefix, that should work out of the box. Otherwise, you might to add some symlinks for pkg-config and automake to find the source. (I need multiple varnishd versions when debugging customer problems, so I let them live in /opt/varnishX.Y/ on my laptop)

Pull/merge the new Makefile.am files from the master branch of libvmod-example.

Header files: remove bin/varnishd/cache.h and add cache/cache.h.

Vmod functions are now called with a vrt context as first argument. %s/struct sess \*sp/const struct vrt_ctx \*ctx/g

The old sess struct has been split, some data is in vrt_ctx->req, and some is in vrt_vtx->req->sp. Look up what is where in cache/cache.h. 

I’ve put up the 3.0->4.0 diff for vmod_policy.c as a gist: https://gist.github.com/lkarsten/8039861

There was a bit trouble of finding varnishtest, as src/Makefile was missing the reference entirely. I just fixed it by hand for now. Another thing for the 4.0 todolist, then.

And finally; 

lkarsten@immer:~/work/libvmod-policy/src$ make check
/opt/varnish/bin/varnishtest -Dvarnishd=/opt/varnish/sbin/varnishd -Dvmod_topbuild=/home/lkarsten/work/libvmod-policy tests/test01.vtc
# top TEST tests/test01.vtc passed (1.574)

 

I have a working Varnish 4.0 vmod. :-D

This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

2 Responses to Converting a Varnish 3.0 VMOD to 4.0

  1. Dag Haavi Finstad says:

    Great stuff, Lasse!

    I recently converted the digest vmod to Varnish 4.0, here’s the commit: https://github.com/varnish/libvmod-digest/commit/a506a51eb8c16a2486e9ac73dc440b5e29ae10e8

    Other things of note that I ran into:
    – Since the tp1 release, the .vcc format has seen some changes. You can now write documentation inline in the .vcc file, and a .rst and a .man.rst will be generated from it. A $ sign is used to discern between regular vmod .vcc definitions and documentation entries. See the std vmod’s https://www.varnish-cache.org/trac/browser/lib/libvmod_std/vmod.vcc for an example.

    – Workspaces: ctx->ws should be used in place of 3.0’s sp->ws. A slight gotcha here is that there still is a ‘ws’ member in struct sess, although this is only used for storing the client’s address and port numbers, and limited to a measly 384 bytes. ctx->ws will be set to a different value depending on which vcl function your vmod routine was invoked from (client side vs backend side). To increase available workspace you will now have to increase one or both of workspace_client/workspace_backend, which is different from 3.0 where you only had to worry about sess_workspace. This is related to how backend fetches in 4.0 are async.

    – There are now typedefs for mapping VCL types to C types. Use VCL_STRING/VCL_DURATION/etc. See vrt.h

    Cheers. :-)

  2. Dag Haavi Finstad says:

    To add to this, in order to set up your environment appropriately when you have varnish4 installed under a non-standard directory, source the following:

    PREFIX=/opt/varnish4-git
    export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig
    export ACLOCAL_PATH=$PREFIX/share/aclocal
    export PATH=$PREFIX/bin:$PREFIX/sbin:$PATH

    where PREFIX is set to whatever you used as –prefix when running ./configure.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s