]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/delete.c
Switch to openldap-data directory
[openldap] / servers / slapd / back-bdb / delete.c
index 36be9b186a8ef71d10c516159e38ce800680eb12..a469fb1265ed84f0c5fea9b7a2c3b42af47c43e2 100644 (file)
@@ -42,9 +42,12 @@ bdb_delete(
 
        if( 0 ) {
 retry: /* transaction retry */
+               if( e != NULL ) {
+                       bdb_cache_return_entry_w(&bdb->bi_cache, e);
+               }
                Debug( LDAP_DEBUG_TRACE, "==> bdb_delete: retrying...\n",
                        0, 0, 0 );
-               rc = txn_abort( ltid );
+               rc = TXN_ABORT( ltid );
                ltid = NULL;
                op->o_private = NULL;
                if( rc != 0 ) {
@@ -55,38 +58,29 @@ retry:      /* transaction retry */
                ldap_pvt_thread_yield();
        }
 
-       if( bdb->bi_txn ) {
-               /* begin transaction */
-               rc = txn_begin( bdb->bi_dbenv, NULL, &ltid, 
-                       bdb->bi_db_opflags );
-               text = NULL;
-               if( rc != 0 ) {
-                       Debug( LDAP_DEBUG_TRACE,
-                               "bdb_delete: txn_begin failed: %s (%d)\n",
-                               db_strerror(rc), rc, 0 );
-                       rc = LDAP_OTHER;
-                       text = "internal error";
-                       goto return_results;
-               }
+       /* begin transaction */
+       rc = TXN_BEGIN( bdb->bi_dbenv, NULL, &ltid, 
+               bdb->bi_db_opflags );
+       text = NULL;
+       if( rc != 0 ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "bdb_delete: txn_begin failed: %s (%d)\n",
+                       db_strerror(rc), rc, 0 );
+               rc = LDAP_OTHER;
+               text = "internal error";
+               goto return_results;
+       }
 #if 0
-               lockid = TXN_ID( ltid );
+       lockid = TXN_ID( ltid );
 #endif
-       }
 
        opinfo.boi_bdb = be;
        opinfo.boi_txn = ltid;
        opinfo.boi_err = 0;
        op->o_private = &opinfo;
 
-       if ( !be_issuffix( be, ndn->bv_val ) ) {
-               rc = dnParent( ndn->bv_val, &pdn.bv_val );
-               if ( rc != LDAP_SUCCESS ) {
-                       text = "internal error";
-                       goto return_results;
-               }
-               if (pdn.bv_val && pdn.bv_val[0]) {
-                       pdn.bv_len = ndn->bv_len - (pdn.bv_val - ndn->bv_val);
-               }
+       if ( !be_issuffix( be, ndn ) ) {
+               dnParent( ndn, &pdn );
        }
 
        if( pdn.bv_len != 0 ) {
@@ -100,7 +94,7 @@ retry:       /* transaction retry */
                }
 #endif
                /* get parent */
-               rc = bdb_dn2entry( be, ltid, &pdn, &p, NULL, 0 );
+               rc = bdb_dn2entry_r( be, ltid, &pdn, &p, NULL, 0 );
 
                switch( rc ) {
                case 0:
@@ -128,9 +122,15 @@ retry:     /* transaction retry */
                rc = access_allowed( be, conn, op, p,
                        children, NULL, ACL_WRITE );
 
-               bdb_entry_return( be, p );
+               bdb_cache_return_entry_r(&bdb->bi_cache, p);
                p = NULL;
 
+               switch( opinfo.boi_err ) {
+               case DB_LOCK_DEADLOCK:
+               case DB_LOCK_NOTGRANTED:
+                       goto retry;
+               }
+
                if ( !rc  ) {
                        Debug( LDAP_DEBUG_TRACE,
                                "<=- bdb_delete: no access to parent\n",
@@ -142,7 +142,8 @@ retry:      /* transaction retry */
        } else {
                /* no parent, must be root to delete */
                if( ! be_isroot( be, &op->o_ndn ) ) {
-                       if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
+                       if ( be_issuffix( be, (struct berval *)&slap_empty_bv )
+                               || be_isupdate( be, &op->o_ndn ) ) {
                                p = (Entry *)&slap_entry_root;
 
                                /* check parent for "children" acl */
@@ -150,6 +151,12 @@ retry:     /* transaction retry */
                                        children, NULL, ACL_WRITE );
                                p = NULL;
 
+                               switch( opinfo.boi_err ) {
+                               case DB_LOCK_DEADLOCK:
+                               case DB_LOCK_NOTGRANTED:
+                                       goto retry;
+                               }
+
                                if ( !rc  ) {
                                        Debug( LDAP_DEBUG_TRACE,
                                                "<=- bdb_delete: no access "
@@ -166,6 +173,7 @@ retry:      /* transaction retry */
                                goto return_results;
                        }
                }
+
 #if 0
                if ( ltid ) {
                        DBT obj;
@@ -178,7 +186,7 @@ retry:      /* transaction retry */
        }
 
        /* get entry for read/modify/write */
-       rc = bdb_dn2entry( be, ltid, ndn, &e, &matched, DB_RMW );
+       rc = bdb_dn2entry_w( be, ltid, ndn, &e, &matched, DB_RMW );
 
        switch( rc ) {
        case 0:
@@ -206,7 +214,7 @@ retry:      /* transaction retry */
                        refs = is_entry_referral( matched )
                                ? get_entry_referrals( be, conn, op, matched )
                                : NULL;
-                       bdb_entry_return( be, matched );
+                       bdb_cache_return_entry_r(&bdb->bi_cache, matched );
                        matched = NULL;
 
                } else {
@@ -225,8 +233,7 @@ retry:      /* transaction retry */
        }
 
        if ( !manageDSAit && is_entry_referral( e ) ) {
-               /* parent is a referral, don't allow add */
-               /* parent is an alias, don't allow add */
+               /* entry is a referral, don't allow delete */
                BerVarray refs = get_entry_referrals( be,
                        conn, op, e );
 
@@ -284,7 +291,7 @@ retry:      /* transaction retry */
        }
 
        /* delete from id2entry */
-       rc = bdb_id2entry_delete( be, ltid, e->e_id );
+       rc = bdb_id2entry_delete( be, ltid, e );
        if ( rc != 0 ) {
                switch( rc ) {
                case DB_LOCK_DEADLOCK:
@@ -324,30 +331,33 @@ retry:    /* transaction retry */
        ldap_pvt_thread_mutex_unlock( &bdb->bi_lastid_mutex );
 #endif
 
-       if( bdb->bi_txn ) {
-               rc = txn_commit( ltid, 0 );
+       if( op->o_noop ) {
+               rc = TXN_ABORT( ltid );
+       } else {
+               rc = TXN_COMMIT( ltid, 0 );
        }
        ltid = NULL;
        op->o_private = NULL;
 
        if( rc != 0 ) {
                Debug( LDAP_DEBUG_TRACE,
-                       "bdb_delete: txn_commit failed: %s (%d)\n",
-                       db_strerror(rc), rc, 0 );
+                       "bdb_delete: txn_%s failed: %s (%d)\n",
+                       op->o_noop ? "abort (no-op)" : "commit",
+                       db_strerror(rc), rc );
                rc = LDAP_OTHER;
                text = "commit failed";
 
        } else {
                Debug( LDAP_DEBUG_TRACE,
-                       "bdb_delete: deleted id=%08lx dn=\"%s\"\n",
-                       e->e_id, e->e_dn, 0 );
+                       "bdb_delete: deleted%s id=%08lx dn=\"%s\"\n",
+                       op->o_noop ? " (no-op)" : "",
+                       e->e_id, e->e_dn );
                rc = LDAP_SUCCESS;
                text = NULL;
        }
 
 return_results:
-       send_ldap_result( conn, op, LDAP_SUCCESS,
-               NULL, text, NULL, NULL );
+       send_ldap_result( conn, op, rc, NULL, text, NULL, NULL );
 
        if(rc == LDAP_SUCCESS && bdb->bi_txn_cp ) {
                ldap_pvt_thread_yield();
@@ -358,11 +368,11 @@ return_results:
 done:
        /* free entry */
        if( e != NULL ) {
-               bdb_entry_return( be, e );
+               bdb_cache_return_entry_w(&bdb->bi_cache, e);
        }
 
        if( ltid != NULL ) {
-               txn_abort( ltid );
+               TXN_ABORT( ltid );
                op->o_private = NULL;
        }