summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2011-09-14 07:17:13 +0930
committerRusty Russell <rusty@rustcorp.com.au>2011-09-14 07:17:13 +0930
commit73e4f35e3d4dd7043a140355e4cd0f10f54c7337 (patch)
tree193cd02c733346d5db787d62a08193e602f7717d /lib
parentbdc5499205367eccef5700cba8af95ba941ac9b2 (diff)
downloadsamba-73e4f35e3d4dd7043a140355e4cd0f10f54c7337.tar.gz
samba-73e4f35e3d4dd7043a140355e4cd0f10f54c7337.tar.bz2
samba-73e4f35e3d4dd7043a140355e4cd0f10f54c7337.zip
tdb_compat: make tdb2s temporarily read-only for tdb_traverse_read()
It doesn't make a difference unless the tdb2 opens a TDB1 on disk, in which case tdb1_traverse() takes a write lock on the entire file. By setting the tdb to read-only first, we simulate the old behaviour. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib')
-rw-r--r--lib/tdb_compat/tdb_compat.c20
-rw-r--r--lib/tdb_compat/tdb_compat.h9
2 files changed, 27 insertions, 2 deletions
diff --git a/lib/tdb_compat/tdb_compat.c b/lib/tdb_compat/tdb_compat.c
index d736db1742..2e43564802 100644
--- a/lib/tdb_compat/tdb_compat.c
+++ b/lib/tdb_compat/tdb_compat.c
@@ -38,6 +38,26 @@ enum TDB_ERROR tdb_transaction_start_nonblock(struct tdb_context *tdb)
return ecode;
}
+/* For TDB1 tdbs, read traverse vs normal matters: write traverse
+ locks the entire thing! */
+int64_t tdb_traverse_read_(struct tdb_context *tdb,
+ int (*fn)(struct tdb_context *,
+ TDB_DATA, TDB_DATA,
+ void *),
+ void *p)
+{
+ int64_t ret;
+
+ if (tdb_get_flags(tdb) & TDB_RDONLY) {
+ return tdb_traverse(tdb, fn, p);
+ }
+
+ tdb_add_flag(tdb, TDB_RDONLY);
+ ret = tdb_traverse(tdb, fn, p);
+ tdb_remove_flag(tdb, TDB_RDONLY);
+ return ret;
+}
+
/*
* This handles TDB_CLEAR_IF_FIRST.
*/
diff --git a/lib/tdb_compat/tdb_compat.h b/lib/tdb_compat/tdb_compat.h
index 80fc3cef80..16d1f48c7d 100644
--- a/lib/tdb_compat/tdb_compat.h
+++ b/lib/tdb_compat/tdb_compat.h
@@ -62,8 +62,13 @@ static inline TDB_DATA tdb_nextkey_compat(struct tdb_context *tdb, TDB_DATA k)
return k;
}
-/* tdb_traverse_read and tdb_traverse are equal: both only take read locks. */
-#define tdb_traverse_read tdb_traverse
+#define tdb_traverse_read(tdb, fn, p) \
+ tdb_traverse_read_(tdb, typesafe_cb_preargs(int, void *, (fn), (p), \
+ struct tdb_context *, \
+ TDB_DATA, TDB_DATA), (p))
+int64_t tdb_traverse_read_(struct tdb_context *tdb,
+ int (*fn)(struct tdb_context *,
+ TDB_DATA, TDB_DATA, void *), void *p);
/* Old-style tdb_errorstr */
#define tdb_errorstr_compat(tdb) tdb_errorstr(tdb_error(tdb))