Merge branch 'master' of github.com:jthornber/thin-provisioning-tools

This commit is contained in:
Joe Thornber 2013-10-11 13:35:21 +01:00
commit b177275816
3 changed files with 76 additions and 7 deletions

View File

@ -60,9 +60,53 @@ namespace {
//----------------------------------------------------------------
superblock_flags::superblock_flags()
{
}
superblock_flags::superblock_flags(uint32_t bits)
{
if (bits & (1 << CLEAN_SHUTDOWN_BIT)) {
flags_.insert(CLEAN_SHUTDOWN);
bits &= ~(1 << CLEAN_SHUTDOWN_BIT);
}
unhandled_flags_ = bits;
}
void
superblock_flags::set_flag(superblock_flags::flag f)
{
flags_.insert(f);
}
bool
superblock_flags::get_flag(flag f) const
{
return flags_.find(f) != flags_.end();
}
uint32_t
superblock_flags::encode() const
{
uint32_t r = 0;
if (get_flag(CLEAN_SHUTDOWN))
r = r | (1 << CLEAN_SHUTDOWN_BIT);
return r;
}
uint32_t
superblock_flags::get_unhandled_flags() const
{
return unhandled_flags_;
}
//----------------------------------------------------------------
superblock::superblock()
: csum(0),
flags(0),
blocknr(SUPERBLOCK_LOCATION),
magic(SUPERBLOCK_MAGIC),
version(VERSION_BEGIN),
@ -95,7 +139,8 @@ void
superblock_traits::unpack(superblock_disk const &disk, superblock &core)
{
core.csum = to_cpu<uint32_t>(disk.csum);
core.flags = to_cpu<uint32_t>(disk.flags);
core.flags = superblock_flags(to_cpu<uint32_t>(disk.flags));
core.blocknr = to_cpu<uint64_t>(disk.blocknr);
::memcpy(core.uuid, disk.uuid, sizeof(core.uuid));
@ -138,7 +183,7 @@ void
superblock_traits::pack(superblock const &core, superblock_disk &disk)
{
disk.csum = to_disk<le32>(core.csum);
disk.flags = to_disk<le32>(core.flags);
disk.flags = to_disk<le32>(core.flags.encode());
disk.blocknr = to_disk<le64>(core.blocknr);
::memcpy(disk.uuid, core.uuid, sizeof(disk.uuid));
@ -258,9 +303,9 @@ caching::check_superblock(superblock const &sb,
block_address nr_metadata_blocks,
damage_visitor &visitor)
{
if (sb.flags != 0) {
if (sb.flags.get_unhandled_flags()) {
ostringstream msg;
msg << "invalid flags: " << hex << sb.flags;
msg << "invalid flags: " << sb.flags.get_unhandled_flags();
visitor.visit(superblock_invalid(msg.str()));
}

View File

@ -4,6 +4,8 @@
#include "persistent-data/endian_utils.h"
#include "persistent-data/data-structures/btree.h"
#include <set>
//----------------------------------------------------------------
namespace caching {
@ -14,11 +16,34 @@ namespace caching {
unsigned const CACHE_POLICY_VERSION_SIZE = 3;
block_address const SUPERBLOCK_LOCATION = 0;
class superblock_flags {
public:
enum flag {
CLEAN_SHUTDOWN
};
enum flag_bits {
CLEAN_SHUTDOWN_BIT = 0
};
superblock_flags();
superblock_flags(uint32_t bits);
void set_flag(flag f);
bool get_flag(flag f) const;
uint32_t encode() const;
uint32_t get_unhandled_flags() const;
private:
uint32_t unhandled_flags_;
std::set<flag> flags_;
};
struct superblock {
superblock();
uint32_t csum;
uint32_t flags;
superblock_flags flags;
uint64_t blocknr;
__u8 uuid[16];

View File

@ -81,7 +81,6 @@ Feature: cache_check
Then it should fail
And it should give no output
@announce
Scenario: A valid metadata area passes
Given valid cache metadata
When I run `cache_check metadata.bin`