[prev in list] [next in list] [prev in thread] [next in thread] 

List:       fedora-directory-commits
Subject:    [389-commits] ldap/servers
From:       Noriko Hosoi <nhosoi () fedoraproject ! org>
Date:       2012-04-25 1:03:58
Message-ID: 20120425010358.ADFB22272 () lists ! fedorahosted ! org
[Download RAW message or body]

 ldap/servers/plugins/usn/usn.c             |  152 +++++++++++++----------------
 ldap/servers/slapd/back-ldbm/ldbm_delete.c |  107 ++++++++------------
 ldap/servers/slapd/pblock.c                |   12 ++
 ldap/servers/slapd/plugin.c                |    1 
 ldap/servers/slapd/slap.h                  |    3 
 ldap/servers/slapd/slapi-plugin.h          |    2 
 6 files changed, 129 insertions(+), 148 deletions(-)

New commits:
commit a5ed82445832092277f5edf2d0440c8d1e931619
Author: Noriko Hosoi <nhosoi@redhat.com>
Date:   Tue Apr 24 17:54:56 2012 -0700

    Trac Ticket #19 - Convert entryUSN plugin to transaction aware type
    
    https://fedorahosted.org/389/ticket/19
    
    Fix description:
    . Separated usn_bepreop operations from usn_betxnpreop operations.
      usn_bepreop_modify and _modrdn add "entryusn: #" to the mods,
      which should be handled before the transaction starts.
    . Introduced SLAPI_PLUGIN_BE_TXN_PRE_DELETE_TOMBSTONE_FN plugin
      hook to modify the tombstone entry at the betxn timing.
    . Eliminated preventryusn (SLAPI_ATTR_ENTRYUSN_PREV). It was used
      to undo the incremented entryusn when the deletion fails.
      Since the operation is now executed in the transaction and it
      is aborted if the operation fails, the explicit undo is not
      needed in the usn postop.
    
    Reviewed by Rich. (Thank you!!)

diff --git a/ldap/servers/plugins/usn/usn.c b/ldap/servers/plugins/usn/usn.c
index 617589e..0d8a065 100644
--- a/ldap/servers/plugins/usn/usn.c
+++ b/ldap/servers/plugins/usn/usn.c
@@ -51,16 +51,18 @@ static void *_usn_identity = NULL;
 
 static int usn_preop_init(Slapi_PBlock *pb);
 static int usn_bepreop_init(Slapi_PBlock *pb);
+static int usn_betxnpreop_init(Slapi_PBlock *pb);
 static int usn_bepostop_init(Slapi_PBlock *pb);
 static int usn_rootdse_init();
 
 static int usn_preop_delete(Slapi_PBlock *pb);
-static int usn_bepreop_add(Slapi_PBlock *pb);
-static int usn_bepreop_delete(Slapi_PBlock *pb);
 static int usn_bepreop_modify(Slapi_PBlock *pb);
+static int usn_betxnpreop_add(Slapi_PBlock *pb);
+static int usn_betxnpreop_delete(Slapi_PBlock *pb);
 static int usn_bepostop(Slapi_PBlock *pb);
 static int usn_bepostop_delete (Slapi_PBlock *pb);
 static int usn_bepostop_modify (Slapi_PBlock *pb);
+
 static int usn_start(Slapi_PBlock *pb);
 static int usn_close(Slapi_PBlock *pb);
 static int usn_get_attr(Slapi_PBlock *pb, const char* type, void *value);
@@ -78,8 +80,8 @@ usn_init(Slapi_PBlock *pb)
 {
     int rc = 0;
     void *identity = NULL;
-	Slapi_Entry *plugin_entry = NULL;
-	int is_betxn = 0;
+    Slapi_Entry *plugin_entry = NULL;
+    int is_betxn = 0;
     const char *plugintype;
 
     slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
@@ -87,10 +89,11 @@ usn_init(Slapi_PBlock *pb)
 
     slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &identity);
 
-	if ((slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &plugin_entry) == 0) &&
-		plugin_entry) {
-		is_betxn = slapi_entry_attr_get_bool(plugin_entry, "nsslapd-pluginbetxn");
-	}
+    if ((slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &plugin_entry) == 0) &&
+        plugin_entry) {
+        is_betxn = slapi_entry_attr_get_bool(plugin_entry,
+                                             "nsslapd-pluginbetxn");
+    }
 
     /* slapi_register_plugin always returns SUCCESS (0) */
     if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION,
@@ -112,20 +115,23 @@ usn_init(Slapi_PBlock *pb)
         goto bail;
     }
 
+    /* usn_preop_init: plugintype is preoperation (not be/betxn) */
     plugintype = "preoperation";
-    if (is_betxn) {
-        plugintype = "betxnpreoperation";
-    }
     rc = slapi_register_plugin(plugintype, 1 /* Enabled */,
                                "usn_preop_init", usn_preop_init,
                                "USN preoperation plugin", NULL, identity);
+
+    /* usn_bepreop_init: plugintype is bepreoperation (not betxn) */
     plugintype = "bepreoperation";
-    if (is_betxn) {
-        plugintype = "betxnpreoperation";
-    }
     rc |= slapi_register_plugin(plugintype, 1 /* Enabled */,
                                "usn_bepreop_init", usn_bepreop_init,
                                "USN bepreoperation plugin", NULL, identity);
+
+    /* usn_bepreop_init: plugintype is betxnpreoperation */
+    plugintype = "betxnpreoperation";
+    rc |= slapi_register_plugin(plugintype, 1 /* Enabled */,
+                               "usn_betxnpreop_init", usn_betxnpreop_init,
+                               "USN betxnpreoperation plugin", NULL, identity);
     plugintype = "bepostoperation";
     if (is_betxn) {
         plugintype = "betxnpostoperation";
@@ -140,22 +146,12 @@ bail:
     return rc;
 }
 
+/* This ops must be preop not be/betxn */
 static int
 usn_preop_init(Slapi_PBlock *pb)
 {
     int rc = 0;
-    Slapi_Entry *plugin_entry = NULL;
-    char *plugin_type = NULL;
     int predel = SLAPI_PLUGIN_PRE_DELETE_FN;
-
-	if ((slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &plugin_entry) == 0) &&
-		plugin_entry &&
-		(plugin_type = slapi_entry_attr_get_charptr(plugin_entry, "nsslapd-plugintype")) \
                &&
-		plugin_type && strstr(plugin_type, "betxn")) {
-        predel = SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN;
-	}
-	slapi_ch_free_string(&plugin_type);
-
     /* set up csn generator for tombstone */
     _usn_csngen = csngen_new(USN_CSNGEN_ID, NULL);
     if (NULL == _usn_csngen) {
@@ -177,30 +173,34 @@ static int
 usn_bepreop_init(Slapi_PBlock *pb)
 {
     int rc = 0;
-    Slapi_Entry *plugin_entry = NULL;
-    char *plugin_type = NULL;
-    int preadd = SLAPI_PLUGIN_BE_PRE_ADD_FN;
     int premod = SLAPI_PLUGIN_BE_PRE_MODIFY_FN;
     int premdn = SLAPI_PLUGIN_BE_PRE_MODRDN_FN;
-    int predel = SLAPI_PLUGIN_BE_PRE_DELETE_FN;
 
-    if ((slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &plugin_entry) == 0) &&
-        plugin_entry &&
-        (plugin_type = slapi_entry_attr_get_charptr(plugin_entry, \
                "nsslapd-plugintype")) &&
-        plugin_type && strstr(plugin_type, "betxn")) {
-        preadd = SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN;
-        premod = SLAPI_PLUGIN_BE_TXN_PRE_MODIFY_FN;
-        premdn = SLAPI_PLUGIN_BE_TXN_PRE_MODRDN_FN;
-        predel = SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN;
+    /* usn_bepreop functions are called at BE_PRE_OP timing,
+     * not at BE_TXN_PREOP */
+    /* modify/modrdn updates mods which is evaluated before the 
+     * transaction start */
+    if ((slapi_pblock_set(pb, premod, (void *)usn_bepreop_modify) != 0) ||
+        (slapi_pblock_set(pb, premdn, (void *)usn_bepreop_modify) != 0)) {
+        slapi_log_error(SLAPI_LOG_FATAL, USN_PLUGIN_SUBSYSTEM,
+                       "usn_bepreop_init: failed to register bepreop plugin\n");
+        rc = -1;
     }
-    slapi_ch_free_string(&plugin_type);
 
-    if (slapi_pblock_set(pb, preadd, (void *)usn_bepreop_add) != 0 ||
-        slapi_pblock_set(pb, predel, (void *)usn_bepreop_delete) != 0 ||
-        slapi_pblock_set(pb, premod, (void *)usn_bepreop_modify) != 0 ||
-        slapi_pblock_set(pb, premdn, (void *)usn_bepreop_modify) != 0) {
+    return rc;
+}
+
+static int
+usn_betxnpreop_init(Slapi_PBlock *pb)
+{
+    int rc = 0;
+    int preadd = SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN;
+    int predel = SLAPI_PLUGIN_BE_TXN_PRE_DELETE_TOMBSTONE_FN;
+
+    if ((slapi_pblock_set(pb, preadd, (void *)usn_betxnpreop_add) != 0) ||
+        (slapi_pblock_set(pb, predel, (void *)usn_betxnpreop_delete) != 0)) { 
         slapi_log_error(SLAPI_LOG_FATAL, USN_PLUGIN_SUBSYSTEM,
-                        "usn_bepreop_init: failed to register bepreop plugin\n");
+                 "usn_betxnpreop_init: failed to register betxnpreop plugin\n");
         rc = -1;
     }
 
@@ -220,7 +220,8 @@ usn_bepostop_init(Slapi_PBlock *pb)
 
     if ((slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY, &plugin_entry) == 0) &&
         plugin_entry &&
-        (plugin_type = slapi_entry_attr_get_charptr(plugin_entry, \
"nsslapd-plugintype")) && +        (plugin_type = \
slapi_entry_attr_get_charptr(plugin_entry, +                                          \
"nsslapd-plugintype")) &&  plugin_type && strstr(plugin_type, "betxn")) {
         postadd = SLAPI_PLUGIN_BE_TXN_POST_ADD_FN;
         postmod = SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN;
@@ -229,12 +230,12 @@ usn_bepostop_init(Slapi_PBlock *pb)
     }
     slapi_ch_free_string(&plugin_type);
 
-    if (slapi_pblock_set(pb, postadd, (void *)usn_bepostop) != 0 ||
-        slapi_pblock_set(pb, postdel, (void *)usn_bepostop_delete) != 0 ||
-        slapi_pblock_set(pb, postmod, (void *)usn_bepostop_modify) != 0 ||
-        slapi_pblock_set(pb, postmdn, (void *)usn_bepostop) != 0) {
+    if ((slapi_pblock_set(pb, postadd, (void *)usn_bepostop) != 0) ||
+        (slapi_pblock_set(pb, postdel, (void *)usn_bepostop_delete) != 0) ||
+        (slapi_pblock_set(pb, postmod, (void *)usn_bepostop_modify) != 0) ||
+        (slapi_pblock_set(pb, postmdn, (void *)usn_bepostop) != 0)) {
         slapi_log_error(SLAPI_LOG_FATAL, USN_PLUGIN_SUBSYSTEM,
-                        "usn_bepostop_init: failed to register bepostop plugin\n");
+                     "usn_bepostop_init: failed to register bepostop plugin\n");
         rc = -1;
     }
 
@@ -356,10 +357,8 @@ bail:
     return rc;
 }
 
-#define KEEP_PREV_USN 1
-
 static void
-_usn_add_next_usn(Slapi_Entry *e, Slapi_Backend *be, int flags)
+_usn_add_next_usn(Slapi_Entry *e, Slapi_Backend *be)
 {
     struct berval usn_berval = {0};
     Slapi_Attr* attr = NULL;
@@ -383,14 +382,6 @@ _usn_add_next_usn(Slapi_Entry *e, Slapi_Backend *be, int flags)
         slapi_value_free(&usn_value);
     } else { /* ENTRYUSN exists; replace it */
         struct berval *new_bvals[2];
-        struct berval **prev_values = NULL;
-        if (KEEP_PREV_USN == flags) {
-            if (0 == slapi_attr_get_bervals_copy(attr, &prev_values)) {
-                slapi_entry_add_values(e,
-                                SLAPI_ATTR_ENTRYUSN_PREV, prev_values);
-                ber_bvecfree(prev_values);
-            }
-        }
         new_bvals[0] = &usn_berval;
         new_bvals[1] = NULL;
         slapi_entry_attr_replace(e, SLAPI_ATTR_ENTRYUSN, new_bvals);
@@ -440,17 +431,17 @@ _usn_mod_next_usn(LDAPMod ***mods, Slapi_Backend *be)
 }
 
 /*
- * usn_bepreop_add - add next USN to the entry to be added
+ * usn_betxnpreop_add - add next USN to the entry to be added
  */
 static int
-usn_bepreop_add(Slapi_PBlock *pb)
+usn_betxnpreop_add(Slapi_PBlock *pb)
 {
     Slapi_Entry *e = NULL;
     Slapi_Backend *be = NULL;
     int rc = LDAP_SUCCESS;
 
     slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
-                    "--> usn_bepreop_add\n");
+                    "--> usn_betxnpreop_add\n");
 
     /* add next USN to the entry; "be" contains the usn counter */
     slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &e);
@@ -463,26 +454,26 @@ usn_bepreop_add(Slapi_PBlock *pb)
         rc = LDAP_PARAM_ERROR;    
         goto bail;
     }
-    _usn_add_next_usn(e, be, 0);
+    _usn_add_next_usn(e, be);
 bail:
     slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
-                    "<-- usn_bepreop_add\n");
+                    "<-- usn_betxnpreop_add\n");
     return rc;
 }
 
 /* 
- * usn_bepreop_delete -- add/replace next USN to the entry
+ * usn_betxnpreop_delete -- add/replace next USN to the entry
  *                       bepreop_delete is not called if the entry is tombstone
  */
 static int
-usn_bepreop_delete(Slapi_PBlock *pb)
+usn_betxnpreop_delete(Slapi_PBlock *pb)
 {
     Slapi_Entry *e = NULL;
     Slapi_Backend *be = NULL;
     int rc = LDAP_SUCCESS;
 
     slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
-                    "--> usn_bepreop_delete\n");
+                    "--> usn_betxnpreop_delete\n");
 
     /* add next USN to the entry; "be" contains the usn counter */
     slapi_pblock_get(pb, SLAPI_DELETE_BEPREOP_ENTRY, &e);
@@ -499,12 +490,11 @@ usn_bepreop_delete(Slapi_PBlock *pb)
         Slapi_Operation *op = NULL;
         slapi_pblock_get(pb, SLAPI_OPERATION, &op);
         slapi_operation_set_flag(op, OP_FLAG_TOMBSTONE_ENTRY);
-    } else {
-        _usn_add_next_usn(e, be, KEEP_PREV_USN);
     }
+    _usn_add_next_usn(e, be);
 bail:
     slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
-                    "<-- usn_bepreop_delete\n");
+                    "<-- usn_betxnpreop_delete\n");
     return rc;
 }
 
@@ -591,7 +581,7 @@ usn_bepostop_modify (Slapi_PBlock *pb)
     for (i = 0; mods && mods[i]; i++) {
         if (0 == strcasecmp(mods[i]->mod_type, SLAPI_ATTR_ENTRYUSN)) {
             if (mods[i]->mod_op & LDAP_MOD_IGNORE) {
-    slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
+                slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
                     "usn_bepostop_mod: MOD_IGNORE detected\n");
                 goto bail; /* conflict occurred.
                               skip incrementing the counter. */
@@ -623,22 +613,20 @@ usn_bepostop_delete (Slapi_PBlock *pb)
 {
     int rc = -1;
     Slapi_Backend *be = NULL;
+    Slapi_Operation *op = NULL;
+    CSN *csn = NULL;
 
     slapi_log_error(SLAPI_LOG_TRACE, USN_PLUGIN_SUBSYSTEM,
                     "--> usn_bepostop\n");
 
+    slapi_pblock_get(pb, SLAPI_OPERATION, &op);
+    csn = operation_get_csn(op);
+    csn_free(&csn);
+    operation_set_csn(op, NULL);
+
     /* if op is not successful, don't increment the counter */
     slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
     if (LDAP_SUCCESS != rc) {
-        Slapi_Entry *e = NULL;
-
-        slapi_pblock_get(pb, SLAPI_DELETE_BEPOSTOP_ENTRY, &e);
-        if (NULL == e) {
-            rc = LDAP_NO_SUCH_OBJECT;    
-            goto bail;
-        }
-        /* okay to return the rc from slapi_entry_delete_values */
-        rc = slapi_entry_delete_values(e, SLAPI_ATTR_ENTRYUSN_PREV, NULL);
         goto bail;
     }
 
@@ -771,5 +759,5 @@ usn_rootdse_search(Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* \
entryAfter,  int
 usn_is_started()
 {
-	return g_plugin_started;
+    return g_plugin_started;
 }
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_delete.c \
b/ldap/servers/slapd/back-ldbm/ldbm_delete.c index fff93c9..569ad0b 100644
--- a/ldap/servers/slapd/back-ldbm/ldbm_delete.c
+++ b/ldap/servers/slapd/back-ldbm/ldbm_delete.c
@@ -95,7 +95,6 @@ ldbm_back_delete( Slapi_PBlock *pb )
 	entry_address *addr;
 	int addordel_flags = 0; /* passed to index_addordel */
 	char *entryusn_str = NULL;
-	char *prev_entryusn_str = NULL;
 	Slapi_Entry *orig_entry = NULL;
 	Slapi_DN parentsdn;
 	int opreturn = 0;
@@ -107,6 +106,7 @@ ldbm_back_delete( Slapi_PBlock *pb )
 	slapi_pblock_get( pb, SLAPI_TXN, (void**)&parent_txn );
 	slapi_pblock_get( pb, SLAPI_OPERATION, &operation );
 	slapi_pblock_get( pb, SLAPI_IS_REPLICATED_OPERATION, &is_replicated_operation );
+	slapi_pblock_get( pb, SLAPI_DELETE_BEPREOP_ENTRY, &orig_entry );
 	
 	/* sdn needs to be initialized before "goto *_return */
 	slapi_sdn_init(&sdn);
@@ -196,10 +196,6 @@ ldbm_back_delete( Slapi_PBlock *pb )
 		goto error_return;
 	}
 
-	/* set entry in case be-preop plugins need to work on it (e.g., USN) */
-	slapi_pblock_get( pb, SLAPI_DELETE_BEPREOP_ENTRY, &orig_entry );
-	slapi_pblock_set( pb, SLAPI_DELETE_BEPREOP_ENTRY, e->ep_entry );
-
 	/* Don't call pre-op for Tombstone entries */
 	if (!delete_tombstone_entry)
 	{
@@ -215,14 +211,15 @@ ldbm_back_delete( Slapi_PBlock *pb )
 		   ldap_result_code==LDAP_INVALID_DN_SYNTAX)
 		{
 			/* restore original entry so the front-end delete code can free it */
-			slapi_pblock_set( pb, SLAPI_DELETE_BEPREOP_ENTRY, orig_entry );
 			/* retval is -1 */
 			goto error_return;
 		}
 		slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
 
-		rc = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_DELETE_FN);
+		/* set entry in case be-preop plugins need to work on it (e.g., USN) */
+		slapi_pblock_set( pb, SLAPI_DELETE_BEPREOP_ENTRY, e->ep_entry );
 
+		rc = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_DELETE_FN);
 		if (rc == -1)
 		{
 			/* 
@@ -233,7 +230,6 @@ ldbm_back_delete( Slapi_PBlock *pb )
 				slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
 			}
 			/* restore original entry so the front-end delete code can free it */
-			slapi_pblock_set( pb, SLAPI_DELETE_BEPREOP_ENTRY, orig_entry );
 			slapi_pblock_get( pb, SLAPI_PLUGIN_OPRETURN, &opreturn );
 			if (!opreturn) {
 				slapi_pblock_set( pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? \
&ldap_result_code : &rc ); @@ -246,8 +242,6 @@ ldbm_back_delete( Slapi_PBlock *pb )
 									OP_FLAG_TOMBSTONE_ENTRY);
 	}
 
-	slapi_pblock_set( pb, SLAPI_DELETE_BEPREOP_ENTRY, orig_entry );
-
 	/*
 	 * Sanity check to avoid to delete a non-tombstone or to tombstone again
 	 * a tombstone entry. This should not happen (see bug 561003).
@@ -380,7 +374,7 @@ ldbm_back_delete( Slapi_PBlock *pb )
 				slapi_pblock_set ( pb, SLAPI_DELETE_GLUE_PARENT_ENTRY,
 					slapi_entry_dup (parent_modify_c.new_entry->ep_entry) );
 			}
-	    }		
+		}
 	}
 	slapi_sdn_done(&parentsdn);
     
@@ -436,21 +430,6 @@ ldbm_back_delete( Slapi_PBlock *pb )
 			operation_get_csn(operation));
 		slapi_entry_add_value(tombstone->ep_entry, SLAPI_ATTR_OBJECTCLASS, tomb_value);
 		slapi_value_free(&tomb_value);
-		
-		/* retrieve previous entry usn value, if any */
-		prev_entryusn_str = slapi_entry_attr_get_charptr(tombstone->ep_entry,
-												SLAPI_ATTR_ENTRYUSN_PREV);
-		if (prev_entryusn_str) {
-			/* discard the previous value from the tombstone entry */
-		    retval = slapi_entry_delete_string(tombstone->ep_entry,
-							SLAPI_ATTR_ENTRYUSN_PREV, prev_entryusn_str);
-			if (0 != retval) {
-				LDAPDebug( LDAP_DEBUG_TRACE,
-							"delete (deleting %s) failed, err=%d\n",
-							SLAPI_ATTR_ENTRYUSN, retval, 0) ;
-			}
-		}
-
 		/* XXXggood above used to be: slapi_entry_add_string(tombstone->ep_entry, \
SLAPI_ATTR_OBJECTCLASS, SLAPI_ATTR_VALUE_TOMBSTONE); */  /* JCMREPL - Add a \
description of what's going on? */  }
@@ -522,10 +501,14 @@ ldbm_back_delete( Slapi_PBlock *pb )
 		/* stash the transaction */
 		slapi_pblock_set(pb, SLAPI_TXN, txn.back_txn_txn);
 
-		/* call the transaction pre delete plugins just after creating the transaction */
-		if ((retval = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN))) {
-			LDAPDebug1Arg( LDAP_DEBUG_TRACE, "SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN plugin "
-						   "returned error code %d\n", retval );
+		/* call the transaction pre delete plugins just after creating
+		 * the transaction */
+		slapi_pblock_set( pb, SLAPI_DELETE_BEPREOP_ENTRY, e->ep_entry );
+		retval = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN);
+		if (retval) {
+			LDAPDebug1Arg( LDAP_DEBUG_TRACE,
+			               "SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN plugin "
+			               "returned error code %d\n", retval );
 			if (!ldap_result_code) {
 				slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
 			}
@@ -533,13 +516,40 @@ ldbm_back_delete( Slapi_PBlock *pb )
 				slapi_pblock_get( pb, SLAPI_PLUGIN_OPRETURN, &opreturn );
 			}
 			if (!opreturn) {
-				slapi_pblock_set( pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? \
&ldap_result_code : &retval ); +				slapi_pblock_set( pb, SLAPI_PLUGIN_OPRETURN,
+				                  ldap_result_code ?
+				                  &ldap_result_code : &retval );
 			}
 			goto error_return;
 		}
 
 		if(create_tombstone_entry)
 		{
+
+			slapi_pblock_set( pb, SLAPI_DELETE_BEPREOP_ENTRY,
+			                  tombstone->ep_entry );
+			rc = plugin_call_plugins(pb,
+			                       SLAPI_PLUGIN_BE_TXN_PRE_DELETE_TOMBSTONE_FN);
+			if (rc == -1) {
+				/* 
+				* Plugin indicated some kind of failure,
+				 * or that this Operation became a No-Op.
+				 */
+				if (!ldap_result_code) {
+					slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
+				}
+				/* restore original entry so the front-end delete code 
+				 * can free it */
+				slapi_pblock_get( pb, SLAPI_PLUGIN_OPRETURN, &opreturn );
+				if (!opreturn) {
+					slapi_pblock_set( pb, SLAPI_PLUGIN_OPRETURN,
+					                  ldap_result_code ?
+					                  &ldap_result_code : &rc );
+				}
+				/* retval is -1 */
+				goto error_return;
+			}
+
 			/*
 			 * The entry is not removed from the disk when we tombstone an
 			 * entry. We change the DN, add objectclass=tombstone, and record
@@ -703,30 +713,6 @@ ldbm_back_delete( Slapi_PBlock *pb )
 					goto error_return;
 				}
 			}
-			/* delete a previous value (if it exists) from the entryusn index */
-			if (prev_entryusn_str) {
-				retval = index_addordel_string(be, SLAPI_ATTR_ENTRYUSN,
-								prev_entryusn_str, tombstone->ep_id,
-								BE_INDEX_DEL|BE_INDEX_EQUALITY, &txn);
-				slapi_ch_free_string(&prev_entryusn_str);
-				if (DB_LOCK_DEADLOCK == retval) {
-					LDAPDebug( LDAP_DEBUG_ARGS,
-								"delete (deleting %s) DB_LOCK_DEADLOCK\n",
-								SLAPI_ATTR_ENTRYUSN, 0, 0 );
-					/* Retry txn */
-					continue;
-				}
-				if (0 != retval) {
-					LDAPDebug( LDAP_DEBUG_TRACE, 
-								"delete (deleting %s) failed, err=%d %s\n",
-								SLAPI_ATTR_ENTRYUSN, retval,
-								(msg = dblayer_strerror( retval )) ? msg : "" );
-					if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
-					DEL_SET_ERROR(ldap_result_code, 
-								  LDAP_OPERATIONS_ERROR, retry_count);
-					goto error_return;
-				}
-			}
 			if (entryrdn_get_switch()) /* subtree-rename: on */
 			{
 				Slapi_Attr *attr;
@@ -1111,6 +1097,7 @@ error_return:
 	}
 	
 common_return:
+	slapi_pblock_set( pb, SLAPI_DELETE_BEPREOP_ENTRY, orig_entry );
 	if (tombstone_in_cache)
 	{
 		CACHE_RETURN( &inst->inst_cache, &tombstone );
@@ -1127,17 +1114,7 @@ common_return:
 	 * but not if the operation is purging tombstones.
 	 */
 	if (!delete_tombstone_entry) {
-		if (e) {
-			/* set entry in case be-postop plugins need to work on it
-			 * (e.g., USN) */
-			slapi_pblock_get( pb, SLAPI_DELETE_BEPOSTOP_ENTRY, &orig_entry );
-			slapi_pblock_set( pb, SLAPI_DELETE_BEPOSTOP_ENTRY, e->ep_entry );
-		}
 		plugin_call_plugins (pb, SLAPI_PLUGIN_BE_POST_DELETE_FN);
-		/* set original entry back */
-		if (e) {
-			slapi_pblock_set( pb, SLAPI_DELETE_BEPOSTOP_ENTRY, orig_entry );
-		}
 	}
 
 	/* Need to return to cache after post op plugins are called */
diff --git a/ldap/servers/slapd/pblock.c b/ldap/servers/slapd/pblock.c
index 4b54403..76c031a 100644
--- a/ldap/servers/slapd/pblock.c
+++ b/ldap/servers/slapd/pblock.c
@@ -1087,6 +1087,12 @@ slapi_pblock_get( Slapi_PBlock *pblock, int arg, void *value )
 		}
 		(*(IFP *)value) = pblock->pb_plugin->plg_betxnpredelete;
 		break;
+	case SLAPI_PLUGIN_BE_TXN_PRE_DELETE_TOMBSTONE_FN:
+		if (pblock->pb_plugin->plg_type != SLAPI_PLUGIN_BETXNPREOPERATION) {
+			return( -1 );
+		}
+		(*(IFP *)value) = pblock->pb_plugin->plg_betxnpredeletetombstone;
+		break;
 
 	/* backend post txn operation plugin */
 	case SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN:
@@ -2666,6 +2672,12 @@ slapi_pblock_set( Slapi_PBlock *pblock, int arg, void *value )
 		}
 		pblock->pb_plugin->plg_betxnpredelete = (IFP) value;
 		break;
+	case SLAPI_PLUGIN_BE_TXN_PRE_DELETE_TOMBSTONE_FN:
+		if (pblock->pb_plugin->plg_type != SLAPI_PLUGIN_BETXNPREOPERATION) {
+			return( -1 );
+		}
+		pblock->pb_plugin->plg_betxnpredeletetombstone = (IFP) value;
+		break;
 
 	/* backend postoperation plugin - called just before committing transaction */
 	case SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN:
diff --git a/ldap/servers/slapd/plugin.c b/ldap/servers/slapd/plugin.c
index 4c8e8bd..1585779 100644
--- a/ldap/servers/slapd/plugin.c
+++ b/ldap/servers/slapd/plugin.c
@@ -375,6 +375,7 @@ plugin_call_plugins( Slapi_PBlock *pb, int whichfunction )
 	case SLAPI_PLUGIN_BE_TXN_PRE_MODRDN_FN:
 	case SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN:
 	case SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN:
+	case SLAPI_PLUGIN_BE_TXN_PRE_DELETE_TOMBSTONE_FN:
         plugin_list_number= PLUGIN_LIST_BETXNPREOPERATION;
 		do_op = 1; /* always allow backend callbacks (even during startup) */
 		break;
diff --git a/ldap/servers/slapd/slap.h b/ldap/servers/slapd/slap.h
index 669e304..54a921e 100644
--- a/ldap/servers/slapd/slap.h
+++ b/ldap/servers/slapd/slap.h
@@ -971,6 +971,7 @@ struct slapdplugin {
 			IFP	plg_un_bepre_modrdn;	  /* modrdn */
 			IFP	plg_un_bepre_add;		  /* add */
 			IFP	plg_un_bepre_delete;	  /* delete */
+			IFP	plg_un_bepre_delete_tombstone;	  /* tombstone creation */
 			IFP	plg_un_bepre_close;		  /* close */
 			IFP	plg_un_bepre_backup;	  /* backup */
 		} plg_un_bepre;
@@ -1123,11 +1124,13 @@ struct slapdplugin {
 			IFP	plg_un_betxnpre_modrdn;	  /* modrdn */
 			IFP	plg_un_betxnpre_add;		  /* add */
 			IFP	plg_un_betxnpre_delete;	  /* delete */
+			IFP	plg_un_betxnpre_delete_tombstone;	  /* delete tombstone */
 		} plg_un_betxnpre;
 #define plg_betxnpremodify	plg_un.plg_un_betxnpre.plg_un_betxnpre_modify
 #define plg_betxnpremodrdn	plg_un.plg_un_betxnpre.plg_un_betxnpre_modrdn
 #define plg_betxnpreadd	plg_un.plg_un_betxnpre.plg_un_betxnpre_add
 #define plg_betxnpredelete	plg_un.plg_un_betxnpre.plg_un_betxnpre_delete
+#define plg_betxnpredeletetombstone	plg_un.plg_un_betxnpre.plg_un_betxnpre_delete_tombstone
  
         /* backend txn post-operation plugin structure */
 		struct plg_un_betxnpost_operation {
diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h
index fa4892d..bef2356 100644
--- a/ldap/servers/slapd/slapi-plugin.h
+++ b/ldap/servers/slapd/slapi-plugin.h
@@ -378,7 +378,6 @@ NSPR_API(PRUint32) PR_fprintf(struct PRFileDesc* fd, const char \
*fmt, ...)  #define SLAPI_ATTR_VALUE_PARENT_UNIQUEID	"nsParentUniqueID"
 #define SLAPI_ATTR_NSCP_ENTRYDN 		"nscpEntryDN"
 #define SLAPI_ATTR_ENTRYUSN 			"entryusn"
-#define SLAPI_ATTR_ENTRYUSN_PREV 		"preventryusn"
 #define SLAPI_ATTR_ENTRYDN 				"entrydn"
 
 
@@ -6302,6 +6301,7 @@ typedef struct slapi_plugindesc {
 #define SLAPI_PLUGIN_BE_TXN_PRE_MODIFY_FN		461
 #define SLAPI_PLUGIN_BE_TXN_PRE_MODRDN_FN		462
 #define SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN		463
+#define SLAPI_PLUGIN_BE_TXN_PRE_DELETE_TOMBSTONE_FN		464
 
 /* postoperation plugin functions */
 #define SLAPI_PLUGIN_POST_BIND_FN		501


--
389 commits mailing list
389-commits@lists.fedoraproject.org
https://admin.fedoraproject.org/mailman/listinfo/389-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic