Commit dfae76fd authored by Rusty Russell's avatar Rusty Russell

tdb2: rename set_header to the more appropriate set_used_header.

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