[master] bb4d86c Eliminate obj->exp and use the one we have on objcore instead.

Poul-Henning Kamp phk at FreeBSD.org
Thu Jun 26 17:03:03 CEST 2014


commit bb4d86cb62d5b2ea10b00d8bc0089ec068899594
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Jun 26 15:02:07 2014 +0000

    Eliminate obj->exp and use the one we have on objcore instead.
    
    Essentially identical to patch by Martin

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 9854cc8..554dc8f 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -613,8 +613,6 @@ struct object {
 
 	ssize_t			len;
 
-	struct exp		exp;
-
 	/* VCL only variables */
 	double			last_modified;
 
@@ -830,7 +828,7 @@ void BAN_Init(void);
 void BAN_Shutdown(void);
 void BAN_NewObjCore(struct objcore *oc);
 void BAN_DestroyObj(struct objcore *oc);
-int BAN_CheckObject(struct object *o, struct req *sp);
+int BAN_CheckObject(const struct object *o, struct req *sp);
 void BAN_Reload(const uint8_t *ban, unsigned len);
 struct ban *BAN_TailRef(void);
 void BAN_Compile(void);
@@ -932,9 +930,9 @@ void EXP_Clr(struct exp *e);
 double EXP_Ttl(const struct req *, const struct exp*);
 double EXP_When(const struct exp *exp);
 void EXP_Insert(struct objcore *oc);
-void EXP_Inject(struct objcore *oc, struct lru *lru, double when);
+void EXP_Inject(struct objcore *oc, struct lru *lru);
 void EXP_Init(void);
-void EXP_Rearm(struct object *o, double now, double ttl, double grace,
+void EXP_Rearm(struct objcore *, double now, double ttl, double grace,
     double keep);
 void EXP_Touch(struct objcore *oc, double now);
 int EXP_NukeOne(struct busyobj *, struct lru *lru);
diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index 99f2914..7bd3378 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -900,7 +900,7 @@ ban_evaluate(const uint8_t *bs, const struct http *objhttp,
  */
 
 static int
-ban_check_object(struct object *o, struct vsl_log *vsl,
+ban_check_object(const struct object *o, struct vsl_log *vsl,
     const struct http *req_http)
 {
 	struct ban *b;
@@ -964,13 +964,13 @@ ban_check_object(struct object *o, struct vsl_log *vsl,
 		oc->ban = NULL;
 		VSLb(vsl, SLT_ExpBan, "%u banned lookup", o->vxid);
 		VSC_C_main->bans_obj_killed++;
-		EXP_Rearm(o, o->exp.t_origin, 0, 0, 0);	// XXX fake now
+		EXP_Rearm(oc, oc->exp.t_origin, 0, 0, 0);	// XXX fake now
 		return (1);
 	}
 }
 
 int
-BAN_CheckObject(struct object *o, struct req *req)
+BAN_CheckObject(const struct object *o, struct req *req)
 {
 
 	return (ban_check_object(o, req->vsl, req->http) > 0);
@@ -1105,7 +1105,7 @@ ban_lurker_test_ban(struct worker *wrk, struct vsl_log *vsl, struct ban *bt,
 		}
 		if (i) {
 			VSLb(vsl, SLT_ExpBan, "%u banned by lurker", o->vxid);
-			EXP_Rearm(o, o->exp.t_origin, 0, 0, 0);	// XXX fake now
+			EXP_Rearm(oc, oc->exp.t_origin, 0, 0, 0); // XXX fake now
 			VSC_C_main->bans_lurker_obj_killed++;
 		}
 		(void)HSH_DerefObjCore(&wrk->stats, &oc);
diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c
index ae5ebc7..e03df79 100644
--- a/bin/varnishd/cache/cache_expire.c
+++ b/bin/varnishd/cache/cache_expire.c
@@ -130,7 +130,7 @@ exp_mail_it(struct objcore *oc)
  */
 
 void
-EXP_Inject(struct objcore *oc, struct lru *lru, double when)
+EXP_Inject(struct objcore *oc, struct lru *lru)
 {
 
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
@@ -143,7 +143,7 @@ EXP_Inject(struct objcore *oc, struct lru *lru, double when)
 	Lck_Lock(&lru->mtx);
 	lru->n_objcore++;
 	oc->exp_flags |= OC_EF_OFFLRU | OC_EF_INSERT | OC_EF_EXP;
-	oc->timer_when = when;
+	oc->timer_when = EXP_When(&oc->exp);
 	Lck_Unlock(&lru->mtx);
 
 	exp_mail_it(oc);
@@ -232,32 +232,29 @@ EXP_Touch(struct objcore *oc, double now)
  */
 
 void
-EXP_Rearm(struct object *o, double now, double ttl, double grace, double keep)
+EXP_Rearm(struct objcore *oc, double now, double ttl, double grace, double keep)
 {
-	struct objcore *oc;
 	struct lru *lru;
 	double when;
 
-	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
-	oc = o->objcore;
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	assert(oc->refcnt > 0);
 
 	AN(oc->exp_flags & OC_EF_EXP);
 
 	if (!isnan(ttl))
-		o->exp.ttl = now + ttl - o->exp.t_origin;
+		oc->exp.ttl = now + ttl - oc->exp.t_origin;
 	if (!isnan(grace))
-		o->exp.grace = grace;
+		oc->exp.grace = grace;
 	if (!isnan(keep))
-		o->exp.keep = keep;
+		oc->exp.keep = keep;
 
-	when = EXP_When(&o->exp);
+	when = EXP_When(&oc->exp);
 
 	VSL(SLT_ExpKill, 0, "EXP_Rearm p=%p E=%.9f e=%.9f f=0x%x", oc,
 	    oc->timer_when, when, oc->flags);
 
-	if (when > o->exp.t_origin && when > oc->timer_when)
+	if (when > oc->exp.t_origin && when > oc->timer_when)
 		return;
 
 	lru = oc_getlru(oc);
@@ -400,7 +397,7 @@ exp_inbox(struct exp_priv *ep, struct objcore *oc, double now)
 	if (flags & OC_EF_MOVE) {
 		o = oc_getobj(&ep->wrk->stats, oc);
 		CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
-		oc->timer_when = EXP_When(&o->exp);
+		oc->timer_when = EXP_When(&oc->exp);
 		oc_updatemeta(oc);
 	}
 
@@ -477,7 +474,7 @@ exp_expire(struct exp_priv *ep, double now)
 	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 	VSLb(&ep->vsl, SLT_ExpKill, "EXP_Expired x=%u t=%.0f",
 	    oc_getxid(&ep->wrk->stats, oc) & VSL_IDENTMASK,
-	    EXP_Ttl(NULL, &o->exp) - now);
+	    EXP_Ttl(NULL, &oc->exp) - now);
 	(void)HSH_DerefObjCore(&ep->wrk->stats, &oc);
 	return (0);
 }
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 1b824d5..8c9acbc 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -562,7 +562,8 @@ 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)
-		EXP_Rearm(bo->ims_obj, bo->ims_obj->exp.t_origin, 0, 0, 0);
+		EXP_Rearm(bo->ims_obj->objcore,
+		    bo->ims_obj->objcore->exp.t_origin, 0, 0, 0);
 	return (F_STP_DONE);
 }
 
@@ -652,7 +653,8 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
 
 	assert(al == bo->ims_obj->len);
 	assert(obj->len == al);
-	EXP_Rearm(bo->ims_obj, bo->ims_obj->exp.t_origin, 0, 0, 0);
+	EXP_Rearm(bo->ims_obj->objcore,
+	    bo->ims_obj->objcore->exp.t_origin, 0, 0, 0);
 
 	/* Recycle the backend connection before setting BOS_FINISHED to
 	   give predictable backend reuse behavior for varnishtest */
@@ -757,7 +759,8 @@ vbf_stp_fail(struct worker *wrk, struct busyobj *bo)
 	if (bo->fetch_objcore->exp_flags & OC_EF_EXP) {
 		/* Already unbusied - expire it */
 		AN(bo->fetch_obj);
-		EXP_Rearm(bo->fetch_obj, bo->fetch_obj->exp.t_origin, 0, 0, 0);
+		EXP_Rearm(bo->fetch_objcore,
+		    bo->fetch_objcore->exp.t_origin, 0, 0, 0);
 	}
 	wrk->stats.fetch_failed++;
 	VBO_setstate(bo, BOS_FAILED);
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index d6e404c..f03d901 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -420,17 +420,18 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
 			continue;
 		}
 
+		if (oc->exp.ttl <= 0.)
+			continue;
+
 		o = oc_getobj(&wrk->stats, oc);
 		CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 
-		if (o->exp.ttl <= 0.)
-			continue;
 		if (BAN_CheckObject(o, req))
 			continue;
 		if (o->vary != NULL && !VRY_Match(req, o->vary))
 			continue;
 
-		if (EXP_Ttl(req, &o->exp) >= req->t_req) {
+		if (EXP_Ttl(req, &oc->exp) >= req->t_req) {
 			/* If still valid, use it */
 			assert(oh->refcnt > 1);
 			assert(oc->objhead == oh);
@@ -442,12 +443,12 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
 			*ocp = oc;
 			return (HSH_HIT);
 		}
-		if (o->exp.t_origin > exp_t_origin &&
+		if (oc->exp.t_origin > exp_t_origin &&
 		    !(oc->flags & OC_F_PASS)) {
 			/* record the newest object */
 			exp_oc = oc;
 			exp_o = o;
-			exp_t_origin = o->exp.t_origin;
+			exp_t_origin = oc->exp.t_origin;
 		}
 	}
 
@@ -560,7 +561,6 @@ double keep)
 {
 	struct objcore *oc, **ocp;
 	unsigned spc, nobj, n;
-	struct object *o;
 	double now;
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
@@ -595,12 +595,8 @@ double keep)
 	for (n = 0; n < nobj; n++) {
 		oc = ocp[n];
 		CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
-		o = oc_getobj(&wrk->stats, oc);
-		if (o == NULL)
-			continue;
-		CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
-		EXP_Rearm(o, now, ttl, grace, keep);
-		(void)HSH_DerefObj(&wrk->stats, &o);
+		EXP_Rearm(oc, now, ttl, grace, keep);
+		(void)HSH_DerefObjCore(&wrk->stats, &oc);
 	}
 	WS_Release(wrk->aws, 0);
 	Pool_PurgeStat(nobj);
@@ -618,7 +614,7 @@ HSH_Drop(struct worker *wrk, struct object **oo)
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	AN(oo);
 	CHECK_OBJ_NOTNULL(*oo, OBJECT_MAGIC);
-	(*oo)->exp.ttl = -1.;
+	(*oo)->objcore->exp.ttl = -1.;
 	AZ(HSH_DerefObj(&wrk->stats, oo));
 }
 
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 401ebf1..bc5ffc2 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -121,7 +121,7 @@ cnt_deliver(struct worker *wrk, struct req *req)
 	   age. Truncate to zero in that case).
 	*/
 	http_PrintfHeader(req->resp, "Age: %.0f",
-	    fmax(0., req->t_prev - req->obj->exp.t_origin));
+	    fmax(0., req->t_prev - req->obj->objcore->exp.t_origin));
 
 	http_SetHeader(req->resp, "Via: 1.1 varnish-v4");
 
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 9533f75..28b131f 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -481,10 +481,10 @@ VRT_r_##which##_##fld(const struct vrt_ctx *ctx)		\
 	return(0.0);						\
 }
 
-VRT_DO_EXP_R(obj, ctx->req->obj->exp, ttl,
-   (ctx->req->t_req - ctx->req->obj->exp.t_origin))
-VRT_DO_EXP_R(obj, ctx->req->obj->exp, grace, 0)
-VRT_DO_EXP_R(obj, ctx->req->obj->exp, keep, 0)
+VRT_DO_EXP_R(obj, ctx->req->obj->objcore->exp, ttl,
+   (ctx->req->t_req - ctx->req->obj->objcore->exp.t_origin))
+VRT_DO_EXP_R(obj, ctx->req->obj->objcore->exp, grace, 0)
+VRT_DO_EXP_R(obj, ctx->req->obj->objcore->exp, keep, 0)
 
 VRT_DO_EXP_L(beresp, ctx->bo->fetch_objcore->exp, ttl)
 VRT_DO_EXP_R(beresp, ctx->bo->fetch_objcore->exp, ttl, 0)
diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index ce9c007..413f228 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -286,7 +286,6 @@ STV_MkObject(struct stevedore *stv, struct busyobj *bo,
 
 	HTTP_Setup(o->http, bo->ws_o, bo->vsl, SLT_ObjMethod);
 	o->http->magic = HTTP_MAGIC;
-	o->exp = bo->fetch_objcore->exp;
 	VTAILQ_INIT(&o->store);
 
 	o->objcore = bo->fetch_objcore;
diff --git a/bin/varnishd/storage/storage_persistent_silo.c b/bin/varnishd/storage/storage_persistent_silo.c
index 5627f3f..e470b1a 100644
--- a/bin/varnishd/storage/storage_persistent_silo.c
+++ b/bin/varnishd/storage/storage_persistent_silo.c
@@ -157,7 +157,8 @@ smp_load_seg(struct worker *wrk, const struct smp_sc *sc,
 		smp_init_oc(oc, sg, no);
 		oc->ban = BAN_RefBan(oc, so->ban, sc->tailban);
 		HSH_Insert(wrk, so->hash, oc);
-		EXP_Inject(oc, sg->lru, EXP_When(&so->exp));
+		oc->exp = so->exp;
+		EXP_Inject(oc, sg->lru);
 		sg->nobj++;
 	}
 	Pool_Sumstat(wrk);
@@ -462,7 +463,7 @@ smp_oc_getobj(struct dstat *ds, struct objcore *oc)
 			bad |= 0x100;
 
 		if(bad) {
-			o->exp.ttl = -1;
+			EXP_Clr(&oc->exp);
 			EXP_Clr(&so->exp);
 		}
 
@@ -472,7 +473,7 @@ smp_oc_getobj(struct dstat *ds, struct objcore *oc)
 		oc->flags &= ~OC_F_NEEDFIXUP;
 	}
 	Lck_Unlock(&sg->sc->mtx);
-	EXP_Rearm(o, NAN, NAN, NAN, NAN);	// XXX: Shouldn't be needed
+	EXP_Rearm(oc, NAN, NAN, NAN, NAN);	// XXX: Shouldn't be needed
 	return (o);
 }
 
@@ -495,11 +496,11 @@ smp_oc_updatemeta(struct objcore *oc)
 		/* Lock necessary, we might race close_seg */
 		Lck_Lock(&sg->sc->mtx);
 		so->ban = BAN_Time(oc->ban);
-		so->exp = o->exp;;
+		so->exp = oc->exp;
 		Lck_Unlock(&sg->sc->mtx);
 	} else {
 		so->ban = BAN_Time(oc->ban);
-		so->exp = o->exp;;
+		so->exp = oc->exp;
 	}
 }
 
diff --git a/bin/varnishtest/tests/p00000.vtc b/bin/varnishtest/tests/p00000.vtc
index eb9d29d..9e68fcd 100644
--- a/bin/varnishtest/tests/p00000.vtc
+++ b/bin/varnishtest/tests/p00000.vtc
@@ -3,6 +3,9 @@ varnishtest "Test Basic persistence"
 server s1 {
 	rxreq
 	txresp
+	accept
+	rxreq
+	txresp -status 700
 } -start
 
 shell "rm -f ${tmpdir}/_.per"



More information about the varnish-commit mailing list