ldbm_delete.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
  37. * All rights reserved.
  38. * END COPYRIGHT BLOCK **/
  39. #ifdef HAVE_CONFIG_H
  40. # include <config.h>
  41. #endif
  42. /* delete.c - ldbm backend delete routine */
  43. #include "back-ldbm.h"
  44. #define DEL_SET_ERROR(rc, error, count) \
  45. { \
  46. (rc) = (error); \
  47. (count) = RETRY_TIMES; /* otherwise, the transaction may not be aborted */ \
  48. }
  49. int
  50. ldbm_back_delete( Slapi_PBlock *pb )
  51. {
  52. backend *be;
  53. ldbm_instance *inst = NULL;
  54. struct ldbminfo *li = NULL;
  55. struct backentry *e = NULL;
  56. struct backentry *tombstone = NULL;
  57. struct backentry *original_tombstone = NULL;
  58. const char *dn = NULL;
  59. back_txn txn;
  60. back_txnid parent_txn;
  61. int retval = -1;
  62. char *msg;
  63. char *errbuf = NULL;
  64. int retry_count = 0;
  65. int disk_full = 0;
  66. int parent_found = 0;
  67. int ruv_c_init = 0;
  68. modify_context parent_modify_c = {0};
  69. modify_context ruv_c = {0};
  70. int rc = 0;
  71. int ldap_result_code= LDAP_SUCCESS;
  72. char *ldap_result_message= NULL;
  73. Slapi_DN *sdnp = NULL;
  74. char *e_uniqueid = NULL;
  75. Slapi_DN nscpEntrySDN;
  76. int dblock_acquired= 0;
  77. Slapi_Operation *operation;
  78. CSN *opcsn = NULL;
  79. int is_fixup_operation = 0;
  80. int is_ruv = 0; /* True if the current entry is RUV */
  81. int is_replicated_operation= 0;
  82. int is_tombstone_entry = 0; /* True if the current entry is alreday a tombstone */
  83. int delete_tombstone_entry = 0; /* We must remove the given tombstone entry from the DB */
  84. int create_tombstone_entry = 0; /* We perform a "regular" LDAP delete but since we use */
  85. /* replication, we must create a new tombstone entry */
  86. int tombstone_in_cache = 0;
  87. int e_in_cache = 0;
  88. entry_address *addr;
  89. int addordel_flags = 0; /* passed to index_addordel */
  90. char *entryusn_str = NULL;
  91. Slapi_Entry *orig_entry = NULL;
  92. Slapi_DN parentsdn;
  93. int opreturn = 0;
  94. int free_delete_existing_entry = 0;
  95. slapi_pblock_get( pb, SLAPI_BACKEND, &be);
  96. slapi_pblock_get( pb, SLAPI_PLUGIN_PRIVATE, &li );
  97. slapi_pblock_get( pb, SLAPI_DELETE_TARGET_SDN, &sdnp );
  98. slapi_pblock_get( pb, SLAPI_TARGET_ADDRESS, &addr);
  99. slapi_pblock_get( pb, SLAPI_TXN, (void**)&parent_txn );
  100. slapi_pblock_get( pb, SLAPI_OPERATION, &operation );
  101. slapi_pblock_get( pb, SLAPI_IS_REPLICATED_OPERATION, &is_replicated_operation );
  102. slapi_sdn_init(&nscpEntrySDN);
  103. /* dblayer_txn_init needs to be called before "goto error_return" */
  104. dblayer_txn_init(li,&txn);
  105. /* the calls to perform searches require the parent txn if any
  106. so set txn to the parent_txn until we begin the child transaction */
  107. if (parent_txn) {
  108. txn.back_txn_txn = parent_txn;
  109. } else {
  110. parent_txn = txn.back_txn_txn;
  111. slapi_pblock_set( pb, SLAPI_TXN, parent_txn );
  112. }
  113. if (pb->pb_conn)
  114. {
  115. slapi_log_error (SLAPI_LOG_TRACE, "ldbm_back_delete", "enter conn=%" NSPRIu64 " op=%d\n", pb->pb_conn->c_connid, operation->o_opid);
  116. }
  117. if ((NULL == addr) && (NULL == sdnp))
  118. {
  119. /* retval is -1 */
  120. goto error_return;
  121. }
  122. dn = slapi_sdn_get_dn(sdnp);
  123. ldap_result_code = slapi_dn_syntax_check(pb, dn, 1);
  124. if (ldap_result_code)
  125. {
  126. ldap_result_code = LDAP_INVALID_DN_SYNTAX;
  127. slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
  128. /* retval is -1 */
  129. goto error_return;
  130. }
  131. is_fixup_operation = operation_is_flag_set(operation, OP_FLAG_REPL_FIXUP);
  132. is_ruv = operation_is_flag_set(operation, OP_FLAG_REPL_RUV);
  133. delete_tombstone_entry = operation_is_flag_set(operation, OP_FLAG_TOMBSTONE_ENTRY);
  134. inst = (ldbm_instance *) be->be_instance_info;
  135. /* The dblock serializes writes to the database,
  136. * which reduces deadlocking in the db code,
  137. * which means that we run faster.
  138. *
  139. * But, this lock is re-enterant for the fixup
  140. * operations that the URP code in the Replication
  141. * plugin generates.
  142. */
  143. if(SERIALLOCK(li) && !operation_is_flag_set(operation,OP_FLAG_REPL_FIXUP))
  144. {
  145. dblayer_lock_backend(be);
  146. dblock_acquired= 1;
  147. }
  148. /*
  149. * We are about to pass the last abandon test, so from now on we are
  150. * committed to finish this operation. Set status to "will complete"
  151. * before we make our last abandon check to avoid race conditions in
  152. * the code that processes abandon operations.
  153. */
  154. if (operation) {
  155. operation->o_status = SLAPI_OP_STATUS_WILL_COMPLETE;
  156. }
  157. if ( slapi_op_abandoned( pb ) ) {
  158. /* retval is -1 */
  159. goto error_return;
  160. }
  161. /* find and lock the entry we are about to modify */
  162. if ( (e = find_entry2modify( pb, be, addr, &txn )) == NULL )
  163. {
  164. ldap_result_code= LDAP_NO_SUCH_OBJECT;
  165. /* retval is -1 */
  166. goto error_return; /* error result sent by find_entry2modify() */
  167. }
  168. e_in_cache = 1; /* e is cached */
  169. if ( slapi_entry_has_children( e->ep_entry ) )
  170. {
  171. ldap_result_code= LDAP_NOT_ALLOWED_ON_NONLEAF;
  172. /* retval is -1 */
  173. goto error_return;
  174. }
  175. /* Don't call pre-op for Tombstone entries */
  176. if (!delete_tombstone_entry)
  177. {
  178. int rc = 0;
  179. /*
  180. * Some present state information is passed through the PBlock to the
  181. * backend pre-op plugin. To ensure a consistent snapshot of this state
  182. * we wrap the reading of the entry with the dblock.
  183. */
  184. ldap_result_code= get_copy_of_entry(pb, addr, &txn,
  185. SLAPI_DELETE_EXISTING_ENTRY, !is_replicated_operation);
  186. free_delete_existing_entry = 1;
  187. if(ldap_result_code==LDAP_OPERATIONS_ERROR ||
  188. ldap_result_code==LDAP_INVALID_DN_SYNTAX)
  189. {
  190. /* restore original entry so the front-end delete code can free it */
  191. /* retval is -1 */
  192. goto error_return;
  193. }
  194. slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
  195. rc = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_DELETE_FN);
  196. if (rc == -1)
  197. {
  198. /*
  199. * Plugin indicated some kind of failure,
  200. * or that this Operation became a No-Op.
  201. */
  202. if (!ldap_result_code) {
  203. slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
  204. }
  205. /* restore original entry so the front-end delete code can free it */
  206. slapi_pblock_get( pb, SLAPI_PLUGIN_OPRETURN, &opreturn );
  207. if (!opreturn) {
  208. slapi_pblock_set( pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? &ldap_result_code : &rc );
  209. }
  210. /* retval is -1 */
  211. goto error_return;
  212. }
  213. /* the flag could be set in a preop plugin (e.g., USN) */
  214. delete_tombstone_entry = operation_is_flag_set(operation,
  215. OP_FLAG_TOMBSTONE_ENTRY);
  216. }
  217. /*
  218. * Sanity check to avoid to delete a non-tombstone or to tombstone again
  219. * a tombstone entry. This should not happen (see bug 561003).
  220. */
  221. is_tombstone_entry = slapi_entry_flag_is_set(e->ep_entry, SLAPI_ENTRY_FLAG_TOMBSTONE);
  222. if (delete_tombstone_entry) {
  223. PR_ASSERT(is_tombstone_entry);
  224. if (!is_tombstone_entry) {
  225. slapi_log_error(SLAPI_LOG_FATAL, "ldbm_back_delete",
  226. "Attempt to delete a non-tombstone entry %s\n", dn);
  227. delete_tombstone_entry = 0;
  228. }
  229. } else {
  230. PR_ASSERT(!is_tombstone_entry);
  231. if (is_tombstone_entry) {
  232. slapi_log_error(SLAPI_LOG_FATAL, "ldbm_back_delete",
  233. "Attempt to Tombstone again a tombstone entry %s\n", dn);
  234. delete_tombstone_entry = 1;
  235. }
  236. }
  237. /*
  238. * If a CSN is set, we need to tombstone the entry,
  239. * rather than deleting it outright.
  240. */
  241. opcsn = operation_get_csn (operation);
  242. if (!delete_tombstone_entry)
  243. {
  244. if ((opcsn == NULL) && !is_fixup_operation && operation->o_csngen_handler)
  245. {
  246. /*
  247. * Current op is a user request. Opcsn will be assigned
  248. * by entry_assign_operation_csn() if the dn is in an
  249. * updatable replica.
  250. */
  251. opcsn = entry_assign_operation_csn ( pb, e->ep_entry, NULL );
  252. }
  253. if (opcsn != NULL)
  254. {
  255. if (!is_fixup_operation)
  256. {
  257. entry_set_maxcsn (e->ep_entry, opcsn);
  258. }
  259. }
  260. /*
  261. * We are dealing with replication and if we haven't been called to
  262. * remove a tombstone, then it's because we want to create a new one.
  263. */
  264. if ( slapi_operation_get_replica_attr (pb, operation, "nsds5ReplicaTombstonePurgeInterval",
  265. &create_tombstone_entry) == 0 )
  266. {
  267. create_tombstone_entry = (create_tombstone_entry < 0) ? 0 : 1;
  268. }
  269. }
  270. #if DEBUG
  271. slapi_log_error(SLAPI_LOG_REPL, "ldbm_back_delete",
  272. "entry: %s - flags: delete %d is_tombstone_entry %d create %d \n",
  273. dn, delete_tombstone_entry, is_tombstone_entry, create_tombstone_entry);
  274. #endif
  275. /* Save away a copy of the entry, before modifications */
  276. slapi_pblock_set( pb, SLAPI_ENTRY_PRE_OP, slapi_entry_dup( e->ep_entry ));
  277. /* JCMACL - Shouldn't the access check be before the has children check...
  278. * otherwise we're revealing the fact that an entry exists and has children */
  279. ldap_result_code = plugin_call_acl_plugin (pb, e->ep_entry, NULL, NULL, SLAPI_ACL_DELETE,
  280. ACLPLUGIN_ACCESS_DEFAULT, &errbuf );
  281. if ( ldap_result_code != LDAP_SUCCESS )
  282. {
  283. ldap_result_message= errbuf;
  284. /* retval is -1 */
  285. goto error_return;
  286. }
  287. /*
  288. * Get the entry's parent. We do this here because index_read
  289. * seems to deadlock the database when dblayer_txn_begin is
  290. * called.
  291. */
  292. slapi_sdn_init(&parentsdn);
  293. slapi_sdn_get_backend_parent_ext(sdnp, &parentsdn, pb->pb_backend, is_tombstone_entry);
  294. if ( !slapi_sdn_isempty(&parentsdn) )
  295. {
  296. struct backentry *parent = NULL;
  297. entry_address parent_addr;
  298. parent_addr.sdn = &parentsdn;
  299. parent_addr.uniqueid = NULL;
  300. parent = find_entry2modify_only_ext(pb, be, &parent_addr,
  301. TOMBSTONE_INCLUDED, &txn);
  302. if (NULL != parent) {
  303. int isglue;
  304. size_t haschildren = 0;
  305. int op = PARENTUPDATE_DEL;
  306. /* Unfortunately findentry doesn't tell us whether it just
  307. * didn't find the entry, or if there was an error, so we
  308. * have to assume that the parent wasn't found */
  309. parent_found = 1;
  310. /* Modify the parent in memory */
  311. modify_init(&parent_modify_c,parent);
  312. if (create_tombstone_entry) {
  313. op |= PARENTUPDATE_CREATE_TOMBSTONE;
  314. } else if (delete_tombstone_entry) {
  315. op |= PARENTUPDATE_DELETE_TOMBSTONE;
  316. }
  317. retval = parent_update_on_childchange(&parent_modify_c,
  318. op, &haschildren);
  319. /* The modify context now contains info needed later */
  320. if (0 != retval) {
  321. ldap_result_code= LDAP_OPERATIONS_ERROR;
  322. goto error_return;
  323. }
  324. /*
  325. * Replication urp_post_delete will delete the parent entry
  326. * if it is a glue entry without any more children.
  327. * Those urp condition checkings are done here to
  328. * save unnecessary entry dup.
  329. */
  330. isglue = slapi_entry_attr_hasvalue (parent_modify_c.new_entry->ep_entry,
  331. SLAPI_ATTR_OBJECTCLASS, "glue");
  332. if ( opcsn && parent_modify_c.new_entry && !haschildren && isglue)
  333. {
  334. slapi_pblock_set ( pb, SLAPI_DELETE_GLUE_PARENT_ENTRY,
  335. slapi_entry_dup (parent_modify_c.new_entry->ep_entry) );
  336. }
  337. }
  338. }
  339. slapi_sdn_done(&parentsdn);
  340. if(create_tombstone_entry)
  341. {
  342. /*
  343. * The entry is not removed from the disk when we tombstone an
  344. * entry. We change the DN, add objectclass=tombstone, and record
  345. * the UniqueID of the parent entry.
  346. */
  347. const char *childuniqueid= slapi_entry_get_uniqueid(e->ep_entry);
  348. const char *parentuniqueid= NULL;
  349. char *tombstone_dn = compute_entry_tombstone_dn(slapi_entry_get_dn(e->ep_entry),
  350. childuniqueid);
  351. Slapi_Value *tomb_value;
  352. slapi_sdn_set_ndn_byval(&nscpEntrySDN, slapi_sdn_get_ndn(slapi_entry_get_sdn(e->ep_entry)));
  353. /* Copy the entry unique_id for URP conflict checking */
  354. e_uniqueid = slapi_ch_strdup(childuniqueid);
  355. if(parent_modify_c.old_entry!=NULL)
  356. {
  357. /* The suffix entry has no parent */
  358. parentuniqueid= slapi_entry_get_uniqueid(parent_modify_c.old_entry->ep_entry);
  359. }
  360. tombstone = backentry_dup( e );
  361. slapi_entry_set_dn(tombstone->ep_entry,tombstone_dn); /* Consumes DN */
  362. if (entryrdn_get_switch()) /* subtree-rename: on */
  363. {
  364. Slapi_RDN *srdn = slapi_entry_get_srdn(tombstone->ep_entry);
  365. char *tombstone_rdn =
  366. compute_entry_tombstone_rdn(slapi_entry_get_rdn_const(e->ep_entry),
  367. childuniqueid);
  368. /* e_srdn has "uniaqueid=..., <ORIG RDN>" */
  369. slapi_rdn_replace_rdn(srdn, tombstone_rdn);
  370. slapi_ch_free_string(&tombstone_rdn);
  371. }
  372. /* Set tombstone flag on ep_entry */
  373. slapi_entry_set_flag(tombstone->ep_entry, SLAPI_ENTRY_FLAG_TOMBSTONE);
  374. if(parentuniqueid!=NULL)
  375. {
  376. /* The suffix entry has no parent */
  377. slapi_entry_add_string(tombstone->ep_entry, SLAPI_ATTR_VALUE_PARENT_UNIQUEID, parentuniqueid);
  378. }
  379. slapi_entry_add_string(tombstone->ep_entry, SLAPI_ATTR_NSCP_ENTRYDN, slapi_sdn_get_ndn(&nscpEntrySDN));
  380. tomb_value = slapi_value_new_string(SLAPI_ATTR_VALUE_TOMBSTONE);
  381. value_update_csn(tomb_value, CSN_TYPE_VALUE_UPDATED,
  382. operation_get_csn(operation));
  383. slapi_entry_add_value(tombstone->ep_entry, SLAPI_ATTR_OBJECTCLASS, tomb_value);
  384. slapi_value_free(&tomb_value);
  385. /* XXXggood above used to be: slapi_entry_add_string(tombstone->ep_entry, SLAPI_ATTR_OBJECTCLASS, SLAPI_ATTR_VALUE_TOMBSTONE); */
  386. /* JCMREPL - Add a description of what's going on? */
  387. if ( (original_tombstone = backentry_dup( tombstone )) == NULL ) {
  388. ldap_result_code= LDAP_OPERATIONS_ERROR;
  389. goto error_return;
  390. }
  391. }
  392. if (!is_ruv && !is_fixup_operation && !delete_tombstone_entry) {
  393. ruv_c_init = ldbm_txn_ruv_modify_context( pb, &ruv_c );
  394. if (-1 == ruv_c_init) {
  395. LDAPDebug( LDAP_DEBUG_ANY,
  396. "ldbm_back_delete: ldbm_txn_ruv_modify_context "
  397. "failed to construct RUV modify context\n",
  398. 0, 0, 0);
  399. ldap_result_code= LDAP_OPERATIONS_ERROR;
  400. retval = 0;
  401. goto error_return;
  402. }
  403. }
  404. /*
  405. * So, we believe that no code up till here actually added anything
  406. * to the persistent store. From now on, we're transacted
  407. */
  408. txn.back_txn_txn = NULL; /* ready to create the child transaction */
  409. for (retry_count = 0; retry_count < RETRY_TIMES; retry_count++) {
  410. if (txn.back_txn_txn && (txn.back_txn_txn != parent_txn)) {
  411. Slapi_Entry *ent = NULL;
  412. dblayer_txn_abort(li,&txn);
  413. slapi_pblock_set(pb, SLAPI_TXN, parent_txn);
  414. /* reset original entry */
  415. slapi_pblock_get( pb, SLAPI_DELETE_EXISTING_ENTRY, &ent );
  416. if (ent && free_delete_existing_entry) {
  417. slapi_entry_free(ent);
  418. slapi_pblock_set( pb, SLAPI_DELETE_EXISTING_ENTRY, NULL );
  419. }
  420. slapi_pblock_set( pb, SLAPI_DELETE_EXISTING_ENTRY, slapi_entry_dup( e->ep_entry ) );
  421. free_delete_existing_entry = 1; /* must free the dup */
  422. if (create_tombstone_entry) {
  423. slapi_sdn_set_ndn_byval(&nscpEntrySDN, slapi_sdn_get_ndn(slapi_entry_get_sdn(e->ep_entry)));
  424. }
  425. /* reset tombstone entry */
  426. if (original_tombstone) {
  427. if (tombstone_in_cache) {
  428. CACHE_REMOVE(&inst->inst_cache, tombstone);
  429. CACHE_RETURN(&inst->inst_cache, &tombstone);
  430. tombstone_in_cache = 0;
  431. } else {
  432. backentry_free(&tombstone);
  433. }
  434. tombstone = original_tombstone;
  435. if ( (original_tombstone = backentry_dup( tombstone )) == NULL ) {
  436. ldap_result_code= LDAP_OPERATIONS_ERROR;
  437. goto error_return;
  438. }
  439. }
  440. /* reset original entry in cache */
  441. if (!e_in_cache) {
  442. CACHE_ADD(&inst->inst_cache, e, NULL);
  443. e_in_cache = 1;
  444. }
  445. /* We're re-trying */
  446. LDAPDebug0Args(LDAP_DEBUG_BACKLDBM,
  447. "Delete Retrying Transaction\n");
  448. #ifndef LDBM_NO_BACKOFF_DELAY
  449. {
  450. PRIntervalTime interval;
  451. interval = PR_MillisecondsToInterval(slapi_rand() % 100);
  452. DS_Sleep(interval);
  453. }
  454. #endif
  455. }
  456. retval = dblayer_txn_begin(li,parent_txn,&txn);
  457. if (0 != retval) {
  458. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  459. ldap_result_code= LDAP_OPERATIONS_ERROR;
  460. goto error_return;
  461. }
  462. /* stash the transaction */
  463. slapi_pblock_set(pb, SLAPI_TXN, txn.back_txn_txn);
  464. /* call the transaction pre delete plugins just after creating
  465. * the transaction */
  466. /* these should not need to modify the entry to be deleted -
  467. if for some reason they ever do, do not use e->ep_entry since
  468. it could be in the cache and referenced by other search threads -
  469. instead, have them modify a copy of the entry */
  470. retval = plugin_call_plugins(pb, SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN);
  471. if (retval) {
  472. LDAPDebug1Arg( LDAP_DEBUG_TRACE,
  473. "SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN plugin "
  474. "returned error code %d\n", retval );
  475. if (!ldap_result_code) {
  476. slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
  477. }
  478. if (!opreturn) {
  479. slapi_pblock_get( pb, SLAPI_PLUGIN_OPRETURN, &opreturn );
  480. }
  481. if (!opreturn) {
  482. slapi_pblock_set( pb, SLAPI_PLUGIN_OPRETURN,
  483. ldap_result_code ?
  484. &ldap_result_code : &retval );
  485. }
  486. goto error_return;
  487. }
  488. if(create_tombstone_entry)
  489. {
  490. slapi_pblock_get( pb, SLAPI_DELETE_BEPREOP_ENTRY, &orig_entry );
  491. /* this is ok because no other threads should be accessing
  492. the tombstone entry */
  493. slapi_pblock_set( pb, SLAPI_DELETE_BEPREOP_ENTRY,
  494. tombstone->ep_entry );
  495. rc = plugin_call_plugins(pb,
  496. SLAPI_PLUGIN_BE_TXN_PRE_DELETE_TOMBSTONE_FN);
  497. if (rc == -1) {
  498. /*
  499. * Plugin indicated some kind of failure,
  500. * or that this Operation became a No-Op.
  501. */
  502. if (!ldap_result_code) {
  503. slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
  504. }
  505. /* restore original entry so the front-end delete code
  506. * can free it */
  507. slapi_pblock_get( pb, SLAPI_PLUGIN_OPRETURN, &opreturn );
  508. if (!opreturn) {
  509. slapi_pblock_set( pb, SLAPI_PLUGIN_OPRETURN,
  510. ldap_result_code ?
  511. &ldap_result_code : &rc );
  512. }
  513. /* retval is -1 */
  514. goto error_return;
  515. }
  516. slapi_pblock_set( pb, SLAPI_DELETE_BEPREOP_ENTRY, orig_entry );
  517. orig_entry = NULL;
  518. /*
  519. * The entry is not removed from the disk when we tombstone an
  520. * entry. We change the DN, add objectclass=tombstone, and record
  521. * the UniqueID of the parent entry.
  522. */
  523. /* Note: cache_add (tombstone) fails since the original entry having
  524. * the same ID is already in the cache. Thus, we have to add it
  525. * tentatively for now, then cache_add again when the original
  526. * entry is removed from the cache.
  527. */
  528. if (cache_add_tentative( &inst->inst_cache, tombstone, NULL) == 0) {
  529. tombstone_in_cache = 1;
  530. } else if (!(tombstone->ep_state & ENTRY_STATE_NOTINCACHE)) {
  531. LDAPDebug1Arg(LDAP_DEBUG_CACHE,
  532. "id2entry_add tombstone (%s) is in cache\n",
  533. slapi_entry_get_dn(tombstone->ep_entry));
  534. tombstone_in_cache = 1;
  535. }
  536. retval = id2entry_add( be, tombstone, &txn );
  537. if (DB_LOCK_DEADLOCK == retval) {
  538. LDAPDebug( LDAP_DEBUG_ARGS, "delete 1 DB_LOCK_DEADLOCK\n", 0, 0, 0 );
  539. /* Abort and re-try */
  540. continue;
  541. }
  542. if (0 != retval) {
  543. LDAPDebug( LDAP_DEBUG_ANY, "id2entry_add failed, err=%d %s\n",
  544. retval, (msg = dblayer_strerror( retval )) ? msg : "", 0 );
  545. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  546. DEL_SET_ERROR(ldap_result_code,
  547. LDAP_OPERATIONS_ERROR, retry_count);
  548. goto error_return;
  549. }
  550. if (cache_replace( &inst->inst_cache, e, tombstone ) != 0 ) {
  551. LDAPDebug0Args( LDAP_DEBUG_BACKLDBM, "ldbm_back_delete cache_replace failed\n");
  552. DEL_SET_ERROR(ldap_result_code,
  553. LDAP_OPERATIONS_ERROR, retry_count);
  554. retval= -1;
  555. goto error_return;
  556. } else {
  557. e_in_cache = 0; /* e un-cached */
  558. }
  559. /* tombstone was already added to the cache via cache_add_tentative (to reserve its spot in the cache)
  560. and/or id2entry_add - so it already had one refcount - cache_replace adds another refcount -
  561. drop the extra ref added by cache_replace */
  562. CACHE_RETURN( &inst->inst_cache, &tombstone );
  563. }
  564. else
  565. {
  566. /* delete the entry from disk */
  567. retval = id2entry_delete( be, e, &txn );
  568. if (DB_LOCK_DEADLOCK == retval)
  569. {
  570. LDAPDebug( LDAP_DEBUG_ARGS, "delete 2 DEADLOCK\n", 0, 0, 0 );
  571. /* Retry txn */
  572. continue;
  573. }
  574. if (retval != 0 ) {
  575. if (retval == DB_RUNRECOVERY ||
  576. LDBM_OS_ERR_IS_DISKFULL(retval)) {
  577. disk_full = 1;
  578. }
  579. DEL_SET_ERROR(ldap_result_code,
  580. LDAP_OPERATIONS_ERROR, retry_count);
  581. goto error_return;
  582. }
  583. }
  584. /* delete from attribute indexes */
  585. addordel_flags = BE_INDEX_DEL|BE_INDEX_PRESENCE|BE_INDEX_EQUALITY;
  586. if (delete_tombstone_entry)
  587. {
  588. addordel_flags |= BE_INDEX_TOMBSTONE; /* tell index code we are deleting a tombstone */
  589. }
  590. retval = index_addordel_entry( be, e, addordel_flags, &txn );
  591. if (DB_LOCK_DEADLOCK == retval)
  592. {
  593. LDAPDebug( LDAP_DEBUG_ARGS, "delete 1 DEADLOCK\n", 0, 0, 0 );
  594. /* Retry txn */
  595. continue;
  596. }
  597. if (retval != 0) {
  598. LDAPDebug( LDAP_DEBUG_TRACE, "index_del_entry failed\n", 0, 0, 0 );
  599. DEL_SET_ERROR(ldap_result_code, LDAP_OPERATIONS_ERROR, retry_count);
  600. goto error_return;
  601. }
  602. if(create_tombstone_entry)
  603. {
  604. /*
  605. * The tombstone entry is removed from all attribute indexes
  606. * above, but we want it to remain in the nsUniqueID and nscpEntryDN indexes
  607. * and for objectclass=tombstone.
  608. */
  609. retval = index_addordel_string(be, SLAPI_ATTR_OBJECTCLASS,
  610. SLAPI_ATTR_VALUE_TOMBSTONE,
  611. tombstone->ep_id,BE_INDEX_ADD, &txn);
  612. if (DB_LOCK_DEADLOCK == retval) {
  613. LDAPDebug( LDAP_DEBUG_ARGS,
  614. "delete (adding %s) DB_LOCK_DEADLOCK\n",
  615. SLAPI_ATTR_VALUE_TOMBSTONE, 0, 0 );
  616. /* Retry txn */
  617. continue;
  618. }
  619. if (0 != retval) {
  620. LDAPDebug( LDAP_DEBUG_TRACE,
  621. "delete (adding %s) failed, err=%d %s\n",
  622. SLAPI_ATTR_VALUE_TOMBSTONE, retval,
  623. (msg = dblayer_strerror( retval )) ? msg : "" );
  624. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  625. DEL_SET_ERROR(ldap_result_code,
  626. LDAP_OPERATIONS_ERROR, retry_count);
  627. goto error_return;
  628. }
  629. retval = index_addordel_string(be, SLAPI_ATTR_UNIQUEID,
  630. slapi_entry_get_uniqueid(tombstone->ep_entry),
  631. tombstone->ep_id,BE_INDEX_ADD,&txn);
  632. if (DB_LOCK_DEADLOCK == retval) {
  633. LDAPDebug( LDAP_DEBUG_ARGS,
  634. "delete (adding %s) DB_LOCK_DEADLOCK\n",
  635. SLAPI_ATTR_UNIQUEID, 0, 0 );
  636. /* Retry txn */
  637. continue;
  638. }
  639. if (0 != retval) {
  640. LDAPDebug( LDAP_DEBUG_TRACE,
  641. "delete (adding %s) failed, err=%d %s\n",
  642. SLAPI_ATTR_UNIQUEID, retval,
  643. (msg = dblayer_strerror( retval )) ? msg : "" );
  644. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  645. DEL_SET_ERROR(ldap_result_code,
  646. LDAP_OPERATIONS_ERROR, retry_count);
  647. goto error_return;
  648. }
  649. retval = index_addordel_string(be, SLAPI_ATTR_NSCP_ENTRYDN,
  650. slapi_sdn_get_ndn(&nscpEntrySDN),
  651. tombstone->ep_id, BE_INDEX_ADD, &txn);
  652. if (DB_LOCK_DEADLOCK == retval) {
  653. LDAPDebug( LDAP_DEBUG_ARGS,
  654. "delete (adding %s) DB_LOCK_DEADLOCK\n",
  655. SLAPI_ATTR_NSCP_ENTRYDN, 0, 0 );
  656. /* Retry txn */
  657. continue;
  658. }
  659. if (0 != retval) {
  660. LDAPDebug( LDAP_DEBUG_TRACE,
  661. "delete (adding %s) failed, err=%d %s\n",
  662. SLAPI_ATTR_NSCP_ENTRYDN, retval,
  663. (msg = dblayer_strerror( retval )) ? msg : "" );
  664. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  665. DEL_SET_ERROR(ldap_result_code,
  666. LDAP_OPERATIONS_ERROR, retry_count);
  667. goto error_return;
  668. }
  669. /* add a new usn to the entryusn index */
  670. entryusn_str = slapi_entry_attr_get_charptr(tombstone->ep_entry,
  671. SLAPI_ATTR_ENTRYUSN);
  672. if (entryusn_str) {
  673. retval = index_addordel_string(be, SLAPI_ATTR_ENTRYUSN,
  674. entryusn_str, tombstone->ep_id, BE_INDEX_ADD, &txn);
  675. slapi_ch_free_string(&entryusn_str);
  676. if (DB_LOCK_DEADLOCK == retval) {
  677. LDAPDebug( LDAP_DEBUG_ARGS,
  678. "delete (adding %s) DB_LOCK_DEADLOCK\n",
  679. SLAPI_ATTR_ENTRYUSN, 0, 0 );
  680. /* Retry txn */
  681. continue;
  682. }
  683. if (0 != retval) {
  684. LDAPDebug( LDAP_DEBUG_TRACE,
  685. "delete (adding %s) failed, err=%d %s\n",
  686. SLAPI_ATTR_ENTRYUSN, retval,
  687. (msg = dblayer_strerror( retval )) ? msg : "" );
  688. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  689. DEL_SET_ERROR(ldap_result_code,
  690. LDAP_OPERATIONS_ERROR, retry_count);
  691. goto error_return;
  692. }
  693. }
  694. if (entryrdn_get_switch()) /* subtree-rename: on */
  695. {
  696. Slapi_Attr *attr;
  697. Slapi_Value **svals;
  698. /* To maintain tombstonenumsubordinates,
  699. * parentid is needed for tombstone, as well. */
  700. slapi_entry_attr_find(tombstone->ep_entry, LDBM_PARENTID_STR,
  701. &attr);
  702. if (attr) {
  703. svals = attr_get_present_values(attr);
  704. retval = index_addordel_values_sv(be, LDBM_PARENTID_STR,
  705. svals, NULL, e->ep_id,
  706. BE_INDEX_ADD, &txn);
  707. if (DB_LOCK_DEADLOCK == retval) {
  708. LDAPDebug0Args( LDAP_DEBUG_ARGS,
  709. "delete (updating " LDBM_PARENTID_STR ") DB_LOCK_DEADLOCK\n");
  710. /* Retry txn */
  711. continue;
  712. }
  713. if ( retval ) {
  714. LDAPDebug( LDAP_DEBUG_TRACE,
  715. "delete (deleting %s) failed, err=%d %s\n",
  716. LDBM_PARENTID_STR, retval,
  717. (msg = dblayer_strerror( retval )) ? msg : "" );
  718. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  719. DEL_SET_ERROR(ldap_result_code,
  720. LDAP_OPERATIONS_ERROR, retry_count);
  721. goto error_return;
  722. }
  723. }
  724. retval = entryrdn_index_entry(be, e, BE_INDEX_DEL, &txn);
  725. if (DB_LOCK_DEADLOCK == retval) {
  726. LDAPDebug0Args( LDAP_DEBUG_ARGS,
  727. "delete (deleting entryrdn) DB_LOCK_DEADLOCK\n");
  728. /* Retry txn */
  729. continue;
  730. }
  731. if (0 != retval) {
  732. LDAPDebug2Args( LDAP_DEBUG_TRACE,
  733. "delete (deleting entryrdn) failed, err=%d %s\n",
  734. retval,
  735. (msg = dblayer_strerror( retval )) ? msg : "" );
  736. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  737. DEL_SET_ERROR(ldap_result_code,
  738. LDAP_OPERATIONS_ERROR, retry_count);
  739. goto error_return;
  740. }
  741. retval = entryrdn_index_entry(be, tombstone, BE_INDEX_ADD, &txn);
  742. if (DB_LOCK_DEADLOCK == retval) {
  743. LDAPDebug0Args( LDAP_DEBUG_ARGS,
  744. "adding (adding tombstone entryrdn) DB_LOCK_DEADLOCK\n");
  745. /* Retry txn */
  746. continue;
  747. }
  748. if (0 != retval) {
  749. LDAPDebug2Args( LDAP_DEBUG_TRACE,
  750. "adding (adding tombstone entryrdn) failed, err=%d %s\n",
  751. retval,
  752. (msg = dblayer_strerror( retval )) ? msg : "" );
  753. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  754. DEL_SET_ERROR(ldap_result_code,
  755. LDAP_OPERATIONS_ERROR, retry_count);
  756. goto error_return;
  757. }
  758. }
  759. } /* create_tombstone_entry */
  760. else if (delete_tombstone_entry)
  761. {
  762. /*
  763. * We need to remove the Tombstone entry from the remaining indexes:
  764. * objectclass=nsTombstone, nsUniqueID, nscpEntryDN
  765. */
  766. char *nscpedn = NULL;
  767. retval = index_addordel_string(be, SLAPI_ATTR_OBJECTCLASS,
  768. SLAPI_ATTR_VALUE_TOMBSTONE, e->ep_id,
  769. BE_INDEX_DEL, &txn);
  770. if (DB_LOCK_DEADLOCK == retval) {
  771. LDAPDebug( LDAP_DEBUG_ARGS,
  772. "delete (deleting %s) DB_LOCK_DEADLOCK\n",
  773. SLAPI_ATTR_VALUE_TOMBSTONE, 0, 0 );
  774. /* Retry txn */
  775. continue;
  776. }
  777. if (0 != retval) {
  778. LDAPDebug( LDAP_DEBUG_TRACE,
  779. "delete (deleting %s) failed, err=%d %s\n",
  780. SLAPI_ATTR_VALUE_TOMBSTONE, retval,
  781. (msg = dblayer_strerror( retval )) ? msg : "" );
  782. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  783. DEL_SET_ERROR(ldap_result_code,
  784. LDAP_OPERATIONS_ERROR, retry_count);
  785. goto error_return;
  786. }
  787. retval = index_addordel_string(be, SLAPI_ATTR_UNIQUEID,
  788. slapi_entry_get_uniqueid(e->ep_entry),
  789. e->ep_id, BE_INDEX_DEL, &txn);
  790. if (DB_LOCK_DEADLOCK == retval) {
  791. LDAPDebug( LDAP_DEBUG_ARGS,
  792. "delete (deleting %s) DB_LOCK_DEADLOCK\n",
  793. SLAPI_ATTR_UNIQUEID, 0, 0 );
  794. /* Retry txn */
  795. continue;
  796. }
  797. if (0 != retval) {
  798. LDAPDebug( LDAP_DEBUG_TRACE,
  799. "delete (deleting %s) failed, err=%d %s\n",
  800. SLAPI_ATTR_UNIQUEID, retval,
  801. (msg = dblayer_strerror( retval )) ? msg : "" );
  802. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  803. DEL_SET_ERROR(ldap_result_code,
  804. LDAP_OPERATIONS_ERROR, retry_count);
  805. goto error_return;
  806. }
  807. nscpedn = slapi_entry_attr_get_charptr(e->ep_entry,
  808. SLAPI_ATTR_NSCP_ENTRYDN);
  809. if (nscpedn) {
  810. retval = index_addordel_string(be, SLAPI_ATTR_NSCP_ENTRYDN,
  811. nscpedn, e->ep_id, BE_INDEX_DEL, &txn);
  812. slapi_ch_free((void **)&nscpedn);
  813. if (DB_LOCK_DEADLOCK == retval) {
  814. LDAPDebug( LDAP_DEBUG_ARGS,
  815. "delete (deleting %s) DB_LOCK_DEADLOCK\n",
  816. SLAPI_ATTR_NSCP_ENTRYDN, 0, 0 );
  817. /* Retry txn */
  818. continue;
  819. }
  820. if (0 != retval) {
  821. LDAPDebug( LDAP_DEBUG_TRACE,
  822. "delete (deleting %s) failed, err=%d %s\n",
  823. SLAPI_ATTR_NSCP_ENTRYDN, retval,
  824. (msg = dblayer_strerror( retval )) ? msg : "" );
  825. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  826. DEL_SET_ERROR(ldap_result_code,
  827. LDAP_OPERATIONS_ERROR, retry_count);
  828. goto error_return;
  829. }
  830. }
  831. /* delete usn from the entryusn index */
  832. entryusn_str = slapi_entry_attr_get_charptr(e->ep_entry,
  833. SLAPI_ATTR_ENTRYUSN);
  834. if (entryusn_str) {
  835. retval = index_addordel_string(be, SLAPI_ATTR_ENTRYUSN,
  836. entryusn_str, e->ep_id,
  837. BE_INDEX_DEL|BE_INDEX_EQUALITY, &txn);
  838. slapi_ch_free_string(&entryusn_str);
  839. if (DB_LOCK_DEADLOCK == retval) {
  840. LDAPDebug( LDAP_DEBUG_ARGS,
  841. "delete (deleting %s) DB_LOCK_DEADLOCK\n",
  842. SLAPI_ATTR_ENTRYUSN, 0, 0 );
  843. /* Retry txn */
  844. continue;
  845. }
  846. if (0 != retval) {
  847. LDAPDebug( LDAP_DEBUG_TRACE,
  848. "delete (deleting %s) failed, err=%d %s\n",
  849. SLAPI_ATTR_ENTRYUSN, retval,
  850. (msg = dblayer_strerror( retval )) ? msg : "" );
  851. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  852. DEL_SET_ERROR(ldap_result_code,
  853. LDAP_OPERATIONS_ERROR, retry_count);
  854. goto error_return;
  855. }
  856. }
  857. if (entryrdn_get_switch()) /* subtree-rename: on */
  858. {
  859. retval = entryrdn_index_entry(be, e, BE_INDEX_DEL, &txn);
  860. if (DB_LOCK_DEADLOCK == retval) {
  861. LDAPDebug0Args( LDAP_DEBUG_ARGS,
  862. "delete (deleting entryrdn) DB_LOCK_DEADLOCK\n");
  863. /* Retry txn */
  864. continue;
  865. }
  866. if (0 != retval) {
  867. LDAPDebug2Args( LDAP_DEBUG_TRACE,
  868. "delete (deleting entryrdn) failed, err=%d %s\n",
  869. retval,
  870. (msg = dblayer_strerror( retval )) ? msg : "" );
  871. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  872. DEL_SET_ERROR(ldap_result_code,
  873. LDAP_OPERATIONS_ERROR, retry_count);
  874. goto error_return;
  875. }
  876. }
  877. } /* delete_tombstone_entry */
  878. if (parent_found) {
  879. /* Push out the db modifications from the parent entry */
  880. retval = modify_update_all(be,pb,&parent_modify_c,&txn);
  881. if (DB_LOCK_DEADLOCK == retval)
  882. {
  883. LDAPDebug( LDAP_DEBUG_ARGS, "del 4 DEADLOCK\n", 0, 0, 0 );
  884. /* Retry txn */
  885. continue;
  886. }
  887. if (0 != retval) {
  888. LDAPDebug( LDAP_DEBUG_TRACE, "delete 3 BAD, err=%d %s\n",
  889. retval, (msg = dblayer_strerror( retval )) ? msg : "", 0 );
  890. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  891. DEL_SET_ERROR(ldap_result_code,
  892. LDAP_OPERATIONS_ERROR, retry_count);
  893. goto error_return;
  894. }
  895. }
  896. /*
  897. * first check if searchentry needs to be removed
  898. * Remove the entry from the Virtual List View indexes.
  899. */
  900. if (!delete_tombstone_entry && !is_ruv &&
  901. !vlv_delete_search_entry(pb,e->ep_entry,inst)) {
  902. retval = vlv_update_all_indexes(&txn, be, pb, e, NULL);
  903. if (DB_LOCK_DEADLOCK == retval)
  904. {
  905. LDAPDebug( LDAP_DEBUG_ARGS, "delete DEADLOCK vlv_update_index\n", 0, 0, 0 );
  906. /* Retry txn */
  907. continue;
  908. }
  909. if (retval != 0 ) {
  910. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  911. DEL_SET_ERROR(ldap_result_code,
  912. LDAP_OPERATIONS_ERROR, retry_count);
  913. goto error_return;
  914. }
  915. }
  916. if (ruv_c_init) {
  917. retval = modify_update_all( be, pb, &ruv_c, &txn );
  918. if (DB_LOCK_DEADLOCK == retval) {
  919. /* Abort and re-try */
  920. continue;
  921. }
  922. if (0 != retval) {
  923. LDAPDebug( LDAP_DEBUG_ANY,
  924. "modify_update_all failed, err=%d %s\n", retval,
  925. (msg = dblayer_strerror( retval )) ? msg : "", 0 );
  926. if (LDBM_OS_ERR_IS_DISKFULL(retval))
  927. disk_full = 1;
  928. ldap_result_code= LDAP_OPERATIONS_ERROR;
  929. goto error_return;
  930. }
  931. }
  932. if (retval == 0 ) {
  933. break;
  934. }
  935. }
  936. if (retry_count == RETRY_TIMES) {
  937. /* Failed */
  938. LDAPDebug( LDAP_DEBUG_ANY, "Retry count exceeded in delete\n", 0, 0, 0 );
  939. ldap_result_code= LDAP_BUSY;
  940. retval = -1;
  941. goto error_return;
  942. }
  943. /* call the transaction post delete plugins just before the commit */
  944. if (plugin_call_plugins(pb, SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN)) {
  945. LDAPDebug0Args( LDAP_DEBUG_ANY, "SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN plugin "
  946. "returned error code\n" );
  947. if (!ldap_result_code) {
  948. slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
  949. }
  950. if (!ldap_result_code) {
  951. LDAPDebug0Args( LDAP_DEBUG_ANY, "SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN plugin "
  952. "returned error code but did not set SLAPI_RESULT_CODE\n" );
  953. ldap_result_code = LDAP_OPERATIONS_ERROR;
  954. slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
  955. }
  956. if (!opreturn) {
  957. slapi_pblock_get( pb, SLAPI_PLUGIN_OPRETURN, &opreturn );
  958. }
  959. if (!retval) {
  960. retval = -1;
  961. }
  962. if (!opreturn) {
  963. slapi_pblock_set( pb, SLAPI_PLUGIN_OPRETURN, &retval );
  964. }
  965. goto error_return;
  966. }
  967. retval = dblayer_txn_commit(li,&txn);
  968. /* after commit - txn is no longer valid - replace SLAPI_TXN with parent */
  969. slapi_pblock_set(pb, SLAPI_TXN, parent_txn);
  970. if (0 != retval)
  971. {
  972. if (LDBM_OS_ERR_IS_DISKFULL(retval)) disk_full = 1;
  973. ldap_result_code= LDAP_OPERATIONS_ERROR;
  974. goto error_return;
  975. }
  976. /* delete from cache and clean up */
  977. if (e) {
  978. if (e_in_cache) {
  979. CACHE_REMOVE(&inst->inst_cache, e);
  980. }
  981. cache_unlock_entry(&inst->inst_cache, e);
  982. CACHE_RETURN(&inst->inst_cache, &e);
  983. e = NULL;
  984. }
  985. if (parent_found)
  986. {
  987. /* Replace the old parent entry with the newly modified one */
  988. modify_switch_entries( &parent_modify_c,be);
  989. }
  990. if (ruv_c_init) {
  991. if (modify_switch_entries(&ruv_c, be) != 0 ) {
  992. ldap_result_code= LDAP_OPERATIONS_ERROR;
  993. LDAPDebug( LDAP_DEBUG_ANY,
  994. "ldbm_back_delete: modify_switch_entries failed\n", 0, 0, 0);
  995. retval = -1;
  996. goto error_return;
  997. }
  998. }
  999. rc= 0;
  1000. goto common_return;
  1001. error_return:
  1002. if (tombstone_in_cache)
  1003. {
  1004. CACHE_REMOVE( &inst->inst_cache, tombstone );
  1005. CACHE_RETURN( &inst->inst_cache, &tombstone );
  1006. tombstone = NULL;
  1007. tombstone_in_cache = 0;
  1008. }
  1009. else
  1010. {
  1011. backentry_free( &tombstone );
  1012. }
  1013. if (retval == DB_RUNRECOVERY) {
  1014. dblayer_remember_disk_filled(li);
  1015. ldbm_nasty("Delete",79,retval);
  1016. disk_full = 1;
  1017. }
  1018. if (disk_full) {
  1019. rc= return_on_disk_full(li);
  1020. goto diskfull_return;
  1021. }
  1022. else
  1023. rc= SLAPI_FAIL_GENERAL;
  1024. /* It is safer not to abort when the transaction is not started. */
  1025. if (txn.back_txn_txn && (txn.back_txn_txn != parent_txn)) {
  1026. /* make sure SLAPI_RESULT_CODE and SLAPI_PLUGIN_OPRETURN are set */
  1027. int val = 0;
  1028. slapi_pblock_get(pb, SLAPI_RESULT_CODE, &val);
  1029. if (!val) {
  1030. if (!ldap_result_code) {
  1031. ldap_result_code = LDAP_OPERATIONS_ERROR;
  1032. }
  1033. slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
  1034. }
  1035. slapi_pblock_get( pb, SLAPI_PLUGIN_OPRETURN, &val );
  1036. if (!val) {
  1037. opreturn = retval;
  1038. slapi_pblock_set( pb, SLAPI_PLUGIN_OPRETURN, &retval );
  1039. }
  1040. /* call the transaction post delete plugins just before the commit */
  1041. if (plugin_call_plugins(pb, SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN)) {
  1042. LDAPDebug1Arg( LDAP_DEBUG_ANY, "SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN plugin "
  1043. "returned error code %d\n", retval );
  1044. if (!ldap_result_code) {
  1045. slapi_pblock_get(pb, SLAPI_RESULT_CODE, &ldap_result_code);
  1046. }
  1047. if (!opreturn) {
  1048. slapi_pblock_get( pb, SLAPI_PLUGIN_OPRETURN, &opreturn );
  1049. }
  1050. if (!opreturn) {
  1051. slapi_pblock_set( pb, SLAPI_PLUGIN_OPRETURN, ldap_result_code ? &ldap_result_code : &retval );
  1052. }
  1053. }
  1054. dblayer_txn_abort(li,&txn); /* abort crashes in case disk full */
  1055. /* txn is no longer valid - reset the txn pointer to the parent */
  1056. slapi_pblock_set(pb, SLAPI_TXN, parent_txn);
  1057. }
  1058. common_return:
  1059. if (orig_entry) {
  1060. /* NOTE: #define SLAPI_DELETE_BEPREOP_ENTRY SLAPI_ENTRY_PRE_OP */
  1061. /* so if orig_entry is NULL, we will wipe out SLAPI_ENTRY_PRE_OP
  1062. for the post op plugins */
  1063. slapi_pblock_set( pb, SLAPI_DELETE_BEPREOP_ENTRY, orig_entry );
  1064. }
  1065. if (tombstone_in_cache)
  1066. {
  1067. CACHE_RETURN( &inst->inst_cache, &tombstone );
  1068. tombstone = NULL;
  1069. tombstone_in_cache = 0;
  1070. }
  1071. else
  1072. {
  1073. backentry_free( &tombstone );
  1074. }
  1075. /* result code could be used in the bepost plugin functions. */
  1076. slapi_pblock_set(pb, SLAPI_RESULT_CODE, &ldap_result_code);
  1077. /*
  1078. * The bepostop is called even if the operation fails,
  1079. * but not if the operation is purging tombstones.
  1080. */
  1081. if (!delete_tombstone_entry) {
  1082. plugin_call_plugins (pb, SLAPI_PLUGIN_BE_POST_DELETE_FN);
  1083. }
  1084. /* Need to return to cache after post op plugins are called */
  1085. if (retval) { /* error case */
  1086. if (e) {
  1087. cache_unlock_entry( &inst->inst_cache, e );
  1088. CACHE_RETURN( &inst->inst_cache, &e );
  1089. }
  1090. }
  1091. if (ruv_c_init) {
  1092. modify_term(&ruv_c, be);
  1093. }
  1094. diskfull_return:
  1095. if(ldap_result_code!=-1)
  1096. {
  1097. slapi_send_ldap_result( pb, ldap_result_code, NULL, ldap_result_message, 0, NULL );
  1098. }
  1099. modify_term(&parent_modify_c,be);
  1100. if(dblock_acquired)
  1101. {
  1102. dblayer_unlock_backend(be);
  1103. }
  1104. if (rc == 0 && opcsn && !is_fixup_operation && !delete_tombstone_entry)
  1105. {
  1106. /* URP Naming Collision
  1107. * When an entry is deleted by a replicated delete operation
  1108. * we must check for entries that have had a naming collision
  1109. * with this entry. Now that this name has been given up, one
  1110. * of those entries can take over the name.
  1111. */
  1112. slapi_pblock_set(pb, SLAPI_URP_NAMING_COLLISION_DN, slapi_ch_strdup(dn));
  1113. }
  1114. if (free_delete_existing_entry) {
  1115. done_with_pblock_entry(pb, SLAPI_DELETE_EXISTING_ENTRY);
  1116. } else { /* owned by someone else */
  1117. slapi_pblock_set(pb, SLAPI_DELETE_EXISTING_ENTRY, NULL);
  1118. }
  1119. backentry_free(&original_tombstone);
  1120. slapi_ch_free((void**)&errbuf);
  1121. slapi_sdn_done(&nscpEntrySDN);
  1122. slapi_ch_free_string(&e_uniqueid);
  1123. if (pb->pb_conn)
  1124. {
  1125. slapi_log_error (SLAPI_LOG_TRACE, "ldbm_back_delete", "leave conn=%" NSPRIu64 " op=%d\n", pb->pb_conn->c_connid, operation->o_opid);
  1126. }
  1127. return rc;
  1128. }