andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 4 months ago
Clone
dc8c34
From a65b2927980028eba4574f59f9c216ffb0347356 Mon Sep 17 00:00:00 2001
dc8c34
From: Noriko Hosoi <nhosoi@redhat.com>
dc8c34
Date: Wed, 20 Mar 2013 18:25:41 -0700
dc8c34
Subject: [PATCH 39/42] Ticket #634 - Deadlock in DNA plug-in
dc8c34
dc8c34
Bug description: Fix for Ticket #576 -
dc8c34
DNA: use event queue for config update only at the start up
dc8c34
(commit 7c11ed17796ba8b17afa5758fcfdf1c937b54ef4)
dc8c34
modified the timing of updating the shared config in the
dc8c34
database.  The write operation was no need to be in the DNA
dc8c34
write lock, but it was located in it, which caused the dead-
dc8c34
lock.
dc8c34
dc8c34
Fix description: This patch releases the dna write lock before
dc8c34
updating the shared config in the database.
dc8c34
dc8c34
https://fedorahosted.org/389/ticket/634
dc8c34
dc8c34
Reviewed by Nathan (Thank you!!)
dc8c34
---
dc8c34
 ldap/servers/plugins/dna/dna.c | 45 +++++++++++-------------------------------
dc8c34
 1 file changed, 11 insertions(+), 34 deletions(-)
dc8c34
dc8c34
diff --git a/ldap/servers/plugins/dna/dna.c b/ldap/servers/plugins/dna/dna.c
dc8c34
index 080e357..d3dfa52 100644
dc8c34
--- a/ldap/servers/plugins/dna/dna.c
dc8c34
+++ b/ldap/servers/plugins/dna/dna.c
dc8c34
@@ -666,6 +666,7 @@ dna_load_plugin_config(int use_eventq)
dc8c34
 
dc8c34
     if (LDAP_SUCCESS != result) {
dc8c34
         status = DNA_FAILURE;
dc8c34
+        dna_unlock();
dc8c34
         goto cleanup;
dc8c34
     }
dc8c34
 
dc8c34
@@ -673,6 +674,7 @@ dna_load_plugin_config(int use_eventq)
dc8c34
                      &entries);
dc8c34
     if (NULL == entries || NULL == entries[0]) {
dc8c34
         status = DNA_SUCCESS;
dc8c34
+        dna_unlock();
dc8c34
         goto cleanup;
dc8c34
     }
dc8c34
 
dc8c34
@@ -682,6 +684,7 @@ dna_load_plugin_config(int use_eventq)
dc8c34
          * looking for valid ones. */
dc8c34
         dna_parse_config_entry(entries[i], 1);
dc8c34
     }
dc8c34
+    dna_unlock();
dc8c34
 
dc8c34
     if (use_eventq) {
dc8c34
         /* Setup an event to update the shared config 30
dc8c34
@@ -692,14 +695,13 @@ dna_load_plugin_config(int use_eventq)
dc8c34
         time(&now;;
dc8c34
         slapi_eq_once(dna_update_config_event, NULL, now + 30);
dc8c34
     } else {
dc8c34
-        int nolock = 1; /* no need to lock since dna write lock is held. */
dc8c34
-        dna_update_config_event(0, &nolock);
dc8c34
+        int arg = 0; /* not used. */
dc8c34
+        dna_update_config_event(0, &arg;;
dc8c34
     }
dc8c34
 
dc8c34
 cleanup:
dc8c34
     slapi_free_search_results_internal(search_pb);
dc8c34
     slapi_pblock_destroy(search_pb);
dc8c34
-    dna_unlock();
dc8c34
     slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
dc8c34
                     "<-- dna_load_plugin_config\n");
dc8c34
 
dc8c34
@@ -1247,15 +1249,8 @@ dna_update_config_event(time_t event_time, void *arg)
dc8c34
     Slapi_PBlock *pb = NULL;
dc8c34
     struct configEntry *config_entry = NULL;
dc8c34
     PRCList *list = NULL;
dc8c34
-    int nolock = 0;
dc8c34
 
dc8c34
-    if (arg) {
dc8c34
-        nolock = *(int *)arg;
dc8c34
-    }
dc8c34
-    if (!nolock) {
dc8c34
-        /* Get read lock to prevent config changes */
dc8c34
-        dna_read_lock();
dc8c34
-    }
dc8c34
+    dna_read_lock();
dc8c34
 
dc8c34
     /* Bail out if the plug-in close function was just called. */
dc8c34
     if (!g_plugin_started) {
dc8c34
@@ -1300,9 +1295,7 @@ dna_update_config_event(time_t event_time, void *arg)
dc8c34
     }
dc8c34
 
dc8c34
 bail:
dc8c34
-    if (!nolock) {
dc8c34
-        dna_unlock();
dc8c34
-    }
dc8c34
+    dna_unlock();
dc8c34
     slapi_pblock_destroy(pb);
dc8c34
 }
dc8c34
 
dc8c34
@@ -2785,7 +2778,6 @@ _dna_pre_op_add(Slapi_PBlock *pb, Slapi_Entry *e, char **errstr)
dc8c34
     char **generated_types = NULL;
dc8c34
     PRUint64 setval = 0;
dc8c34
     int i;
dc8c34
-    int issharedconfig = 0;
dc8c34
 
dc8c34
     /* Bail out if the plug-in close function was just called. */
dc8c34
     if (!g_plugin_started) {
dc8c34
@@ -2803,12 +2795,7 @@ _dna_pre_op_add(Slapi_PBlock *pb, Slapi_Entry *e, char **errstr)
dc8c34
      *  We also check if we need to get the next range of values, and grab them.
dc8c34
      *  We do this here so we don't have to do it in the be_txn_preop.
dc8c34
      */
dc8c34
-    /* Has write lock for config entries. */
dc8c34
-    issharedconfig = slapi_entry_attr_hasvalue(e, SLAPI_ATTR_OBJECTCLASS,
dc8c34
-                                               DNA_SHAREDCONFIG);
dc8c34
-    if (!issharedconfig) {
dc8c34
-        dna_read_lock();
dc8c34
-    }
dc8c34
+    dna_read_lock();
dc8c34
 
dc8c34
     if (!PR_CLIST_IS_EMPTY(dna_global_config)) {
dc8c34
         list = PR_LIST_HEAD(dna_global_config);
dc8c34
@@ -2966,9 +2953,7 @@ next:
dc8c34
         }
dc8c34
     }
dc8c34
 
dc8c34
-    if (!issharedconfig) {
dc8c34
-        dna_unlock();
dc8c34
-    }
dc8c34
+    dna_unlock();
dc8c34
 
dc8c34
     slapi_ch_array_free(generated_types);
dc8c34
 bail:
dc8c34
@@ -3427,7 +3412,6 @@ static int dna_be_txn_pre_op(Slapi_PBlock *pb, int modtype)
dc8c34
     char *type = NULL;
dc8c34
     int numvals, e_numvals = 0;
dc8c34
     int i, len, ret = 0;
dc8c34
-    int issharedconfig = 0;
dc8c34
 
dc8c34
     slapi_log_error(SLAPI_LOG_TRACE, DNA_PLUGIN_SUBSYSTEM,
dc8c34
                     "--> dna_be_txn_pre_op\n");
dc8c34
@@ -3463,12 +3447,7 @@ static int dna_be_txn_pre_op(Slapi_PBlock *pb, int modtype)
dc8c34
         slapi_mods_init_passin(smods, mods);
dc8c34
     }
dc8c34
 
dc8c34
-    /* Has write lock for config entries. */
dc8c34
-    issharedconfig = slapi_entry_attr_hasvalue(e, SLAPI_ATTR_OBJECTCLASS,
dc8c34
-                                               DNA_SHAREDCONFIG);
dc8c34
-    if (!issharedconfig) {
dc8c34
-        dna_read_lock();
dc8c34
-    }
dc8c34
+    dna_read_lock();
dc8c34
 
dc8c34
     if (!PR_CLIST_IS_EMPTY(dna_global_config)) {
dc8c34
         list = PR_LIST_HEAD(dna_global_config);
dc8c34
@@ -3659,9 +3638,7 @@ next:
dc8c34
             list = PR_NEXT_LINK(list);
dc8c34
         }
dc8c34
     }
dc8c34
-    if (!issharedconfig) {
dc8c34
-        dna_unlock();
dc8c34
-    }
dc8c34
+    dna_unlock();
dc8c34
 bail:
dc8c34
 
dc8c34
     if (LDAP_CHANGETYPE_MODIFY == modtype) {
dc8c34
-- 
dc8c34
1.8.1.4
dc8c34