]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/transaction.c
tdb2: cleanup oob handling.
[ccan] / ccan / tdb2 / transaction.c
index 9205828a8a16138d754e0013b68d9b91396b1894..eda65c520842240e871ed3439378432f102a4d9c 100644 (file)
@@ -348,15 +348,14 @@ static void transaction_write_existing(struct tdb_context *tdb, tdb_off_t off,
 static enum TDB_ERROR transaction_oob(struct tdb_context *tdb, tdb_off_t len,
                                      bool probe)
 {
-       if (len <= tdb->file->map_size) {
+       if (len <= tdb->file->map_size || probe) {
                return TDB_SUCCESS;
        }
-       if (!probe) {
-               tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
-                          "tdb_oob len %lld beyond transaction size %lld",
-                          (long long)len,
-                          (long long)tdb->file->map_size);
-       }
+
+       tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
+                  "tdb_oob len %lld beyond transaction size %lld",
+                  (long long)len,
+                  (long long)tdb->file->map_size);
        return TDB_ERR_IO;
 }
 
@@ -509,7 +508,7 @@ static void _tdb_transaction_cancel(struct tdb_context *tdb)
        tdb_transaction_unlock(tdb, F_WRLCK);
 
        if (tdb_has_open_lock(tdb))
-               tdb_unlock_open(tdb);
+               tdb_unlock_open(tdb, F_WRLCK);
 
        SAFE_FREE(tdb->transaction);
 }
@@ -1005,7 +1004,7 @@ static enum TDB_ERROR _tdb_transaction_prepare_commit(struct tdb_context *tdb)
 
        /* get the open lock - this prevents new users attaching to the database
           during the commit */
-       ecode = tdb_lock_open(tdb, TDB_LOCK_WAIT|TDB_LOCK_NOCHECK);
+       ecode = tdb_lock_open(tdb, F_WRLCK, TDB_LOCK_WAIT|TDB_LOCK_NOCHECK);
        if (ecode != TDB_SUCCESS) {
                return ecode;
        }