tdb2: unify tdb1_delete into tdb_delete.
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 31 Aug 2011 06:01:06 +0000 (15:31 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 31 Aug 2011 06:01:06 +0000 (15:31 +0930)
Switch on the TDB_VERSION1 flag.

ccan/tdb2/private.h
ccan/tdb2/tdb.c
ccan/tdb2/tdb1.h
ccan/tdb2/tdb1_tdb.c
ccan/tdb2/test/run-tdb1-3G-file.c
ccan/tdb2/test/run-tdb1-incompatible.c
ccan/tdb2/test/run-tdb1-nested-transactions.c
ccan/tdb2/test/run-tdb1-no-lock-during-traverse.c

index 1c307fc3c5313c4c13c37c7098554907f4d68e64..f050fad8518b908de67b0d846f922e4ea5473625 100644 (file)
@@ -651,6 +651,7 @@ int tdb1_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag);
 enum TDB_ERROR tdb1_fetch(struct tdb_context *tdb, TDB_DATA key,
                          TDB_DATA *data);
 int tdb1_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf);
+int tdb1_delete(struct tdb_context *tdb, TDB_DATA key);
 
 /* tdb.c: */
 enum TDB_ERROR COLD tdb_logerr(struct tdb_context *tdb,
index 9f3da1c01ff3363663cb14c4c6cca430367a0faa..57b0777845e78805ff56298fd10517b4c8f351cb 100644 (file)
@@ -302,6 +302,12 @@ enum TDB_ERROR tdb_delete(struct tdb_context *tdb, struct tdb_data key)
        struct hash_info h;
        enum TDB_ERROR ecode;
 
+       if (tdb->flags & TDB_VERSION1) {
+               if (tdb1_delete(tdb, key) == -1)
+                       return tdb->last_error;
+               return TDB_SUCCESS;
+       }
+
        off = find_and_lock(tdb, key, F_WRLCK, &h, &rec, NULL);
        if (TDB_OFF_IS_ERR(off)) {
                return tdb->last_error = off;
index 62b94da44afd05ebe0a2f90f0303b8cf2c1a1ce8..77d673ae089247b72b72f524da5526217ca3bf4e 100644 (file)
@@ -45,8 +45,6 @@ int tdb1_parse_record(struct tdb_context *tdb, TDB_DATA key,
                                            void *private_data),
                              void *private_data);
 
-int tdb1_delete(struct tdb_context *tdb, TDB_DATA key);
-
 TDB_DATA tdb1_firstkey(struct tdb_context *tdb);
 
 TDB_DATA tdb1_nextkey(struct tdb_context *tdb, TDB_DATA key);
index 895a8c2ae59218ab43778905df0787c31a96b104..16e945974eaf9e2bcbf6ed213c6e5096bfb18c49 100644 (file)
@@ -434,6 +434,7 @@ int tdb1_delete(struct tdb_context *tdb, TDB_DATA key)
        uint32_t hash = tdb_hash(tdb, key.dptr, key.dsize);
        int ret;
 
+       assert(tdb->flags & TDB_VERSION1);
        ret = tdb1_delete_hash(tdb, key, hash);
        return ret;
 }
index 5e0e64e8155331d7c42a67291d74c1cf1909b294..116c655438106fdffed0c74a35ea62b618701b33 100644 (file)
@@ -104,7 +104,7 @@ int main(int argc, char *argv[])
        ok1(tdb1_traverse(tdb, test_traverse, &orig_data) == 1);
 
        /* Delete should work. */
-       ok1(tdb1_delete(tdb, key) == 0);
+       ok1(tdb_delete(tdb, key) == TDB_SUCCESS);
 
        ok1(tdb1_traverse(tdb, test_traverse, NULL) == 0);
 
index d2e07107aaacea36f2097f591fad768c1eae34b4..e6b2994e203ed57e0f45d3e95d32a8a9cc97ddf0 100644 (file)
@@ -153,7 +153,7 @@ int main(int argc, char *argv[])
                               O_RDWR, 0600, &jhash_attr);
                ok1(tdb);
                ok1(log_count == 0);
-               ok1(tdb1_fetch(tdb, d, &d) == TDB_SUCCESS);
+               ok1(tdb_fetch(tdb, d, &d) == TDB_SUCCESS);
                ok1(d.dsize == 5);
                free(d.dptr);
                ok1(tdb1_check(tdb, NULL, NULL) == 0);
@@ -202,7 +202,7 @@ int main(int argc, char *argv[])
                               &dumbhash_attr);
                ok1(tdb);
                ok1(log_count == 0);
-               ok1(tdb1_fetch(tdb, d, &d) == TDB_SUCCESS);
+               ok1(tdb_fetch(tdb, d, &d) == TDB_SUCCESS);
                ok1(d.dsize == 5);
                free(d.dptr);
                ok1(tdb1_check(tdb, NULL, NULL) == 0);
index 89e47d3fbf5ef4bb7a289dcfd358759398df4aae..645b4bc1470a23a541b459e9c1ff6f375b394ab1 100644 (file)
@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
 
        ok1(tdb1_transaction_start(tdb) == 0);
        ok1(tdb1_transaction_start(tdb) == 0);
-       ok1(tdb1_delete(tdb, key) == 0);
+       ok1(tdb_delete(tdb, key) == TDB_SUCCESS);
        ok1(tdb1_transaction_commit(tdb) == 0);
        ok1(!tdb1_exists(tdb, key));
        ok1(tdb1_transaction_cancel(tdb) == 0);
@@ -61,7 +61,7 @@ int main(int argc, char *argv[])
 
        ok1(tdb1_transaction_start(tdb) == 0);
        ok1(tdb1_transaction_start(tdb) == 0);
-       ok1(tdb1_delete(tdb, key) == 0);
+       ok1(tdb_delete(tdb, key) == TDB_SUCCESS);
        ok1(tdb1_transaction_commit(tdb) == 0);
        ok1(!tdb1_exists(tdb, key));
        ok1(tdb1_transaction_commit(tdb) == 0);
index 94c125dcadb8be9817cd6078e2637e6366809eda..383b74cb87d59965b5ec194aa6cedac8a6a01c6d 100644 (file)
@@ -40,7 +40,7 @@ static void delete_entries(struct tdb_context *tdb)
                key.dsize = sizeof(i);
                key.dptr = (void *)&i;
 
-               ok1(tdb1_delete(tdb, key) == 0);
+               ok1(tdb_delete(tdb, key) == TDB_SUCCESS);
        }
 }
 
@@ -52,7 +52,7 @@ static int delete_other(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
        memcpy(&i, key.dptr, 4);
        i = (i + 1) % NUM_ENTRIES;
        key.dptr = (void *)&i;
-       if (tdb1_delete(tdb, key) != 0)
+       if (tdb_delete(tdb, key) != TDB_SUCCESS)
                (*(int *)private_data)++;
        return 0;
 }
@@ -60,7 +60,7 @@ static int delete_other(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
 static int delete_self(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
                        void *private_data)
 {
-       ok1(tdb1_delete(tdb, key) == 0);
+       ok1(tdb_delete(tdb, key) == TDB_SUCCESS);
        return 0;
 }