Commit 2c76f5b2 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Collect all the stuff which implements objects on top of "simple"

stevedores and call it "SML".

I bet this is going to surprise Martin :-)
parent 15aad353
......@@ -113,6 +113,7 @@ noinst_HEADERS = \
mgt/mgt_cli.h \
mgt/mgt_param.h \
storage/storage.h \
storage/storage_simple.h \
storage/storage_persistent.h \
waiter/waiter_priv.h \
waiter/mgt_waiter.h
......
This diff is collapsed.
......@@ -183,8 +183,8 @@ STV_Config(const char *spec)
ARGV_ERR("(-s%s) too many arguments\n", stv->name);
AN(stv->alloc);
if (stv->allocobj == NULL)
stv->allocobj = stv_default_allocobj;
AN(stv->allocobj);
AN(stv->methods);
if (!strcmp(stv->ident, TRANSIENT_STORAGE)) {
stv->transient = 1;
......
......@@ -44,6 +44,7 @@
#include "cache/cache.h"
#include "storage/storage.h"
#include "storage/storage_simple.h"
#include "vsha256.h"
......
......@@ -131,65 +131,6 @@ STV_alloc(const struct stevedore *stv, size_t size)
return (st);
}
/*--------------------------------------------------------------------
* This function is called by stevedores ->allocobj() method, which
* very often will be stv_default_allocobj() below, to convert a slab
* of storage into object which the stevedore can then register in its
* internal state, before returning it to STV_NewObject().
* As you probably guessed: All this for persistence.
*/
struct object *
STV_MkObject(const struct stevedore *stv, struct objcore *oc, void *ptr)
{
struct object *o;
CHECK_OBJ_NOTNULL(stv, STEVEDORE_MAGIC);
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
assert(PAOK(ptr));
o = ptr;
INIT_OBJ(o, OBJECT_MAGIC);
VTAILQ_INIT(&o->list);
oc->stobj->magic = STOREOBJ_MAGIC;
oc->stobj->stevedore = stv;
AN(stv->methods);
oc->stobj->priv = o;
return (o);
}
/*--------------------------------------------------------------------
* This is the default ->allocobj() which all stevedores who do not
* implement persistent storage can rely on.
*/
int
stv_default_allocobj(const struct stevedore *stv, struct objcore *oc,
unsigned wsl)
{
struct object *o;
struct storage *st;
unsigned ltot;
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
ltot = sizeof(struct object) + PRNDUP(wsl);
st = stv->alloc(stv, ltot);
if (st == NULL)
return (0);
if (st->space < ltot) {
stv->free(st);
return (0);
}
o = STV_MkObject(stv, oc, st->ptr);
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
st->len = sizeof(*o);
o->objstore = st;
return (1);
}
/*-------------------------------------------------------------------
* Allocate storage for an object, based on the header information.
* XXX: If we know (a hint of) the length, we could allocate space
......
......@@ -55,46 +55,17 @@ struct storage {
unsigned space;
};
/* Object ------------------------------------------------------------*/
VTAILQ_HEAD(storagehead, storage);
struct object {
unsigned magic;
#define OBJECT_MAGIC 0x32851d42
struct storage *objstore;
char oa_vxid[4];
uint8_t *oa_vary;
uint8_t *oa_http;
uint8_t oa_flags[1];
char oa_gzipbits[32];
char oa_lastmodified[8];
struct storagehead list;
ssize_t len;
struct storage *esidata;
};
/* Methods on objcore ------------------------------------------------*/
#ifdef VARNISH_CACHE_CHILD
typedef void updatemeta_f(struct worker *, struct objcore *oc);
typedef void freeobj_f(struct worker *, struct objcore *oc);
typedef struct lru *getlru_f(const struct objcore *oc);
/*
* Stevedores can either be simple, and provide just this method:
*/
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);
typedef struct object *getobj_f(struct worker *, 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);
/*
* Or the can be "complex" and provide all of these methods:
* (Described in comments in cache_obj.c)
*/
typedef int objiterator_f(struct worker *, struct objcore *oc,
void *priv, objiterate_f *func);
typedef int objgetspace_f(struct worker *, struct objcore *,
......@@ -109,11 +80,11 @@ typedef void *objsetattr_f(struct worker *, struct objcore *,
typedef uint64_t objgetlen_f(struct worker *, struct objcore *);
struct storeobj_methods {
freeobj_f *freeobj;
getlru_f *getlru;
updatemeta_f *updatemeta;
objfree_f *objfree;
objgetlru_f *objgetlru;
objupdatemeta_f *objupdatemeta;
getobj_f *getobj;
sml_getobj_f *sml_getobj;
objiterator_f *objiterator;
objgetspace_f *objgetspace;
......@@ -152,10 +123,6 @@ typedef void storage_banexport_f(const struct stevedore *, const uint8_t *bans,
#include "tbl/vrt_stv_var.h"
#undef VRTSTVTYPE
extern storage_allocobj_f stv_default_allocobj;
extern const struct storeobj_methods default_oc_methods;
/*--------------------------------------------------------------------*/
struct stevedore {
......@@ -199,8 +166,6 @@ extern struct stevedore *stv_transient;
int STV_GetFile(const char *fn, int *fdp, const char **fnp, const char *ctx);
uintmax_t STV_FileSize(int fd, const char *size, unsigned *granularity,
const char *ctx);
struct object *STV_MkObject(const struct stevedore *, struct objcore *,
void *ptr);
struct lru *LRU_Alloc(void);
void LRU_Free(struct lru *lru);
......
......@@ -39,6 +39,7 @@
#include "cache/cache.h"
#include "storage/storage.h"
#include "storage/storage_simple.h"
#include "vnum.h"
#include "vfil.h"
......@@ -535,7 +536,8 @@ const struct stevedore smf_stevedore = {
.alloc = smf_alloc,
.trim = smf_trim,
.free = smf_free,
.methods = &default_oc_methods,
.allocobj = SML_allocobj,
.methods = &SML_methods,
};
#ifdef INCLUDE_TEST_DRIVER
......
......@@ -36,6 +36,7 @@
#include "cache/cache.h"
#include "storage/storage.h"
#include "storage/storage_simple.h"
#include "vnum.h"
......@@ -251,7 +252,8 @@ const struct stevedore sma_stevedore = {
.alloc = sma_alloc,
.free = sma_free,
.trim = sma_trim,
.methods = &default_oc_methods,
.allocobj = SML_allocobj,
.methods = &SML_methods,
.var_free_space = sma_free_space,
.var_used_space = sma_used_space,
};
......@@ -44,6 +44,7 @@
#include "cache/cache.h"
#include "storage/storage.h"
#include "storage/storage_simple.h"
#include "hash/hash_slinger.h"
#include "vcli.h"
......@@ -53,6 +54,8 @@
#include "storage/storage_persistent.h"
static struct storeobj_methods smp_oc_realmethods;
/*--------------------------------------------------------------------*/
/*
......@@ -526,7 +529,7 @@ smp_allocobj(const struct stevedore *stv, struct objcore *oc, unsigned wsl)
assert(st->space >= ltot);
o = STV_MkObject(stv, oc, st->ptr);
o = SML_MkObject(stv, oc, st->ptr);
AN(oc->stobj->stevedore);
assert(oc->stobj->stevedore == stv);
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
......@@ -592,7 +595,7 @@ const struct stevedore smp_stevedore = {
.signal_close = smp_signal_close,
.baninfo = smp_baninfo,
.banexport = smp_banexport,
.methods = &smp_oc_methods,
.methods = &smp_oc_realmethods,
};
/*--------------------------------------------------------------------
......@@ -682,6 +685,11 @@ void
SMP_Init(void)
{
CLI_AddFuncs(debug_cmds);
smp_oc_realmethods = SML_methods;
smp_oc_realmethods.sml_getobj = smp_oc_methods.sml_getobj;
smp_oc_realmethods.objupdatemeta = smp_oc_methods.objupdatemeta;
smp_oc_realmethods.objfree = smp_oc_methods.objfree;
smp_oc_realmethods.objgetlru = smp_oc_methods.objgetlru;
}
/*--------------------------------------------------------------------
......
......@@ -40,6 +40,7 @@
#include "cache/cache.h"
#include "storage/storage.h"
#include "storage/storage_simple.h"
#include "hash/hash_slinger.h"
#include "vsha256.h"
......@@ -387,7 +388,7 @@ smp_loaded_st(const struct smp_sc *sc, const struct smp_seg *sg,
*/
static struct object *
smp_oc_getobj(struct worker *wrk, struct objcore *oc)
smp_oc_sml_getobj(struct worker *wrk, struct objcore *oc)
{
struct object *o;
struct smp_seg *sg;
......@@ -401,7 +402,7 @@ smp_oc_getobj(struct worker *wrk, struct objcore *oc)
AN(oc->stobj->stevedore);
/* Some calls are direct, but they should match anyway */
assert(oc->stobj->stevedore->methods->getobj == smp_oc_getobj);
assert(oc->stobj->stevedore->methods->sml_getobj == smp_oc_sml_getobj);
CAST_OBJ_NOTNULL(sg, oc->stobj->priv, SMP_SEG_MAGIC);
so = smp_find_so(sg, oc->stobj->priv2);
......@@ -455,7 +456,7 @@ smp_oc_getobj(struct worker *wrk, struct objcore *oc)
}
static void
smp_oc_updatemeta(struct worker *wrk, struct objcore *oc)
smp_oc_objupdatemeta(struct worker *wrk, struct objcore *oc)
{
struct object *o;
struct smp_seg *sg;
......@@ -463,7 +464,7 @@ smp_oc_updatemeta(struct worker *wrk, struct objcore *oc)
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
o = smp_oc_getobj(wrk, oc);
o = smp_oc_sml_getobj(wrk, oc);
AN(o);
CAST_OBJ_NOTNULL(sg, oc->stobj->priv, SMP_SEG_MAGIC);
......@@ -482,8 +483,8 @@ smp_oc_updatemeta(struct worker *wrk, struct objcore *oc)
}
}
static void __match_proto__(freeobj_f)
smp_oc_freeobj(struct worker *wrk, struct objcore *oc)
static void __match_proto__(objfree_f)
smp_oc_objfree(struct worker *wrk, struct objcore *oc)
{
struct smp_seg *sg;
struct smp_object *so;
......@@ -516,8 +517,8 @@ smp_oc_freeobj(struct worker *wrk, struct objcore *oc)
* Find the per-segment lru list for this object
*/
static struct lru * __match_proto__(getlru_f)
smp_oc_getlru(const struct objcore *oc)
static struct lru * __match_proto__(objgetlru_f)
smp_oc_objgetlru(const struct objcore *oc)
{
struct smp_seg *sg;
......@@ -526,10 +527,10 @@ smp_oc_getlru(const struct objcore *oc)
}
const struct storeobj_methods smp_oc_methods = {
.getobj = smp_oc_getobj,
.updatemeta = smp_oc_updatemeta,
.freeobj = smp_oc_freeobj,
.getlru = smp_oc_getlru,
.sml_getobj = smp_oc_sml_getobj,
.objupdatemeta = smp_oc_objupdatemeta,
.objfree = smp_oc_objfree,
.objgetlru = smp_oc_objgetlru,
};
/*--------------------------------------------------------------------*/
......
This diff is collapsed.
/*-
* 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.
*
* SML is a set of methods for simple stevedores which just do simple
* memory allocation and leave all the high-level stuff to SML.
*
*/
/* Object ------------------------------------------------------------*/
VTAILQ_HEAD(storagehead, storage);
struct object {
unsigned magic;
#define OBJECT_MAGIC 0x32851d42
struct storage *objstore;
char oa_vxid[4];
uint8_t *oa_vary;
uint8_t *oa_http;
uint8_t oa_flags[1];
char oa_gzipbits[32];
char oa_lastmodified[8];
struct storagehead list;
ssize_t len;
struct storage *esidata;
};
extern const struct storeobj_methods SML_methods;
struct object *SML_MkObject(const struct stevedore *, struct objcore *,
void *ptr);
storage_allocobj_f SML_allocobj;
......@@ -41,6 +41,7 @@
#include "cache/cache.h"
#include "storage/storage.h"
#include "storage/storage_simple.h"
static size_t smu_max = SIZE_MAX;
static MTX smu_mtx;
......@@ -161,7 +162,8 @@ const struct stevedore smu_stevedore = {
.alloc = smu_alloc,
.free = smu_free,
.trim = smu_trim,
.methods = &default_oc_methods,
.allocobj = SML_allocobj,
.methods = &SML_methods,
};
#endif /* HAVE_UMEM_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