43f4de
From 638561615c37e8eace986e268811335c12d1b6a1 Mon Sep 17 00:00:00 2001
43f4de
From: Mark Andrews <marka@isc.org>
43f4de
Date: Thu, 12 Dec 2019 20:41:44 +1100
43f4de
Subject: [PATCH] give zspill its own lock
43f4de
43f4de
(cherry picked from commit a52189e8e67a20097539fe3e6f7da4e4c01dc340)
43f4de
---
43f4de
 lib/dns/resolver.c | 45 +++++++++++++++++++++++++++++----------------
43f4de
 1 file changed, 29 insertions(+), 16 deletions(-)
43f4de
43f4de
diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c
43f4de
index 9f65c0596a..04367f82c6 100644
43f4de
--- a/lib/dns/resolver.c
43f4de
+++ b/lib/dns/resolver.c
43f4de
@@ -460,20 +460,21 @@ struct dns_resolver {
43f4de
 	isc_mutex_t			lock;
43f4de
 	isc_mutex_t			nlock;
43f4de
 	isc_mutex_t			primelock;
43f4de
+	isc_mutex_t			zspill_lock;
43f4de
 	dns_rdataclass_t		rdclass;
43f4de
 	isc_socketmgr_t *		socketmgr;
43f4de
 	isc_timermgr_t *		timermgr;
43f4de
 	isc_taskmgr_t *			taskmgr;
43f4de
 	dns_view_t *			view;
43f4de
-	bool			frozen;
43f4de
+	bool				frozen;
43f4de
 	unsigned int			options;
43f4de
 	dns_dispatchmgr_t *		dispatchmgr;
43f4de
 	dns_dispatchset_t *		dispatches4;
43f4de
-	bool			exclusivev4;
43f4de
+	bool				exclusivev4;
43f4de
 	dns_dispatchset_t *		dispatches6;
43f4de
 	isc_dscp_t			querydscp4;
43f4de
 	isc_dscp_t			querydscp6;
43f4de
-	bool			exclusivev6;
43f4de
+	bool				exclusivev6;
43f4de
 	unsigned int			nbuckets;
43f4de
 	fctxbucket_t *			buckets;
43f4de
 	zonebucket_t *			dbuckets;
43f4de
@@ -492,7 +493,7 @@ struct dns_resolver {
43f4de
 	unsigned int			spillatmax;
43f4de
 	unsigned int			spillatmin;
43f4de
 	isc_timer_t *			spillattimer;
43f4de
-	bool			zero_no_soa_ttl;
43f4de
+	bool				zero_no_soa_ttl;
43f4de
 	unsigned int			query_timeout;
43f4de
 	unsigned int			maxdepth;
43f4de
 	unsigned int			maxqueries;
43f4de
@@ -502,14 +503,16 @@ struct dns_resolver {
43f4de
 	unsigned int			retryinterval; /* in milliseconds */
43f4de
 	unsigned int			nonbackofftries;
43f4de
 
43f4de
+	/* Locked by lock. */
43f4de
+	unsigned int			zspill;		/* fetches-per-zone */
43f4de
+
43f4de
 	/* Locked by lock. */
43f4de
 	unsigned int			references;
43f4de
-	bool			exiting;
43f4de
+	bool				exiting;
43f4de
 	isc_eventlist_t			whenshutdown;
43f4de
 	unsigned int			activebuckets;
43f4de
-	bool			priming;
43f4de
+	bool				priming;
43f4de
 	unsigned int			spillat;	/* clients-per-query */
43f4de
-	unsigned int			zspill;		/* fetches-per-zone */
43f4de
 
43f4de
 	dns_badcache_t  * 		badcache;	 /* Bad cache. */
43f4de
 
43f4de
@@ -1257,7 +1260,7 @@ fcount_incr(fetchctx_t *fctx, bool force) {
43f4de
 	isc_result_t result = ISC_R_SUCCESS;
43f4de
 	zonebucket_t *dbucket;
43f4de
 	fctxcount_t *counter;
43f4de
-	unsigned int bucketnum, spill;
43f4de
+	unsigned int bucketnum;
43f4de
 
43f4de
 	REQUIRE(fctx != NULL);
43f4de
 	REQUIRE(fctx->res != NULL);
43f4de
@@ -1266,10 +1269,6 @@ fcount_incr(fetchctx_t *fctx, bool force) {
43f4de
 	bucketnum = dns_name_fullhash(&fctx->domain, false)
43f4de
 			% RES_DOMAIN_BUCKETS;
43f4de
 
43f4de
-	LOCK(&fctx->res->lock);
43f4de
-	spill = fctx->res->zspill;
43f4de
-	UNLOCK(&fctx->res->lock);
43f4de
-
43f4de
 	dbucket = &fctx->res->dbuckets[bucketnum];
43f4de
 
43f4de
 	LOCK(&dbucket->lock);
43f4de
@@ -1297,6 +1296,12 @@ fcount_incr(fetchctx_t *fctx, bool force) {
43f4de
 			ISC_LIST_APPEND(dbucket->list, counter, link);
43f4de
 		}
43f4de
 	} else {
43f4de
+		unsigned int spill;
43f4de
+
43f4de
+		LOCK(&fctx->res->zspill_lock);
43f4de
+		spill = fctx->res->zspill;
43f4de
+		UNLOCK(&fctx->res->zspill_lock);
43f4de
+
43f4de
 		if (!force && spill != 0 && counter->count >= spill) {
43f4de
 			counter->dropped++;
43f4de
 			fcount_logspill(fctx, counter);
43f4de
@@ -8811,6 +8816,7 @@ destroy(dns_resolver_t *res) {
43f4de
 
43f4de
 	INSIST(res->nfctx == 0);
43f4de
 
43f4de
+	DESTROYLOCK(&res->zspill_lock);
43f4de
 	DESTROYLOCK(&res->primelock);
43f4de
 	DESTROYLOCK(&res->nlock);
43f4de
 	DESTROYLOCK(&res->lock);
43f4de
@@ -9089,10 +9095,14 @@ dns_resolver_create(dns_view_t *view,
43f4de
 	if (result != ISC_R_SUCCESS)
43f4de
 		goto cleanup_nlock;
43f4de
 
43f4de
+	result = isc_mutex_init(&res->zspill_lock);
43f4de
+	if (result != ISC_R_SUCCESS)
43f4de
+		goto cleanup_primelock;
43f4de
+
43f4de
 	task = NULL;
43f4de
 	result = isc_task_create(taskmgr, 0, &task);
43f4de
 	if (result != ISC_R_SUCCESS)
43f4de
-		goto cleanup_primelock;
43f4de
+		goto cleanup_zspill_lock;
43f4de
 	isc_task_setname(task, "resolver_task", NULL);
43f4de
 
43f4de
 	result = isc_timer_create(timermgr, isc_timertype_inactive, NULL, NULL,
43f4de
@@ -9100,7 +9110,7 @@ dns_resolver_create(dns_view_t *view,
43f4de
 				  &res->spillattimer);
43f4de
 	isc_task_detach(&task);
43f4de
 	if (result != ISC_R_SUCCESS)
43f4de
-		goto cleanup_primelock;
43f4de
+		goto cleanup_zspill_lock;
43f4de
 
43f4de
 #if USE_ALGLOCK
43f4de
 	result = isc_rwlock_init(&res->alglock, 0, 0);
43f4de
@@ -9133,6 +9143,9 @@ dns_resolver_create(dns_view_t *view,
43f4de
 	isc_timer_detach(&res->spillattimer);
43f4de
 #endif
43f4de
 
43f4de
+ cleanup_zspill_lock:
43f4de
+	DESTROYLOCK(&res->zspill_lock);
43f4de
+
43f4de
  cleanup_primelock:
43f4de
 	DESTROYLOCK(&res->primelock);
43f4de
 
43f4de
@@ -10275,9 +10288,9 @@ dns_resolver_setfetchesperzone(dns_resolver_t *resolver, uint32_t clients)
43f4de
 {
43f4de
 	REQUIRE(VALID_RESOLVER(resolver));
43f4de
 
43f4de
-	LOCK(&resolver->lock);
43f4de
+	LOCK(&resolver->zspill_lock);
43f4de
 	resolver->zspill = clients;
43f4de
-	UNLOCK(&resolver->lock);
43f4de
+	UNLOCK(&resolver->zspill_lock);
43f4de
 }
43f4de
 
43f4de
 
43f4de
-- 
43f4de
2.21.0
43f4de