3f2a16
From b6320643194a3b435f2a6ae4569ace19db6ac795 Mon Sep 17 00:00:00 2001
3f2a16
From: =?UTF-8?q?Petr=20Men=C5=A1=C3=ADk?= <pemensik@redhat.com>
3f2a16
Date: Fri, 11 Feb 2022 14:19:10 +0100
3f2a16
Subject: [PATCH] Propagate extra hp threads to dyndb plugins
3f2a16
3f2a16
Plugin may require extra threads for processing its own source data. If
3f2a16
that plugin needs to call isc_task_send() from those threads, it needs
3f2a16
extra hp threads initialized. Allow plugin to read how many such threads
3f2a16
it can use. Allows plugin to fail initialization if not enough workers
3f2a16
were initialized.
3f2a16
---
3f2a16
 bin/named/server.c          |  9 +++++----
3f2a16
 lib/dns/dyndb.c             |  4 +++-
3f2a16
 lib/dns/include/dns/dyndb.h | 22 +++++++++++++---------
3f2a16
 3 files changed, 21 insertions(+), 14 deletions(-)
3f2a16
3f2a16
diff --git a/bin/named/server.c b/bin/named/server.c
3f2a16
index 721464db8e..27e23fd52e 100644
3f2a16
--- a/bin/named/server.c
3f2a16
+++ b/bin/named/server.c
3f2a16
@@ -5581,10 +5581,11 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config,
3f2a16
 
3f2a16
 		if (dctx == NULL) {
3f2a16
 			const void *hashinit = isc_hash_get_initializer();
3f2a16
-			CHECK(dns_dyndb_createctx(mctx, hashinit, named_g_lctx,
3f2a16
-						  view, named_g_server->zonemgr,
3f2a16
-						  named_g_server->task,
3f2a16
-						  named_g_timermgr, &dctx));
3f2a16
+			CHECK(dns_dyndb_createctx(
3f2a16
+				mctx, hashinit, named_g_lctx, view,
3f2a16
+				named_g_server->zonemgr, named_g_server->task,
3f2a16
+				named_g_timermgr, named_g_hp_extra_workers,
3f2a16
+				&dctx));
3f2a16
 		}
3f2a16
 
3f2a16
 		CHECK(configure_dyndb(dyndb, mctx, dctx));
3f2a16
diff --git a/lib/dns/dyndb.c b/lib/dns/dyndb.c
3f2a16
index 1caf90bab7..7d2784c5fa 100644
3f2a16
--- a/lib/dns/dyndb.c
3f2a16
+++ b/lib/dns/dyndb.c
3f2a16
@@ -408,7 +408,8 @@ dns_dyndb_cleanup(bool exiting) {
3f2a16
 isc_result_t
3f2a16
 dns_dyndb_createctx(isc_mem_t *mctx, const void *hashinit, isc_log_t *lctx,
3f2a16
 		    dns_view_t *view, dns_zonemgr_t *zmgr, isc_task_t *task,
3f2a16
-		    isc_timermgr_t *tmgr, dns_dyndbctx_t **dctxp) {
3f2a16
+		    isc_timermgr_t *tmgr, unsigned int extra_workers,
3f2a16
+		    dns_dyndbctx_t **dctxp) {
3f2a16
 	dns_dyndbctx_t *dctx;
3f2a16
 
3f2a16
 	REQUIRE(dctxp != NULL && *dctxp == NULL);
3f2a16
@@ -429,6 +430,7 @@ dns_dyndb_createctx(isc_mem_t *mctx, const void *hashinit, isc_log_t *lctx,
3f2a16
 	dctx->hashinit = hashinit;
3f2a16
 	dctx->lctx = lctx;
3f2a16
 	dctx->memdebug = &isc_mem_debugging;
3f2a16
+	dctx->extra_workers = extra_workers;
3f2a16
 
3f2a16
 	isc_mem_attach(mctx, &dctx->mctx);
3f2a16
 	dctx->magic = DNS_DYNDBCTX_MAGIC;
3f2a16
diff --git a/lib/dns/include/dns/dyndb.h b/lib/dns/include/dns/dyndb.h
3f2a16
index bda744a8d9..a93947d340 100644
3f2a16
--- a/lib/dns/include/dns/dyndb.h
3f2a16
+++ b/lib/dns/include/dns/dyndb.h
3f2a16
@@ -35,14 +35,15 @@ ISC_LANG_BEGINDECLS
3f2a16
  */
3f2a16
 struct dns_dyndbctx {
3f2a16
 	unsigned int	magic;
3f2a16
-	const void	   *hashinit;
3f2a16
-	isc_mem_t	  *mctx;
3f2a16
-	isc_log_t	  *lctx;
3f2a16
-	dns_view_t	   *view;
3f2a16
-	dns_zonemgr_t  *zmgr;
3f2a16
-	isc_task_t	   *task;
3f2a16
+	const void *	hashinit;
3f2a16
+	isc_mem_t *	mctx;
3f2a16
+	isc_log_t *	lctx;
3f2a16
+	dns_view_t *	view;
3f2a16
+	dns_zonemgr_t * zmgr;
3f2a16
+	isc_task_t *	task;
3f2a16
 	isc_timermgr_t *timermgr;
3f2a16
-	unsigned int   *memdebug;
3f2a16
+	unsigned int *	memdebug;
3f2a16
+	unsigned int	extra_workers;
3f2a16
 };
3f2a16
 
3f2a16
 #define DNS_DYNDBCTX_MAGIC    ISC_MAGIC('D', 'd', 'b', 'c')
3f2a16
@@ -58,7 +59,7 @@ struct dns_dyndbctx {
3f2a16
  */
3f2a16
 #ifndef DNS_DYNDB_VERSION
3f2a16
 #define DNS_DYNDB_VERSION 1
3f2a16
-#define DNS_DYNDB_AGE	  0
3f2a16
+#define DNS_DYNDB_AGE	  1
3f2a16
 #endif /* ifndef DNS_DYNDB_VERSION */
3f2a16
 
3f2a16
 typedef isc_result_t
3f2a16
@@ -135,7 +136,8 @@ dns_dyndb_cleanup(bool exiting);
3f2a16
 isc_result_t
3f2a16
 dns_dyndb_createctx(isc_mem_t *mctx, const void *hashinit, isc_log_t *lctx,
3f2a16
 		    dns_view_t *view, dns_zonemgr_t *zmgr, isc_task_t *task,
3f2a16
-		    isc_timermgr_t *tmgr, dns_dyndbctx_t **dctxp);
3f2a16
+		    isc_timermgr_t *tmgr, unsigned int extra_workers,
3f2a16
+		    dns_dyndbctx_t **dctxp);
3f2a16
 /*%
3f2a16
  * Create a dyndb initialization context structure, with
3f2a16
  * pointers to structures in the server that the dyndb module will
3f2a16
@@ -143,6 +145,8 @@ dns_dyndb_createctx(isc_mem_t *mctx, const void *hashinit, isc_log_t *lctx,
3f2a16
  * etc). This structure is expected to last only until all dyndb
3f2a16
  * modules have been loaded and initialized; after that it will be
3f2a16
  * destroyed with dns_dyndb_destroyctx().
3f2a16
+ * extra workers specifies how many extra worker threads can plugin
3f2a16
+ * use to send tasks to named threads by isc_task_send()
3f2a16
  *
3f2a16
  * Returns:
3f2a16
  *\li	#ISC_R_SUCCESS
3f2a16
-- 
3f2a16
2.34.1
3f2a16