[era] superblock packing

This commit is contained in:
Joe Thornber 2014-01-08 15:31:42 +00:00
parent 4df679174c
commit 2250abe605
5 changed files with 67 additions and 7 deletions

View File

@ -48,6 +48,7 @@ SOURCE=\
caching/xml_format.cc \
\
era/era_detail.cc \
era/superblock.cc \
\
persistent-data/checksum.cc \
persistent-data/error_set.cc \

View File

@ -8,6 +8,7 @@ using namespace era;
//----------------------------------------------------------------
namespace {
#if 0
le32 pack_hash_detail(uint32_t hash1, uint32_t hash2, uint32_t nr_probes) {
throw std::runtime_error("not implemented");
}
@ -15,22 +16,28 @@ namespace {
void unpack_hash_detail(le32 packed, uint32_t &hash1, uint32_t &hash2, uint32_t &nr_probes) {
throw std::runtime_error("not implemented");
}
#endif
}
void
era_detail_traits::unpack(disk_type const &disk, value_type &value)
{
value.nr_blocks = to_cpu<uint32_t>(disk.nr_blocks);
value.nr_bits = to_cpu<uint32_t>(disk.nr_bits);
unpack_hash_detail(disk.hash_fns_and_probes, value.hash1, value.hash2, value.nr_probes);
value.nr_set = to_cpu<uint32_t>(disk.nr_set);
value.bloom_root = to_cpu<uint64_t>(disk.bloom_root);
//unpack_hash_detail(disk.hash_fns_and_probes, value.hash1, value.hash2, value.nr_probes);
}
void
era_detail_traits::pack(value_type const &value, disk_type &disk)
{
disk.nr_blocks = to_disk<le32>(value.nr_blocks);
disk.nr_bits = to_disk<le32>(value.nr_bits);
disk.hash_fns_and_probes = pack_hash_detail(value.hash1, value.hash2, value.nr_probes);
disk.nr_set = to_disk<le32>(value.nr_set);
disk.bloom_root = to_disk<le64>(value.bloom_root);
// disk.hash_fns_and_probes = pack_hash_detail(value.hash1, value.hash2, value.nr_probes);
}
//----------------------------------------------------------------

View File

@ -7,13 +7,16 @@
namespace era {
struct era_detail_disk {
base::le32 nr_blocks;
base::le32 nr_bits;
base::le32 hash_fns_and_probes;
base::le32 nr_set;
base::le64 bloom_root;
} __attribute__ ((packed));
struct era_detail {
uint32_t nr_blocks;
uint32_t nr_bits;
uint32_t nr_set;
uint32_t hash1;
uint32_t hash2;

View File

@ -1,6 +1,7 @@
#include "era/superblock.h"
#include "persistent-data/checksum.h"
#include "persistent-data/errors.h"
using namespace base;
using namespace era;
@ -11,15 +12,20 @@ using namespace persistent_data;
namespace {
using namespace base;
size_t const SPACE_MAP_ROOT_SIZE = 128;
size_t const UUID_LEN = 16;
struct superblock_disk {
le32 csum;
le32 flags;
le64 blocknr;
__u8 uuid[16];
__u8 uuid[UUID_LEN];
le64 magic;
le32 version;
__u8 metadata_space_map_root[SPACE_MAP_ROOT_SIZE];
le32 data_block_size;
le32 metadata_block_size;
le32 nr_blocks;
@ -27,8 +33,9 @@ namespace {
le32 current_era;
era_detail_disk current_detail;
le64 bloom_filters_root;
le64 bloom_tree_root;
le64 era_array_root;
} __attribute__ ((packed));
struct superblock_traits {
@ -56,7 +63,7 @@ superblock::superblock()
metadata_block_size(8),
nr_blocks(0),
current_era(0),
era_root(0),
bloom_tree_root(0),
era_array_root(0)
{
memset(uuid, 0, sizeof(uuid));
@ -65,6 +72,48 @@ superblock::superblock()
//----------------------------------------------------------------
void
superblock_traits::unpack(disk_type const &disk, value_type &value)
{
//value.flags = to_cpu<uint32_t>(disk.flags);
value.blocknr = to_cpu<uint64_t>(disk.blocknr);
value.magic = to_cpu<uint64_t>(disk.magic);
value.version = to_cpu<uint32_t>(disk.version);
memcpy(value.metadata_space_map_root, disk.metadata_space_map_root,
sizeof(value.metadata_space_map_root));
value.data_block_size = to_cpu<uint32_t>(disk.data_block_size);
value.metadata_block_size = to_cpu<uint32_t>(disk.metadata_block_size);
value.nr_blocks = to_cpu<uint32_t>(disk.nr_blocks);
value.current_era = to_cpu<uint32_t>(disk.current_era);
era_detail_traits::unpack(disk.current_detail, value.current_detail);
value.bloom_tree_root = to_cpu<uint64_t>(disk.bloom_tree_root);
value.era_array_root = to_cpu<uint64_t>(disk.era_array_root);
}
void
superblock_traits::pack(value_type const &value, disk_type &disk)
{
//disk.flags = to_disk<uint32_t>(value.flags);
disk.blocknr = to_disk<le64>(value.blocknr);
disk.magic = to_disk<le64>(value.magic);
disk.version = to_disk<le32>(value.version);
memcpy(disk.metadata_space_map_root, value.metadata_space_map_root,
sizeof(disk.metadata_space_map_root));
disk.data_block_size = to_disk<le32>(value.data_block_size);
disk.metadata_block_size = to_disk<le32>(value.metadata_block_size);
disk.nr_blocks = to_disk<le32>(value.nr_blocks);
disk.current_era = to_disk<le32>(value.current_era);
era_detail_traits::pack(value.current_detail, disk.current_detail);
disk.bloom_tree_root = to_disk<le64>(value.bloom_tree_root);
disk.era_array_root = to_disk<le64>(value.era_array_root);
}
//----------------------------------------------------------------
namespace validator {
using namespace persistent_data;

View File

@ -59,7 +59,7 @@ namespace era {
era_detail current_detail;
// A btree of undigested era_details
uint64_t era_root;
uint64_t bloom_tree_root;
// Big array holding the digested era/block info.
uint64_t era_array_root;