summaryrefslogtreecommitdiff
path: root/lib/tdb2
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2011-09-14 07:59:13 +0930
committerRusty Russell <rusty@rustcorp.com.au>2011-09-14 07:59:13 +0930
commit8e14a3e06d42b0302868dc3911a2e607e42a51b3 (patch)
treeada1f4891472e6a4d3904327fb7f6bc0264f915c /lib/tdb2
parent5d9dd8d541a761e0af2c8d50ee55485f2cef3e01 (diff)
downloadsamba-8e14a3e06d42b0302868dc3911a2e607e42a51b3.tar.gz
samba-8e14a3e06d42b0302868dc3911a2e607e42a51b3.tar.bz2
samba-8e14a3e06d42b0302868dc3911a2e607e42a51b3.zip
tdb2: unify tdb1_check and tdb1_summary into tdb_check and tdb_summary.
Switch on the TDB_VERSION1 flag. Also, change tdb1_check's checkfn argument to return an error code (and set tdb->last_error accordingly). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (Imported from CCAN commit ef92843f2c74ab9d4fa7f167a2182e5e8955df91)
Diffstat (limited to 'lib/tdb2')
-rw-r--r--lib/tdb2/check.c6
-rw-r--r--lib/tdb2/private.h9
-rw-r--r--lib/tdb2/summary.c8
-rw-r--r--lib/tdb2/tdb1.h7
-rw-r--r--lib/tdb2/tdb1_check.c14
-rw-r--r--lib/tdb2/test/run-tdb1-check.c12
-rw-r--r--lib/tdb2/test/run-tdb1-corrupt.c4
-rw-r--r--lib/tdb2/test/run-tdb1-incompatible.c12
-rw-r--r--lib/tdb2/test/run-tdb1-oldhash.c8
-rw-r--r--lib/tdb2/test/run-tdb1-readonly-check.c10
-rw-r--r--lib/tdb2/test/run-tdb1-wronghash-fail.c10
-rw-r--r--lib/tdb2/test/tdb1-external-agent.c2
12 files changed, 62 insertions, 40 deletions
diff --git a/lib/tdb2/check.c b/lib/tdb2/check.c
index 6d846f4142..b3874c6d27 100644
--- a/lib/tdb2/check.c
+++ b/lib/tdb2/check.c
@@ -782,6 +782,12 @@ enum TDB_ERROR tdb_check_(struct tdb_context *tdb,
uint64_t features;
enum TDB_ERROR ecode;
+ if (tdb->flags & TDB_VERSION1) {
+ if (tdb1_check(tdb, check, data) == -1)
+ return tdb->last_error;
+ return TDB_SUCCESS;
+ }
+
ecode = tdb_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, false);
if (ecode != TDB_SUCCESS) {
return tdb->last_error = ecode;
diff --git a/lib/tdb2/private.h b/lib/tdb2/private.h
index 67bc97dad1..816d5f70f8 100644
--- a/lib/tdb2/private.h
+++ b/lib/tdb2/private.h
@@ -643,6 +643,12 @@ struct tdb_context {
#define TDB1_BYTEREV(x) (((((x)&0xff)<<24)|((x)&0xFF00)<<8)|(((x)>>8)&0xFF00)|((x)>>24))
+/* tdb1_check.c: */
+int tdb1_check(struct tdb_context *tdb,
+ enum TDB_ERROR (*check)(TDB_DATA key, TDB_DATA data, void *),
+ void *private_data);
+
+
/* tdb1_open.c: */
int tdb1_new_database(struct tdb_context *tdb,
struct tdb_attribute_tdb1_hashsize *hashsize);
@@ -670,6 +676,9 @@ int tdb1_traverse(struct tdb_context *tdb,
int (*)(struct tdb_context *, TDB_DATA, TDB_DATA, void *),
void *private_data);
+/* tdb1_summary.c: */
+char *tdb1_summary(struct tdb_context *tdb);
+
/* tdb1_tdb.c: */
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,
diff --git a/lib/tdb2/summary.c b/lib/tdb2/summary.c
index 26cdd3e4fe..3960a20dba 100644
--- a/lib/tdb2/summary.c
+++ b/lib/tdb2/summary.c
@@ -161,6 +161,14 @@ enum TDB_ERROR tdb_summary(struct tdb_context *tdb,
char *hashesg, *freeg, *keysg, *datag, *extrag, *uncoalg;
enum TDB_ERROR ecode;
+ if (tdb->flags & TDB_VERSION1) {
+ /* tdb1 doesn't do graphs. */
+ *summary = tdb1_summary(tdb);
+ if (!*summary)
+ return tdb->last_error;
+ return TDB_SUCCESS;
+ }
+
hashesg = freeg = keysg = datag = extrag = uncoalg = NULL;
ecode = tdb_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, false);
diff --git a/lib/tdb2/tdb1.h b/lib/tdb2/tdb1.h
index b565b11408..2855d0c1b0 100644
--- a/lib/tdb2/tdb1.h
+++ b/lib/tdb2/tdb1.h
@@ -48,19 +48,12 @@ void tdb1_increment_seqnum_nonblock(struct tdb_context *tdb);
uint64_t tdb1_incompatible_hash(const void *key, size_t len, uint64_t seed, void *);
-int tdb1_check(struct tdb_context *tdb,
- int (*check) (TDB_DATA key, TDB_DATA data, void *private_data),
- void *private_data);
-
/* @} ******************************************************************/
/* wipe and repack */
int tdb1_wipe_all(struct tdb_context *tdb);
int tdb1_repack(struct tdb_context *tdb);
-/* Debug functions. Not used in production. */
-char *tdb1_summary(struct tdb_context *tdb);
-
extern TDB_DATA tdb1_null;
#endif /* tdb1.h */
diff --git a/lib/tdb2/tdb1_check.c b/lib/tdb2/tdb1_check.c
index c3c3c60f43..4d71712c47 100644
--- a/lib/tdb2/tdb1_check.c
+++ b/lib/tdb2/tdb1_check.c
@@ -236,7 +236,8 @@ static bool tdb1_check_used_record(struct tdb_context *tdb,
tdb1_off_t off,
const struct tdb1_record *rec,
unsigned char **hashes,
- int (*check)(TDB_DATA, TDB_DATA, void *),
+ enum TDB_ERROR (*check)(TDB_DATA, TDB_DATA,
+ void *),
void *private_data)
{
TDB_DATA key, data;
@@ -270,13 +271,18 @@ static bool tdb1_check_used_record(struct tdb_context *tdb,
/* If they supply a check function and this record isn't dead,
get data and feed it. */
if (check && rec->magic != TDB1_DEAD_MAGIC) {
+ enum TDB_ERROR ecode;
+
data = get_bytes(tdb, off + sizeof(*rec) + rec->key_len,
rec->data_len);
if (!data.dptr)
goto fail_put_key;
- if (check(key, data, private_data) == -1)
+ ecode = check(key, data, private_data);
+ if (ecode != TDB_SUCCESS) {
+ tdb->last_error = ecode;
goto fail_put_data;
+ }
put_bytes(tdb, data);
}
@@ -323,8 +329,8 @@ size_t tdb1_dead_space(struct tdb_context *tdb, tdb1_off_t off)
}
int tdb1_check(struct tdb_context *tdb,
- int (*check)(TDB_DATA key, TDB_DATA data, void *private_data),
- void *private_data)
+ enum TDB_ERROR (*check)(TDB_DATA key, TDB_DATA data, void *),
+ void *private_data)
{
unsigned int h;
unsigned char **hashes;
diff --git a/lib/tdb2/test/run-tdb1-check.c b/lib/tdb2/test/run-tdb1-check.c
index d2360f02fd..e939d04036 100644
--- a/lib/tdb2/test/run-tdb1-check.c
+++ b/lib/tdb2/test/run-tdb1-check.c
@@ -19,7 +19,7 @@ int main(int argc, char *argv[])
O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
ok1(tdb);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
key.dsize = strlen("hi");
key.dptr = (void *)"hi";
@@ -27,18 +27,18 @@ int main(int argc, char *argv[])
data.dptr = (void *)"world";
ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
tdb_close(tdb);
tdb = tdb_open("run-check.tdb1", TDB_VERSION1, O_RDWR, 0, &tap_log_attr);
ok1(tdb);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
tdb_close(tdb);
tdb = tdb_open("test/tdb1.corrupt", TDB_VERSION1, O_RDWR, 0,
&tap_log_attr);
ok1(tdb);
- ok1(tdb1_check(tdb, NULL, NULL) == -1);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_ERR_CORRUPT);
ok1(tdb_error(tdb) == TDB_ERR_CORRUPT);
tdb_close(tdb);
@@ -46,13 +46,13 @@ int main(int argc, char *argv[])
tdb = tdb_open("test/old-nohash-le.tdb1", TDB_VERSION1, O_RDWR, 0,
&tap_log_attr);
ok1(tdb);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
tdb_close(tdb);
tdb = tdb_open("test/old-nohash-be.tdb1", TDB_VERSION1, O_RDWR, 0,
&tap_log_attr);
ok1(tdb);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
tdb_close(tdb);
return exit_status();
diff --git a/lib/tdb2/test/run-tdb1-corrupt.c b/lib/tdb2/test/run-tdb1-corrupt.c
index 373f079512..35bc4c3f22 100644
--- a/lib/tdb2/test/run-tdb1-corrupt.c
+++ b/lib/tdb2/test/run-tdb1-corrupt.c
@@ -45,7 +45,7 @@ static void check_test(struct tdb_context *tdb)
TDB_DATA key, data;
unsigned int i, verifiable, corrupt, sizes[2], dsize, ksize;
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
key.dptr = (void *)"hello";
data.dsize = strlen("world");
@@ -81,7 +81,7 @@ static void check_test(struct tdb_context *tdb)
for (i = 0, corrupt = 0; i < tdb->file->map_size * CHAR_BIT; i++) {
tdb1_flip_bit(tdb, i);
memset(sizes, 0, sizeof(sizes));
- if (tdb1_check(tdb, check, sizes) != 0)
+ if (tdb_check(tdb, check, sizes) == TDB_ERR_CORRUPT)
corrupt++;
else if (sizes[0] != ksize || sizes[1] != dsize)
corrupt++;
diff --git a/lib/tdb2/test/run-tdb1-incompatible.c b/lib/tdb2/test/run-tdb1-incompatible.c
index e6b2994e20..46ab566920 100644
--- a/lib/tdb2/test/run-tdb1-incompatible.c
+++ b/lib/tdb2/test/run-tdb1-incompatible.c
@@ -105,7 +105,7 @@ int main(int argc, char *argv[])
ok1(tdb_fetch(tdb, d, &d) == TDB_SUCCESS);
ok1(d.dsize == 5);
free(d.dptr);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
tdb_close(tdb);
log_count = 0;
@@ -113,7 +113,7 @@ int main(int argc, char *argv[])
TDB_VERSION1, O_RDONLY, 0, &jhash_attr);
ok1(tdb);
ok1(log_count == 0);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
tdb_close(tdb);
log_count = 0;
@@ -121,7 +121,7 @@ int main(int argc, char *argv[])
TDB_VERSION1, O_RDONLY, 0, &jhash_attr);
ok1(tdb);
ok1(log_count == 0);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
tdb_close(tdb);
/* OK, now create with incompatible hash. */
@@ -156,7 +156,7 @@ int main(int argc, char *argv[])
ok1(tdb_fetch(tdb, d, &d) == TDB_SUCCESS);
ok1(d.dsize == 5);
free(d.dptr);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
tdb_close(tdb);
/* Can open by letting it figure it out itself. */
@@ -170,7 +170,7 @@ int main(int argc, char *argv[])
ok1(tdb_fetch(tdb, d, &d) == TDB_SUCCESS);
ok1(d.dsize == 5);
free(d.dptr);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
tdb_close(tdb);
/* FIXME: Not possible with TDB2 :( */
@@ -205,7 +205,7 @@ int main(int argc, char *argv[])
ok1(tdb_fetch(tdb, d, &d) == TDB_SUCCESS);
ok1(d.dsize == 5);
free(d.dptr);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
tdb_close(tdb);
}
diff --git a/lib/tdb2/test/run-tdb1-oldhash.c b/lib/tdb2/test/run-tdb1-oldhash.c
index 185001db74..f9cffa25a6 100644
--- a/lib/tdb2/test/run-tdb1-oldhash.c
+++ b/lib/tdb2/test/run-tdb1-oldhash.c
@@ -20,25 +20,25 @@ int main(int argc, char *argv[])
tdb = tdb_open("test/old-nohash-le.tdb1", TDB_VERSION1, O_RDWR, 0,
&tap_log_attr);
ok1(tdb);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
tdb_close(tdb);
tdb = tdb_open("test/old-nohash-be.tdb1", TDB_VERSION1, O_RDWR, 0,
&tap_log_attr);
ok1(tdb);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
tdb_close(tdb);
tdb = tdb_open("test/old-nohash-le.tdb1", TDB_VERSION1, O_RDWR, 0,
&incompat_hash_attr);
ok1(tdb);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
tdb_close(tdb);
tdb = tdb_open("test/old-nohash-be.tdb1", TDB_VERSION1, O_RDWR, 0,
&incompat_hash_attr);
ok1(tdb);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
tdb_close(tdb);
return exit_status();
diff --git a/lib/tdb2/test/run-tdb1-readonly-check.c b/lib/tdb2/test/run-tdb1-readonly-check.c
index 471f813da2..f42a8f5e27 100644
--- a/lib/tdb2/test/run-tdb1-readonly-check.c
+++ b/lib/tdb2/test/run-tdb1-readonly-check.c
@@ -1,5 +1,5 @@
-/* We should be able to tdb1_check a O_RDONLY tdb, and we were previously allowed
- * to tdb1_check() inside a transaction (though that's paranoia!). */
+/* We should be able to tdb_check a O_RDONLY tdb, and we were previously allowed
+ * to tdb_check() inside a transaction (though that's paranoia!). */
#include "tdb2-source.h"
#include <ccan/tap/tap.h>
#include <stdlib.h>
@@ -28,11 +28,11 @@ int main(int argc, char *argv[])
data.dptr = (void *)"world";
ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
/* We are also allowed to do a check inside a transaction. */
ok1(tdb_transaction_start(tdb) == TDB_SUCCESS);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
ok1(tdb_close(tdb) == 0);
tdb = tdb_open("run-readonly-check.tdb1",
@@ -40,7 +40,7 @@ int main(int argc, char *argv[])
ok1(tdb);
ok1(tdb_store(tdb, key, data, TDB_MODIFY) == TDB_ERR_RDONLY);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
ok1(tdb_close(tdb) == 0);
return exit_status();
diff --git a/lib/tdb2/test/run-tdb1-wronghash-fail.c b/lib/tdb2/test/run-tdb1-wronghash-fail.c
index c7e789f2ca..63c1bdf1e4 100644
--- a/lib/tdb2/test/run-tdb1-wronghash-fail.c
+++ b/lib/tdb2/test/run-tdb1-wronghash-fail.c
@@ -102,7 +102,7 @@ int main(int argc, char *argv[])
0, &incompat_hash_attr);
ok1(tdb);
ok1(log_count == 0);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
tdb_close(tdb);
log_count = 0;
@@ -110,7 +110,7 @@ int main(int argc, char *argv[])
0, &incompat_hash_attr);
ok1(tdb);
ok1(log_count == 0);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
tdb_close(tdb);
/* It should open with jenkins hash if we don't specify. */
@@ -119,7 +119,7 @@ int main(int argc, char *argv[])
&log_attr);
ok1(tdb);
ok1(log_count == 0);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
tdb_close(tdb);
log_count = 0;
@@ -127,7 +127,7 @@ int main(int argc, char *argv[])
&log_attr);
ok1(tdb);
ok1(log_count == 0);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
tdb_close(tdb);
log_count = 0;
@@ -135,7 +135,7 @@ int main(int argc, char *argv[])
0, &log_attr);
ok1(tdb);
ok1(log_count == 0);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
tdb_close(tdb);
diff --git a/lib/tdb2/test/tdb1-external-agent.c b/lib/tdb2/test/tdb1-external-agent.c
index 6b6f87dea5..150150754a 100644
--- a/lib/tdb2/test/tdb1-external-agent.c
+++ b/lib/tdb2/test/tdb1-external-agent.c
@@ -74,7 +74,7 @@ static enum agent_return do_operation(enum operation op, const char *name)
ret = tdb_transaction_commit(tdb) == TDB_SUCCESS ? SUCCESS : OTHER_FAILURE;
break;
case CHECK:
- ret = tdb1_check(tdb, NULL, NULL) == 0 ? SUCCESS : OTHER_FAILURE;
+ ret = tdb_check(tdb, NULL, NULL) == TDB_SUCCESS ? SUCCESS : OTHER_FAILURE;
break;
case NEEDS_RECOVERY:
ret = tdb1_needs_recovery(tdb) ? SUCCESS : FAILED;