258 lines
9.5 KiB
Diff
258 lines
9.5 KiB
Diff
From 0e98684fb9a4db555b92d5fd2c261f26e89dc16f Mon Sep 17 00:00:00 2001
|
|
From: Mark Reynolds <mreynolds@redhat.com>
|
|
Date: Mon, 2 Mar 2026 14:31:29 -0500
|
|
Subject: [PATCH 08/13] Issue 7271 - implement a pre-close plugin function
|
|
|
|
Description:
|
|
|
|
replication protocol could benefit from being notifioed the shutdown process
|
|
has started before calling the "close" plugin function. This would allow the
|
|
replication protocol to wake up and adjust its active thread count to prevent
|
|
a hang during shutdown.
|
|
|
|
relates: https://github.com/389ds/389-ds-base/issues/7271
|
|
|
|
Reviewed by: progier, spichugi, and vashirov(Thanks!!!)
|
|
---
|
|
ldap/servers/plugins/replication/repl5_init.c | 20 +++++++++++-----
|
|
ldap/servers/slapd/daemon.c | 6 ++++-
|
|
ldap/servers/slapd/pblock.c | 14 ++++++++++-
|
|
ldap/servers/slapd/plugin.c | 24 ++++++++++++++++++-
|
|
ldap/servers/slapd/proto-slap.h | 3 ++-
|
|
ldap/servers/slapd/slap.h | 3 ++-
|
|
ldap/servers/slapd/slapi-plugin.h | 5 ++--
|
|
7 files changed, 62 insertions(+), 13 deletions(-)
|
|
|
|
diff --git a/ldap/servers/plugins/replication/repl5_init.c b/ldap/servers/plugins/replication/repl5_init.c
|
|
index 9b6523a2e..dd4870746 100644
|
|
--- a/ldap/servers/plugins/replication/repl5_init.c
|
|
+++ b/ldap/servers/plugins/replication/repl5_init.c
|
|
@@ -1,6 +1,6 @@
|
|
/** BEGIN COPYRIGHT BLOCK
|
|
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
|
|
- * Copyright (C) 2005 Red Hat, Inc.
|
|
+ * Copyright (C) 2026 Red Hat, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* License: GPL (version 3 or any later version).
|
|
@@ -122,6 +122,8 @@ static PRUintn thread_private_agmtname; /* thread private index for logging*/
|
|
static PRUintn thread_private_cache;
|
|
static PRUintn thread_primary_csn;
|
|
|
|
+static int multisupplier_pre_stop(Slapi_PBlock *pb __attribute__((unused)));
|
|
+
|
|
char *
|
|
get_thread_private_agmtname()
|
|
{
|
|
@@ -832,10 +834,6 @@ multimaster_stop(Slapi_PBlock *pb __attribute__((unused)))
|
|
int rc = 0; /* OK */
|
|
|
|
if (!multimaster_stopped_flag) {
|
|
- if (!is_ldif_dump) {
|
|
- /* Shut down replication agreements */
|
|
- agmtlist_shutdown();
|
|
- }
|
|
/* if we are cleaning a ruv, stop */
|
|
stop_ruv_cleaning();
|
|
/* unregister backend state change notification */
|
|
@@ -849,6 +847,16 @@ multimaster_stop(Slapi_PBlock *pb __attribute__((unused)))
|
|
return rc;
|
|
}
|
|
|
|
+static int
|
|
+multisupplier_pre_stop(Slapi_PBlock *pb __attribute__((unused)))
|
|
+{
|
|
+ if (!multisupplier_stopped_flag) {
|
|
+ /* Shut down replication agreements which will stop all the
|
|
+ * replication protocol threads */
|
|
+ agmtlist_shutdown();
|
|
+ }
|
|
+ return 0;
|
|
+}
|
|
|
|
PRBool
|
|
multimaster_started()
|
|
@@ -896,7 +904,7 @@ replication_multimaster_plugin_init(Slapi_PBlock *pb)
|
|
rc = slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&multimasterdesc);
|
|
rc = slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN, (void *)multimaster_start);
|
|
rc = slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN, (void *)multimaster_stop);
|
|
-
|
|
+ rc = slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_CLOSE_FN, (void *)multisupplier_pre_stop);
|
|
/* Register the plugin interfaces we implement */
|
|
/* preop acquires csn generator handle */
|
|
rc = slapi_register_plugin("preoperation", 1 /* Enabled */,
|
|
diff --git a/ldap/servers/slapd/daemon.c b/ldap/servers/slapd/daemon.c
|
|
index 2534483c1..c2977aa6f 100644
|
|
--- a/ldap/servers/slapd/daemon.c
|
|
+++ b/ldap/servers/slapd/daemon.c
|
|
@@ -1,6 +1,6 @@
|
|
/** BEGIN COPYRIGHT BLOCK
|
|
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
|
|
- * Copyright (C) 2021 Red Hat, Inc.
|
|
+ * Copyright (C) 2026 Red Hat, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* License: GPL (version 3 or any later version).
|
|
@@ -1367,6 +1367,10 @@ slapd_daemon(daemon_ports_t *ports)
|
|
task_cancel_all();
|
|
}
|
|
|
|
+ /* Call plugin pre close functions */
|
|
+ plugin_pre_closeall();
|
|
+
|
|
+ /* Now wait for active threads to terminate */
|
|
threads = g_get_active_threadcnt();
|
|
if (threads > 0) {
|
|
slapi_log_err(SLAPI_LOG_INFO, "slapd_daemon",
|
|
diff --git a/ldap/servers/slapd/pblock.c b/ldap/servers/slapd/pblock.c
|
|
index 7c1cdc81c..b97c1acef 100644
|
|
--- a/ldap/servers/slapd/pblock.c
|
|
+++ b/ldap/servers/slapd/pblock.c
|
|
@@ -1,6 +1,6 @@
|
|
/** BEGIN COPYRIGHT BLOCK
|
|
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
|
|
- * Copyright (C) 2005 Red Hat, Inc.
|
|
+ * Copyright (C) 2026 Red Hat, Inc.
|
|
* Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
|
|
* All rights reserved.
|
|
*
|
|
@@ -2524,6 +2524,14 @@ slapi_pblock_get(Slapi_PBlock *pblock, int arg, void *value)
|
|
}
|
|
break;
|
|
|
|
+ case SLAPI_PLUGIN_PRE_CLOSE_FN:
|
|
+ if (pblock->pb_plugin != NULL) {
|
|
+ (*(IFP *)value) = pblock->pb_plugin->plg_pre_close;
|
|
+ } else {
|
|
+ (*(IFP *)value) = NULL;
|
|
+ }
|
|
+ break;
|
|
+
|
|
default:
|
|
slapi_log_err(SLAPI_LOG_ERR, "slapi_pblock_get", "Unknown parameter block argument %d\n", arg);
|
|
PR_ASSERT(0);
|
|
@@ -4218,6 +4226,10 @@ slapi_pblock_set(Slapi_PBlock *pblock, int arg, void *value)
|
|
pblock->pb_misc->pb_aci_target_check = *((int *)value);
|
|
break;
|
|
|
|
+ case SLAPI_PLUGIN_PRE_CLOSE_FN:
|
|
+ pblock->pb_plugin->plg_pre_close = (IFP)value;
|
|
+ break;
|
|
+
|
|
default:
|
|
slapi_log_err(SLAPI_LOG_ERR, "slapi_pblock_set",
|
|
"Unknown parameter block argument %d\n", arg);
|
|
diff --git a/ldap/servers/slapd/plugin.c b/ldap/servers/slapd/plugin.c
|
|
index 449be2142..8b62dba32 100644
|
|
--- a/ldap/servers/slapd/plugin.c
|
|
+++ b/ldap/servers/slapd/plugin.c
|
|
@@ -1,6 +1,6 @@
|
|
/** BEGIN COPYRIGHT BLOCK
|
|
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
|
|
- * Copyright (C) 2005 Red Hat, Inc.
|
|
+ * Copyright (C) 2026 Red Hat, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* License: GPL (version 3 or any later version).
|
|
@@ -1881,6 +1881,28 @@ plugin_dependency_closeall(void)
|
|
}
|
|
}
|
|
|
|
+/* Call the pre close functions of all the plugins */
|
|
+void
|
|
+plugin_pre_closeall(void)
|
|
+{
|
|
+ Slapi_PBlock *pb = NULL;
|
|
+ int plugins_pre_closed = 0;
|
|
+ int index = 0;
|
|
+
|
|
+ while (plugins_pre_closed < global_plugins_started) {
|
|
+ if (global_plugin_shutdown_order[index].name) {
|
|
+ if (!global_plugin_shutdown_order[index].removed) {
|
|
+ pb = slapi_pblock_new();
|
|
+ plugin_call_one(global_plugin_shutdown_order[index].plugin,
|
|
+ SLAPI_PLUGIN_PRE_CLOSE_FN, pb);
|
|
+ slapi_pblock_destroy(pb);
|
|
+ }
|
|
+ plugins_pre_closed++;
|
|
+ }
|
|
+ index++;
|
|
+ }
|
|
+}
|
|
+
|
|
void
|
|
plugin_freeall(void)
|
|
{
|
|
diff --git a/ldap/servers/slapd/proto-slap.h b/ldap/servers/slapd/proto-slap.h
|
|
index 6e473a08e..ab42c0e0f 100644
|
|
--- a/ldap/servers/slapd/proto-slap.h
|
|
+++ b/ldap/servers/slapd/proto-slap.h
|
|
@@ -1,6 +1,6 @@
|
|
/** BEGIN COPYRIGHT BLOCK
|
|
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
|
|
- * Copyright (C) 2005 Red Hat, Inc.
|
|
+ * Copyright (C) 2026 Red Hat, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* License: GPL (version 3 or any later version).
|
|
@@ -959,6 +959,7 @@ int plugin_call_exop_plugins(Slapi_PBlock *pb, struct slapdplugin *p);
|
|
Slapi_Backend *plugin_extended_op_getbackend(Slapi_PBlock *pb, struct slapdplugin *p);
|
|
const char *plugin_extended_op_oid2string(const char *oid);
|
|
void plugin_closeall(int close_backends, int close_globals);
|
|
+void plugin_pre_closeall(void);
|
|
void plugin_dependency_freeall(void);
|
|
void plugin_startall(int argc, char **argv, char **plugin_list);
|
|
void plugin_get_plugin_dependencies(char *plugin_name, char ***names);
|
|
diff --git a/ldap/servers/slapd/slap.h b/ldap/servers/slapd/slap.h
|
|
index e6b49d366..0f67dda7d 100644
|
|
--- a/ldap/servers/slapd/slap.h
|
|
+++ b/ldap/servers/slapd/slap.h
|
|
@@ -1,6 +1,6 @@
|
|
/** BEGIN COPYRIGHT BLOCK
|
|
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
|
|
- * Copyright (C) 2009 Red Hat, Inc.
|
|
+ * Copyright (C) 2026 Red Hat, Inc.
|
|
* Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
|
|
* All rights reserved.
|
|
*
|
|
@@ -1009,6 +1009,7 @@ struct slapdplugin
|
|
char *plg_libpath; /* library path for dll/so */
|
|
char *plg_initfunc; /* init symbol */
|
|
IFP plg_close; /* close function */
|
|
+ IFP plg_pre_close; /* pre close function */
|
|
Slapi_PluginDesc plg_desc; /* vendor's info */
|
|
char *plg_name; /* used for plugin rdn in cn=config */
|
|
struct slapdplugin *plg_next; /* for plugin lists */
|
|
diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h
|
|
index 6517665a9..5dd78004c 100644
|
|
--- a/ldap/servers/slapd/slapi-plugin.h
|
|
+++ b/ldap/servers/slapd/slapi-plugin.h
|
|
@@ -1,6 +1,6 @@
|
|
/* BEGIN COPYRIGHT BLOCK
|
|
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
|
|
- * Copyright (C) 2009 Red Hat, Inc.
|
|
+ * Copyright (C) 2026 Red Hat, Inc.
|
|
* Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
|
|
* All rights reserved.
|
|
*
|
|
@@ -6789,7 +6789,7 @@ time_t slapi_current_time(void) __attribute__((deprecated));
|
|
* and should NOT be used for timer information.
|
|
*/
|
|
int32_t slapi_clock_gettime(struct timespec *tp);
|
|
-/*
|
|
+/*
|
|
* slapi_clock_gettime should have better been called
|
|
* slapi_clock_utc_gettime but sice the function pre-existed
|
|
* we are just adding an alias (to avoid risking to break
|
|
@@ -7093,6 +7093,7 @@ typedef struct slapi_plugindesc
|
|
|
|
/* miscellaneous plugin functions */
|
|
#define SLAPI_PLUGIN_CLOSE_FN 210
|
|
+#define SLAPI_PLUGIN_PRE_CLOSE_FN 211
|
|
#define SLAPI_PLUGIN_START_FN 212
|
|
#define SLAPI_PLUGIN_CLEANUP_FN 232
|
|
#define SLAPI_PLUGIN_POSTSTART_FN 233
|
|
--
|
|
2.52.0
|
|
|