summaryrefslogtreecommitdiff
path: root/source4/lib/tdb/common/tdb.c
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib/tdb/common/tdb.c')
-rw-r--r--source4/lib/tdb/common/tdb.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/source4/lib/tdb/common/tdb.c b/source4/lib/tdb/common/tdb.c
index 25103d826e..70d050e7e6 100644
--- a/source4/lib/tdb/common/tdb.c
+++ b/source4/lib/tdb/common/tdb.c
@@ -31,10 +31,10 @@
TDB_DATA tdb_null;
/*
- increment the tdb sequence number if the tdb has been opened using
+ non-blocking increment of the tdb sequence number if the tdb has been opened using
the TDB_SEQNUM flag
*/
-static void tdb_increment_seqnum(struct tdb_context *tdb)
+void tdb_increment_seqnum_nonblock(struct tdb_context *tdb)
{
tdb_off_t seqnum=0;
@@ -42,16 +42,29 @@ static void tdb_increment_seqnum(struct tdb_context *tdb)
return;
}
- if (tdb_brlock(tdb, TDB_SEQNUM_OFS, F_WRLCK, F_SETLKW, 1, 1) != 0) {
- return;
- }
-
/* we ignore errors from this, as we have no sane way of
dealing with them.
*/
tdb_ofs_read(tdb, TDB_SEQNUM_OFS, &seqnum);
seqnum++;
tdb_ofs_write(tdb, TDB_SEQNUM_OFS, &seqnum);
+}
+
+/*
+ increment the tdb sequence number if the tdb has been opened using
+ the TDB_SEQNUM flag
+*/
+static void tdb_increment_seqnum(struct tdb_context *tdb)
+{
+ if (!(tdb->flags & TDB_SEQNUM)) {
+ return;
+ }
+
+ if (tdb_brlock(tdb, TDB_SEQNUM_OFS, F_WRLCK, F_SETLKW, 1, 1) != 0) {
+ return;
+ }
+
+ tdb_increment_seqnum_nonblock(tdb);
tdb_brlock(tdb, TDB_SEQNUM_OFS, F_UNLCK, F_SETLKW, 1, 1);
}
@@ -649,3 +662,11 @@ int tdb_get_flags(struct tdb_context *tdb)
return tdb->flags;
}
+
+/*
+ enable sequence number handling on an open tdb
+*/
+void tdb_enable_seqnum(struct tdb_context *tdb)
+{
+ tdb->flags |= TDB_SEQNUM;
+}