diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2011-09-14 07:52:13 +0930 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2011-09-14 07:52:13 +0930 |
commit | 61095999cc158482f68fa53f16160033128615e8 (patch) | |
tree | 998a9345aec2084538f30196a5b2ac94ef48da51 /lib/tdb2 | |
parent | 02f5b8fef868b7f77f1ac385740328757bff4d93 (diff) | |
download | samba-61095999cc158482f68fa53f16160033128615e8.tar.gz samba-61095999cc158482f68fa53f16160033128615e8.tar.bz2 samba-61095999cc158482f68fa53f16160033128615e8.zip |
tdb2: unify tdb1_append into tdb_append
Switch on the TDB_VERSION1 flag.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
(Imported from CCAN commit 8bc38cb177928ef739440c32e33a8eaf23a5dd22)
Diffstat (limited to 'lib/tdb2')
-rw-r--r-- | lib/tdb2/private.h | 1 | ||||
-rw-r--r-- | lib/tdb2/tdb.c | 6 | ||||
-rw-r--r-- | lib/tdb2/tdb1.h | 2 | ||||
-rw-r--r-- | lib/tdb2/tdb1_tdb.c | 2 | ||||
-rw-r--r-- | 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); |