tdb2: rename set_header to the more appropriate set_used_header.
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 23 Nov 2010 03:10:59 +0000 (13:40 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 23 Nov 2010 03:10:59 +0000 (13:40 +1030)
ccan/tdb2/free.c
ccan/tdb2/private.h
ccan/tdb2/tdb.c
ccan/tdb2/test/layout.c
ccan/tdb2/test/run-001-encode.c

index 8f81f9d99aae0a378db0163e6cd389bda336d060..6fd82c5c540d0ee2767d60385c43654606396c8b 100644 (file)
@@ -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;
 
index aebfa020b1db88f3aaeab574bd905bcb273a0bf6..387e49f61182af8fe33028840ebc3be073fea70a 100644 (file)
@@ -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);
index 8bae9fc298516738f3e896aa4c31edfa7350f893..f7a6a5b358a77b33692296479052f37e0a202ad5 100644 (file)
@@ -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));
index b125f67663c71fa7ddc9df637be01d028200b308..3049d3214e62736ec95ddbe979cafe7784034593 100644 (file)
@@ -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);
index b209ed82359089fd00da537c7e79845f4358384e..09b3ab35850cc5b69c692059bdc2396f550abd50 100644 (file)
@@ -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);