Commit dfae76fd authored by Rusty Russell's avatar Rusty Russell

tdb2: rename set_header to the more appropriate set_used_header.

parent 076c398e
......@@ -418,9 +418,9 @@ again:
assert(keylen + datalen + leftover <= best.data_len);
/* We need to mark non-free before we drop lock, otherwise
* coalesce() could try to merge it! */
if (set_header(tdb, &rec, keylen, datalen,
best.data_len - leftover,
hashlow) != 0)
if (set_used_header(tdb, &rec, keylen, datalen,
best.data_len - leftover,
hashlow) != 0)
goto unlock_err;
if (tdb_write_convert(tdb, best_off, &rec, sizeof(rec)) != 0)
......@@ -493,10 +493,10 @@ static tdb_off_t get_free(struct tdb_context *tdb,
return 0;
}
int set_header(struct tdb_context *tdb,
struct tdb_used_record *rec,
uint64_t keylen, uint64_t datalen,
uint64_t actuallen, unsigned hashlow)
int set_used_header(struct tdb_context *tdb,
struct tdb_used_record *rec,
uint64_t keylen, uint64_t datalen,
uint64_t actuallen, unsigned hashlow)
{
uint64_t keybits = (fls64(keylen) + 1) / 2;
......
......@@ -382,10 +382,10 @@ int add_free_record(struct tdb_context *tdb,
tdb_off_t off, tdb_len_t len_with_header);
/* Set up header for a used record. */
int set_header(struct tdb_context *tdb,
struct tdb_used_record *rec,
uint64_t keylen, uint64_t datalen,
uint64_t actuallen, unsigned hashlow);
int set_used_header(struct tdb_context *tdb,
struct tdb_used_record *rec,
uint64_t keylen, uint64_t datalen,
uint64_t actuallen, unsigned hashlow);
/* Used by tdb_check to verify. */
unsigned int size_to_bucket(tdb_len_t data_len);
......
......@@ -111,9 +111,9 @@ static int tdb_new_database(struct tdb_context *tdb,
/* Free is empty. */
newdb.hdr.free_list = offsetof(struct new_database, flist);
memset(&newdb.flist, 0, sizeof(newdb.flist));
set_header(NULL, &newdb.flist.hdr, 0,
sizeof(newdb.flist) - sizeof(newdb.flist.hdr),
sizeof(newdb.flist) - sizeof(newdb.flist.hdr), 1);
set_used_header(NULL, &newdb.flist.hdr, 0,
sizeof(newdb.flist) - sizeof(newdb.flist.hdr),
sizeof(newdb.flist) - sizeof(newdb.flist.hdr), 1);
/* Magic food */
memset(newdb.hdr.magic_food, 0, sizeof(newdb.hdr.magic_food));
......@@ -364,7 +364,7 @@ static int update_rec_hdr(struct tdb_context *tdb,
{
uint64_t dataroom = rec_data_length(rec) + rec_extra_padding(rec);
if (set_header(tdb, rec, keylen, datalen, keylen + dataroom, h))
if (set_used_header(tdb, rec, keylen, datalen, keylen + dataroom, h))
return -1;
return tdb_write_convert(tdb, off, rec, sizeof(*rec));
......
......@@ -97,9 +97,9 @@ static void set_data_record(void *mem, struct tdb_context *tdb,
{
struct tdb_used_record *u = mem;
set_header(tdb, u, used->key.dsize, used->data.dsize,
used->key.dsize + used->data.dsize + used->extra,
tdb_hash(tdb, used->key.dptr, used->key.dsize));
set_used_header(tdb, u, used->key.dsize, used->data.dsize,
used->key.dsize + used->data.dsize + used->extra,
tdb_hash(tdb, used->key.dptr, used->key.dsize));
memcpy(u + 1, used->key.dptr, used->key.dsize);
memcpy((char *)(u + 1) + used->key.dsize,
used->data.dptr, used->data.dsize);
......@@ -111,7 +111,7 @@ static void set_hashtable(void *mem, struct tdb_context *tdb,
struct tdb_used_record *u = mem;
tdb_len_t len = sizeof(tdb_off_t) << TDB_SUBLEVEL_HASH_BITS;
set_header(tdb, u, 0, len, len + htable->extra, 0);
set_used_header(tdb, u, 0, len, len + htable->extra, 0);
memset(u + 1, 0, len);
}
......@@ -121,9 +121,9 @@ static void set_freelist(void *mem, struct tdb_context *tdb,
{
struct tdb_freelist *flist = mem;
memset(flist, 0, sizeof(*flist));
set_header(tdb, &flist->hdr, 0,
sizeof(*flist) - sizeof(flist->hdr),
sizeof(*flist) - sizeof(flist->hdr), 1);
set_used_header(tdb, &flist->hdr, 0,
sizeof(*flist) - sizeof(flist->hdr),
sizeof(*flist) - sizeof(flist->hdr), 1);
if (last_flist) {
flist = (struct tdb_freelist *)((char *)hdr + last_flist);
......
......@@ -18,12 +18,14 @@ int main(int argc, char *argv[])
/* We should be able to encode any data value. */
for (i = 0; i < 64; i++)
ok1(set_header(&tdb, &rec, 0, 1ULL << i, 1ULL << i, 0) == 0);
ok1(set_used_header(&tdb, &rec, 0, 1ULL << i, 1ULL << i, 0)
== 0);
/* And any key and data with < 64 bits between them. */
for (i = 0; i < 32; i++) {
tdb_len_t dlen = 1ULL >> (63 - i), klen = 1ULL << i;
ok1(set_header(&tdb, &rec, klen, dlen, klen + dlen, 0) == 0);
ok1(set_used_header(&tdb, &rec, klen, dlen, klen + dlen, 0)
== 0);
}
/* We should neatly encode all values. */
......@@ -32,7 +34,7 @@ int main(int argc, char *argv[])
uint64_t klen = 1ULL << (i < 16 ? i : 15);
uint64_t dlen = 1ULL << i;
uint64_t xlen = 1ULL << (i < 32 ? i : 31);
ok1(set_header(&tdb, &rec, klen, dlen, klen + dlen + xlen, h)
ok1(set_used_header(&tdb, &rec, klen, dlen, klen+dlen+xlen, h)
== 0);
ok1(rec_key_length(&rec) == klen);
ok1(rec_data_length(&rec) == dlen);
......
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