s4-ldb: fixed nested searches inside ldb modules
authorAndrew Tridgell <tridge@samba.org>
Wed, 9 Dec 2009 03:37:26 +0000 (14:37 +1100)
committerAndrew Tridgell <tridge@samba.org>
Wed, 9 Dec 2009 07:18:25 +0000 (18:18 +1100)
We need to keep a search count in ltdb to allow for nesting
of searches inside a module

Signed-off-by: Andrew Tridgell <tridge@samba.org>
source4/lib/ldb/ldb_tdb/ldb_tdb.c
source4/lib/ldb/ldb_tdb/ldb_tdb.h

index 7fb3cdc067c9a19ee2a07891d474c405505cd477..48409f2cba6b2f90f8176b1d00ed5c2d17966650 100644 (file)
@@ -88,10 +88,16 @@ int ltdb_lock_read(struct ldb_module *module)
 {
        void *data = ldb_module_get_private(module);
        struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
-       if (ltdb->in_transaction == 0) {
-               return tdb_lockall_read(ltdb->tdb);
+       int ret = 0;
+
+       if (ltdb->in_transaction == 0 &&
+           ltdb->read_lock_count == 0) {
+               ret = tdb_lockall_read(ltdb->tdb);
        }
-       return 0;
+       if (ret == 0) {
+               ltdb->read_lock_count++;
+       }
+       return ret;
 }
 
 /*
@@ -101,9 +107,10 @@ int ltdb_unlock_read(struct ldb_module *module)
 {
        void *data = ldb_module_get_private(module);
        struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
-       if (ltdb->in_transaction == 0) {
+       if (ltdb->in_transaction == 0 && ltdb->read_lock_count == 1) {
                return tdb_unlockall_read(ltdb->tdb);
        }
+       ltdb->read_lock_count--;
        return 0;
 }
 
index 0f17c82eaa49c9a99d8d1961c402aeda11fc0ac0..bb4cb3f8b504e777efd6d428477dfc86bbb2f4f5 100644 (file)
@@ -31,6 +31,7 @@ struct ltdb_private {
        bool check_base;
        struct ltdb_idxptr *idxptr;
        bool prepared_commit;
+       int read_lock_count;
 };
 
 /*