[master] dec41ee Isolate VSC from VSM

Poul-Henning Kamp phk at FreeBSD.org
Wed Jun 7 13:37:05 CEST 2017


commit dec41ee7062634b58cd0c82185ff0ce2bfe31ec5
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Jun 7 11:35:51 2017 +0000

    Isolate VSC from VSM

diff --git a/lib/libvarnishapi/Makefile.am b/lib/libvarnishapi/Makefile.am
index 0e5f34c..54f1884 100644
--- a/lib/libvarnishapi/Makefile.am
+++ b/lib/libvarnishapi/Makefile.am
@@ -14,7 +14,7 @@ libvarnishapi_la_LDFLAGS = $(AM_LDFLAGS) -version-info 1:6:0
 libvarnishapi_la_SOURCES = \
 	vjsn.c \
 	vjsn.h \
-	vsm_api.h \
+	vsc_priv.h \
 	vsl_api.h \
 	vxp.h \
 	vxp_tokens.h \
diff --git a/lib/libvarnishapi/vsc.c b/lib/libvarnishapi/vsc.c
index c42f501..37334f2 100644
--- a/lib/libvarnishapi/vsc.c
+++ b/lib/libvarnishapi/vsc.c
@@ -49,7 +49,7 @@
 #include "vapi/vsc.h"
 #include "vapi/vsm.h"
 
-#include "vsm_api.h"
+#include "vsc_priv.h"
 
 struct vsc_vf {
 	unsigned		magic;
@@ -111,18 +111,20 @@ static const size_t nlevels =
 static struct vsc *
 vsc_setup(struct VSM_data *vd)
 {
+	struct vsc *vsc;
 
-	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
-	if (vd->vsc == NULL) {
-		ALLOC_OBJ(vd->vsc, VSC_MAGIC);
-		AN(vd->vsc);
-		VTAILQ_INIT(&vd->vsc->vf_list);
-		VTAILQ_INIT(&vd->vsc->pt_list);
-		VTAILQ_INIT(&vd->vsc->sf_list_include);
-		VTAILQ_INIT(&vd->vsc->sf_list_exclude);
+	vsc = VSM_GetVSC(vd);
+	if (vsc == NULL) {
+		ALLOC_OBJ(vsc, VSC_MAGIC);
+		AN(vsc);
+		VTAILQ_INIT(&vsc->vf_list);
+		VTAILQ_INIT(&vsc->pt_list);
+		VTAILQ_INIT(&vsc->sf_list_include);
+		VTAILQ_INIT(&vsc->sf_list_exclude);
+		VSM_SetVSC(vd, vsc);
 	}
-	CHECK_OBJ_NOTNULL(vd->vsc, VSC_MAGIC);
-	return (vd->vsc);
+	CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC);
+	return (vsc);
 }
 
 /*--------------------------------------------------------------------*/
@@ -168,13 +170,9 @@ vsc_delete_sf_list(struct vsc_sf_head *head)
 }
 
 void
-VSC_Delete(struct VSM_data *vd)
+VSC_Delete(struct vsc *vsc)
 {
-	struct vsc *vsc;
 
-	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
-	vsc = vd->vsc;
-	vd->vsc = NULL;
 	CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC);
 	vsc_delete_sf_list(&vsc->sf_list_include);
 	vsc_delete_sf_list(&vsc->sf_list_exclude);
@@ -343,7 +341,7 @@ vsc_build_pt_list(struct VSM_data *vd)
 		vve = vjsn_child(vf->vjsn->value, "elem");
 		AN(vve);
 		VTAILQ_FOREACH(vv, &vve->children, list) {
-			vdsc = calloc(sizeof *vd, 1);
+			vdsc = calloc(sizeof *vdsc, 1);
 			AN(vdsc);
 
 #define DOF(n, k)						\
diff --git a/lib/libvarnishapi/vsc_priv.h b/lib/libvarnishapi/vsc_priv.h
new file mode 100644
index 0000000..363f6cc
--- /dev/null
+++ b/lib/libvarnishapi/vsc_priv.h
@@ -0,0 +1,36 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2015 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+struct vsc;
+struct VSM_data;
+
+void VSM_SetVSC(struct VSM_data *, struct vsc *);
+struct vsc *VSM_GetVSC(const struct VSM_data *);
+void VSC_Delete(struct vsc *);
diff --git a/lib/libvarnishapi/vsl_cursor.c b/lib/libvarnishapi/vsl_cursor.c
index c90f93d..1c9b2ba 100644
--- a/lib/libvarnishapi/vsl_cursor.c
+++ b/lib/libvarnishapi/vsl_cursor.c
@@ -54,7 +54,6 @@
 #include "vapi/vsm.h"
 
 #include "vsl_api.h"
-#include "vsm_api.h"
 
 struct vslc_vsm {
 	unsigned			magic;
@@ -125,7 +124,6 @@ vslc_vsm_next(const struct VSL_cursor *cursor)
 
 	CAST_OBJ_NOTNULL(c, cursor->priv_data, VSLC_VSM_MAGIC);
 	assert(&c->cursor == cursor);
-	CHECK_OBJ_NOTNULL(c->vsm, VSM_MAGIC);
 
 	while (1) {
 		i = vslc_vsm_check(&c->cursor, &c->next);
@@ -248,7 +246,6 @@ VSL_CursorVSM(struct VSL_data *vsl, struct VSM_data *vsm, unsigned options)
 	int i;
 
 	CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC);
-	CHECK_OBJ_NOTNULL(vsm, VSM_MAGIC);
 
 	if (!VSM_Get(vsm, &vf, VSL_CLASS, "", "")) {
 		(void)vsl_diag(vsl,
diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c
index 5835014..b7b96b2 100644
--- a/lib/libvarnishapi/vsm.c
+++ b/lib/libvarnishapi/vsm.c
@@ -48,11 +48,11 @@
 #include "vin.h"
 #include "vsb.h"
 #include "vsm_priv.h"
+#include "vsc_priv.h"
 #include "vtim.h"
 
 #include "vapi/vsm.h"
 
-#include "vsm_api.h"
 
 #ifndef MAP_HASSEMAPHORE
 #define MAP_HASSEMAPHORE 0 /* XXX Linux */
@@ -64,6 +64,32 @@ const struct vsm_valid VSM_similar[1] = {{"similar"}};
 
 /*--------------------------------------------------------------------*/
 
+struct vsc;
+
+struct VSM_data {
+	unsigned		magic;
+#define VSM_MAGIC		0x6e3bd69b
+
+	struct vsb		*diag;
+
+	char			*dname;
+	char			*iname;
+
+	struct stat		fstat;
+
+	int			vsm_fd;
+	struct VSM_head		*head;
+	char			*b;
+	char			*e;
+
+	uint64_t		age_ok;
+	double			t_ok;
+
+	struct vsc		*vsc;
+};
+
+/*--------------------------------------------------------------------*/
+
 struct VSM_data *
 VSM_New(void)
 {
@@ -81,7 +107,25 @@ VSM_New(void)
 
 /*--------------------------------------------------------------------*/
 
-int
+void
+VSM_SetVSC(struct VSM_data *vd, struct vsc *vsc)
+{
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+
+	vd->vsc = vsc;
+}
+
+struct vsc *
+VSM_GetVSC(const struct VSM_data *vd)
+{
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+
+	return (vd->vsc);
+}
+
+/*--------------------------------------------------------------------*/
+
+static int
 vsm_diag(struct VSM_data *vd, const char *fmt, ...)
 {
 	va_list ap;
@@ -179,7 +223,7 @@ VSM_Delete(struct VSM_data *vd)
 
 	VSM_Close(vd);
 	if (vd->vsc != NULL)
-		VSC_Delete(vd);
+		VSC_Delete(vd->vsc);
 	VSM_ResetError(vd);
 	free(vd->dname);
 	FREE_OBJ(vd);
diff --git a/lib/libvarnishapi/vsm_api.h b/lib/libvarnishapi/vsm_api.h
deleted file mode 100644
index e9402b0..0000000
--- a/lib/libvarnishapi/vsm_api.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*-
- * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2015 Varnish Software AS
- * All rights reserved.
- *
- * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
-
-struct vsc;
-struct vsb;
-
-struct VSM_data {
-	unsigned		magic;
-#define VSM_MAGIC		0x6e3bd69b
-
-	struct vsb		*diag;
-
-	char			*dname;
-	char			*iname;
-
-	struct stat		fstat;
-
-	int			vsm_fd;
-	struct VSM_head		*head;
-	char			*b;
-	char			*e;
-
-	uint64_t		age_ok;
-	double			t_ok;
-
-	struct vsc		*vsc;
-};
-
-int vsm_diag(struct VSM_data *vd, const char *fmt, ...)
-    __v_printflike(2, 3);
-void VSC_Delete(struct VSM_data *vd);



More information about the varnish-commit mailing list