Commit 007a7e4e authored by Rusty Russell's avatar Rusty Russell

tdb2: shorten attribute members.

It's redundant calling hash.hash_fn for example.  Standardize on fn
and data as names (private conflicts with C++).
parent b8903ca2
......@@ -94,7 +94,7 @@ static enum TDB_ERROR check_hash_tree(struct tdb_context *tdb,
size_t *num_found,
enum TDB_ERROR (*check)(TDB_DATA,
TDB_DATA, void *),
void *private_data);
void *data);
static enum TDB_ERROR check_hash_chain(struct tdb_context *tdb,
tdb_off_t off,
......@@ -105,7 +105,7 @@ static enum TDB_ERROR check_hash_chain(struct tdb_context *tdb,
enum TDB_ERROR (*check)(TDB_DATA,
TDB_DATA,
void *),
void *private_data)
void *data)
{
struct tdb_used_record rec;
enum TDB_ERROR ecode;
......@@ -141,7 +141,7 @@ static enum TDB_ERROR check_hash_chain(struct tdb_context *tdb,
off += sizeof(rec);
ecode = check_hash_tree(tdb, off, 0, hash, 64,
used, num_used, num_found, check, private_data);
used, num_used, num_found, check, data);
if (ecode != TDB_SUCCESS) {
return ecode;
}
......@@ -154,7 +154,7 @@ static enum TDB_ERROR check_hash_chain(struct tdb_context *tdb,
return TDB_SUCCESS;
(*num_found)++;
return check_hash_chain(tdb, off, hash, used, num_used, num_found,
check, private_data);
check, data);
}
static enum TDB_ERROR check_hash_record(struct tdb_context *tdb,
......@@ -167,14 +167,14 @@ static enum TDB_ERROR check_hash_record(struct tdb_context *tdb,
enum TDB_ERROR (*check)(TDB_DATA,
TDB_DATA,
void *),
void *private_data)
void *data)
{
struct tdb_used_record rec;
enum TDB_ERROR ecode;
if (hprefix_bits >= 64)
return check_hash_chain(tdb, off, hprefix, used, num_used,
num_found, check, private_data);
num_found, check, data);
ecode = tdb_read_convert(tdb, off, &rec, sizeof(rec));
if (ecode != TDB_SUCCESS) {
......@@ -210,7 +210,7 @@ static enum TDB_ERROR check_hash_record(struct tdb_context *tdb,
return check_hash_tree(tdb, off,
TDB_SUBLEVEL_HASH_BITS-TDB_HASH_GROUP_BITS,
hprefix, hprefix_bits,
used, num_used, num_found, check, private_data);
used, num_used, num_found, check, data);
}
static int off_cmp(const tdb_off_t *a, const tdb_off_t *b)
......@@ -237,7 +237,7 @@ static enum TDB_ERROR check_hash_tree(struct tdb_context *tdb,
size_t *num_found,
enum TDB_ERROR (*check)(TDB_DATA,
TDB_DATA, void *),
void *private_data)
void *data)
{
unsigned int g, b;
const tdb_off_t *hash;
......@@ -318,7 +318,7 @@ static enum TDB_ERROR check_hash_tree(struct tdb_context *tdb,
+ group_bits
+ TDB_HASH_GROUP_BITS,
used, num_used, num_found,
check, private_data);
check, data);
if (ecode != TDB_SUCCESS) {
goto fail;
}
......@@ -401,7 +401,7 @@ static enum TDB_ERROR check_hash_tree(struct tdb_context *tdb,
check:
if (check) {
TDB_DATA key, data;
TDB_DATA k, d;
const unsigned char *kptr;
kptr = tdb_access_read(tdb,
......@@ -414,10 +414,10 @@ static enum TDB_ERROR check_hash_tree(struct tdb_context *tdb,
goto fail;
}
key = tdb_mkdata(kptr, rec_key_length(&rec));
data = tdb_mkdata(kptr + key.dsize,
rec_data_length(&rec));
ecode = check(key, data, private_data);
k = tdb_mkdata(kptr, rec_key_length(&rec));
d = tdb_mkdata(kptr + k.dsize,
rec_data_length(&rec));
ecode = check(k, d, data);
tdb_access_release(tdb, kptr);
if (ecode != TDB_SUCCESS) {
goto fail;
......@@ -437,7 +437,7 @@ static enum TDB_ERROR check_hash(struct tdb_context *tdb,
tdb_off_t used[],
size_t num_used, size_t num_ftables,
int (*check)(TDB_DATA, TDB_DATA, void *),
void *private_data)
void *data)
{
/* Free tables also show up as used. */
size_t num_found = num_ftables;
......@@ -446,7 +446,7 @@ static enum TDB_ERROR check_hash(struct tdb_context *tdb,
ecode = check_hash_tree(tdb, offsetof(struct tdb_header, hashtable),
TDB_TOPLEVEL_HASH_BITS-TDB_HASH_GROUP_BITS,
0, 0, used, num_used, &num_found,
check, private_data);
check, data);
if (ecode == TDB_SUCCESS) {
if (num_found != num_used) {
ecode = tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
......@@ -772,9 +772,8 @@ static enum TDB_ERROR check_linear(struct tdb_context *tdb,
}
enum TDB_ERROR tdb_check_(struct tdb_context *tdb,
enum TDB_ERROR (*check)(TDB_DATA key, TDB_DATA data,
void *private_data),
void *private_data)
enum TDB_ERROR (*check)(TDB_DATA, TDB_DATA, void *),
void *data)
{
tdb_off_t *fr = NULL, *used = NULL, ft, recovery;
size_t num_free = 0, num_used = 0, num_found = 0, num_ftables = 0;
......@@ -815,8 +814,7 @@ enum TDB_ERROR tdb_check_(struct tdb_context *tdb,
}
/* FIXME: Check key uniqueness? */
ecode = check_hash(tdb, used, num_used, num_ftables, check,
private_data);
ecode = check_hash(tdb, used, num_used, num_ftables, check, data);
if (ecode != TDB_SUCCESS)
goto out;
......
......@@ -31,13 +31,12 @@ static uint64_t jenkins_hash(const void *key, size_t length, uint64_t seed,
void tdb_hash_init(struct tdb_context *tdb)
{
tdb->khash = jenkins_hash;
tdb->hash_priv = NULL;
tdb->hashfn = jenkins_hash;
}
uint64_t tdb_hash(struct tdb_context *tdb, const void *ptr, size_t len)
{
return tdb->khash(ptr, len, tdb->hash_seed, tdb->hash_priv);
return tdb->hashfn(ptr, len, tdb->hash_seed, tdb->hash_data);
}
uint64_t hash_record(struct tdb_context *tdb, tdb_off_t off)
......
......@@ -101,10 +101,10 @@ static enum TDB_ERROR tdb_new_database(struct tdb_context *tdb,
else
newdb.hdr.hash_seed = random_number(tdb);
newdb.hdr.hash_test = TDB_HASH_MAGIC;
newdb.hdr.hash_test = tdb->khash(&newdb.hdr.hash_test,
sizeof(newdb.hdr.hash_test),
newdb.hdr.hash_seed,
tdb->hash_priv);
newdb.hdr.hash_test = tdb->hashfn(&newdb.hdr.hash_test,
sizeof(newdb.hdr.hash_test),
newdb.hdr.hash_seed,
tdb->hash_data);
newdb.hdr.recovery = 0;
newdb.hdr.features_used = newdb.hdr.features_offered = TDB_FEATURE_MASK;
newdb.hdr.seqnum = 0;
......@@ -217,12 +217,12 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
while (attr) {
switch (attr->base.attr) {
case TDB_ATTRIBUTE_LOG:
tdb->logfn = attr->log.log_fn;
tdb->log_private = attr->log.log_private;
tdb->logfn = attr->log.fn;
tdb->log_data = attr->log.data;
break;
case TDB_ATTRIBUTE_HASH:
tdb->khash = attr->hash.hash_fn;
tdb->hash_priv = attr->hash.hash_private;
tdb->hashfn = attr->hash.fn;
tdb->hash_data = attr->hash.data;
break;
case TDB_ATTRIBUTE_SEED:
seed = &attr->seed;
......
......@@ -367,13 +367,13 @@ struct tdb_context {
/* Logging function */
void (*logfn)(struct tdb_context *tdb,
enum tdb_log_level level,
void *log_private,
void *data,
const char *message);
void *log_private;
void *log_data;
/* Hash function. */
uint64_t (*khash)(const void *key, size_t len, uint64_t seed, void *);
void *hash_priv;
uint64_t (*hashfn)(const void *key, size_t len, uint64_t seed, void *);
void *hash_data;
uint64_t hash_seed;
/* Set if we are in a transaction. */
......
......@@ -406,11 +406,11 @@ enum TDB_ERROR COLD tdb_logerr(struct tdb_context *tdb,
va_end(ap);
if (len < 0) {
tdb->logfn(tdb, TDB_LOG_ERROR, tdb->log_private,
tdb->logfn(tdb, TDB_LOG_ERROR, tdb->log_data,
"out of memory formatting message:");
tdb->logfn(tdb, level, tdb->log_private, fmt);
tdb->logfn(tdb, level, tdb->log_data, fmt);
} else {
tdb->logfn(tdb, level, tdb->log_private, message);
tdb->logfn(tdb, level, tdb->log_data, message);
free(message);
}
errno = saved_errno;
......@@ -419,10 +419,10 @@ enum TDB_ERROR COLD tdb_logerr(struct tdb_context *tdb,
enum TDB_ERROR tdb_parse_record_(struct tdb_context *tdb,
TDB_DATA key,
enum TDB_ERROR (*parse)(TDB_DATA key,
TDB_DATA data,
void *p),
void *p)
enum TDB_ERROR (*parse)(TDB_DATA k,
TDB_DATA d,
void *data),
void *data)
{
tdb_off_t off;
struct tdb_used_record rec;
......@@ -443,9 +443,9 @@ enum TDB_ERROR tdb_parse_record_(struct tdb_context *tdb,
if (TDB_PTR_IS_ERR(dptr)) {
ecode = TDB_PTR_ERR(dptr);
} else {
TDB_DATA data = tdb_mkdata(dptr, rec_data_length(&rec));
TDB_DATA d = tdb_mkdata(dptr, rec_data_length(&rec));
ecode = parse(key, data, p);
ecode = parse(key, d, data);
tdb_access_release(tdb, dptr);
}
}
......
......@@ -324,7 +324,7 @@ int64_t tdb_traverse_(struct tdb_context *tdb,
* @tdb: the tdb context returned from tdb_open()
* @key: the key whose record we should hand to @parse
* @parse: the function to call for the data
* @p: the private pointer to hand to @parse (types must match).
* @data: the private pointer to hand to @parse (types must match).
*
* This avoids a copy for many cases, by handing you a pointer into
* the memory-mapped database. It also locks the record to prevent
......@@ -332,18 +332,18 @@ int64_t tdb_traverse_(struct tdb_context *tdb,
*
* Do not alter the data handed to parse()!
*/
#define tdb_parse_record(tdb, key, parse, p) \
#define tdb_parse_record(tdb, key, parse, data) \
tdb_parse_record_((tdb), (key), \
typesafe_cb_preargs(enum TDB_ERROR, void *, \
(parse), (p), \
TDB_DATA, TDB_DATA), (p))
(parse), (data), \
TDB_DATA, TDB_DATA), (data))
enum TDB_ERROR tdb_parse_record_(struct tdb_context *tdb,
TDB_DATA key,
enum TDB_ERROR (*parse)(TDB_DATA key,
TDB_DATA data,
void *p),
void *p);
enum TDB_ERROR (*parse)(TDB_DATA k,
TDB_DATA d,
void *data),
void *data);
/**
* tdb_get_seqnum - get a database sequence number
......@@ -490,7 +490,7 @@ enum TDB_ERROR tdb_wipe_all(struct tdb_context *tdb);
* tdb_check - check a TDB for consistency
* @tdb: the tdb context returned from tdb_open()
* @check: function to check each key/data pair (or NULL)
* @private_data: argument for @check, must match type.
* @data: argument for @check, must match type.
*
* This performs a consistency check of the open database, optionally calling
* a check() function on each record so you can do your own data consistency
......@@ -499,18 +499,18 @@ enum TDB_ERROR tdb_wipe_all(struct tdb_context *tdb);
*
* Returns TDB_SUCCESS or an error.
*/
#define tdb_check(tdb, check, private_data) \
#define tdb_check(tdb, check, data) \
tdb_check_((tdb), typesafe_cb_preargs(enum TDB_ERROR, void *, \
(check), (private_data), \
(check), (data), \
struct tdb_data, \
struct tdb_data), \
(private_data))
(data))
enum TDB_ERROR tdb_check_(struct tdb_context *tdb,
enum TDB_ERROR (*check)(struct tdb_data key,
struct tdb_data data,
void *private_data),
void *private_data);
enum TDB_ERROR (*check)(struct tdb_data k,
struct tdb_data d,
void *data),
void *data);
/**
* tdb_error - get the last error (not threadsafe)
......@@ -640,11 +640,11 @@ enum tdb_log_level {
*/
struct tdb_attribute_log {
struct tdb_attribute_base base; /* .attr = TDB_ATTRIBUTE_LOG */
void (*log_fn)(struct tdb_context *tdb,
enum tdb_log_level level,
void *log_private,
const char *message);
void *log_private;
void (*fn)(struct tdb_context *tdb,
enum tdb_log_level level,
void *data,
const char *message);
void *data;
};
/**
......@@ -661,9 +661,9 @@ struct tdb_attribute_log {
*/
struct tdb_attribute_hash {
struct tdb_attribute_base base; /* .attr = TDB_ATTRIBUTE_HASH */
uint64_t (*hash_fn)(const void *key, size_t len, uint64_t seed,
void *priv);
void *hash_private;
uint64_t (*fn)(const void *key, size_t len, uint64_t seed,
void *data);
void *data;
};
/**
......
......@@ -9,7 +9,7 @@ bool suppress_logging;
union tdb_attribute tap_log_attr = {
.log = { .base = { .attr = TDB_ATTRIBUTE_LOG },
.log_fn = tap_log_fn }
.fn = tap_log_fn }
};
void tap_log_fn(struct tdb_context *tdb,
......
......@@ -25,7 +25,7 @@ int main(int argc, char *argv[])
struct tdb_data key = { (unsigned char *)&v, sizeof(v) };
struct tdb_data dbuf = { (unsigned char *)&v, sizeof(v) };
union tdb_attribute hattr = { .hash = { .base = { TDB_ATTRIBUTE_HASH },
.hash_fn = clash } };
.fn = clash } };
int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
TDB_NOMMAP|TDB_CONVERT,
......
......@@ -23,8 +23,8 @@ int main(int argc, char *argv[])
uint64_t seed = 16014841315512641303ULL;
union tdb_attribute fixed_hattr
= { .hash = { .base = { TDB_ATTRIBUTE_HASH },
.hash_fn = fixedhash,
.hash_private = &seed } };
.fn = fixedhash,
.data = &seed } };
int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
TDB_NOMMAP|TDB_CONVERT };
......
......@@ -146,11 +146,11 @@ int main(int argc, char *argv[])
uint64_t seed = 16014841315512641303ULL;
union tdb_attribute clash_hattr
= { .hash = { .base = { TDB_ATTRIBUTE_HASH },
.hash_fn = clash } };
.fn = clash } };
union tdb_attribute fixed_hattr
= { .hash = { .base = { TDB_ATTRIBUTE_HASH },
.hash_fn = fixedhash,
.hash_private = &seed } };
.fn = fixedhash,
.data = &seed } };
int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
TDB_NOMMAP|TDB_CONVERT };
......
......@@ -49,7 +49,7 @@ int main(int argc, char *argv[])
struct tdb_data key = { (unsigned char *)&kdata, sizeof(kdata) };
struct tdb_data dbuf = { (unsigned char *)&kdata, sizeof(kdata) };
union tdb_attribute hattr = { .hash = { .base = { TDB_ATTRIBUTE_HASH },
.hash_fn = myhash } };
.fn = myhash } };
int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
TDB_NOMMAP|TDB_CONVERT,
......
......@@ -29,7 +29,7 @@ int main(int argc, char *argv[])
struct tdb_data key = { (unsigned char *)&j, sizeof(j) };
struct tdb_data dbuf = { (unsigned char *)&j, sizeof(j) };
union tdb_attribute hattr = { .hash = { .base = { TDB_ATTRIBUTE_HASH },
.hash_fn = badhash } };
.fn = badhash } };
int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
TDB_NOMMAP|TDB_CONVERT,
......
......@@ -27,7 +27,7 @@ int main(int argc, char *argv[])
struct tdb_data key = { (unsigned char *)&i, sizeof(i) };
struct tdb_data data = { (unsigned char *)&i, sizeof(i) };
union tdb_attribute hattr = { .hash = { .base = { TDB_ATTRIBUTE_HASH },
.hash_fn = failhash } };
.fn = failhash } };
hattr.base.next = &tap_log_attr;
plan_tests(1 + 2 * NUM_RECORDS + 1);
......
......@@ -21,7 +21,7 @@ static void my_log_fn(struct tdb_context *tdb,
static union tdb_attribute log_attr = {
.log = { .base = { .attr = TDB_ATTRIBUTE_LOG },
.log_fn = my_log_fn }
.fn = my_log_fn }
};
int main(int argc, char *argv[])
......
......@@ -114,8 +114,8 @@ int main(int argc, char *argv[])
TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
TDB_NOMMAP|TDB_CONVERT };
union tdb_attribute hattr = { .hash = { .base = { TDB_ATTRIBUTE_HASH },
.hash_fn = fixedhash,
.hash_private = &seed } };
.fn = fixedhash,
.data = &seed } };
hattr.base.next = &tap_log_attr;
......
......@@ -95,7 +95,7 @@ static void dump_and_clear_stats(struct tdb_attribute_stats *stats)
}
static void tdb_log(struct tdb_context *tdb, enum tdb_log_level level,
void *private, const char *message)
void *data, const char *message)
{
fputs(message, stderr);
}
......@@ -118,7 +118,7 @@ int main(int argc, char *argv[])
log.base.attr = TDB_ATTRIBUTE_LOG;
log.base.next = &seed;
log.log.log_fn = tdb_log;
log.log.fn = tdb_log;
memset(&stats, 0, sizeof(stats));
stats.base.attr = TDB_ATTRIBUTE_STATS;
......
......@@ -233,7 +233,7 @@ static void create_tdb(const char *tdbname)
union tdb_attribute log_attr;
log_attr.base.attr = TDB_ATTRIBUTE_LOG;
log_attr.base.next = NULL;
log_attr.log.log_fn = tdb_log;
log_attr.log.fn = tdb_log;
if (tdb) tdb_close(tdb);
tdb = tdb_open(tdbname, (disable_mmap?TDB_NOMMAP:0),
......@@ -248,7 +248,7 @@ static void open_tdb(const char *tdbname)
union tdb_attribute log_attr;
log_attr.base.attr = TDB_ATTRIBUTE_LOG;
log_attr.base.next = NULL;
log_attr.log.log_fn = tdb_log;
log_attr.log.fn = tdb_log;
if (tdb) tdb_close(tdb);
tdb = tdb_open(tdbname, disable_mmap?TDB_NOMMAP:0, O_RDWR, 0600,
......
......@@ -43,7 +43,7 @@ static union tdb_attribute log_attr;
static union tdb_attribute seed_attr;
static void tdb_log(struct tdb_context *tdb, enum tdb_log_level level,
void *private, const char *message)
void *data, const char *message)
{
fputs(message, stdout);
fflush(stdout);
......@@ -327,7 +327,7 @@ int main(int argc, char * const *argv)
log_attr.base.attr = TDB_ATTRIBUTE_LOG;
log_attr.base.next = &seed_attr;
log_attr.log.log_fn = tdb_log;
log_attr.log.fn = tdb_log;
seed_attr.base.attr = TDB_ATTRIBUTE_SEED;
while ((c = getopt(argc, argv, "n:l:s:thkS")) != -1) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment