From 61095999cc158482f68fa53f16160033128615e8 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 14 Sep 2011 07:52:13 +0930 Subject: [PATCH] tdb2: unify tdb1_append into tdb_append Switch on the TDB_VERSION1 flag. Signed-off-by: Rusty Russell (Imported from CCAN commit 8bc38cb177928ef739440c32e33a8eaf23a5dd22) --- lib/tdb2/private.h | 1 + lib/tdb2/tdb.c | 6 ++++++ lib/tdb2/tdb1.h | 2 -- lib/tdb2/tdb1_tdb.c | 2 ++ lib/tdb2/test/run-tdb1-zero-append.c | 4 ++-- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/tdb2/private.h b/lib/tdb2/private.h index 1c794753f9..97a214f74a 100644 --- a/lib/tdb2/private.h +++ b/lib/tdb2/private.h @@ -662,6 +662,7 @@ int tdb1_transaction_cancel(struct tdb_context *tdb); 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); /* tdb.c: */ enum TDB_ERROR COLD tdb_logerr(struct tdb_context *tdb, diff --git a/lib/tdb2/tdb.c b/lib/tdb2/tdb.c index c9c95c602c..be2ff0d676 100644 --- a/lib/tdb2/tdb.c +++ b/lib/tdb2/tdb.c @@ -185,6 +185,12 @@ enum TDB_ERROR tdb_append(struct tdb_context *tdb, struct tdb_data new_dbuf; enum TDB_ERROR ecode; + if (tdb->flags & TDB_VERSION1) { + if (tdb1_append(tdb, key, dbuf) == -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; diff --git a/lib/tdb2/tdb1.h b/lib/tdb2/tdb1.h index e320428385..62b94da44a 100644 --- a/lib/tdb2/tdb1.h +++ b/lib/tdb2/tdb1.h @@ -47,8 +47,6 @@ int tdb1_parse_record(struct tdb_context *tdb, TDB_DATA key, int tdb1_delete(struct tdb_context *tdb, TDB_DATA key); -int tdb1_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf); - TDB_DATA tdb1_firstkey(struct tdb_context *tdb); TDB_DATA tdb1_nextkey(struct tdb_context *tdb, TDB_DATA key); diff --git a/lib/tdb2/tdb1_tdb.c b/lib/tdb2/tdb1_tdb.c index bba16338e9..895a8c2ae5 100644 --- a/lib/tdb2/tdb1_tdb.c +++ b/lib/tdb2/tdb1_tdb.c @@ -627,6 +627,8 @@ int tdb1_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf) TDB_DATA dbuf; int ret = -1; + assert(tdb->flags & TDB_VERSION1); + /* find which hash bucket it is in */ hash = tdb_hash(tdb, key.dptr, key.dsize); if (tdb1_lock(tdb, TDB1_BUCKET(hash), F_WRLCK) == -1) diff --git a/lib/tdb2/test/run-tdb1-zero-append.c b/lib/tdb2/test/run-tdb1-zero-append.c index 560b5bc8dd..fdc9cdce35 100644 --- a/lib/tdb2/test/run-tdb1-zero-append.c +++ b/lib/tdb2/test/run-tdb1-zero-append.c @@ -25,8 +25,8 @@ int main(int argc, char *argv[]) data.dptr = (void *)"world"; data.dsize = 0; - ok1(tdb1_append(tdb, key, data) == 0); - ok1(tdb1_append(tdb, key, data) == 0); + ok1(tdb_append(tdb, key, data) == TDB_SUCCESS); + ok1(tdb_append(tdb, key, data) == TDB_SUCCESS); ok1(tdb_fetch(tdb, key, &data) == TDB_SUCCESS); ok1(data.dsize == 0); free(data.dptr); -- 2.45.1