[master] 96bdcca Add oc_methods to struct stevedore, and pull them from there.
Poul-Henning Kamp
phk at FreeBSD.org
Mon Jun 30 10:14:35 CEST 2014
commit 96bdccae881d2d57136674c1e9920ed581c12f4b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Jun 30 07:48:55 2014 +0000
Add oc_methods to struct stevedore, and pull them from there.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index c4c20a1..55377d2 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -418,8 +418,8 @@ struct objcore {
unsigned magic;
#define OBJCORE_MAGIC 0x4d301302
int refcnt;
- struct stevedore *stevedore;
- struct objcore_methods *methods;
+ const struct stevedore *stevedore;
+ const struct objcore_methods *methods;
void *priv;
uintptr_t priv2;
struct objhead *objhead;
@@ -1100,6 +1100,7 @@ enum objiter_status {
struct objiter *ObjIterBegin(struct worker *, struct object *);
enum objiter_status ObjIter(struct objiter *, void **, ssize_t *);
void ObjIterEnd(struct objiter **);
+void ObjTrimStore(struct objcore *oc, struct dstat *ds);
/* cache_panic.c */
void PAN_Init(void);
diff --git a/bin/varnishd/cache/cache_fetch_proc.c b/bin/varnishd/cache/cache_fetch_proc.c
index 429052d..0666c45 100644
--- a/bin/varnishd/cache/cache_fetch_proc.c
+++ b/bin/varnishd/cache/cache_fetch_proc.c
@@ -245,21 +245,8 @@ VFP_Fetch_Body(struct busyobj *bo, ssize_t est)
vfp_suck_fini(bo);
- /*
- * Trim or delete the last segment, if any
- */
-
- st = VTAILQ_LAST(&bo->fetch_obj->store, storagehead);
- /* XXX: Temporary: Only trim if we are not streaming */
- if (st != NULL && !bo->do_stream) {
- /* None of this this is safe under streaming */
- if (st->len == 0) {
- VTAILQ_REMOVE(&bo->fetch_obj->store, st, list);
- STV_free(st);
- } else if (st->len < st->space) {
- STV_trim(st, st->len, 1);
- }
- }
+ if (!bo->do_stream)
+ ObjTrimStore(bo->fetch_objcore, bo->stats);
}
void
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index a92d29f..038a751 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -31,6 +31,7 @@
#include <stdlib.h>
#include "cache.h"
+#include "storage/storage.h"
#include "hash/hash_slinger.h"
struct objiter {
@@ -133,3 +134,26 @@ ObjIterEnd(struct objiter **oi)
FREE_OBJ((*oi));
*oi = NULL;
}
+
+void
+ObjTrimStore(struct objcore *oc, struct dstat *ds)
+{
+ const struct stevedore *stv;
+ struct storage *st;
+ struct object *o;
+
+ CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+ stv = oc->stevedore;
+ CHECK_OBJ_NOTNULL(stv, STEVEDORE_MAGIC);
+ o = oc_getobj(ds, oc);
+ CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
+ st = VTAILQ_LAST(&o->store, storagehead);
+ if (st == NULL)
+ return;
+ if (st->len == 0) {
+ VTAILQ_REMOVE(&o->store, st, list);
+ STV_free(st);
+ } else if (st->len < st->space) {
+ STV_trim(st, st->len, 1);
+ }
+}
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 575d049..7294439 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -42,7 +42,7 @@
#include "common/heritage.h"
#include "cache_backend.h"
-#include "waiter/waiter.h"
+#include "storage/storage.h"
#include "vcl.h"
/*
@@ -235,6 +235,14 @@ pan_objcore(const char *typ, const struct objcore *oc)
VSB_printf(pan_vsp, " refcnt = %d\n", oc->refcnt);
VSB_printf(pan_vsp, " flags = 0x%x\n", oc->flags);
VSB_printf(pan_vsp, " objhead = %p\n", oc->objhead);
+ VSB_printf(pan_vsp, " stevedore = %p", oc->stevedore);
+ if (oc->stevedore != NULL) {
+ VSB_printf(pan_vsp, " (%s", oc->stevedore->name);
+ if (strlen(oc->stevedore->ident))
+ VSB_printf(pan_vsp, " %s", oc->stevedore->ident);
+ VSB_printf(pan_vsp, ")");
+ }
+ VSB_printf(pan_vsp, "\n");
VSB_printf(pan_vsp, " }\n");
}
diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index 35f362a..a20c58b 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -95,14 +95,13 @@ default_oc_getlru(const struct objcore *oc)
return (stv->lru);
}
-static struct objcore_methods default_oc_methods = {
+const struct objcore_methods default_oc_methods = {
.getobj = default_oc_getobj,
.getxid = default_oc_getxid,
.freeobj = default_oc_freeobj,
.getlru = default_oc_getlru,
};
-
/*--------------------------------------------------------------------
*/
@@ -291,7 +290,8 @@ STV_MkObject(struct stevedore *stv, struct busyobj *bo,
o->objcore = bo->fetch_objcore;
o->objcore->stevedore = stv;
- o->objcore->methods = &default_oc_methods;
+ AN(stv->methods);
+ o->objcore->methods = stv->methods;
o->objcore->priv = o;
o->objcore->priv2 = (uintptr_t)stv;
VSLb(bo->vsl, SLT_Storage, "%s %s", stv->name, stv->ident);
@@ -385,6 +385,8 @@ STV_NewObject(struct busyobj *bo, const char *hint,
CHECK_OBJ_NOTNULL(o->objstore, STORAGE_MAGIC);
CHECK_OBJ_NOTNULL(o->objcore, OBJCORE_MAGIC);
assert(o->objcore->stevedore == stv);
+ AN(stv->methods);
+ AN(o->objcore->methods);
return (o);
}
diff --git a/bin/varnishd/storage/storage.h b/bin/varnishd/storage/storage.h
index 47fabad..29531b0 100644
--- a/bin/varnishd/storage/storage.h
+++ b/bin/varnishd/storage/storage.h
@@ -60,6 +60,8 @@ typedef void storage_banexport_f(const struct stevedore *, const uint8_t *bans,
extern storage_allocobj_f stv_default_allocobj;
+extern const struct objcore_methods default_oc_methods;
+
/*--------------------------------------------------------------------*/
struct stevedore {
@@ -78,6 +80,9 @@ struct stevedore {
storage_baninfo_f *baninfo; /* --//-- */
storage_banexport_f *banexport; /* --//-- */
+ const struct objcore_methods
+ *methods;
+
struct lru *lru;
#define VRTSTVVAR(nm, vtype, ctype, dval) storage_var_##ctype *var_##nm;
diff --git a/bin/varnishd/storage/storage_file.c b/bin/varnishd/storage/storage_file.c
index c48200c..3d0e006 100644
--- a/bin/varnishd/storage/storage_file.c
+++ b/bin/varnishd/storage/storage_file.c
@@ -541,13 +541,14 @@ smf_free(struct storage *s)
/*--------------------------------------------------------------------*/
const struct stevedore smf_stevedore = {
- .magic = STEVEDORE_MAGIC,
- .name = "file",
- .init = smf_init,
- .open = smf_open,
- .alloc = smf_alloc,
- .trim = smf_trim,
- .free = smf_free,
+ .magic = STEVEDORE_MAGIC,
+ .name = "file",
+ .init = smf_init,
+ .open = smf_open,
+ .alloc = smf_alloc,
+ .trim = smf_trim,
+ .free = smf_free,
+ .methods = &default_oc_methods,
};
#ifdef INCLUDE_TEST_DRIVER
diff --git a/bin/varnishd/storage/storage_malloc.c b/bin/varnishd/storage/storage_malloc.c
index adb6cd2..9549281 100644
--- a/bin/varnishd/storage/storage_malloc.c
+++ b/bin/varnishd/storage/storage_malloc.c
@@ -245,13 +245,14 @@ sma_open(const struct stevedore *st)
}
const struct stevedore sma_stevedore = {
- .magic = STEVEDORE_MAGIC,
- .name = "malloc",
- .init = sma_init,
- .open = sma_open,
- .alloc = sma_alloc,
- .free = sma_free,
- .trim = sma_trim,
+ .magic = STEVEDORE_MAGIC,
+ .name = "malloc",
+ .init = sma_init,
+ .open = sma_open,
+ .alloc = sma_alloc,
+ .free = sma_free,
+ .trim = sma_trim,
+ .methods = &default_oc_methods,
.var_free_space = sma_free_space,
.var_used_space = sma_used_space,
};
diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index 008afe7..a22e126 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -535,6 +535,8 @@ smp_allocobj(struct stevedore *stv, struct busyobj *bo,
ltot = st->len = st->space;
o = STV_MkObject(stv, bo, st->ptr, ltot, soc);
+ AN(bo->fetch_objcore->stevedore);
+ assert(bo->fetch_objcore->stevedore == stv);
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
o->objstore = st;
bo->stats->n_object++;
@@ -601,6 +603,7 @@ const struct stevedore smp_stevedore = {
.signal_close = smp_signal_close,
.baninfo = smp_baninfo,
.banexport = smp_banexport,
+ .methods = &smp_oc_methods,
};
/*--------------------------------------------------------------------
diff --git a/bin/varnishd/storage/storage_persistent.h b/bin/varnishd/storage/storage_persistent.h
index 2d46297..7d423e1 100644
--- a/bin/varnishd/storage/storage_persistent.h
+++ b/bin/varnishd/storage/storage_persistent.h
@@ -310,6 +310,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 objcore_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 e470b1a..c0180d8 100644
--- a/bin/varnishd/storage/storage_persistent_silo.c
+++ b/bin/varnishd/storage/storage_persistent_silo.c
@@ -154,6 +154,8 @@ smp_load_seg(struct worker *wrk, const struct smp_sc *sc,
AN(oc);
oc->flags |= OC_F_NEEDFIXUP;
oc->flags &= ~OC_F_BUSY;
+ oc->stevedore = sc->parent;
+ oc->methods = sc->parent->methods;
smp_init_oc(oc, sg, no);
oc->ban = BAN_RefBan(oc, so->ban, sc->tailban);
HSH_Insert(wrk, so->hash, oc);
@@ -546,7 +548,7 @@ smp_oc_getlru(const struct objcore *oc)
return (sg->lru);
}
-static struct objcore_methods smp_oc_methods = {
+const struct objcore_methods smp_oc_methods = {
.getxid = smp_oc_getxid,
.getobj = smp_oc_getobj,
.updatemeta = smp_oc_updatemeta,
@@ -562,5 +564,4 @@ smp_init_oc(struct objcore *oc, struct smp_seg *sg, unsigned objidx)
oc->priv = sg;
oc->priv2 = objidx;
- oc->methods = &smp_oc_methods;
}
diff --git a/bin/varnishd/storage/storage_umem.c b/bin/varnishd/storage/storage_umem.c
index 52d238d..1e93598 100644
--- a/bin/varnishd/storage/storage_umem.c
+++ b/bin/varnishd/storage/storage_umem.c
@@ -154,13 +154,14 @@ smu_open(const struct stevedore *st)
}
const struct stevedore smu_stevedore = {
- .magic = STEVEDORE_MAGIC,
- .name = "umem",
- .init = smu_init,
- .open = smu_open,
- .alloc = smu_alloc,
- .free = smu_free,
- .trim = smu_trim,
+ .magic = STEVEDORE_MAGIC,
+ .name = "umem",
+ .init = smu_init,
+ .open = smu_open,
+ .alloc = smu_alloc,
+ .free = smu_free,
+ .trim = smu_trim,
+ .methods = &default_oc_methods,
};
#endif /* HAVE_UMEM_H */
More information about the varnish-commit
mailing list