Commit 5eaf46e9 authored by Rusty Russell's avatar Rusty Russell

tdb2: make tdb2 compile clean under -Wshadow.

This isn't a general requirement for CCAN modules, but Samba uses it, so
make sure tdb2 doesn't upset it.
parent fc00f140
...@@ -453,7 +453,7 @@ static bool check_free(struct tdb_context *tdb, ...@@ -453,7 +453,7 @@ static bool check_free(struct tdb_context *tdb,
static bool check_free_table(struct tdb_context *tdb, static bool check_free_table(struct tdb_context *tdb,
tdb_off_t ftable_off, tdb_off_t ftable_off,
unsigned ftable_num, unsigned ftable_num,
tdb_off_t free[], tdb_off_t fr[],
size_t num_free, size_t num_free,
size_t *num_found) size_t *num_found)
{ {
...@@ -487,7 +487,7 @@ static bool check_free_table(struct tdb_context *tdb, ...@@ -487,7 +487,7 @@ static bool check_free_table(struct tdb_context *tdb,
return false; return false;
/* FIXME: Check hash bits */ /* FIXME: Check hash bits */
p = asearch(&off, free, num_free, off_cmp); p = asearch(&off, fr, num_free, off_cmp);
if (!p) { if (!p) {
tdb_logerr(tdb, TDB_ERR_CORRUPT, tdb_logerr(tdb, TDB_ERR_CORRUPT,
TDB_DEBUG_ERROR, TDB_DEBUG_ERROR,
...@@ -522,7 +522,7 @@ size_t dead_space(struct tdb_context *tdb, tdb_off_t off) ...@@ -522,7 +522,7 @@ size_t dead_space(struct tdb_context *tdb, tdb_off_t off)
static bool check_linear(struct tdb_context *tdb, static bool check_linear(struct tdb_context *tdb,
tdb_off_t **used, size_t *num_used, 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 recovery)
{ {
tdb_off_t off; tdb_off_t off;
...@@ -603,7 +603,7 @@ static bool check_linear(struct tdb_context *tdb, ...@@ -603,7 +603,7 @@ static bool check_linear(struct tdb_context *tdb,
} }
/* This record should be in free lists. */ /* This record should be in free lists. */
if (frec_ftable(&rec.f) != TDB_FTABLE_NONE if (frec_ftable(&rec.f) != TDB_FTABLE_NONE
&& !append(free, num_free, off)) && !append(fr, num_free, off))
return false; return false;
} else if (rec_magic(&rec.u) == TDB_USED_MAGIC } else if (rec_magic(&rec.u) == TDB_USED_MAGIC
|| rec_magic(&rec.u) == TDB_CHAIN_MAGIC || rec_magic(&rec.u) == TDB_CHAIN_MAGIC
...@@ -661,7 +661,7 @@ int tdb_check(struct tdb_context *tdb, ...@@ -661,7 +661,7 @@ int tdb_check(struct tdb_context *tdb,
int (*check)(TDB_DATA key, TDB_DATA data, void *private_data), int (*check)(TDB_DATA key, TDB_DATA data, void *private_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; 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) if (tdb_allrecord_lock(tdb, F_RDLCK, TDB_LOCK_WAIT, false) != 0)
...@@ -676,13 +676,13 @@ int tdb_check(struct tdb_context *tdb, ...@@ -676,13 +676,13 @@ int tdb_check(struct tdb_context *tdb,
goto fail; goto fail;
/* First we do a linear scan, checking all records. */ /* 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; goto fail;
for (ft = first_ftable(tdb); ft; ft = next_ftable(tdb, ft)) { for (ft = first_ftable(tdb); ft; ft = next_ftable(tdb, ft)) {
if (ft == TDB_OFF_ERR) if (ft == TDB_OFF_ERR)
goto fail; 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)) &num_found))
goto fail; goto fail;
num_ftables++; num_ftables++;
......
...@@ -64,7 +64,7 @@ uint64_t hash_record(struct tdb_context *tdb, tdb_off_t off) ...@@ -64,7 +64,7 @@ uint64_t hash_record(struct tdb_context *tdb, tdb_off_t off)
} }
/* 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); assert(num <= 32);
return (val >> start) & ((1U << num) - 1); return (val >> start) & ((1U << num) - 1);
...@@ -75,7 +75,7 @@ static uint32_t bits(uint64_t val, unsigned start, unsigned num) ...@@ -75,7 +75,7 @@ static uint32_t bits(uint64_t val, unsigned start, unsigned num)
static uint32_t use_bits(struct hash_info *h, unsigned num) static uint32_t use_bits(struct hash_info *h, unsigned num)
{ {
h->hash_used += 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,
...@@ -119,8 +119,8 @@ static bool match(struct tdb_context *tdb, ...@@ -119,8 +119,8 @@ static bool match(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) if (bits_from(val, TDB_OFF_HASH_EXTRA_BIT, TDB_OFF_UPPER_STEAL_EXTRA)
!= bits(h->h, 64 - h->hash_used - TDB_OFF_UPPER_STEAL_EXTRA, != bits_from(h->h, 64 - h->hash_used - TDB_OFF_UPPER_STEAL_EXTRA,
TDB_OFF_UPPER_STEAL_EXTRA)) { TDB_OFF_UPPER_STEAL_EXTRA)) {
add_stat(tdb, compare_wrong_offsetbits, 1); add_stat(tdb, compare_wrong_offsetbits, 1);
return false; return false;
...@@ -378,7 +378,7 @@ static tdb_off_t encode_offset(tdb_off_t new_off, struct hash_info *h) ...@@ -378,7 +378,7 @@ static tdb_off_t encode_offset(tdb_off_t new_off, struct hash_info *h)
{ {
return h->home_bucket return h->home_bucket
| new_off | new_off
| ((uint64_t)bits(h->h, | ((uint64_t)bits_from(h->h,
64 - h->hash_used - TDB_OFF_UPPER_STEAL_EXTRA, 64 - h->hash_used - TDB_OFF_UPPER_STEAL_EXTRA,
TDB_OFF_UPPER_STEAL_EXTRA) TDB_OFF_UPPER_STEAL_EXTRA)
<< TDB_OFF_HASH_EXTRA_BIT); << TDB_OFF_HASH_EXTRA_BIT);
...@@ -683,13 +683,13 @@ int next_in_hash(struct tdb_context *tdb, int ltype, ...@@ -683,13 +683,13 @@ int next_in_hash(struct tdb_context *tdb, int ltype,
TDB_DATA *kbuf, size_t *dlen) TDB_DATA *kbuf, size_t *dlen)
{ {
const unsigned group_bits = TDB_TOPLEVEL_HASH_BITS-TDB_HASH_GROUP_BITS; 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
<< (64 - group_bits); << (64 - group_bits);
hlock_range = 1ULL << group_bits; hl_range = 1ULL << group_bits;
if (tdb_lock_hashes(tdb, hlock_start, hlock_range, ltype, if (tdb_lock_hashes(tdb, hl_start, hl_range, ltype,
TDB_LOCK_WAIT) != 0) TDB_LOCK_WAIT) != 0)
return -1; return -1;
...@@ -699,8 +699,7 @@ int next_in_hash(struct tdb_context *tdb, int ltype, ...@@ -699,8 +699,7 @@ int next_in_hash(struct tdb_context *tdb, int ltype,
if (tdb_read_convert(tdb, off, &rec, sizeof(rec))) { if (tdb_read_convert(tdb, off, &rec, sizeof(rec))) {
tdb_unlock_hashes(tdb, tdb_unlock_hashes(tdb,
hlock_start, hlock_range, hl_start, hl_range, ltype);
ltype);
return -1; return -1;
} }
if (rec_magic(&rec) != TDB_USED_MAGIC) { if (rec_magic(&rec) != TDB_USED_MAGIC) {
...@@ -726,11 +725,11 @@ int next_in_hash(struct tdb_context *tdb, int ltype, ...@@ -726,11 +725,11 @@ int next_in_hash(struct tdb_context *tdb, int ltype,
off + sizeof(rec), off + sizeof(rec),
kbuf->dsize); 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->toplevel_group++;
tinfo->levels[0].hashtable tinfo->levels[0].hashtable
...@@ -767,7 +766,7 @@ static int chainlock(struct tdb_context *tdb, const TDB_DATA *key, ...@@ -767,7 +766,7 @@ static int chainlock(struct tdb_context *tdb, const TDB_DATA *key,
unsigned int group, gbits; unsigned int group, gbits;
gbits = TDB_TOPLEVEL_HASH_BITS - TDB_HASH_GROUP_BITS; 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);
...@@ -790,7 +789,7 @@ int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key) ...@@ -790,7 +789,7 @@ int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key)
unsigned int group, gbits; unsigned int group, gbits;
gbits = TDB_TOPLEVEL_HASH_BITS - TDB_HASH_GROUP_BITS; 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);
......
...@@ -552,7 +552,7 @@ int tdb_access_commit(struct tdb_context *tdb, void *p) ...@@ -552,7 +552,7 @@ int tdb_access_commit(struct tdb_context *tdb, void *p)
} }
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,
bool write) bool write_mode)
{ {
if (unlikely(!tdb->map_ptr)) if (unlikely(!tdb->map_ptr))
return NULL; return NULL;
...@@ -562,10 +562,10 @@ static void *tdb_direct(struct tdb_context *tdb, tdb_off_t off, size_t len, ...@@ -562,10 +562,10 @@ static void *tdb_direct(struct tdb_context *tdb, tdb_off_t off, size_t len,
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) if ((uintptr_t)s < (uintptr_t)tdb->stats + tdb->stats->size)
*stat += val; *s += val;
} }
static const struct tdb_methods io_methods = { static const struct tdb_methods io_methods = {
......
...@@ -38,7 +38,7 @@ static int count_hash(struct tdb_context *tdb, ...@@ -38,7 +38,7 @@ static int count_hash(struct tdb_context *tdb,
static bool summarize(struct tdb_context *tdb, static bool summarize(struct tdb_context *tdb,
struct tally *hashes, struct tally *hashes,
struct tally *ftables, struct tally *ftables,
struct tally *free, struct tally *fr,
struct tally *keys, struct tally *keys,
struct tally *data, struct tally *data,
struct tally *extra, struct tally *extra,
...@@ -69,7 +69,7 @@ static bool summarize(struct tdb_context *tdb, ...@@ -69,7 +69,7 @@ static bool summarize(struct tdb_context *tdb,
len = sizeof(p->r) + p->r.max_len; len = sizeof(p->r) + p->r.max_len;
} else if (frec_magic(&p->f) == TDB_FREE_MAGIC) { } else if (frec_magic(&p->f) == TDB_FREE_MAGIC) {
len = frec_len(&p->f); len = frec_len(&p->f);
tally_add(free, len); tally_add(fr, len);
tally_add(buckets, size_to_bucket(len)); tally_add(buckets, size_to_bucket(len));
len += sizeof(p->u); len += sizeof(p->u);
unc++; unc++;
......
...@@ -11,15 +11,15 @@ ...@@ -11,15 +11,15 @@
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; unsigned int i;
/* Now, free table should be completely exhausted in zone 0 */ /* 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)
abort(); abort();
for (i = 0; i < sizeof(free.buckets)/sizeof(free.buckets[0]); i++) { for (i = 0; i < sizeof(ftab.buckets)/sizeof(ftab.buckets[0]); i++) {
if (free.buckets[i]) if (ftab.buckets[i])
return false; return false;
} }
return true; return true;
......
...@@ -363,7 +363,7 @@ static int transaction_expand_file(struct tdb_context *tdb, tdb_off_t addition) ...@@ -363,7 +363,7 @@ static int transaction_expand_file(struct tdb_context *tdb, tdb_off_t addition)
} }
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;
...@@ -371,7 +371,7 @@ static void *transaction_direct(struct tdb_context *tdb, tdb_off_t off, ...@@ -371,7 +371,7 @@ static void *transaction_direct(struct tdb_context *tdb, tdb_off_t off,
end_blk = (off + len - 1) / getpagesize(); end_blk = (off + len - 1) / getpagesize();
/* Can only do direct if in single block and we've already copied. */ /* Can only do direct if in single block and we've already copied. */
if (write) { if (write_mode) {
if (blk != end_blk) if (blk != end_blk)
return NULL; return NULL;
if (blk >= tdb->transaction->num_blocks) if (blk >= tdb->transaction->num_blocks)
...@@ -395,7 +395,7 @@ static void *transaction_direct(struct tdb_context *tdb, tdb_off_t off, ...@@ -395,7 +395,7 @@ static void *transaction_direct(struct tdb_context *tdb, tdb_off_t off,
return NULL; return NULL;
blk++; blk++;
} }
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 = {
......
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