[Fedora-directory-commits] ldapserver/ldap/servers/slapd libglobs.c, 1.20, 1.21 proto-slap.h, 1.28, 1.29 connection.c, 1.16, 1.17 daemon.c, 1.14, 1.15 task.c, 1.12, 1.13 monitor.c, 1.6, 1.7 psearch.c, 1.8, 1.9 fe.h, 1.7, 1.8 globals.c, 1.6, 1.7
Noriko Hosoi (nhosoi)
fedora-directory-commits at redhat.com
Thu Sep 20 16:54:41 UTC 2007
Author: nhosoi
Update of /cvs/dirsec/ldapserver/ldap/servers/slapd
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv31746
Modified Files:
libglobs.c proto-slap.h connection.c daemon.c task.c monitor.c
psearch.c fe.h globals.c
Log Message:
Resolves: #240897
Summary: CRM 1474928 : ds7.1 db index/vlv not handling a stop-slapd, hangs slapd
Description:
1. moved active thread count from ns-slapd to libslapd for the task threads to
use.
2. provided APIs to increment/decrement/get the active thread count
3. let task threads increment the active thread count when it's spawned and
decrement it when it quits.
Index: libglobs.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/libglobs.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- libglobs.c 17 Sep 2007 22:48:10 -0000 1.20
+++ libglobs.c 20 Sep 2007 16:54:38 -0000 1.21
@@ -735,6 +735,29 @@
}
/*
+ * counter for active threads
+ */
+static PRInt32 active_threads = 0;
+
+void
+g_incr_active_threadcnt()
+{
+ PR_AtomicIncrement(&active_threads);
+}
+
+void
+g_decr_active_threadcnt()
+{
+ PR_AtomicDecrement(&active_threads);
+}
+
+int
+g_get_active_threadcnt()
+{
+ return (int)active_threads;
+}
+
+/*
** Setting this flag forces the server to shutdown.
*/
static int slapd_shutdown;
Index: proto-slap.h
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/proto-slap.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- proto-slap.h 11 Jul 2007 01:14:05 -0000 1.28
+++ proto-slap.h 20 Sep 2007 16:54:38 -0000 1.29
@@ -203,6 +203,9 @@
int g_get_deftime();
void be_unbindall( Connection *conn, Operation *op);
int be_nbackends_public();
+void g_incr_active_threadcnt();
+void g_decr_active_threadcnt();
+int g_get_active_threadcnt();
/*
* bind.c
Index: connection.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/connection.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- connection.c 14 May 2007 22:04:55 -0000 1.16
+++ connection.c 20 Sep 2007 16:54:38 -0000 1.17
@@ -402,7 +402,7 @@
LDAPDebug( LDAP_DEBUG_ANY, "PR_CreateThread failed, " SLAPI_COMPONENT_NAME_NSPR " error %d (%s)\n",
prerr, slapd_pr_strerror( prerr ), 0 );
} else {
- PR_AtomicIncrement(&active_threads);
+ g_incr_active_threadcnt();
}
}
}
@@ -746,7 +746,7 @@
}
}
}
- PR_AtomicDecrement(&active_threads);
+ g_decr_active_threadcnt();
}
static int handle_read_data(Connection *conn,Operation **op,
@@ -1948,9 +1948,11 @@
No bother to do so much calcuation, short-cut to non-turbo mode if no activities in passed interval */
new_mode = 0;
} else {
+ double activet = 0.0;
connection_find_our_rank(conn,&connection_count, &our_rank);
LDAPDebug(LDAP_DEBUG_CONNS,"conn %d turbo rank = %d out of %d conns\n",conn->c_connid,our_rank,connection_count);
- threshold_rank = (int)((double)active_threads * ((double)CONN_TURBO_PERCENTILE / 100.0) );
+ activet = (double)g_get_active_threadcnt();
+ threshold_rank = (int)(activet * ((double)CONN_TURBO_PERCENTILE / 100.0));
/* adjust threshold_rank according number of connections,
less turbo threads as more connections,
@@ -2023,7 +2025,7 @@
if( op_shutdown ) {
LDAPDebug( LDAP_DEBUG_TRACE,
"op_thread received shutdown signal\n", 0, 0, 0 );
- PR_AtomicDecrement(&active_threads);
+ g_decr_active_threadcnt();
return;
}
@@ -2039,7 +2041,7 @@
case CONN_SHUTDOWN:
LDAPDebug( LDAP_DEBUG_TRACE,
"op_thread received shutdown signal\n", 0, 0, 0 );
- PR_AtomicDecrement(&active_threads);
+ g_decr_active_threadcnt();
return;
case CONN_FOUND_WORK_TO_DO:
default:
@@ -2102,7 +2104,7 @@
case CONN_SHUTDOWN:
LDAPDebug( LDAP_DEBUG_TRACE,
"op_thread received shutdown signal\n", 0, 0, 0 );
- PR_AtomicDecrement(&active_threads);
+ g_decr_active_threadcnt();
return;
default:
break;
@@ -2333,7 +2335,7 @@
#ifdef _WIN32
LDAPDebug( LDAP_DEBUG_ANY,
"slapd shutting down - waiting for %d threads to terminate\n",
- active_threads, 0, 0 );
+ g_get_active_threadcnt(), 0, 0 );
/* kill off each worker waiting on GetQueuedCompletionStatus */
for ( i = 0; i < max_threads; ++ i )
{
Index: daemon.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/daemon.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- daemon.c 3 Aug 2007 22:14:41 -0000 1.14
+++ daemon.c 20 Sep 2007 16:54:38 -0000 1.15
@@ -352,7 +352,7 @@
configure_ns_socket( &ns );
}
#endif
-
+
return ns;
}
@@ -807,15 +807,16 @@
housekeeping_stop(); /* Run this after op_thread_cleanup() logged sth */
#ifndef _WIN32
- if ( active_threads > 0 ) {
+ threads = g_get_active_threadcnt();
+ if ( threads > 0 ) {
LDAPDebug( LDAP_DEBUG_ANY,
"slapd shutting down - waiting for %d thread%s to terminate\n",
- active_threads, ( active_threads > 1 ) ? "s" : "", 0 );
+ threads, ( threads > 1 ) ? "s" : "", 0 );
}
#endif
- threads = active_threads;
- while ( active_threads > 0 ) {
+ threads = g_get_active_threadcnt();
+ while ( threads > 0 ) {
PRPollDesc xpd;
char x;
int spe = 0;
@@ -845,11 +846,11 @@
/* no data */
}
DS_Sleep(PR_INTERVAL_NO_WAIT);
- if ( threads != active_threads ) {
+ if ( threads != g_get_active_threadcnt() ) {
LDAPDebug( LDAP_DEBUG_TRACE,
"slapd shutting down - waiting for %d threads to terminate\n",
- active_threads, 0, 0 );
- threads = active_threads;
+ g_get_active_threadcnt(), 0, 0 );
+ threads = g_get_active_threadcnt();
}
}
@@ -1247,7 +1248,7 @@
snmp_collator_update();
prevtime = curtime;
- num_active_threads = active_threads;
+ num_active_threads = g_get_active_threadcnt();
if ( (num_active_threads == 0) ||
(difftime(curtime, housekeeping_fire_time) >=
slapd_housekeeping_timer*3) ) {
Index: task.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/task.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- task.c 7 Sep 2007 19:08:45 -0000 1.12
+++ task.c 20 Sep 2007 16:54:38 -0000 1.13
@@ -73,9 +73,9 @@
static int task_modify(Slapi_PBlock *pb, Slapi_Entry *e,
- Slapi_Entry *eAfter, int *returncode, char *returntext, void *arg);
+ Slapi_Entry *eAfter, int *returncode, char *returntext, void *arg);
static int task_deny(Slapi_PBlock *pb, Slapi_Entry *e,
- Slapi_Entry *eAfter, int *returncode, char *returntext, void *arg);
+ Slapi_Entry *eAfter, int *returncode, char *returntext, void *arg);
static int task_generic_destructor(Slapi_Task *task);
/* create a new task, fill in DN, and setup modify callback */
@@ -94,16 +94,16 @@
task->task_dn = slapi_ch_strdup(dn);
task->destructor = task_generic_destructor;
slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, dn,
- LDAP_SCOPE_BASE, "(objectclass=*)", task_modify, (void *)task);
+ LDAP_SCOPE_BASE, "(objectclass=*)", task_modify, (void *)task);
slapi_config_register_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP, dn,
- LDAP_SCOPE_BASE, "(objectclass=*)", task_deny, NULL);
+ LDAP_SCOPE_BASE, "(objectclass=*)", task_deny, NULL);
/* don't add entries under this one */
#if 0
/* don't know why, but this doesn't work. it makes the current add
* operation fail. :(
*/
slapi_config_register_callback(SLAPI_OPERATION_ADD, DSE_FLAG_PREOP, dn,
- LDAP_SCOPE_SUBTREE, "(objectclass=*)", task_deny, NULL);
+ LDAP_SCOPE_SUBTREE, "(objectclass=*)", task_deny, NULL);
#endif
return task;
@@ -139,11 +139,11 @@
}
slapi_config_remove_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP,
- task->task_dn, LDAP_SCOPE_BASE, "(objectclass=*)", task_modify);
+ task->task_dn, LDAP_SCOPE_BASE, "(objectclass=*)", task_modify);
slapi_config_remove_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP,
- task->task_dn, LDAP_SCOPE_BASE, "(objectclass=*)", task_deny);
+ task->task_dn, LDAP_SCOPE_BASE, "(objectclass=*)", task_deny);
slapi_delete_internal_set_pb(pb, task->task_dn, NULL, NULL,
- (void *)plugin_get_default_component_id(), 0);
+ (void *)plugin_get_default_component_id(), 0);
slapi_delete_internal_pb(pb);
slapi_pblock_destroy(pb);
@@ -175,7 +175,7 @@
void
slapi_destroy_task(void *arg)
{
- destroy_task(1, arg);
+ destroy_task(1, arg);
}
/********** some useful helper functions **********/
@@ -204,7 +204,7 @@
int ret = 0;
slapi_search_internal_set_pb(pb, dn, LDAP_SCOPE_BASE, "(objectclass=*)",
- NULL, 0, NULL, NULL, (void *)plugin_get_default_component_id(), 0);
+ NULL, 0, NULL, NULL, (void *)plugin_get_default_component_id(), 0);
slapi_search_internal_pb(pb);
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &ret);
if (ret != LDAP_SUCCESS) {
@@ -225,17 +225,17 @@
static void modify_internal_entry(char *dn, LDAPMod **mods)
{
Slapi_PBlock pb;
- Slapi_Operation *op;
+ Slapi_Operation *op;
int ret = 0;
int tries = 0;
int dont_write_file = 1;
do {
- pblock_init(&pb);
+ pblock_init(&pb);
- slapi_modify_internal_set_pb(&pb, dn, mods, NULL, NULL,
- (void *)plugin_get_default_component_id(), 0);
+ slapi_modify_internal_set_pb(&pb, dn, mods, NULL, NULL,
+ (void *)plugin_get_default_component_id(), 0);
/* all modifications to the cn=tasks subtree are transient --
* we erase them all when the server starts up next time, so there's
@@ -243,10 +243,10 @@
*/
slapi_pblock_set(&pb, SLAPI_DSE_DONT_WRITE_WHEN_ADDING, &dont_write_file);
- /* Make sure these mods are not logged in audit or changelog */
- slapi_pblock_get(&pb, SLAPI_OPERATION, &op);
- operation_set_flag(op, OP_FLAG_ACTION_NOLOG);
-
+ /* Make sure these mods are not logged in audit or changelog */
+ slapi_pblock_get(&pb, SLAPI_OPERATION, &op);
+ operation_set_flag(op, OP_FLAG_ACTION_NOLOG);
+
slapi_modify_internal_pb(&pb);
slapi_pblock_get(&pb, SLAPI_PLUGIN_INTOP_RESULT, &ret);
if (ret != LDAP_SUCCESS) {
@@ -257,13 +257,13 @@
if (tries == 3) {
LDAPDebug(LDAP_DEBUG_ANY, "WARNING: can't modify task "
"entry '%s'; %s (%d)\n", dn, ldap_err2string(ret), ret);
- pblock_done(&pb);
+ pblock_done(&pb);
return;
}
DS_Sleep(PR_SecondsToInterval(1));
}
- pblock_done(&pb);
+ pblock_done(&pb);
} while (ret != LDAP_SUCCESS);
}
@@ -283,9 +283,9 @@
va_list ap;
if (! task->task_status)
- task->task_status = (char *)slapi_ch_malloc(10 * LOG_BUFFER);
+ task->task_status = (char *)slapi_ch_malloc(10 * LOG_BUFFER);
if (! task->task_status)
- return; /* out of memory? */
+ return; /* out of memory? */
va_start(ap, format);
PR_vsnprintf(task->task_status, (10 * LOG_BUFFER), format, ap);
@@ -308,22 +308,22 @@
len = 2 + strlen(buffer) + (task->task_log ? strlen(task->task_log) : 0);
if ((len > MAX_SCROLLBACK_BUFFER) && task->task_log) {
- size_t i;
- char *newbuf;
+ size_t i;
+ char *newbuf;
- /* start from middle of buffer, and find next linefeed */
- i = strlen(task->task_log)/2;
- while (task->task_log[i] && (task->task_log[i] != '\n'))
- i++;
- if (task->task_log[i])
- i++;
- len = strlen(task->task_log) - i + 2 + strlen(buffer);
- newbuf = (char *)slapi_ch_malloc(len);
- if (! newbuf)
- return; /* out of memory? */
- strcpy(newbuf, task->task_log + i);
- slapi_ch_free((void **)&task->task_log);
- task->task_log = newbuf;
+ /* start from middle of buffer, and find next linefeed */
+ i = strlen(task->task_log)/2;
+ while (task->task_log[i] && (task->task_log[i] != '\n'))
+ i++;
+ if (task->task_log[i])
+ i++;
+ len = strlen(task->task_log) - i + 2 + strlen(buffer);
+ newbuf = (char *)slapi_ch_malloc(len);
+ if (! newbuf)
+ return; /* out of memory? */
+ strcpy(newbuf, task->task_log + i);
+ slapi_ch_free((void **)&task->task_log);
+ task->task_log = newbuf;
} else {
if (! task->task_log) {
task->task_log = (char *)slapi_ch_malloc(len);
@@ -331,8 +331,8 @@
} else {
task->task_log = (char *)slapi_ch_realloc(task->task_log, len);
}
- if (! task->task_log)
- return; /* out of memory? */
+ if (! task->task_log)
+ return; /* out of memory? */
}
if (task->task_log[0])
@@ -359,7 +359,7 @@
static int task_deny(Slapi_PBlock *pb, Slapi_Entry *e,
- Slapi_Entry *eAfter, int *returncode, char *returntext, void *arg)
+ Slapi_Entry *eAfter, int *returncode, char *returntext, void *arg)
{
/* internal operations (conn=NULL) are allowed to do whatever they want */
if (pb->pb_conn == NULL) {
@@ -372,7 +372,7 @@
}
static int task_modify(Slapi_PBlock *pb, Slapi_Entry *e,
- Slapi_Entry *eAfter, int *returncode, char *returntext, void *arg)
+ Slapi_Entry *eAfter, int *returncode, char *returntext, void *arg)
{
Slapi_Task *task = (Slapi_Task *)arg;
LDAPMod **mods;
@@ -420,7 +420,7 @@
}
static int task_import_add(Slapi_PBlock *pb, Slapi_Entry *e,
- Slapi_Entry *eAfter, int *returncode, char *returntext, void *arg)
+ Slapi_Entry *eAfter, int *returncode, char *returntext, void *arg)
{
Slapi_Attr *attr;
Slapi_Value *val = NULL;
@@ -433,7 +433,7 @@
Slapi_PBlock mypb;
Slapi_Task *task;
char *nameFrombe_name = NULL;
- const char *encrypt_on_import = NULL;
+ const char *encrypt_on_import = NULL;
if ((cn = fetch_attr(e, "cn", NULL)) == NULL) {
*returncode = LDAP_OBJECT_CLASS_VIOLATION;
@@ -465,40 +465,40 @@
char **instances, **ip;
int counter;
- if (slapi_lookup_instance_name_by_suffixes(include, exclude,
- &instances) < 0) {
- LDAPDebug(LDAP_DEBUG_ANY,
- "ERROR: No backend instance is specified.\n", 0, 0, 0);
- *returncode = LDAP_OBJECT_CLASS_VIOLATION;
- return SLAPI_DSE_CALLBACK_ERROR;
- }
+ if (slapi_lookup_instance_name_by_suffixes(include, exclude,
+ &instances) < 0) {
+ LDAPDebug(LDAP_DEBUG_ANY,
+ "ERROR: No backend instance is specified.\n", 0, 0, 0);
+ *returncode = LDAP_OBJECT_CLASS_VIOLATION;
+ return SLAPI_DSE_CALLBACK_ERROR;
+ }
if (instances) {
for (ip = instances, counter = 0; ip && *ip; ip++, counter++)
;
- if (counter == 1){
- instance_name = *instances;
- nameFrombe_name = *instances;
-
- }
- else if (counter == 0) {
- LDAPDebug(LDAP_DEBUG_ANY,
- "ERROR: No backend instance is specified.\n", 0, 0, 0);
- *returncode = LDAP_OBJECT_CLASS_VIOLATION;
- return SLAPI_DSE_CALLBACK_ERROR;
- } else {
- LDAPDebug(LDAP_DEBUG_ANY,
- "ERROR: Multiple backend instances are specified: "
- "%s, %s, ...\n", instances[0], instances[1], 0);
- *returncode = LDAP_OBJECT_CLASS_VIOLATION;
- return SLAPI_DSE_CALLBACK_ERROR;
- }
- } else {
- *returncode = LDAP_OBJECT_CLASS_VIOLATION;
- return SLAPI_DSE_CALLBACK_ERROR;
- }
- }
+ if (counter == 1){
+ instance_name = *instances;
+ nameFrombe_name = *instances;
+
+ }
+ else if (counter == 0) {
+ LDAPDebug(LDAP_DEBUG_ANY,
+ "ERROR: No backend instance is specified.\n", 0, 0, 0);
+ *returncode = LDAP_OBJECT_CLASS_VIOLATION;
+ return SLAPI_DSE_CALLBACK_ERROR;
+ } else {
+ LDAPDebug(LDAP_DEBUG_ANY,
+ "ERROR: Multiple backend instances are specified: "
+ "%s, %s, ...\n", instances[0], instances[1], 0);
+ *returncode = LDAP_OBJECT_CLASS_VIOLATION;
+ return SLAPI_DSE_CALLBACK_ERROR;
+ }
+ } else {
+ *returncode = LDAP_OBJECT_CLASS_VIOLATION;
+ return SLAPI_DSE_CALLBACK_ERROR;
+ }
+ }
/* lookup the backend */
be = slapi_be_select_by_instance_name(instance_name);
@@ -576,9 +576,9 @@
mypb.pb_ldif_exclude = exclude;
mypb.pb_task = task;
mypb.pb_task_flags = TASK_RUNNING_AS_TASK;
- if (NULL != encrypt_on_import && 0 == strcasecmp(encrypt_on_import, "true") ) {
- mypb.pb_ldif_encrypt = 1;
- }
+ if (NULL != encrypt_on_import && 0 == strcasecmp(encrypt_on_import, "true") ) {
+ mypb.pb_ldif_encrypt = 1;
+ }
rv = (*mypb.pb_plugin->plg_ldif2db)(&mypb);
if (rv == 0) {
@@ -615,6 +615,7 @@
int count;
Slapi_Task *task = pb->pb_task;
+ g_incr_active_threadcnt();
for (count = 0, inp = instance_names; *inp; inp++, count++)
;
task->task_work = count;
@@ -623,7 +624,7 @@
slapi_task_status_changed(task);
for (inp = instance_names; *inp; inp++) {
- int release_me = 0;
+ int release_me = 0;
/* lookup the backend */
be = slapi_be_select_by_instance_name((const char *)*inp);
if (be == NULL) {
@@ -639,39 +640,39 @@
/* ldif_file name for each? */
if (pb->pb_ldif_printkey & EXPORT_APPENDMODE) {
- if (inp == instance_names) { /* first export */
- pb->pb_ldif_printkey |= EXPORT_APPENDMODE_1;
- } else {
- pb->pb_ldif_printkey &= ~EXPORT_APPENDMODE_1;
- }
- } else {
- if (strcmp(ldif_file, "-")) { /* not '-' */
- char *p;
+ if (inp == instance_names) { /* first export */
+ pb->pb_ldif_printkey |= EXPORT_APPENDMODE_1;
+ } else {
+ pb->pb_ldif_printkey &= ~EXPORT_APPENDMODE_1;
+ }
+ } else {
+ if (strcmp(ldif_file, "-")) { /* not '-' */
+ char *p;
#if defined( _WIN32 )
- char sep = '\\';
- if (NULL != strchr(ldif_file, '/'))
- sep = '/';
+ char sep = '\\';
+ if (NULL != strchr(ldif_file, '/'))
+ sep = '/';
#else
- char sep = '/';
+ char sep = '/';
#endif
- this_ldif_file = (char *)slapi_ch_malloc(strlen(ldif_file) +
+ this_ldif_file = (char *)slapi_ch_malloc(strlen(ldif_file) +
strlen(*inp) + 2);
- p = strrchr(ldif_file, sep);
- if (NULL == p) {
- sprintf(this_ldif_file, "%s_%s", *inp, ldif_file);
- } else {
- char *q;
-
- q = p + 1;
- *p = '\0';
- sprintf(this_ldif_file, "%s%c%s_%s",
- ldif_file, sep, *inp, q);
- *p = sep;
- }
- pb->pb_ldif_file = this_ldif_file;
- release_me = 1;
- }
- }
+ p = strrchr(ldif_file, sep);
+ if (NULL == p) {
+ sprintf(this_ldif_file, "%s_%s", *inp, ldif_file);
+ } else {
+ char *q;
+
+ q = p + 1;
+ *p = '\0';
+ sprintf(this_ldif_file, "%s%c%s_%s",
+ ldif_file, sep, *inp, q);
+ *p = sep;
+ }
+ pb->pb_ldif_file = this_ldif_file;
+ release_me = 1;
+ }
+ }
slapi_task_log_notice(task, "Beginning export of '%s'", *inp);
LDAPDebug(LDAP_DEBUG_ANY, "Beginning export of '%s'\n", *inp, 0, 0);
@@ -714,10 +715,11 @@
task->task_exitcode = rv;
task->task_state = SLAPI_TASK_FINISHED;
slapi_task_status_changed(task);
+ g_decr_active_threadcnt();
}
static int task_export_add(Slapi_PBlock *pb, Slapi_Entry *e,
- Slapi_Entry *eAfter, int *returncode, char *returntext, void *arg)
+ Slapi_Entry *eAfter, int *returncode, char *returntext, void *arg)
{
Slapi_Attr *attr;
Slapi_Value *val = NULL;
@@ -748,16 +750,16 @@
goto out;
}
- decrypt_on_export = fetch_attr(e, "nsExportDecrypt", NULL);
+ decrypt_on_export = fetch_attr(e, "nsExportDecrypt", NULL);
/* nsInstances -- from here on, memory has been allocated */
if (slapi_entry_attr_find(e, "nsInstance", &attr) == 0) {
- for (idx = slapi_attr_first_value(attr, &val);
+ for (idx = slapi_attr_first_value(attr, &val);
idx >= 0; idx = slapi_attr_next_value(attr, idx, &val)) {
charray_add(&instance_names,
slapi_ch_strdup(slapi_value_get_string(val)));
instance_cnt++;
- }
+ }
}
/* include/exclude suffixes */
@@ -879,7 +881,7 @@
}
if (be->be_database->plg_db2ldif == NULL) {
LDAPDebug(LDAP_DEBUG_ANY, "ERROR: no db2ldif function defined for "
- "backend %s\n", be->be_database->plg_name, 0, 0);
+ "backend %s\n", be->be_database->plg_name, 0, 0);
*returncode = LDAP_UNWILLING_TO_PERFORM;
rv = SLAPI_DSE_CALLBACK_ERROR;
goto out;
@@ -914,14 +916,14 @@
mypb->pb_instance_name = (char *)instance_names;
mypb->pb_task = task;
mypb->pb_task_flags = TASK_RUNNING_AS_TASK;
- if (NULL != decrypt_on_export && 0 == strcasecmp(decrypt_on_export, "true") ) {
- mypb->pb_ldif_encrypt = 1;
- }
+ if (NULL != decrypt_on_export && 0 == strcasecmp(decrypt_on_export, "true") ) {
+ mypb->pb_ldif_encrypt = 1;
+ }
/* start the export as a separate thread */
thread = PR_CreateThread(PR_USER_THREAD, task_export_thread,
- (void *)mypb, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
- PR_UNJOINABLE_THREAD, SLAPD_DEFAULT_THREAD_STACKSIZE);
+ (void *)mypb, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
+ PR_UNJOINABLE_THREAD, SLAPD_DEFAULT_THREAD_STACKSIZE);
if (thread == NULL) {
LDAPDebug(LDAP_DEBUG_ANY,
"unable to create ldbm2ldif thread!\n", 0, 0, 0);
@@ -955,6 +957,7 @@
Slapi_Task *task = pb->pb_task;
int rv;
+ g_incr_active_threadcnt();
task->task_work = 1;
task->task_progress = 0;
task->task_state = SLAPI_TASK_RUNNING;
@@ -983,10 +986,11 @@
slapi_ch_free((void **)&pb->pb_seq_val);
slapi_pblock_destroy(pb);
+ g_decr_active_threadcnt();
}
static int task_backup_add(Slapi_PBlock *pb, Slapi_Entry *e,
- Slapi_Entry *eAfter, int *returncode, char *returntext, void *arg)
+ Slapi_Entry *eAfter, int *returncode, char *returntext, void *arg)
{
Slapi_Backend *be = NULL;
PRThread *thread = NULL;
@@ -1070,8 +1074,8 @@
/* start the backup as a separate thread */
thread = PR_CreateThread(PR_USER_THREAD, task_backup_thread,
- (void *)mypb, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
- PR_UNJOINABLE_THREAD, SLAPD_DEFAULT_THREAD_STACKSIZE);
+ (void *)mypb, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
+ PR_UNJOINABLE_THREAD, SLAPD_DEFAULT_THREAD_STACKSIZE);
if (thread == NULL) {
LDAPDebug(LDAP_DEBUG_ANY,
"unable to create backup thread!\n", 0, 0, 0);
@@ -1099,6 +1103,7 @@
Slapi_Task *task = pb->pb_task;
int rv;
+ g_incr_active_threadcnt();
task->task_work = 1;
task->task_progress = 0;
task->task_state = SLAPI_TASK_RUNNING;
@@ -1127,10 +1132,11 @@
slapi_ch_free((void **)&pb->pb_seq_val);
slapi_pblock_destroy(pb);
+ g_decr_active_threadcnt();
}
static int task_restore_add(Slapi_PBlock *pb, Slapi_Entry *e,
- Slapi_Entry *eAfter, int *returncode, char *returntext, void *arg)
+ Slapi_Entry *eAfter, int *returncode, char *returntext, void *arg)
{
Slapi_Backend *be = NULL;
const char *cn = NULL;
@@ -1222,8 +1228,8 @@
/* start the restore as a separate thread */
thread = PR_CreateThread(PR_USER_THREAD, task_restore_thread,
- (void *)mypb, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
- PR_UNJOINABLE_THREAD, SLAPD_DEFAULT_THREAD_STACKSIZE);
+ (void *)mypb, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
+ PR_UNJOINABLE_THREAD, SLAPD_DEFAULT_THREAD_STACKSIZE);
if (thread == NULL) {
LDAPDebug(LDAP_DEBUG_ANY,
"unable to create restore thread!\n", 0, 0, 0);
@@ -1251,6 +1257,7 @@
Slapi_Task *task = pb->pb_task;
int rv;
+ g_incr_active_threadcnt();
task->task_work = 1;
task->task_progress = 0;
task->task_state = SLAPI_TASK_RUNNING;
@@ -1271,10 +1278,11 @@
charray_free(pb->pb_db2index_attrs);
slapi_ch_free((void **)&pb->pb_instance_name);
slapi_pblock_destroy(pb);
+ g_decr_active_threadcnt();
}
static int task_index_add(Slapi_PBlock *pb, Slapi_Entry *e,
- Slapi_Entry *eAfter, int *returncode, char *returntext, void *arg)
+ Slapi_Entry *eAfter, int *returncode, char *returntext, void *arg)
{
const char *instance_name;
const char *cn;
@@ -1317,7 +1325,7 @@
/* normal indexes */
if (slapi_entry_attr_find(e, "nsIndexAttribute", &attr) == 0) {
- for (idx = slapi_attr_first_value(attr, &val);
+ for (idx = slapi_attr_first_value(attr, &val);
idx >= 0; idx = slapi_attr_next_value(attr, idx, &val)) {
const char *indexname = slapi_value_get_string(val);
char *index = slapi_ch_smprintf("t%s", indexname);
@@ -1325,12 +1333,12 @@
if (index != NULL) {
charray_add(&indexlist, index);
}
- }
+ }
}
/* vlv indexes */
if (slapi_entry_attr_find(e, "nsIndexVlvAttribute", &attr) == 0) {
- for (idx = slapi_attr_first_value(attr, &val);
+ for (idx = slapi_attr_first_value(attr, &val);
idx >= 0; idx = slapi_attr_next_value(attr, idx, &val)) {
const char *indexname = slapi_value_get_string(val);
char *index = slapi_ch_smprintf("T%s", indexname);
@@ -1338,7 +1346,7 @@
if (index != NULL) {
charray_add(&indexlist, index);
}
- }
+ }
}
if (NULL == indexlist) {
@@ -1375,8 +1383,8 @@
/* start the db2index as a separate thread */
thread = PR_CreateThread(PR_USER_THREAD, task_index_thread,
- (void *)mypb, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
- PR_UNJOINABLE_THREAD, SLAPD_DEFAULT_THREAD_STACKSIZE);
+ (void *)mypb, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
+ PR_UNJOINABLE_THREAD, SLAPD_DEFAULT_THREAD_STACKSIZE);
if (thread == NULL) {
LDAPDebug(LDAP_DEBUG_ANY,
"unable to create index thread!\n", 0, 0, 0);
@@ -1576,62 +1584,62 @@
*/
void task_cleanup(void)
{
- Slapi_PBlock *pb = slapi_pblock_new();
- Slapi_Entry **entries = NULL;
- int ret = 0, i, x;
- Slapi_DN *rootDN;
-
- slapi_search_internal_set_pb(pb, TASK_BASE_DN, LDAP_SCOPE_SUBTREE,
- "(objectclass=*)", NULL, 0, NULL, NULL,
- (void *)plugin_get_default_component_id(), 0);
- slapi_search_internal_pb(pb);
- slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &ret);
- if (ret != LDAP_SUCCESS) {
- LDAPDebug(LDAP_DEBUG_ANY, "WARNING: entire cn=tasks tree seems to "
- "be AWOL!\n", 0, 0, 0);
- slapi_pblock_destroy(pb);
- return;
- }
-
- slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
- if (NULL == entries) {
- LDAPDebug(LDAP_DEBUG_ANY, "WARNING: entire cn=tasks tree seems to "
- "be AWOL!\n", 0, 0, 0);
- slapi_pblock_destroy(pb);
- return;
- }
-
- rootDN = slapi_sdn_new_dn_byval(TASK_BASE_DN);
-
- /* rotate through entries, skipping the base dn */
- for (i = 0; entries[i] != NULL; i++) {
- const Slapi_DN *sdn = slapi_entry_get_sdn_const(entries[i]);
- Slapi_PBlock *mypb;
- Slapi_Operation *op;
-
- if (slapi_sdn_compare(sdn, rootDN) == 0)
- continue;
-
- mypb = slapi_pblock_new();
- if (mypb == NULL) {
- continue;
- }
- slapi_delete_internal_set_pb(mypb, slapi_sdn_get_dn(sdn), NULL, NULL,
- plugin_get_default_component_id(), 0);
-
- /* Make sure these deletes don't appear in the audit and change logs */
- slapi_pblock_get(mypb, SLAPI_OPERATION, &op);
- operation_set_flag(op, OP_FLAG_ACTION_NOLOG);
-
- x = 1;
- slapi_pblock_set(mypb, SLAPI_DSE_DONT_WRITE_WHEN_ADDING, &x);
- slapi_delete_internal_pb(mypb);
- slapi_pblock_destroy(mypb);
- }
-
- slapi_sdn_free(&rootDN);
- slapi_free_search_results_internal(pb);
- slapi_pblock_destroy(pb);
+ Slapi_PBlock *pb = slapi_pblock_new();
+ Slapi_Entry **entries = NULL;
+ int ret = 0, i, x;
+ Slapi_DN *rootDN;
+
+ slapi_search_internal_set_pb(pb, TASK_BASE_DN, LDAP_SCOPE_SUBTREE,
+ "(objectclass=*)", NULL, 0, NULL, NULL,
+ (void *)plugin_get_default_component_id(), 0);
+ slapi_search_internal_pb(pb);
+ slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &ret);
+ if (ret != LDAP_SUCCESS) {
+ LDAPDebug(LDAP_DEBUG_ANY, "WARNING: entire cn=tasks tree seems to "
+ "be AWOL!\n", 0, 0, 0);
+ slapi_pblock_destroy(pb);
+ return;
+ }
+
+ slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
+ if (NULL == entries) {
+ LDAPDebug(LDAP_DEBUG_ANY, "WARNING: entire cn=tasks tree seems to "
+ "be AWOL!\n", 0, 0, 0);
+ slapi_pblock_destroy(pb);
+ return;
+ }
+
+ rootDN = slapi_sdn_new_dn_byval(TASK_BASE_DN);
+
+ /* rotate through entries, skipping the base dn */
+ for (i = 0; entries[i] != NULL; i++) {
+ const Slapi_DN *sdn = slapi_entry_get_sdn_const(entries[i]);
+ Slapi_PBlock *mypb;
+ Slapi_Operation *op;
+
+ if (slapi_sdn_compare(sdn, rootDN) == 0)
+ continue;
+
+ mypb = slapi_pblock_new();
+ if (mypb == NULL) {
+ continue;
+ }
+ slapi_delete_internal_set_pb(mypb, slapi_sdn_get_dn(sdn), NULL, NULL,
+ plugin_get_default_component_id(), 0);
+
+ /* Make sure these deletes don't appear in the audit and change logs */
+ slapi_pblock_get(mypb, SLAPI_OPERATION, &op);
+ operation_set_flag(op, OP_FLAG_ACTION_NOLOG);
+
+ x = 1;
+ slapi_pblock_set(mypb, SLAPI_DSE_DONT_WRITE_WHEN_ADDING, &x);
+ slapi_delete_internal_pb(mypb);
+ slapi_pblock_destroy(mypb);
+ }
+
+ slapi_sdn_free(&rootDN);
+ slapi_free_search_results_internal(pb);
+ slapi_pblock_destroy(pb);
}
/* name is, for exmaple, "import" */
@@ -1639,7 +1647,7 @@
{
char *dn = NULL;
Slapi_PBlock *pb = NULL;
- Slapi_Operation *op;
+ Slapi_Operation *op;
LDAPMod *mods[3];
LDAPMod mod[3];
const char *objectclass[3];
@@ -1676,10 +1684,10 @@
plugin_get_default_component_id(), 0);
x = 1;
slapi_pblock_set(pb, SLAPI_DSE_DONT_WRITE_WHEN_ADDING, &x);
- /* Make sure these adds don't appear in the audit and change logs */
- slapi_pblock_get(pb, SLAPI_OPERATION, &op);
- operation_set_flag(op, OP_FLAG_ACTION_NOLOG);
-
+ /* Make sure these adds don't appear in the audit and change logs */
+ slapi_pblock_get(pb, SLAPI_OPERATION, &op);
+ operation_set_flag(op, OP_FLAG_ACTION_NOLOG);
+
slapi_add_internal_pb(pb);
slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &x);
if ((x != LDAP_SUCCESS) && (x != LDAP_ALREADY_EXISTS)) {
@@ -1692,12 +1700,12 @@
/* register add callback */
slapi_config_register_callback(SLAPI_OPERATION_ADD, DSE_FLAG_PREOP,
- dn, LDAP_SCOPE_SUBTREE, "(objectclass=*)", func, NULL);
+ dn, LDAP_SCOPE_SUBTREE, "(objectclass=*)", func, NULL);
/* deny modify/delete of the root task entry */
slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP,
- dn, LDAP_SCOPE_BASE, "(objectclass=*)", task_deny, NULL);
+ dn, LDAP_SCOPE_BASE, "(objectclass=*)", task_deny, NULL);
slapi_config_register_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP,
- dn, LDAP_SCOPE_BASE, "(objectclass=*)", task_deny, NULL);
+ dn, LDAP_SCOPE_BASE, "(objectclass=*)", task_deny, NULL);
ret = 0;
Index: monitor.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/monitor.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- monitor.c 10 Nov 2006 23:45:40 -0000 1.6
+++ monitor.c 20 Sep 2007 16:54:38 -0000 1.7
@@ -86,7 +86,7 @@
attrlist_replace( &e->e_attrs, "version", vals );
slapi_ch_free( (void **) &val.bv_val );
- sprintf( buf, "%d", active_threads );
+ sprintf( buf, "%d", g_get_active_threadcnt() );
val.bv_val = buf;
val.bv_len = strlen( buf );
attrlist_replace( &e->e_attrs, "threads", vals );
Index: psearch.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/psearch.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- psearch.c 10 Nov 2006 23:45:40 -0000 1.8
+++ psearch.c 20 Sep 2007 16:54:38 -0000 1.9
@@ -295,7 +295,7 @@
char **pbattrs = NULL;
int conn_acq_flag = 0;
- PR_AtomicIncrement( &active_threads );
+ g_incr_active_threadcnt();
/* need to acquire a reference to this connection so that it will not
be released or cleaned up out from under us */
@@ -443,7 +443,7 @@
pe_ch_free( &peq );
}
slapi_ch_free((void **) &ps );
- PR_AtomicDecrement(&active_threads);
+ g_decr_active_threadcnt();
}
Index: fe.h
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/fe.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- fe.h 3 Aug 2007 22:14:41 -0000 1.7
+++ fe.h 20 Sep 2007 16:54:38 -0000 1.8
@@ -56,7 +56,6 @@
#endif /* DONT_DECLARE_SLAPD_LDAP_DEBUG */
#endif
#endif
-extern int active_threads;
extern PRInt32 ops_initiated;
extern PRInt32 ops_completed;
extern PRLock *ops_mutex;
Index: globals.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/slapd/globals.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- globals.c 10 Nov 2006 23:45:40 -0000 1.6
+++ globals.c 20 Sep 2007 16:54:38 -0000 1.7
@@ -88,14 +88,12 @@
/*
* global variables that need mutex protection
*/
-int active_threads;
PRInt32 ops_initiated;
PRInt32 ops_completed;
PRLock *ops_mutex;
int num_conns;
PRLock *num_conns_mutex;
-
/*
DEC/COMPAQ has released a patch for 4.0d (e?) which will speed up
malloc/free considerably in multithreaded multiprocessor
More information about the Fedora-directory-commits
mailing list