summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2012-04-16 15:23:06 +0200
committerVolker Lendecke <vl@samba.org>2012-04-17 10:20:59 +0200
commit6235b761f6eab3ec3d8492ba146e8d9efe6944a6 (patch)
tree707a2211a222e8d6d809acc53d1d5a9235adae40
parent4460ba5288fc84dce9060e1e15e3ae25114b2455 (diff)
downloadsamba-6235b761f6eab3ec3d8492ba146e8d9efe6944a6.tar.gz
samba-6235b761f6eab3ec3d8492ba146e8d9efe6944a6.tar.bz2
samba-6235b761f6eab3ec3d8492ba146e8d9efe6944a6.zip
tdb-compat: Add tdb_chainlock_nonblock
-rw-r--r--lib/tdb_compat/tdb_compat.c24
-rw-r--r--lib/tdb_compat/tdb_compat.h2
2 files changed, 26 insertions, 0 deletions
diff --git a/lib/tdb_compat/tdb_compat.c b/lib/tdb_compat/tdb_compat.c
index 0406eff55e..7fd3caf6b5 100644
--- a/lib/tdb_compat/tdb_compat.c
+++ b/lib/tdb_compat/tdb_compat.c
@@ -38,6 +38,30 @@ enum TDB_ERROR tdb_transaction_start_nonblock(struct tdb_context *tdb)
return ecode;
}
+enum TDB_ERROR tdb_chainlock_nonblock(struct tdb_context *tdb, TDB_DATA key)
+{
+ union tdb_attribute locking, orig;
+ enum TDB_ERROR ecode;
+
+ orig.base.attr = TDB_ATTRIBUTE_FLOCK;
+ ecode = tdb_get_attribute(tdb, &orig);
+ if (ecode != TDB_SUCCESS)
+ return ecode;
+
+ /* Replace locking function with our own. */
+ locking = orig;
+ locking.flock.data = &orig;
+ locking.flock.lock = lock_nonblock;
+
+ ecode = tdb_set_attribute(tdb, &locking);
+ if (ecode != TDB_SUCCESS)
+ return ecode;
+
+ ecode = tdb_chainlock(tdb, key);
+ tdb_unset_attribute(tdb, TDB_ATTRIBUTE_FLOCK);
+ 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,
diff --git a/lib/tdb_compat/tdb_compat.h b/lib/tdb_compat/tdb_compat.h
index 0d58075c80..e0a2bf8e5e 100644
--- a/lib/tdb_compat/tdb_compat.h
+++ b/lib/tdb_compat/tdb_compat.h
@@ -87,6 +87,8 @@ int tdb_reopen_all(int parent_longlived);
/* tdb2 does nonblocking functions via attibutes. */
enum TDB_ERROR tdb_transaction_start_nonblock(struct tdb_context *tdb);
+enum TDB_ERROR tdb_chainlock_nonblock(struct tdb_context *tdb, TDB_DATA key);
+
/* Convenient (typesafe) wrapper for tdb open with logging */
#define tdb_open_compat(name, hsize, tdb_fl, open_fl, mode, log_fn, log_data) \