This isn't a general requirement for CCAN modules, but Samba uses it, so
make sure tdb2 doesn't upset it.
static bool check_free_table(struct tdb_context *tdb,
tdb_off_t ftable_off,
unsigned ftable_num,
static bool check_free_table(struct tdb_context *tdb,
tdb_off_t ftable_off,
unsigned ftable_num,
size_t num_free,
size_t *num_found)
{
size_t num_free,
size_t *num_found)
{
return false;
/* FIXME: Check hash bits */
return false;
/* FIXME: Check hash bits */
- p = asearch(&off, free, num_free, off_cmp);
+ p = asearch(&off, fr, num_free, off_cmp);
if (!p) {
tdb_logerr(tdb, TDB_ERR_CORRUPT,
TDB_DEBUG_ERROR,
if (!p) {
tdb_logerr(tdb, TDB_ERR_CORRUPT,
TDB_DEBUG_ERROR,
static bool check_linear(struct tdb_context *tdb,
tdb_off_t **used, size_t *num_used,
static bool check_linear(struct tdb_context *tdb,
tdb_off_t **used, size_t *num_used,
- tdb_off_t **free, size_t *num_free,
+ tdb_off_t **fr, size_t *num_free,
tdb_off_t recovery)
{
tdb_off_t off;
tdb_off_t recovery)
{
tdb_off_t off;
}
/* This record should be in free lists. */
if (frec_ftable(&rec.f) != TDB_FTABLE_NONE
}
/* This record should be in free lists. */
if (frec_ftable(&rec.f) != TDB_FTABLE_NONE
- && !append(free, num_free, off))
+ && !append(fr, num_free, off))
return false;
} else if (rec_magic(&rec.u) == TDB_USED_MAGIC
|| rec_magic(&rec.u) == TDB_CHAIN_MAGIC
return false;
} else if (rec_magic(&rec.u) == TDB_USED_MAGIC
|| rec_magic(&rec.u) == TDB_CHAIN_MAGIC
int (*check)(TDB_DATA key, TDB_DATA data, void *private_data),
void *private_data)
{
int (*check)(TDB_DATA key, TDB_DATA data, void *private_data),
void *private_data)
{
- tdb_off_t *free = NULL, *used = NULL, ft, recovery;
+ tdb_off_t *fr = NULL, *used = NULL, ft, recovery;
size_t num_free = 0, num_used = 0, num_found = 0, num_ftables = 0;
if (tdb_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, false) != 0)
size_t num_free = 0, num_used = 0, num_found = 0, num_ftables = 0;
if (tdb_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, false) != 0)
goto fail;
/* First we do a linear scan, checking all records. */
goto fail;
/* First we do a linear scan, checking all records. */
- if (!check_linear(tdb, &used, &num_used, &free, &num_free, recovery))
+ if (!check_linear(tdb, &used, &num_used, &fr, &num_free, recovery))
goto fail;
for (ft = first_ftable(tdb); ft; ft = next_ftable(tdb, ft)) {
if (ft == TDB_OFF_ERR)
goto fail;
goto fail;
for (ft = first_ftable(tdb); ft; ft = next_ftable(tdb, ft)) {
if (ft == TDB_OFF_ERR)
goto fail;
- if (!check_free_table(tdb, ft, num_ftables, free, num_free,
+ if (!check_free_table(tdb, ft, num_ftables, fr, num_free,
&num_found))
goto fail;
num_ftables++;
&num_found))
goto fail;
num_ftables++;
}
/* Get bits from a value. */
}
/* Get bits from a value. */
-static uint32_t bits(uint64_t val, unsigned start, unsigned num)
+static uint32_t bits_from(uint64_t val, unsigned start, unsigned num)
{
assert(num <= 32);
return (val >> start) & ((1U << num) - 1);
{
assert(num <= 32);
return (val >> start) & ((1U << num) - 1);
static uint32_t use_bits(struct hash_info *h, unsigned num)
{
h->hash_used += num;
static uint32_t use_bits(struct hash_info *h, unsigned num)
{
h->hash_used += num;
- return bits(h->h, 64 - h->hash_used, num);
+ return bits_from(h->h, 64 - h->hash_used, num);
}
static bool key_matches(struct tdb_context *tdb,
}
static bool key_matches(struct tdb_context *tdb,
}
/* Top bits of offset == next bits of hash. */
}
/* Top bits of offset == next bits of hash. */
- if (bits(val, TDB_OFF_HASH_EXTRA_BIT, TDB_OFF_UPPER_STEAL_EXTRA)
- != bits(h->h, 64 - h->hash_used - TDB_OFF_UPPER_STEAL_EXTRA,
+ if (bits_from(val, TDB_OFF_HASH_EXTRA_BIT, TDB_OFF_UPPER_STEAL_EXTRA)
+ != bits_from(h->h, 64 - h->hash_used - TDB_OFF_UPPER_STEAL_EXTRA,
TDB_OFF_UPPER_STEAL_EXTRA)) {
add_stat(tdb, compare_wrong_offsetbits, 1);
return false;
TDB_OFF_UPPER_STEAL_EXTRA)) {
add_stat(tdb, compare_wrong_offsetbits, 1);
return false;
{
return h->home_bucket
| new_off
{
return h->home_bucket
| new_off
- | ((uint64_t)bits(h->h,
+ | ((uint64_t)bits_from(h->h,
64 - h->hash_used - TDB_OFF_UPPER_STEAL_EXTRA,
TDB_OFF_UPPER_STEAL_EXTRA)
<< TDB_OFF_HASH_EXTRA_BIT);
64 - h->hash_used - TDB_OFF_UPPER_STEAL_EXTRA,
TDB_OFF_UPPER_STEAL_EXTRA)
<< TDB_OFF_HASH_EXTRA_BIT);
TDB_DATA *kbuf, size_t *dlen)
{
const unsigned group_bits = TDB_TOPLEVEL_HASH_BITS-TDB_HASH_GROUP_BITS;
TDB_DATA *kbuf, size_t *dlen)
{
const unsigned group_bits = TDB_TOPLEVEL_HASH_BITS-TDB_HASH_GROUP_BITS;
- tdb_off_t hlock_start, hlock_range, off;
+ tdb_off_t hl_start, hl_range, off;
while (tinfo->toplevel_group < (1 << group_bits)) {
while (tinfo->toplevel_group < (1 << group_bits)) {
- hlock_start = (tdb_off_t)tinfo->toplevel_group
+ hl_start = (tdb_off_t)tinfo->toplevel_group
- hlock_range = 1ULL << group_bits;
- if (tdb_lock_hashes(tdb, hlock_start, hlock_range, ltype,
+ hl_range = 1ULL << group_bits;
+ if (tdb_lock_hashes(tdb, hl_start, hl_range, ltype,
TDB_LOCK_WAIT) != 0)
return -1;
TDB_LOCK_WAIT) != 0)
return -1;
if (tdb_read_convert(tdb, off, &rec, sizeof(rec))) {
tdb_unlock_hashes(tdb,
if (tdb_read_convert(tdb, off, &rec, sizeof(rec))) {
tdb_unlock_hashes(tdb,
- hlock_start, hlock_range,
- ltype);
+ hl_start, hl_range, ltype);
return -1;
}
if (rec_magic(&rec) != TDB_USED_MAGIC) {
return -1;
}
if (rec_magic(&rec) != TDB_USED_MAGIC) {
off + sizeof(rec),
kbuf->dsize);
}
off + sizeof(rec),
kbuf->dsize);
}
- tdb_unlock_hashes(tdb, hlock_start, hlock_range, ltype);
+ tdb_unlock_hashes(tdb, hl_start, hl_range, ltype);
return kbuf->dptr ? 1 : -1;
}
return kbuf->dptr ? 1 : -1;
}
- tdb_unlock_hashes(tdb, hlock_start, hlock_range, ltype);
+ tdb_unlock_hashes(tdb, hl_start, hl_range, ltype);
tinfo->toplevel_group++;
tinfo->levels[0].hashtable
tinfo->toplevel_group++;
tinfo->levels[0].hashtable
unsigned int group, gbits;
gbits = TDB_TOPLEVEL_HASH_BITS - TDB_HASH_GROUP_BITS;
unsigned int group, gbits;
gbits = TDB_TOPLEVEL_HASH_BITS - TDB_HASH_GROUP_BITS;
- group = bits(h, 64 - gbits, gbits);
+ group = bits_from(h, 64 - gbits, gbits);
lockstart = hlock_range(group, &locksize);
lockstart = hlock_range(group, &locksize);
unsigned int group, gbits;
gbits = TDB_TOPLEVEL_HASH_BITS - TDB_HASH_GROUP_BITS;
unsigned int group, gbits;
gbits = TDB_TOPLEVEL_HASH_BITS - TDB_HASH_GROUP_BITS;
- group = bits(h, 64 - gbits, gbits);
+ group = bits_from(h, 64 - gbits, gbits);
lockstart = hlock_range(group, &locksize);
lockstart = hlock_range(group, &locksize);
}
static void *tdb_direct(struct tdb_context *tdb, tdb_off_t off, size_t len,
}
static void *tdb_direct(struct tdb_context *tdb, tdb_off_t off, size_t len,
{
if (unlikely(!tdb->map_ptr))
return NULL;
{
if (unlikely(!tdb->map_ptr))
return NULL;
return (char *)tdb->map_ptr + off;
}
return (char *)tdb->map_ptr + off;
}
-void add_stat_(struct tdb_context *tdb, uint64_t *stat, size_t val)
+void add_stat_(struct tdb_context *tdb, uint64_t *s, size_t val)
- if ((uintptr_t)stat < (uintptr_t)tdb->stats + tdb->stats->size)
- *stat += val;
+ if ((uintptr_t)s < (uintptr_t)tdb->stats + tdb->stats->size)
+ *s += val;
}
static const struct tdb_methods io_methods = {
}
static const struct tdb_methods io_methods = {
static bool summarize(struct tdb_context *tdb,
struct tally *hashes,
struct tally *ftables,
static bool summarize(struct tdb_context *tdb,
struct tally *hashes,
struct tally *ftables,
struct tally *keys,
struct tally *data,
struct tally *extra,
struct tally *keys,
struct tally *data,
struct tally *extra,
len = sizeof(p->r) + p->r.max_len;
} else if (frec_magic(&p->f) == TDB_FREE_MAGIC) {
len = frec_len(&p->f);
len = sizeof(p->r) + p->r.max_len;
} else if (frec_magic(&p->f) == TDB_FREE_MAGIC) {
len = frec_len(&p->f);
tally_add(buckets, size_to_bucket(len));
len += sizeof(p->u);
unc++;
tally_add(buckets, size_to_bucket(len));
len += sizeof(p->u);
unc++;
static bool empty_freetable(struct tdb_context *tdb)
{
static bool empty_freetable(struct tdb_context *tdb)
{
- struct tdb_freetable free;
+ struct tdb_freetable ftab;
unsigned int i;
/* Now, free table should be completely exhausted in zone 0 */
unsigned int i;
/* Now, free table should be completely exhausted in zone 0 */
- if (tdb_read_convert(tdb, tdb->ftable_off, &free, sizeof(free)) != 0)
+ if (tdb_read_convert(tdb, tdb->ftable_off, &ftab, sizeof(ftab)) != 0)
- for (i = 0; i < sizeof(free.buckets)/sizeof(free.buckets[0]); i++) {
- if (free.buckets[i])
+ for (i = 0; i < sizeof(ftab.buckets)/sizeof(ftab.buckets[0]); i++) {
+ if (ftab.buckets[i])
return false;
}
return true;
return false;
}
return true;
}
static void *transaction_direct(struct tdb_context *tdb, tdb_off_t off,
}
static void *transaction_direct(struct tdb_context *tdb, tdb_off_t off,
- size_t len, bool write)
+ size_t len, bool write_mode)
{
size_t blk = off / getpagesize(), end_blk;
{
size_t blk = off / getpagesize(), end_blk;
end_blk = (off + len - 1) / getpagesize();
/* Can only do direct if in single block and we've already copied. */
end_blk = (off + len - 1) / getpagesize();
/* Can only do direct if in single block and we've already copied. */
if (blk != end_blk)
return NULL;
if (blk >= tdb->transaction->num_blocks)
if (blk != end_blk)
return NULL;
if (blk >= tdb->transaction->num_blocks)
- return tdb->transaction->io_methods->direct(tdb, off, len, write);
+ return tdb->transaction->io_methods->direct(tdb, off, len, false);
}
static const struct tdb_methods transaction_methods = {
}
static const struct tdb_methods transaction_methods = {