2011-12-16 00:04:31 +05:30
|
|
|
// Copyright (C) 2011 Red Hat, Inc. All rights reserved.
|
2011-12-06 19:23:05 +05:30
|
|
|
//
|
2011-12-06 19:13:56 +05:30
|
|
|
// This file is part of the thin-provisioning-tools source.
|
|
|
|
//
|
|
|
|
// thin-provisioning-tools is free software: you can redistribute it
|
|
|
|
// and/or modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation, either version 3 of
|
|
|
|
// the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// thin-provisioning-tools is distributed in the hope that it will be
|
|
|
|
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
|
|
|
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with thin-provisioning-tools. If not, see
|
|
|
|
// <http://www.gnu.org/licenses/>.
|
|
|
|
|
2011-10-28 16:01:00 +05:30
|
|
|
#ifndef METADATA_LL_H
|
|
|
|
#define METADATA_LL_H
|
|
|
|
|
2013-11-19 15:53:35 +05:30
|
|
|
#include "base/endian_utils.h"
|
|
|
|
|
2013-01-02 18:25:41 +05:30
|
|
|
#include "persistent-data/block.h"
|
2013-01-12 00:56:51 +05:30
|
|
|
#include "persistent-data/data-structures/btree.h"
|
2013-01-11 03:06:38 +05:30
|
|
|
#include "persistent-data/space-maps/disk.h"
|
2013-01-02 18:25:41 +05:30
|
|
|
#include "persistent-data/transaction_manager.h"
|
2011-10-28 16:01:00 +05:30
|
|
|
|
2013-05-20 20:39:13 +05:30
|
|
|
#include "thin-provisioning/device_tree.h"
|
2013-05-20 22:07:46 +05:30
|
|
|
#include "thin-provisioning/mapping_tree.h"
|
2013-05-21 17:16:07 +05:30
|
|
|
#include "thin-provisioning/superblock.h"
|
2013-01-11 03:06:38 +05:30
|
|
|
|
2011-10-28 16:01:00 +05:30
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace thin_provisioning {
|
|
|
|
// FIXME: don't use namespaces in a header
|
|
|
|
using namespace base;
|
|
|
|
using namespace persistent_data;
|
|
|
|
|
|
|
|
typedef uint64_t sector_t;
|
|
|
|
typedef uint32_t thin_dev_t;
|
|
|
|
|
|
|
|
//------------------------------------------------
|
|
|
|
|
|
|
|
// FIXME: should these be in a sub-namespace?
|
|
|
|
typedef persistent_data::transaction_manager::ptr tm_ptr;
|
|
|
|
|
|
|
|
// The tools require different interfaces onto the metadata than
|
|
|
|
// the in kernel driver. This class gives access to the low-level
|
|
|
|
// implementation of metadata. Implement more specific interfaces
|
|
|
|
// on top of this.
|
2011-10-28 16:55:06 +05:30
|
|
|
struct metadata {
|
2011-10-28 18:56:06 +05:30
|
|
|
enum open_type {
|
|
|
|
CREATE,
|
|
|
|
OPEN
|
|
|
|
};
|
|
|
|
|
2013-04-25 20:57:07 +05:30
|
|
|
typedef block_manager<>::read_ref read_ref;
|
|
|
|
typedef block_manager<>::write_ref write_ref;
|
|
|
|
typedef boost::shared_ptr<metadata> ptr;
|
|
|
|
|
|
|
|
metadata(block_manager<>::ptr bm, open_type ot,
|
|
|
|
sector_t data_block_size = 128,
|
|
|
|
block_address nr_data_blocks = 0); // Only used if CREATE
|
2015-12-15 15:38:07 +05:30
|
|
|
|
|
|
|
// Ideally we'd like the metadata snap argument to be a
|
|
|
|
// boolean, and we'd read the snap location from the
|
|
|
|
// superblock. But the command line interface for some of
|
|
|
|
// the tools allows the user to pass in a block, which
|
|
|
|
// they've retrieved from the pool status. So we have to
|
|
|
|
// support 3 cases:
|
|
|
|
//
|
|
|
|
// i) Read superblock
|
|
|
|
// ii) Read the metadata snap as given in the superblock
|
|
|
|
// iii) Read the metadata snap given on command line, checking it matches superblock.
|
|
|
|
//
|
2016-02-16 19:38:43 +05:30
|
|
|
metadata(block_manager<>::ptr bm, bool read_space_maps = true); // (i)
|
2015-12-15 15:38:07 +05:30
|
|
|
metadata(block_manager<>::ptr,
|
|
|
|
boost::optional<block_address> metadata_snap); // (ii) and (iii)
|
2013-04-25 20:57:07 +05:30
|
|
|
|
2019-04-17 16:45:46 +05:30
|
|
|
// This is used by repair, when we rebuild the superblock
|
|
|
|
metadata(block_manager<>::ptr bm, superblock_detail::superblock const &sb);
|
|
|
|
|
2011-10-28 16:01:00 +05:30
|
|
|
void commit();
|
|
|
|
|
|
|
|
|
|
|
|
tm_ptr tm_;
|
2013-05-21 17:16:07 +05:30
|
|
|
superblock_detail::superblock sb_;
|
2011-10-28 16:01:00 +05:30
|
|
|
|
|
|
|
checked_space_map::ptr metadata_sm_;
|
|
|
|
checked_space_map::ptr data_sm_;
|
2013-05-20 20:39:13 +05:30
|
|
|
device_tree::ptr details_;
|
2011-10-28 20:58:24 +05:30
|
|
|
dev_tree::ptr mappings_top_level_;
|
|
|
|
mapping_tree::ptr mappings_;
|
2015-12-15 15:38:07 +05:30
|
|
|
|
|
|
|
private:
|
|
|
|
void open_space_maps();
|
|
|
|
void open_btrees();
|
2011-10-28 16:01:00 +05:30
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
#endif
|