[master] 52f4ccf Put the objcore methods into their own .h file.

Poul-Henning Kamp phk at FreeBSD.org
Tue Dec 15 11:41:09 CET 2015


commit 52f4ccfcb7e4d205a2a66d4920f421ee72e51659
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Dec 15 10:40:25 2015 +0000

    Put the objcore methods into their own .h file.
    
    This saves a ugly ifdef for mgt code in storage.h

diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index 1f1f110..6bb046c 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -104,6 +104,7 @@ noinst_HEADERS = \
 	builtin_vcl.h \
 	cache/cache_ban.h \
 	cache/cache_esi.h \
+	cache/cache_obj.h \
 	cache/cache_pool.h \
 	cache/cache_priv.h \
 	common/heritage.h \
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index cadd0f1..35e7a2f 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -43,11 +43,12 @@
 #include <stdlib.h>
 
 #include "cache.h"
+#include "cache_obj.h"
 #include "vend.h"
 #include "storage/storage.h"
 #include "hash/hash_slinger.h"
 
-static const struct storeobj_methods *
+static const struct obj_methods *
 obj_getmethods(const struct objcore *oc)
 {
 
@@ -66,7 +67,7 @@ int
 ObjIterate(struct worker *wrk, struct objcore *oc,
     void *priv, objiterate_f *func)
 {
-	const struct storeobj_methods *om = obj_getmethods(oc);
+	const struct obj_methods *om = obj_getmethods(oc);
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	AN(func);
@@ -86,7 +87,7 @@ ObjIterate(struct worker *wrk, struct objcore *oc,
 int
 ObjGetSpace(struct worker *wrk, struct objcore *oc, ssize_t *sz, uint8_t **ptr)
 {
-	const struct storeobj_methods *om = obj_getmethods(oc);
+	const struct obj_methods *om = obj_getmethods(oc);
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	AN(sz);
@@ -107,7 +108,7 @@ ObjGetSpace(struct worker *wrk, struct objcore *oc, ssize_t *sz, uint8_t **ptr)
 void
 ObjExtend(struct worker *wrk, struct objcore *oc, ssize_t l)
 {
-	const struct storeobj_methods *om = obj_getmethods(oc);
+	const struct obj_methods *om = obj_getmethods(oc);
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	assert(l > 0);
@@ -125,7 +126,7 @@ ObjExtend(struct worker *wrk, struct objcore *oc, ssize_t l)
 uint64_t
 ObjGetLen(struct worker *wrk, struct objcore *oc)
 {
-	const struct storeobj_methods *om = obj_getmethods(oc);
+	const struct obj_methods *om = obj_getmethods(oc);
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 
@@ -143,7 +144,7 @@ ObjGetLen(struct worker *wrk, struct objcore *oc)
 void
 ObjTrimStore(struct worker *wrk, struct objcore *oc)
 {
-	const struct storeobj_methods *om = obj_getmethods(oc);
+	const struct obj_methods *om = obj_getmethods(oc);
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 
@@ -162,7 +163,7 @@ ObjTrimStore(struct worker *wrk, struct objcore *oc)
 void
 ObjSlim(struct worker *wrk, struct objcore *oc)
 {
-	const struct storeobj_methods *om = obj_getmethods(oc);
+	const struct obj_methods *om = obj_getmethods(oc);
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 
@@ -175,7 +176,7 @@ ObjSlim(struct worker *wrk, struct objcore *oc)
 void
 ObjUpdateMeta(struct worker *wrk, struct objcore *oc)
 {
-	const struct storeobj_methods *m = obj_getmethods(oc);
+	const struct obj_methods *m = obj_getmethods(oc);
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 
@@ -188,7 +189,7 @@ ObjUpdateMeta(struct worker *wrk, struct objcore *oc)
 void
 ObjFreeObj(struct worker *wrk, struct objcore *oc)
 {
-	const struct storeobj_methods *m = obj_getmethods(oc);
+	const struct obj_methods *m = obj_getmethods(oc);
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 
@@ -202,7 +203,7 @@ ObjFreeObj(struct worker *wrk, struct objcore *oc)
 struct lru *
 ObjGetLRU(const struct objcore *oc)
 {
-	const struct storeobj_methods *m = obj_getmethods(oc);
+	const struct obj_methods *m = obj_getmethods(oc);
 
 	AN(m->objgetlru);
 	return (m->objgetlru(oc));
@@ -218,7 +219,7 @@ void *
 ObjGetattr(struct worker *wrk, struct objcore *oc, enum obj_attr attr,
    ssize_t *len)
 {
-	const struct storeobj_methods *om = obj_getmethods(oc);
+	const struct obj_methods *om = obj_getmethods(oc);
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 
@@ -237,7 +238,7 @@ void *
 ObjSetattr(struct worker *wrk, struct objcore *oc, enum obj_attr attr,
     ssize_t len, const void *ptr)
 {
-	const struct storeobj_methods *om = obj_getmethods(oc);
+	const struct obj_methods *om = obj_getmethods(oc);
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 
diff --git a/bin/varnishd/cache/cache_obj.h b/bin/varnishd/cache/cache_obj.h
new file mode 100644
index 0000000..3b2a937
--- /dev/null
+++ b/bin/varnishd/cache/cache_obj.h
@@ -0,0 +1,68 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2011 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.
+ *
+ */
+
+/* Methods on objcore ------------------------------------------------*/
+
+typedef void objupdatemeta_f(struct worker *, struct objcore *);
+typedef void objfree_f(struct worker *, struct objcore *);
+typedef struct lru *objgetlru_f(const struct objcore *);
+
+/* This method is only used by SML (...to get to persistent) */
+typedef struct object *sml_getobj_f(struct worker *, struct objcore *);
+
+typedef int objiterator_f(struct worker *, struct objcore *,
+    void *priv, objiterate_f *func);
+typedef int objgetspace_f(struct worker *, struct objcore *,
+     ssize_t *sz, uint8_t **ptr);
+typedef void objextend_f(struct worker *, struct objcore *, ssize_t l);
+typedef void objtrimstore_f(struct worker *, struct objcore *);
+typedef void objslim_f(struct worker *, struct objcore *);
+typedef void *objgetattr_f(struct worker *, struct objcore *,
+    enum obj_attr attr, ssize_t *len);
+typedef void *objsetattr_f(struct worker *, struct objcore *,
+    enum obj_attr attr, ssize_t len, const void *ptr);
+typedef uint64_t objgetlen_f(struct worker *, struct objcore *);
+
+struct obj_methods {
+	objfree_f	*objfree;
+	objgetlru_f	*objgetlru;
+	objupdatemeta_f	*objupdatemeta;
+
+	sml_getobj_f	*sml_getobj;
+
+	objiterator_f	*objiterator;
+	objgetspace_f	*objgetspace;
+	objextend_f	*objextend;
+	objgetlen_f	*objgetlen;
+	objtrimstore_f	*objtrimstore;
+	objslim_f	*objslim;
+	objgetattr_f	*objgetattr;
+	objsetattr_f	*objsetattr;
+};
diff --git a/bin/varnishd/storage/storage.h b/bin/varnishd/storage/storage.h
index a42a9cb..0d0d429 100644
--- a/bin/varnishd/storage/storage.h
+++ b/bin/varnishd/storage/storage.h
@@ -39,6 +39,7 @@ struct worker;
 struct lru;
 struct vsl_log;
 struct vfp_ctx;
+struct obj_methods;
 
 /* Storage -----------------------------------------------------------*/
 
@@ -55,53 +56,6 @@ struct storage {
 	unsigned		space;
 };
 
-/* Methods on objcore ------------------------------------------------*/
-
-#ifdef VARNISH_CACHE_CHILD
-
-typedef void objupdatemeta_f(struct worker *, struct objcore *oc);
-typedef void objfree_f(struct worker *, struct objcore *oc);
-typedef struct lru *objgetlru_f(const struct objcore *oc);
-
-/* This method is only used by SML (...to get to persistent) */
-typedef struct object *sml_getobj_f(struct worker *, struct objcore *oc);
-
-typedef int objiterator_f(struct worker *, struct objcore *oc,
-    void *priv, objiterate_f *func);
-typedef int objgetspace_f(struct worker *, struct objcore *,
-     ssize_t *sz, uint8_t **ptr);
-typedef void objextend_f(struct worker *, struct objcore *, ssize_t l);
-typedef void objtrimstore_f(struct worker *, struct objcore *);
-typedef void objslim_f(struct worker *, struct objcore *);
-typedef void *objgetattr_f(struct worker *, struct objcore *,
-    enum obj_attr attr, ssize_t *len);
-typedef void *objsetattr_f(struct worker *, struct objcore *,
-    enum obj_attr attr, ssize_t len, const void *ptr);
-typedef uint64_t objgetlen_f(struct worker *, struct objcore *);
-
-struct storeobj_methods {
-	objfree_f	*objfree;
-	objgetlru_f	*objgetlru;
-	objupdatemeta_f	*objupdatemeta;
-
-	sml_getobj_f	*sml_getobj;
-
-	objiterator_f	*objiterator;
-	objgetspace_f	*objgetspace;
-	objextend_f	*objextend;
-	objgetlen_f	*objgetlen;
-	objtrimstore_f	*objtrimstore;
-	objslim_f	*objslim;
-	objgetattr_f	*objgetattr;
-	objsetattr_f	*objsetattr;
-};
-
-#else
-
-struct storeobj_methods;
-
-#endif
-
 /* Prototypes --------------------------------------------------------*/
 
 typedef void storage_init_f(struct stevedore *, int ac, char * const *av);
@@ -141,7 +95,7 @@ struct stevedore {
 	storage_baninfo_f	*baninfo;	/* --//-- */
 	storage_banexport_f	*banexport;	/* --//-- */
 
-	const struct storeobj_methods
+	const struct obj_methods
 				*methods;
 
 	struct lru		*lru;
diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index a71f150..5b9910f 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -43,6 +43,7 @@
 #include <stdlib.h>
 
 #include "cache/cache.h"
+#include "cache/cache_obj.h"
 #include "storage/storage.h"
 #include "storage/storage_simple.h"
 
@@ -54,7 +55,7 @@
 
 #include "storage/storage_persistent.h"
 
-static struct storeobj_methods smp_oc_realmethods;
+static struct obj_methods smp_oc_realmethods;
 
 /*--------------------------------------------------------------------*/
 
diff --git a/bin/varnishd/storage/storage_persistent.h b/bin/varnishd/storage/storage_persistent.h
index 3a1d4f2..b20ef02 100644
--- a/bin/varnishd/storage/storage_persistent.h
+++ b/bin/varnishd/storage/storage_persistent.h
@@ -307,7 +307,7 @@ void smp_new_seg(struct smp_sc *sc);
 void smp_close_seg(struct smp_sc *sc, struct smp_seg *sg);
 void smp_init_oc(struct objcore *oc, struct smp_seg *sg, unsigned objidx);
 void smp_save_segs(struct smp_sc *sc);
-extern const struct storeobj_methods smp_oc_methods;
+extern const struct obj_methods smp_oc_methods;
 
 /* storage_persistent_subr.c */
 
diff --git a/bin/varnishd/storage/storage_persistent_silo.c b/bin/varnishd/storage/storage_persistent_silo.c
index 8b370c6..e8034cd 100644
--- a/bin/varnishd/storage/storage_persistent_silo.c
+++ b/bin/varnishd/storage/storage_persistent_silo.c
@@ -39,6 +39,7 @@
 #include <stdlib.h>
 
 #include "cache/cache.h"
+#include "cache/cache_obj.h"
 #include "storage/storage.h"
 #include "storage/storage_simple.h"
 
@@ -526,7 +527,7 @@ smp_oc_objgetlru(const struct objcore *oc)
 	return (sg->lru);
 }
 
-const struct storeobj_methods smp_oc_methods = {
+const struct obj_methods smp_oc_methods = {
 	.sml_getobj =		smp_oc_sml_getobj,
 	.objupdatemeta =		smp_oc_objupdatemeta,
 	.objfree =		smp_oc_objfree,
diff --git a/bin/varnishd/storage/storage_simple.c b/bin/varnishd/storage/storage_simple.c
index b8eedec..11d55dc 100644
--- a/bin/varnishd/storage/storage_simple.c
+++ b/bin/varnishd/storage/storage_simple.c
@@ -33,6 +33,7 @@
 #include <stdlib.h>
 
 #include "cache/cache.h"
+#include "cache/cache_obj.h"
 #include "hash/hash_slinger.h"
 
 #include "storage/storage.h"
@@ -103,7 +104,7 @@ SML_allocobj(const struct stevedore *stv, struct objcore *oc,
 static struct object *
 getobj(struct worker *wrk, struct objcore *oc)
 {
-	const struct storeobj_methods *m;
+	const struct obj_methods *m;
 	struct object *o;
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
@@ -494,7 +495,7 @@ sml_setattr(struct worker *wrk, struct objcore *oc, enum obj_attr attr,
 }
 
 
-const struct storeobj_methods SML_methods = {
+const struct obj_methods SML_methods = {
 	.objfree	= sml_objfree,
 	.objgetlru	= sml_objgetlru,
 	.objiterator	= sml_iterator,
diff --git a/bin/varnishd/storage/storage_simple.h b/bin/varnishd/storage/storage_simple.h
index b199e7a..ce4a286 100644
--- a/bin/varnishd/storage/storage_simple.h
+++ b/bin/varnishd/storage/storage_simple.h
@@ -53,7 +53,7 @@ struct object {
 	struct storage		*esidata;
 };
 
-extern const struct storeobj_methods SML_methods;
+extern const struct obj_methods SML_methods;
 
 struct object *SML_MkObject(const struct stevedore *, struct objcore *,
     void *ptr);
diff --git a/bin/varnishd/storage/storage_umem.c b/bin/varnishd/storage/storage_umem.c
index aa268ec..71919b8 100644
--- a/bin/varnishd/storage/storage_umem.c
+++ b/bin/varnishd/storage/storage_umem.c
@@ -40,6 +40,7 @@
 #include <umem.h>
 
 #include "cache/cache.h"
+#include "cache/cache_obj.h"
 #include "storage/storage.h"
 #include "storage/storage_simple.h"
 



More information about the varnish-commit mailing list