Commit 52f4ccfc authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Put the objcore methods into their own .h file.

This saves a ugly ifdef for mgt code in storage.h
parent 2c76f5b2
......@@ -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 \
......
......@@ -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);
......
/*-
* Copyright (c) 2006 Verdens Gang AS
* Copyright (c) 2006-2011 Varnish Software AS
* All rights reserved.
*
* Author: Poul-Henning Kamp <phk@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;
};
......@@ -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;
......
......@@ -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;
/*--------------------------------------------------------------------*/
......
......@@ -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 */
......
......@@ -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,
......
......@@ -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,
......
......@@ -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);
......
......@@ -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"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment