[master] e534b4b Collapse signal_close and close into just one stevedore method.

Poul-Henning Kamp phk at FreeBSD.org
Tue Feb 9 12:26:15 CET 2016


commit e534b4bc82468b1fef14c0e80411cc297ebc21a1
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Feb 9 11:18:11 2016 +0000

    Collapse signal_close and close into just one stevedore method.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index eb16777..e87eaa3 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -1078,8 +1078,6 @@ void RFC2616_Vary_AE(struct http *hp);
 /* stevedore.c */
 int STV_NewObject(struct worker *, struct objcore *,
     const char *hint, unsigned len);
-void STV_open(void);
-void STV_close(void);
 
 /*
  * A normal pointer difference is signed, but we never want a negative value
diff --git a/bin/varnishd/cache/cache_priv.h b/bin/varnishd/cache/cache_priv.h
index 3f64c8e..181f739 100644
--- a/bin/varnishd/cache/cache_priv.h
+++ b/bin/varnishd/cache/cache_priv.h
@@ -132,6 +132,8 @@ void VRTPRIV_dynamic_kill(struct vrt_privs *privs, uintptr_t id);
 void VMOD_Init(void);
 
 /* stevedore.c */
+void STV_open(void);
+void STV_close(void);
 int STV_BanInfoDrop(const uint8_t *ban, unsigned len);
 int STV_BanInfoNew(const uint8_t *ban, unsigned len);
 void STV_BanExport(const uint8_t *banlist, unsigned len);
diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index a7648ec..2ce76dd 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -127,6 +127,7 @@ STV_open(void)
 {
 	struct stevedore *stv;
 
+	ASSERT_CLI();
 	VTAILQ_FOREACH(stv, &stv_stevedores, list) {
 		if (stv->open != NULL)
 			stv->open(stv);
@@ -141,22 +142,19 @@ void
 STV_close(void)
 {
 	struct stevedore *stv;
-
-	/* Signal intent to close */
-	VTAILQ_FOREACH(stv, &stv_stevedores, list)
-		if (stv->signal_close != NULL)
-			stv->signal_close(stv);
-	stv = stv_transient;
-	if (stv->signal_close != NULL)
-		stv->signal_close(stv);
-
-	/* Close each in turn */
-	VTAILQ_FOREACH(stv, &stv_stevedores, list)
+	int i;
+
+	ASSERT_CLI();
+	for (i = 1; i >= 0; i--) {
+		/* First send close warning */
+		VTAILQ_FOREACH(stv, &stv_stevedores, list)
+			if (stv->close != NULL)
+				stv->close(stv, i);
+		stv = stv_transient;
 		if (stv->close != NULL)
-			stv->close(stv);
-	stv = stv_transient;
-	if (stv->close != NULL)
-		stv->close(stv);
+			if (stv->close != NULL)
+				stv->close(stv, i);
+	}
 }
 
 /*-------------------------------------------------------------------
diff --git a/bin/varnishd/storage/storage.h b/bin/varnishd/storage/storage.h
index 462c74c..b17440f 100644
--- a/bin/varnishd/storage/storage.h
+++ b/bin/varnishd/storage/storage.h
@@ -66,8 +66,7 @@ typedef void storage_init_f(struct stevedore *, int ac, char * const *av);
 typedef void storage_open_f(struct stevedore *);
 typedef int storage_allocobj_f(struct worker *, const struct stevedore *,
     struct objcore *, unsigned ltot, int really);
-typedef void storage_close_f(const struct stevedore *);
-typedef void storage_signal_close_f(const struct stevedore *);
+typedef void storage_close_f(const struct stevedore *, int pass);
 typedef int storage_baninfo_f(const struct stevedore *, enum baninfo event,
     const uint8_t *ban, unsigned len);
 typedef void storage_banexport_f(const struct stevedore *, const uint8_t *bans,
@@ -96,7 +95,6 @@ struct stevedore {
 	storage_open_f		*open;
 	storage_close_f		*close;
 	storage_allocobj_f	*allocobj;
-	storage_signal_close_f	*signal_close;
 	storage_baninfo_f	*baninfo;
 	storage_banexport_f	*banexport;
 
diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index ba1a450..d52c2cc 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -387,24 +387,8 @@ smp_open(struct stevedore *st)
  * Close a silo
  */
 
-static void
-smp_signal_close(const struct stevedore *st)
-{
-	struct smp_sc	*sc;
-
-	ASSERT_CLI();
-
-	CAST_OBJ_NOTNULL(sc, st->priv, SMP_SC_MAGIC);
-	Lck_Lock(&sc->mtx);
-	if (sc->cur_seg != NULL)
-		smp_close_seg(sc, sc->cur_seg);
-	AZ(sc->cur_seg);
-	sc->flags |= SMP_SC_STOP;
-	Lck_Unlock(&sc->mtx);
-}
-
-static void
-smp_close(const struct stevedore *st)
+static void __match_proto__(storage_close_f)
+smp_close(const struct stevedore *st, int warn)
 {
 	struct smp_sc	*sc;
 	void *status;
@@ -412,9 +396,17 @@ smp_close(const struct stevedore *st)
 	ASSERT_CLI();
 
 	CAST_OBJ_NOTNULL(sc, st->priv, SMP_SC_MAGIC);
-
-	AZ(pthread_join(sc->bgthread, &status));
-	AZ(status);
+	if (warn) {
+		Lck_Lock(&sc->mtx);
+		if (sc->cur_seg != NULL)
+			smp_close_seg(sc, sc->cur_seg);
+		AZ(sc->cur_seg);
+		sc->flags |= SMP_SC_STOP;
+		Lck_Unlock(&sc->mtx);
+	} else {
+		AZ(pthread_join(sc->bgthread, &status));
+		AZ(status);
+	}
 }
 
 /*--------------------------------------------------------------------
@@ -603,7 +595,6 @@ const struct stevedore smp_stevedore = {
 	.open		= smp_open,
 	.close		= smp_close,
 	.allocobj	= smp_allocobj,
-	.signal_close	= smp_signal_close,
 	.baninfo	= smp_baninfo,
 	.banexport	= smp_banexport,
 	.methods	= &smp_oc_realmethods,



More information about the varnish-commit mailing list