Merge pull request #135 from mingnus/master

[thin_metadata_pack] Improve block scanning performance
This commit is contained in:
Joe Thornber 2020-05-26 09:53:27 +01:00 committed by GitHub
commit d9e18fecf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,7 +26,7 @@
#include "persistent-data/file_utils.h" #include "persistent-data/file_utils.h"
#include "persistent-data/space-maps/disk.h" #include "persistent-data/space-maps/disk.h"
#include "persistent-data/validators.h" #include "persistent-data/checksum.h"
#include "thin-provisioning/commands.h" #include "thin-provisioning/commands.h"
#include "thin-provisioning/superblock.h" #include "thin-provisioning/superblock.h"
#include "version.h" #include "version.h"
@ -42,6 +42,11 @@ namespace {
using namespace std; using namespace std;
constexpr uint64_t MAGIC = 0xa537a0aa6309ef77; constexpr uint64_t MAGIC = 0xa537a0aa6309ef77;
uint32_t const SUPERBLOCK_CSUM_SEED = 160774;
uint32_t const BITMAP_CSUM_XOR = 240779;
uint32_t const INDEX_CSUM_XOR = 160478;
uint32_t const BTREE_CSUM_XOR = 121107;
// Pack file format // Pack file format
// ---------------- // ----------------
// //
@ -56,25 +61,24 @@ namespace {
class is_metadata_functor { class is_metadata_functor {
public: public:
is_metadata_functor() is_metadata_functor() {
: superblock_v_(superblock_validator()),
btree_node_v_(create_btree_node_validator()),
bitmap_v_(bitmap_validator()),
index_v_(index_validator()) {
} }
bool operator() (void const *raw) const { bool operator() (void const *raw) const {
return superblock_v_->check_raw(raw) || uint32_t const *cksum = reinterpret_cast<uint32_t const*>(raw);
btree_node_v_->check_raw(raw) || base::crc32c sum(*cksum);
bitmap_v_->check_raw(raw) || sum.append(cksum + 1, MD_BLOCK_SIZE - sizeof(uint32_t));
index_v_->check_raw(raw);
}
private: switch (sum.get_sum()) {
bcache::validator::ptr superblock_v_; case SUPERBLOCK_CSUM_SEED:
bcache::validator::ptr btree_node_v_; case INDEX_CSUM_XOR:
bcache::validator::ptr bitmap_v_; case BITMAP_CSUM_XOR:
bcache::validator::ptr index_v_; case BTREE_CSUM_XOR:
return true;
default:
return false;
}
}
}; };
void prealloc_file(string const &file, off_t len) { void prealloc_file(string const &file, off_t len) {