[master] 4fdc58e Implement a first erzats version of ObjGetattr()

Poul-Henning Kamp phk at FreeBSD.org
Wed Jul 30 11:34:59 CEST 2014


commit 4fdc58eed9fe491b0532c8a30f479680ef682eda
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Jul 30 09:34:27 2014 +0000

    Implement a first erzats version of ObjGetattr()

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index c142c07..38fff60 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -374,14 +374,12 @@ struct storage {
  */
 
 typedef struct object *getobj_f(struct dstat *ds, struct objcore *oc);
-typedef unsigned getxid_f(struct dstat *ds, struct objcore *oc);
 typedef void updatemeta_f(struct objcore *oc);
 typedef void freeobj_f(struct dstat *ds, struct objcore *oc);
 typedef struct lru *getlru_f(const struct objcore *oc);
 
 struct objcore_methods {
 	getobj_f	*getobj;
-	getxid_f	*getxid;
 	updatemeta_f	*updatemeta;
 	freeobj_f	*freeobj;
 	getlru_f	*getlru;
@@ -547,6 +545,12 @@ struct body {
 	struct storagehead	list;
 };
 
+enum obj_attr {
+#define OBJ_ATTR(U, l)	OA_##U,
+#include "tbl/obj_attr.h"
+#undef OBJ_ATTR
+};
+
 struct object {
 	unsigned		magic;
 #define OBJECT_MAGIC		0x32851d42
@@ -1055,6 +1059,8 @@ struct object *ObjGetObj(struct objcore *, struct dstat *);
 void ObjUpdateMeta(struct objcore *);
 void ObjFreeObj(struct objcore *, struct dstat *);
 struct lru *ObjGetLRU(const struct objcore *);
+ssize_t ObjGetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr,
+    void *ptr, ssize_t len);
 
 /* cache_panic.c */
 void PAN_Init(void);
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index f6c93c7..df5b906 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -544,7 +544,7 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 
 	VBO_setstate(bo, BOS_FINISHED);
 	VSLb_ts_busyobj(bo, "BerespBody", W_TIM_real(wrk));
-	if (bo->ims_obj != NULL)
+	if (bo->ims_oc != NULL)
 		EXP_Rearm(bo->ims_oc, bo->ims_oc->exp.t_origin, 0, 0, 0);
 	return (F_STP_DONE);
 }
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index ba0979b..b138fd1 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -172,15 +172,6 @@ ObjTrimStore(struct objcore *oc, struct dstat *ds)
 	}
 }
 
-unsigned
-ObjGetXID(struct objcore *oc, struct dstat *ds)
-{
-	const struct objcore_methods *m = obj_getmethods(oc);
-
-	AN(ds);
-	AN(m->getxid);
-	return (m->getxid(ds, oc));
-}
 
 struct object *
 ObjGetObj(struct objcore *oc, struct dstat *ds)
@@ -221,3 +212,32 @@ ObjGetLRU(const struct objcore *oc)
 	AN(m->getlru);
 	return (m->getlru(oc));
 }
+
+ssize_t
+ObjGetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr,
+    void *ptr, ssize_t len)
+{
+	struct object *o;
+
+	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+	o = ObjGetObj(oc, ds);
+	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
+	switch (attr) {
+	case OA_VXID:
+		assert(len == sizeof o->vxid);
+		memcpy(ptr, &o->vxid, sizeof o->vxid);
+		return (sizeof o->vxid);
+	default:
+		break;
+	}
+	WRONG("Unsupported OBJ_ATTR");
+}
+
+unsigned
+ObjGetXID(struct objcore *oc, struct dstat *ds)
+{
+	uint32_t u;
+
+	assert(ObjGetattr(oc, ds, OA_VXID, &u, sizeof u) == sizeof u);
+	return (u);
+}
diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index ad2106b..751c0a3 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -48,15 +48,6 @@ static const struct stevedore * volatile stv_next;
  * Default objcore methods
  */
 
-static unsigned __match_proto__(getxid_f)
-default_oc_getxid(struct dstat *ds, struct objcore *oc)
-{
-	struct object *o;
-
-	o = ObjGetObj(oc, ds);
-	return (o->vxid);
-}
-
 static struct object * __match_proto__(getobj_f)
 default_oc_getobj(struct dstat *ds, struct objcore *oc)
 {
@@ -97,7 +88,6 @@ default_oc_getlru(const struct objcore *oc)
 
 const struct objcore_methods default_oc_methods = {
 	.getobj = default_oc_getobj,
-	.getxid = default_oc_getxid,
 	.freeobj = default_oc_freeobj,
 	.getlru = default_oc_getlru,
 };
diff --git a/bin/varnishd/storage/storage_persistent_silo.c b/bin/varnishd/storage/storage_persistent_silo.c
index 9e747ce..ba56ddc 100644
--- a/bin/varnishd/storage/storage_persistent_silo.c
+++ b/bin/varnishd/storage/storage_persistent_silo.c
@@ -379,35 +379,6 @@ smp_loaded_st(const struct smp_sc *sc, const struct smp_seg *sg,
  * objcore methods for persistent objects
  */
 
-static unsigned __match_proto__(getxid_f)
-smp_oc_getxid(struct dstat *ds, struct objcore *oc)
-{
-	struct object *o;
-	struct smp_seg *sg;
-	struct smp_object *so;
-
-	(void)ds;
-	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
-
-	CAST_OBJ_NOTNULL(sg, oc->priv, SMP_SEG_MAGIC);
-	so = smp_find_so(sg, oc->priv2);
-
-	o = (void*)(sg->sc->base + so->ptr);
-	/*
-	 * The object may not be in this segment since we allocate it
-	 * In a separate operation than the smp_object.  We could check
-	 * that it is in a later segment, but that would be complicated.
-	 * XXX: For now, be happy if it is inside th silo
-	 */
-	ASSERT_PTR_IN_SILO(sg->sc, o);
-	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
-	return (o->vxid);
-}
-
-/*---------------------------------------------------------------------
- * objcore methods for persistent objects
- */
-
 static struct object *
 smp_oc_getobj(struct dstat *ds, struct objcore *oc)
 {
@@ -548,7 +519,6 @@ smp_oc_getlru(const struct objcore *oc)
 }
 
 const struct objcore_methods smp_oc_methods = {
-	.getxid =		smp_oc_getxid,
 	.getobj =		smp_oc_getobj,
 	.updatemeta =		smp_oc_updatemeta,
 	.freeobj =		smp_oc_freeobj,



More information about the varnish-commit mailing list