Switch on the TDB_VERSION1 flag. Also, change tdb1_check's checkfn argument
to return an error code (and set tdb->last_error accordingly).
12 files changed:
uint64_t features;
enum TDB_ERROR ecode;
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;
ecode = tdb_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, false);
if (ecode != TDB_SUCCESS) {
return tdb->last_error = ecode;
#define TDB1_BYTEREV(x) (((((x)&0xff)<<24)|((x)&0xFF00)<<8)|(((x)>>8)&0xFF00)|((x)>>24))
#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);
/* tdb1_open.c: */
int tdb1_new_database(struct tdb_context *tdb,
struct tdb_attribute_tdb1_hashsize *hashsize);
int (*)(struct tdb_context *, TDB_DATA, TDB_DATA, void *),
void *private_data);
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,
/* 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,
char *hashesg, *freeg, *keysg, *datag, *extrag, *uncoalg;
enum TDB_ERROR ecode;
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);
hashesg = freeg = keysg = datag = extrag = uncoalg = NULL;
ecode = tdb_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, false);
uint64_t tdb1_incompatible_hash(const void *key, size_t len, uint64_t seed, void *);
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);
/* @} ******************************************************************/
/* 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 */
extern TDB_DATA tdb1_null;
#endif /* tdb1.h */
tdb1_off_t off,
const struct tdb1_record *rec,
unsigned char **hashes,
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;
void *private_data)
{
TDB_DATA key, data;
/* If they supply a check function and this record isn't dead,
get data and feed it. */
if (check && rec->magic != TDB1_DEAD_MAGIC) {
/* 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;
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;
}
int tdb1_check(struct tdb_context *tdb,
}
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;
{
unsigned int h;
unsigned char **hashes;
O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
ok1(tdb);
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";
key.dsize = strlen("hi");
key.dptr = (void *)"hi";
data.dptr = (void *)"world";
ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS);
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);
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);
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);
ok1(tdb_error(tdb) == TDB_ERR_CORRUPT);
tdb_close(tdb);
tdb = tdb_open("test/old-nohash-le.tdb1", TDB_VERSION1, O_RDWR, 0,
&tap_log_attr);
ok1(tdb);
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);
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();
tdb_close(tdb);
return exit_status();
TDB_DATA key, data;
unsigned int i, verifiable, corrupt, sizes[2], dsize, ksize;
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");
key.dptr = (void *)"hello";
data.dsize = strlen("world");
for (i = 0, corrupt = 0; i < tdb->file->map_size * CHAR_BIT; i++) {
tdb1_flip_bit(tdb, i);
memset(sizes, 0, sizeof(sizes));
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++;
corrupt++;
else if (sizes[0] != ksize || sizes[1] != dsize)
corrupt++;
ok1(tdb_fetch(tdb, d, &d) == TDB_SUCCESS);
ok1(d.dsize == 5);
free(d.dptr);
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;
tdb_close(tdb);
log_count = 0;
TDB_VERSION1, O_RDONLY, 0, &jhash_attr);
ok1(tdb);
ok1(log_count == 0);
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;
tdb_close(tdb);
log_count = 0;
TDB_VERSION1, O_RDONLY, 0, &jhash_attr);
ok1(tdb);
ok1(log_count == 0);
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. */
tdb_close(tdb);
/* OK, now create with incompatible hash. */
ok1(tdb_fetch(tdb, d, &d) == TDB_SUCCESS);
ok1(d.dsize == 5);
free(d.dptr);
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. */
tdb_close(tdb);
/* Can open by letting it figure it out itself. */
ok1(tdb_fetch(tdb, d, &d) == TDB_SUCCESS);
ok1(d.dsize == 5);
free(d.dptr);
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 :( */
tdb_close(tdb);
/* FIXME: Not possible with TDB2 :( */
ok1(tdb_fetch(tdb, d, &d) == TDB_SUCCESS);
ok1(d.dsize == 5);
free(d.dptr);
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 = tdb_open("test/old-nohash-le.tdb1", TDB_VERSION1, O_RDWR, 0,
&tap_log_attr);
ok1(tdb);
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);
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);
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);
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();
tdb_close(tdb);
return exit_status();
-/* 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>
#include "tdb2-source.h"
#include <ccan/tap/tap.h>
#include <stdlib.h>
data.dptr = (void *)"world";
ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS);
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);
/* 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",
ok1(tdb_close(tdb) == 0);
tdb = tdb_open("run-readonly-check.tdb1",
ok1(tdb);
ok1(tdb_store(tdb, key, data, TDB_MODIFY) == TDB_ERR_RDONLY);
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();
ok1(tdb_close(tdb) == 0);
return exit_status();
0, &incompat_hash_attr);
ok1(tdb);
ok1(log_count == 0);
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;
tdb_close(tdb);
log_count = 0;
0, &incompat_hash_attr);
ok1(tdb);
ok1(log_count == 0);
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. */
tdb_close(tdb);
/* It should open with jenkins hash if we don't specify. */
&log_attr);
ok1(tdb);
ok1(log_count == 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);
log_count = 0;
tdb_close(tdb);
log_count = 0;
&log_attr);
ok1(tdb);
ok1(log_count == 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);
log_count = 0;
tdb_close(tdb);
log_count = 0;
0, &log_attr);
ok1(tdb);
ok1(log_count == 0);
0, &log_attr);
ok1(tdb);
ok1(log_count == 0);
- ok1(tdb1_check(tdb, NULL, NULL) == 0);
+ ok1(tdb_check(tdb, NULL, NULL) == TDB_SUCCESS);
ret = tdb_transaction_commit(tdb) == TDB_SUCCESS ? SUCCESS : OTHER_FAILURE;
break;
case CHECK:
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;
break;
case NEEDS_RECOVERY:
ret = tdb1_needs_recovery(tdb) ? SUCCESS : FAILED;