added _mark calls for tdb_lockall
authorAndrew Tridgell <tridge@samba.org>
Sat, 12 May 2007 04:33:10 +0000 (14:33 +1000)
committerAndrew Tridgell <tridge@samba.org>
Sat, 12 May 2007 04:33:10 +0000 (14:33 +1000)
(This used to be ctdb commit e59134fd2af67c746b907c23fdcde2eccbbe17cf)

ctdb/lib/tdb/common/lock.c
ctdb/lib/tdb/include/tdb.h

index c4a99b571944234b489976f89f3c7ea848e3c1f3..72892febbd3261692e29ea0a1d2d6d3df648389a 100644 (file)
@@ -290,6 +290,10 @@ int tdb_unlock(struct tdb_context *tdb, int list, int ltype)
 /* lock/unlock entire database */
 static int _tdb_lockall(struct tdb_context *tdb, int ltype, int op)
 {
+       bool mark_lock = ((ltype & TDB_MARK_LOCK) == TDB_MARK_LOCK);
+
+       ltype &= ~TDB_MARK_LOCK;
+
        /* There are no locks on read-only dbs */
        if (tdb->read_only || tdb->traverse_read)
                return TDB_ERRCODE(TDB_ERR_LOCK, -1);
@@ -309,7 +313,8 @@ static int _tdb_lockall(struct tdb_context *tdb, int ltype, int op)
                return TDB_ERRCODE(TDB_ERR_LOCK, -1);
        }
 
-       if (tdb->methods->tdb_brlock(tdb, FREELIST_TOP, ltype, op,
+       if (!mark_lock &&
+           tdb->methods->tdb_brlock(tdb, FREELIST_TOP, ltype, op,
                                     0, 4*tdb->header.hash_size)) {
                if (op == F_SETLKW) {
                        TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_lockall failed (%s)\n", strerror(errno)));
@@ -328,6 +333,10 @@ static int _tdb_lockall(struct tdb_context *tdb, int ltype, int op)
 /* unlock entire db */
 static int _tdb_unlockall(struct tdb_context *tdb, int ltype)
 {
+       bool mark_lock = ((ltype & TDB_MARK_LOCK) == TDB_MARK_LOCK);
+
+       ltype &= ~TDB_MARK_LOCK;
+
        /* There are no locks on read-only dbs */
        if (tdb->read_only || tdb->traverse_read) {
                return TDB_ERRCODE(TDB_ERR_LOCK, -1);
@@ -342,7 +351,8 @@ static int _tdb_unlockall(struct tdb_context *tdb, int ltype)
                return 0;
        }
 
-       if (tdb->methods->tdb_brlock(tdb, FREELIST_TOP, F_UNLCK, F_SETLKW, 
+       if (!mark_lock &&
+           tdb->methods->tdb_brlock(tdb, FREELIST_TOP, F_UNLCK, F_SETLKW, 
                                     0, 4*tdb->header.hash_size)) {
                TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_unlockall failed (%s)\n", strerror(errno)));
                return -1;
@@ -360,6 +370,18 @@ int tdb_lockall(struct tdb_context *tdb)
        return _tdb_lockall(tdb, F_WRLCK, F_SETLKW);
 }
 
+/* lock entire database with write lock - mark only */
+int tdb_lockall_mark(struct tdb_context *tdb)
+{
+       return _tdb_lockall(tdb, F_WRLCK | TDB_MARK_LOCK, F_SETLKW);
+}
+
+/* unlock entire database with write lock - unmark only */
+int tdb_lockall_unmark(struct tdb_context *tdb)
+{
+       return _tdb_unlockall(tdb, F_WRLCK | TDB_MARK_LOCK);
+}
+
 /* lock entire database with write lock - nonblocking varient */
 int tdb_lockall_nonblock(struct tdb_context *tdb)
 {
index 30d88b8b88b2a081ac6834944c445482fc7854dc..9a9a4b489afc156e14abf01695225d880a3df6b1 100644 (file)
@@ -121,6 +121,8 @@ int tdb_unlockall(struct tdb_context *tdb);
 int tdb_lockall_read(struct tdb_context *tdb);
 int tdb_lockall_read_nonblock(struct tdb_context *tdb);
 int tdb_unlockall_read(struct tdb_context *tdb);
+int tdb_lockall_mark(struct tdb_context *tdb);
+int tdb_lockall_unmark(struct tdb_context *tdb);
 const char *tdb_name(struct tdb_context *tdb);
 int tdb_fd(struct tdb_context *tdb);
 tdb_log_func tdb_log_fn(struct tdb_context *tdb);