diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2011-09-14 07:50:13 +0930 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2011-09-14 07:50:13 +0930 |
commit | f68a56ce8f38cc1768d8c2dca84f456f4ecfc625 (patch) | |
tree | 640d6e029579d212598615727dc03567c2d6476f /lib/tdb2 | |
parent | cbad6e2c140e59a6ec653bcfe773599a57a5042f (diff) | |
download | samba-f68a56ce8f38cc1768d8c2dca84f456f4ecfc625.tar.gz samba-f68a56ce8f38cc1768d8c2dca84f456f4ecfc625.tar.bz2 samba-f68a56ce8f38cc1768d8c2dca84f456f4ecfc625.zip |
tdb2: unify tdb1_store into tdb_store
Switch on the TDB_VERSION1 flag.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
(Imported from CCAN commit 98c754ffe65bc335f66161d6cc8705d4ea2710ec)
Diffstat (limited to 'lib/tdb2')
-rw-r--r-- | lib/tdb2/private.h | 3 | ||||
-rw-r--r-- | lib/tdb2/tdb.c | 6 | ||||
-rw-r--r-- | lib/tdb2/tdb1.h | 2 | ||||
-rw-r--r-- | lib/tdb2/tdb1_tdb.c | 3 | ||||
-rw-r--r-- | lib/tdb2/test/run-tdb1-3G-file.c | 4 | ||||
-rw-r--r-- | lib/tdb2/test/run-tdb1-check.c | 2 | ||||
-rw-r--r-- | lib/tdb2/test/run-tdb1-corrupt.c | 2 | ||||
-rw-r--r-- | lib/tdb2/test/run-tdb1-die-during-transaction.c | 4 | ||||
-rw-r--r-- | lib/tdb2/test/run-tdb1-endian.c | 12 | ||||
-rw-r--r-- | lib/tdb2/test/run-tdb1-incompatible.c | 6 | ||||
-rw-r--r-- | lib/tdb2/test/run-tdb1-nested-transactions.c | 2 | ||||
-rw-r--r-- | lib/tdb2/test/run-tdb1-nested-traverse.c | 2 | ||||
-rw-r--r-- | lib/tdb2/test/run-tdb1-no-lock-during-traverse.c | 2 | ||||
-rw-r--r-- | lib/tdb2/test/run-tdb1-open-during-transaction.c | 2 | ||||
-rw-r--r-- | lib/tdb2/test/run-tdb1-readonly-check.c | 7 | ||||
-rw-r--r-- | lib/tdb2/test/run-tdb1-summary.c | 4 | ||||
-rw-r--r-- | lib/tdb2/test/run-tdb1-traverse-in-transaction.c | 2 | ||||
-rw-r--r-- | lib/tdb2/test/run-tdb1-wronghash-fail.c | 2 | ||||
-rw-r--r-- | lib/tdb2/test/run-tdb1.c | 12 | ||||
-rw-r--r-- | lib/tdb2/test/tdb1-external-agent.c | 5 |
20 files changed, 47 insertions, 37 deletions
diff --git a/lib/tdb2/private.h b/lib/tdb2/private.h index b7fd5959d1..e4800599ef 100644 --- a/lib/tdb2/private.h +++ b/lib/tdb2/private.h @@ -658,6 +658,9 @@ int tdb1_allrecord_unlock(struct tdb_context *tdb, int ltype); int tdb1_transaction_recover(struct tdb_context *tdb); int tdb1_transaction_cancel(struct tdb_context *tdb); +/* tdb1_tdb.c: */ +int tdb1_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag); + /* tdb.c: */ enum TDB_ERROR COLD tdb_logerr(struct tdb_context *tdb, enum TDB_ERROR ecode, diff --git a/lib/tdb2/tdb.c b/lib/tdb2/tdb.c index 14bf059966..806fb037a4 100644 --- a/lib/tdb2/tdb.c +++ b/lib/tdb2/tdb.c @@ -116,6 +116,12 @@ enum TDB_ERROR tdb_store(struct tdb_context *tdb, struct tdb_used_record rec; enum TDB_ERROR ecode; + if (tdb->flags & TDB_VERSION1) { + if (tdb1_store(tdb, key, dbuf, flag) == -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 c1a68ffc17..e448d75d64 100644 --- a/lib/tdb2/tdb1.h +++ b/lib/tdb2/tdb1.h @@ -49,8 +49,6 @@ int tdb1_parse_record(struct tdb_context *tdb, TDB_DATA key, int tdb1_delete(struct tdb_context *tdb, TDB_DATA key); -int tdb1_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag); - int tdb1_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf); TDB_DATA tdb1_firstkey(struct tdb_context *tdb); diff --git a/lib/tdb2/tdb1_tdb.c b/lib/tdb2/tdb1_tdb.c index cdcf76d368..384654ed94 100644 --- a/lib/tdb2/tdb1_tdb.c +++ b/lib/tdb2/tdb1_tdb.c @@ -26,6 +26,7 @@ */ #include "tdb1_private.h" +#include <assert.h> TDB_DATA tdb1_null; @@ -601,6 +602,8 @@ int tdb1_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag) uint32_t hash; int ret; + assert(tdb->flags & TDB_VERSION1); + if ((tdb->flags & TDB_RDONLY) || tdb->tdb1.traverse_read) { tdb->last_error = TDB_ERR_RDONLY; return -1; diff --git a/lib/tdb2/test/run-tdb1-3G-file.c b/lib/tdb2/test/run-tdb1-3G-file.c index 9194d3a319..0f299a32fe 100644 --- a/lib/tdb2/test/run-tdb1-3G-file.c +++ b/lib/tdb2/test/run-tdb1-3G-file.c @@ -86,7 +86,7 @@ int main(int argc, char *argv[]) orig_data.dsize = strlen("world"); orig_data.dptr = (void *)"world"; - ok1(tdb1_store(tdb, key, orig_data, TDB_INSERT) == 0); + ok1(tdb_store(tdb, key, orig_data, TDB_INSERT) == TDB_SUCCESS); data = tdb1_fetch(tdb, key); ok1(data.dsize == strlen("world")); @@ -110,7 +110,7 @@ int main(int argc, char *argv[]) /* Transactions should work. */ ok1(tdb1_transaction_start(tdb) == 0); - ok1(tdb1_store(tdb, key, orig_data, TDB_INSERT) == 0); + ok1(tdb_store(tdb, key, orig_data, TDB_INSERT) == TDB_SUCCESS); data = tdb1_fetch(tdb, key); ok1(data.dsize == strlen("world")); diff --git a/lib/tdb2/test/run-tdb1-check.c b/lib/tdb2/test/run-tdb1-check.c index 8a0532c4be..d2360f02fd 100644 --- a/lib/tdb2/test/run-tdb1-check.c +++ b/lib/tdb2/test/run-tdb1-check.c @@ -26,7 +26,7 @@ int main(int argc, char *argv[]) data.dsize = strlen("world"); data.dptr = (void *)"world"; - ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0); + ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS); ok1(tdb1_check(tdb, NULL, NULL) == 0); tdb_close(tdb); diff --git a/lib/tdb2/test/run-tdb1-corrupt.c b/lib/tdb2/test/run-tdb1-corrupt.c index f87afd8a6a..373f079512 100644 --- a/lib/tdb2/test/run-tdb1-corrupt.c +++ b/lib/tdb2/test/run-tdb1-corrupt.c @@ -58,7 +58,7 @@ static void check_test(struct tdb_context *tdb) for (key.dsize = 1; key.dsize <= 5; key.dsize++) { ksize += key.dsize; dsize += data.dsize; - if (tdb1_store(tdb, key, data, TDB_INSERT) != 0) + if (tdb_store(tdb, key, data, TDB_INSERT) != TDB_SUCCESS) abort(); } diff --git a/lib/tdb2/test/run-tdb1-die-during-transaction.c b/lib/tdb2/test/run-tdb1-die-during-transaction.c index 4f54f6cbc6..f42513953a 100644 --- a/lib/tdb2/test/run-tdb1-die-during-transaction.c +++ b/lib/tdb2/test/run-tdb1-die-during-transaction.c @@ -155,7 +155,7 @@ reset: /* Put key for agent to fetch. */ key.dsize = strlen(KEY_STRING); key.dptr = (void *)KEY_STRING; - if (tdb1_store(tdb, key, key, TDB_INSERT) != 0) + if (tdb_store(tdb, key, key, TDB_INSERT) != TDB_SUCCESS) return false; /* This is the key we insert in transaction. */ @@ -173,7 +173,7 @@ reset: if (tdb1_transaction_start(tdb) != 0) return false; - if (tdb1_store(tdb, key, key, TDB_INSERT) != 0) + if (tdb_store(tdb, key, key, TDB_INSERT) != TDB_SUCCESS) return false; if (tdb1_transaction_commit(tdb) != 0) diff --git a/lib/tdb2/test/run-tdb1-endian.c b/lib/tdb2/test/run-tdb1-endian.c index 5e529ce2d0..bb5acf627b 100644 --- a/lib/tdb2/test/run-tdb1-endian.c +++ b/lib/tdb2/test/run-tdb1-endian.c @@ -14,7 +14,7 @@ int main(int argc, char *argv[]) hsize.base.next = &tap_log_attr; hsize.tdb1_hashsize.hsize = 1024; - plan_tests(13); + plan_tests(11); tdb = tdb_open("run-endian.tdb1", TDB_VERSION1|TDB_CONVERT, O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize); @@ -25,12 +25,10 @@ int main(int argc, char *argv[]) data.dsize = strlen("world"); data.dptr = (void *)"world"; - ok1(tdb1_store(tdb, key, data, TDB_MODIFY) < 0); - ok1(tdb_error(tdb) == TDB_ERR_NOEXIST); - ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0); - ok1(tdb1_store(tdb, key, data, TDB_INSERT) < 0); - ok1(tdb_error(tdb) == TDB_ERR_EXISTS); - ok1(tdb1_store(tdb, key, data, TDB_MODIFY) == 0); + ok1(tdb_store(tdb, key, data, TDB_MODIFY) == TDB_ERR_NOEXIST); + ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS); + ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_ERR_EXISTS); + ok1(tdb_store(tdb, key, data, TDB_MODIFY) == TDB_SUCCESS); data = tdb1_fetch(tdb, key); ok1(data.dsize == strlen("world")); diff --git a/lib/tdb2/test/run-tdb1-incompatible.c b/lib/tdb2/test/run-tdb1-incompatible.c index 350c78b2b4..13ec5d826f 100644 --- a/lib/tdb2/test/run-tdb1-incompatible.c +++ b/lib/tdb2/test/run-tdb1-incompatible.c @@ -89,7 +89,7 @@ int main(int argc, char *argv[]) ok1(log_count == 0); d.dptr = (void *)"Hello"; d.dsize = 5; - ok1(tdb1_store(tdb, d, d, TDB_INSERT) == 0); + ok1(tdb_store(tdb, d, d, TDB_INSERT) == TDB_SUCCESS); tdb_close(tdb); /* Should not have marked rwlocks field. */ @@ -134,7 +134,7 @@ int main(int argc, char *argv[]) ok1(log_count == 0); d.dptr = (void *)"Hello"; d.dsize = 5; - ok1(tdb1_store(tdb, d, d, TDB_INSERT) == 0); + ok1(tdb_store(tdb, d, d, TDB_INSERT) == TDB_SUCCESS); tdb_close(tdb); /* Should have marked rwlocks field. */ @@ -183,7 +183,7 @@ int main(int argc, char *argv[]) ok1(log_count == 0); d.dptr = (void *)"Hello"; d.dsize = 5; - ok1(tdb1_store(tdb, d, d, TDB_INSERT) == 0); + ok1(tdb_store(tdb, d, d, TDB_INSERT) == TDB_SUCCESS); tdb_close(tdb); /* FIXME: Should have marked rwlocks field. */ diff --git a/lib/tdb2/test/run-tdb1-nested-transactions.c b/lib/tdb2/test/run-tdb1-nested-transactions.c index 63fa1de79f..6a10b46b1b 100644 --- a/lib/tdb2/test/run-tdb1-nested-transactions.c +++ b/lib/tdb2/test/run-tdb1-nested-transactions.c @@ -27,7 +27,7 @@ int main(int argc, char *argv[]) ok1(tdb1_transaction_start(tdb) == 0); data.dptr = (void *)"world"; data.dsize = strlen("world"); - ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0); + ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS); data = tdb1_fetch(tdb, key); ok1(data.dsize == strlen("world")); ok1(memcmp(data.dptr, "world", strlen("world")) == 0); diff --git a/lib/tdb2/test/run-tdb1-nested-traverse.c b/lib/tdb2/test/run-tdb1-nested-traverse.c index 0225620083..ef19911d14 100644 --- a/lib/tdb2/test/run-tdb1-nested-traverse.c +++ b/lib/tdb2/test/run-tdb1-nested-traverse.c @@ -76,7 +76,7 @@ int main(int argc, char *argv[]) data.dptr = (void *)"world"; data.dsize = strlen("world"); - ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0); + ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS); tdb1_traverse(tdb, traverse1, NULL); tdb1_traverse_read(tdb, traverse1, NULL); tdb_close(tdb); diff --git a/lib/tdb2/test/run-tdb1-no-lock-during-traverse.c b/lib/tdb2/test/run-tdb1-no-lock-during-traverse.c index a418556d19..94c125dcad 100644 --- a/lib/tdb2/test/run-tdb1-no-lock-during-traverse.c +++ b/lib/tdb2/test/run-tdb1-no-lock-during-traverse.c @@ -25,7 +25,7 @@ static bool prepare_entries(struct tdb_context *tdb) data.dsize = strlen("world"); data.dptr = (void *)"world"; - if (tdb1_store(tdb, key, data, 0) != 0) + if (tdb_store(tdb, key, data, 0) != TDB_SUCCESS) return false; } return true; diff --git a/lib/tdb2/test/run-tdb1-open-during-transaction.c b/lib/tdb2/test/run-tdb1-open-during-transaction.c index fd3a48086c..879d790647 100644 --- a/lib/tdb2/test/run-tdb1-open-during-transaction.c +++ b/lib/tdb2/test/run-tdb1-open-during-transaction.c @@ -162,7 +162,7 @@ int main(int argc, char *argv[]) data.dptr = (void *)"world"; data.dsize = strlen("world"); - ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0); + ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS); ok1(tdb1_transaction_commit(tdb) == 0); ok(!errors, "We had %u open errors", errors); diff --git a/lib/tdb2/test/run-tdb1-readonly-check.c b/lib/tdb2/test/run-tdb1-readonly-check.c index 9bc9a93a7f..6e1b57323c 100644 --- a/lib/tdb2/test/run-tdb1-readonly-check.c +++ b/lib/tdb2/test/run-tdb1-readonly-check.c @@ -16,7 +16,7 @@ int main(int argc, char *argv[]) hsize.base.next = &tap_log_attr; hsize.tdb1_hashsize.hsize = 1024; - plan_tests(11); + plan_tests(10); tdb = tdb_open("run-readonly-check.tdb1", TDB_VERSION1, O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize); @@ -27,7 +27,7 @@ int main(int argc, char *argv[]) data.dsize = strlen("world"); data.dptr = (void *)"world"; - ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0); + ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS); ok1(tdb1_check(tdb, NULL, NULL) == 0); /* We are also allowed to do a check inside a transaction. */ @@ -39,8 +39,7 @@ int main(int argc, char *argv[]) TDB_DEFAULT, O_RDONLY, 0, &tap_log_attr); ok1(tdb); - ok1(tdb1_store(tdb, key, data, TDB_MODIFY) == -1); - ok1(tdb_error(tdb) == TDB_ERR_RDONLY); + ok1(tdb_store(tdb, key, data, TDB_MODIFY) == TDB_ERR_RDONLY); ok1(tdb1_check(tdb, NULL, NULL) == 0); ok1(tdb_close(tdb) == 0); diff --git a/lib/tdb2/test/run-tdb1-summary.c b/lib/tdb2/test/run-tdb1-summary.c index 45b4737286..5107b8e436 100644 --- a/lib/tdb2/test/run-tdb1-summary.c +++ b/lib/tdb2/test/run-tdb1-summary.c @@ -26,8 +26,10 @@ int main(int argc, char *argv[]) for (j = 0; j < 500; j++) { /* Make sure padding varies to we get some graphs! */ data.dsize = j % (sizeof(j) + 1); - if (tdb1_store(tdb, key, data, TDB_REPLACE) != 0) + if (tdb_store(tdb, key, data, TDB_REPLACE) + != TDB_SUCCESS) { fail("Storing in tdb"); + } } summary = tdb1_summary(tdb); diff --git a/lib/tdb2/test/run-tdb1-traverse-in-transaction.c b/lib/tdb2/test/run-tdb1-traverse-in-transaction.c index 27df05ebb3..90783198d9 100644 --- a/lib/tdb2/test/run-tdb1-traverse-in-transaction.c +++ b/lib/tdb2/test/run-tdb1-traverse-in-transaction.c @@ -57,7 +57,7 @@ int main(int argc, char *argv[]) data.dptr = (void *)"world"; data.dsize = strlen("world"); - ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0); + ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS); ok1(external_agent_operation1(agent, OPEN, tdb->name) == SUCCESS); diff --git a/lib/tdb2/test/run-tdb1-wronghash-fail.c b/lib/tdb2/test/run-tdb1-wronghash-fail.c index 61d56d6c8a..c7e789f2ca 100644 --- a/lib/tdb2/test/run-tdb1-wronghash-fail.c +++ b/lib/tdb2/test/run-tdb1-wronghash-fail.c @@ -60,7 +60,7 @@ int main(int argc, char *argv[]) ok1(log_count == 0); d.dptr = (void *)"Hello"; d.dsize = 5; - ok1(tdb1_store(tdb, d, d, TDB_INSERT) == 0); + ok1(tdb_store(tdb, d, d, TDB_INSERT) == TDB_SUCCESS); tdb_close(tdb); /* Fail to open with different hash. */ diff --git a/lib/tdb2/test/run-tdb1.c b/lib/tdb2/test/run-tdb1.c index 2d551dc538..584d7d6504 100644 --- a/lib/tdb2/test/run-tdb1.c +++ b/lib/tdb2/test/run-tdb1.c @@ -14,7 +14,7 @@ int main(int argc, char *argv[]) hsize.base.next = &tap_log_attr; hsize.tdb1_hashsize.hsize = 1024; - plan_tests(10); + plan_tests(8); tdb = tdb_open("run.tdb1", TDB_VERSION1, O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize); @@ -24,12 +24,10 @@ int main(int argc, char *argv[]) data.dsize = strlen("world"); data.dptr = (void *)"world"; - ok1(tdb1_store(tdb, key, data, TDB_MODIFY) < 0); - ok1(tdb_error(tdb) == TDB_ERR_NOEXIST); - ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0); - ok1(tdb1_store(tdb, key, data, TDB_INSERT) < 0); - ok1(tdb_error(tdb) == TDB_ERR_EXISTS); - ok1(tdb1_store(tdb, key, data, TDB_MODIFY) == 0); + ok1(tdb_store(tdb, key, data, TDB_MODIFY) == TDB_ERR_NOEXIST); + ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS); + ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_ERR_EXISTS); + ok1(tdb_store(tdb, key, data, TDB_MODIFY) == TDB_SUCCESS); data = tdb1_fetch(tdb, key); ok1(data.dsize == strlen("world")); diff --git a/lib/tdb2/test/tdb1-external-agent.c b/lib/tdb2/test/tdb1-external-agent.c index eb52e55f62..4a0d383548 100644 --- a/lib/tdb2/test/tdb1-external-agent.c +++ b/lib/tdb2/test/tdb1-external-agent.c @@ -66,7 +66,10 @@ static enum agent_return do_operation(enum operation op, const char *name) free(data.dptr); break; case STORE: - ret = tdb1_store(tdb, k, k, 0) == 0 ? SUCCESS : OTHER_FAILURE; + if (tdb_store(tdb, k, k, 0) == TDB_SUCCESS) + ret = SUCCESS; + else + ret = OTHER_FAILURE; break; case TRANSACTION_COMMIT: ret = tdb1_transaction_commit(tdb)==0 ? SUCCESS : OTHER_FAILURE; |