]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/operational.c
278173fa2fdef92b04fd67e3859daf89a7c89578
[openldap] / servers / slapd / back-bdb / operational.c
1 /* operational.c - bdb backend operational attributes function */
2 /*
3  * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6
7 #include "portable.h"
8
9 #include <stdio.h>
10
11 #include <ac/string.h>
12 #include <ac/socket.h>
13
14 #include "slap.h"
15 #include "back-bdb.h"
16 #include "proto-bdb.h"
17
18 /*
19  * sets the supported operational attributes (if required)
20  */
21
22 int
23 bdb_operational(
24         BackendDB       *be,
25         Connection      *conn, 
26         Operation       *op,
27         Entry           *e,
28         AttributeName           *attrs,
29         int             opattrs,
30         Attribute       **a )
31 {
32         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
33         Attribute       **aa = a;
34         int             rc;
35         DB_TXN          *ltid = NULL;
36         struct bdb_op_info opinfo;
37         
38         assert( e );
39
40         if ( !opattrs && !ad_inlist( slap_schema.si_ad_hasSubordinates, attrs ) ) {
41                 return 0;
42         }
43
44
45         if( 0 ) {
46 retry:  /* transaction retry */
47                 if( e != NULL ) {
48                         bdb_cache_return_entry_w(&bdb->bi_cache, e);
49                 }
50                 Debug( LDAP_DEBUG_TRACE, "==> bdb_delete: retrying...\n", 
51                                 0, 0, 0 );
52                 rc = TXN_ABORT( ltid );
53                 ltid = NULL;
54                 op->o_private = NULL;
55                 if( rc != 0 ) {
56                         rc = LDAP_OTHER;
57                         goto return_results;
58                 }
59                 ldap_pvt_thread_yield();
60         }
61
62         /* begin transaction */
63         rc = TXN_BEGIN( bdb->bi_dbenv, NULL, &ltid, bdb->bi_db_opflags );
64         if ( rc != 0 ) {
65                 Debug( LDAP_DEBUG_TRACE,
66                         "bdb_operational: txn_begin failed: %s (%d)\n",
67                         db_strerror( rc ), rc, 0 );
68                 rc = LDAP_OTHER;
69                 return rc;
70         }
71
72         opinfo.boi_bdb = be;
73         opinfo.boi_txn = ltid;
74         opinfo.boi_err = 0;
75         op->o_private = &opinfo;
76
77         rc = bdb_dn2id_children( be, ltid, &e->e_nname );
78         
79         switch( rc ) {
80         case DB_LOCK_DEADLOCK:
81         case DB_LOCK_NOTGRANTED:
82                 goto retry;
83
84         case 0:
85         case DB_NOTFOUND:
86                 *aa = slap_operational_hasSubordinate( rc == 0 );
87                 if ( *aa != NULL ) {
88                         aa = &(*aa)->a_next;
89                 }
90                 break;
91
92         default:
93                 Debug(LDAP_DEBUG_ARGS, 
94                         "<=- bdb_operational: has_children failed: %s (%d)\n", 
95                         db_strerror(rc), rc, 0 );
96                 rc = LDAP_OTHER;
97         }
98
99 return_results:
100         if ( rc == LDAP_SUCCESS && bdb->bi_txn_cp ) {
101                 ldap_pvt_thread_yield();
102                 TXN_CHECKPOINT( bdb->bi_dbenv,
103                         bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
104         }
105
106         if ( ltid != NULL ) {
107                 TXN_ABORT( ltid );
108                 op->o_private = NULL;
109         }
110
111         return rc;
112 }
113