[master] 1d0298e1b Bring more clarity to what and how VMODs can veto cold&discard for their VCL.
Poul-Henning Kamp
phk at FreeBSD.org
Wed May 8 08:43:09 UTC 2019
commit 1d0298e1b4a1f106bbcebe8069ed7aa8d17582f8
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed May 8 08:41:34 2019 +0000
Bring more clarity to what and how VMODs can veto
cold&discard for their VCL.
Closes: #2471
diff --git a/bin/varnishd/cache/cache_vcl.h b/bin/varnishd/cache/cache_vcl.h
index d0154266f..ac01706e2 100644
--- a/bin/varnishd/cache/cache_vcl.h
+++ b/bin/varnishd/cache/cache_vcl.h
@@ -62,7 +62,7 @@ struct vclref {
#define VCLREF_MAGIC 0x47fb6848
struct vcl *vcl;
VTAILQ_ENTRY(vclref) list;
- char desc[32];
+ char *desc;
};
extern struct lock vcl_mtx;
diff --git a/bin/varnishd/cache/cache_vrt_vcl.c b/bin/varnishd/cache/cache_vrt_vcl.c
index db1e15243..451d7aea3 100644
--- a/bin/varnishd/cache/cache_vrt_vcl.c
+++ b/bin/varnishd/cache/cache_vrt_vcl.c
@@ -142,28 +142,6 @@ VCL_Rel(struct vcl **vcc)
/*--------------------------------------------------------------------*/
-void
-VRT_VCL_Busy(VRT_CTX)
-{
- CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
-
- CHECK_OBJ_NOTNULL(ctx->vcl, VCL_MAGIC);
- VCL_Ref(ctx->vcl);
-}
-
-void
-VRT_VCL_Unbusy(VRT_CTX)
-{
- CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
- struct vcl *vcl;
-
- CHECK_OBJ_NOTNULL(ctx->vcl, VCL_MAGIC);
- vcl = ctx->vcl;
- VCL_Rel(&vcl);
-}
-
-/*--------------------------------------------------------------------*/
-
VCL_BACKEND
VRT_AddDirector(VRT_CTX, const struct vdi_methods *m, void *priv,
const char *fmt, ...)
@@ -322,6 +300,55 @@ VCL_DefaultProbe(const struct vcl *vcl)
return (vcl->conf->default_probe);
}
+/*--------------------------------------------------------------------*/
+
+struct vclref *
+VRT_VCL_Prevent_Cold(VRT_CTX, const char *desc)
+{
+ struct vclref* ref;
+
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+ CHECK_OBJ_NOTNULL(ctx->vcl, VCL_MAGIC);
+
+ ALLOC_OBJ(ref, VCLREF_MAGIC);
+ AN(ref);
+ ref->vcl = ctx->vcl;
+ REPLACE(ref->desc, desc);
+
+ VCL_Ref(ctx->vcl);
+
+ Lck_Lock(&vcl_mtx);
+ VTAILQ_INSERT_TAIL(&ctx->vcl->ref_list, ref, list);
+ Lck_Unlock(&vcl_mtx);
+
+ return(ref);
+}
+
+void
+VRT_VCL_Allow_Cold(struct vclref **refp)
+{
+ struct vcl *vcl;
+ struct vclref *ref;
+
+ AN(refp);
+ ref = *refp;
+ *refp = NULL;
+
+ CHECK_OBJ_NOTNULL(ref, VCLREF_MAGIC);
+ vcl = ref->vcl;
+ CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
+
+ Lck_Lock(&vcl_mtx);
+ assert(!VTAILQ_EMPTY(&vcl->ref_list));
+ VTAILQ_REMOVE(&vcl->ref_list, ref, list);
+ Lck_Unlock(&vcl_mtx);
+
+ VCL_Rel(&vcl);
+
+ REPLACE(ref->desc, NULL);
+ FREE_OBJ(ref);
+}
+
struct vclref *
VRT_VCL_Prevent_Discard(VRT_CTX, const char *desc)
{
@@ -340,7 +367,7 @@ VRT_VCL_Prevent_Discard(VRT_CTX, const char *desc)
ALLOC_OBJ(ref, VCLREF_MAGIC);
AN(ref);
ref->vcl = vcl;
- bprintf(ref->desc, "%s", desc);
+ REPLACE(ref->desc, desc);
Lck_Lock(&vcl_mtx);
VTAILQ_INSERT_TAIL(&vcl->ref_list, ref, list);
@@ -377,6 +404,7 @@ VRT_VCL_Allow_Discard(struct vclref **refp)
/* No garbage collection here, for the same reasons as in VCL_Rel. */
Lck_Unlock(&vcl_mtx);
+ REPLACE(ref->desc, NULL);
FREE_OBJ(ref);
}
More information about the varnish-commit
mailing list