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-06-23 19:17:08 +05:30
|
|
|
#ifndef MULTISNAP_METADATA_H
|
|
|
|
#define MULTISNAP_METADATA_H
|
|
|
|
|
2011-10-28 16:55:06 +05:30
|
|
|
#include "metadata.h"
|
2011-06-23 19:17:08 +05:30
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
2011-07-22 20:39:56 +05:30
|
|
|
namespace thin_provisioning {
|
2011-10-28 16:51:58 +05:30
|
|
|
// This interface is very like that in the kernel. It'll allow us
|
|
|
|
// to write simulators to try out different space maps etc. Not
|
|
|
|
// currently used by the tools.
|
|
|
|
|
|
|
|
class thin_pool;
|
2011-07-22 20:39:56 +05:30
|
|
|
class thin {
|
|
|
|
public:
|
2020-06-01 22:33:01 +05:30
|
|
|
struct lookup_result {
|
|
|
|
block_address block_;
|
|
|
|
bool shared_;
|
|
|
|
};
|
|
|
|
|
2020-04-30 19:32:43 +05:30
|
|
|
typedef std::shared_ptr<thin> ptr;
|
2020-06-01 22:33:01 +05:30
|
|
|
typedef boost::optional<lookup_result> maybe_address;
|
2011-07-22 20:39:56 +05:30
|
|
|
|
|
|
|
thin_dev_t get_dev_t() const;
|
|
|
|
maybe_address lookup(block_address thin_block);
|
2016-08-10 21:10:48 +05:30
|
|
|
bool insert(block_address thin_block, block_address data_block);
|
2011-07-22 20:39:56 +05:30
|
|
|
void remove(block_address thin_block);
|
|
|
|
|
|
|
|
void set_snapshot_time(uint32_t time);
|
|
|
|
|
|
|
|
block_address get_mapped_blocks() const;
|
|
|
|
void set_mapped_blocks(block_address count);
|
|
|
|
|
|
|
|
private:
|
2011-10-28 16:51:58 +05:30
|
|
|
friend class thin_pool;
|
2020-05-31 18:05:37 +05:30
|
|
|
thin(thin_dev_t dev, thin_pool &pool);
|
2020-05-31 17:44:42 +05:30
|
|
|
thin(thin_dev_t dev, thin_pool &pool,
|
|
|
|
device_tree_detail::device_details const &details);
|
2011-07-22 20:39:56 +05:30
|
|
|
|
|
|
|
thin_dev_t dev_;
|
2020-05-31 18:05:37 +05:30
|
|
|
thin_pool &pool_;
|
2020-05-31 17:44:42 +05:30
|
|
|
device_tree_detail::device_details details_;
|
|
|
|
uint32_t open_count_;
|
|
|
|
bool changed_;
|
2011-07-22 20:39:56 +05:30
|
|
|
};
|
2011-06-27 15:15:30 +05:30
|
|
|
|
2011-10-28 16:51:58 +05:30
|
|
|
class thin_pool {
|
2011-06-23 19:17:08 +05:30
|
|
|
public:
|
2020-04-30 19:32:43 +05:30
|
|
|
typedef std::shared_ptr<thin_pool> ptr;
|
2011-06-23 19:17:08 +05:30
|
|
|
|
2020-05-30 22:48:45 +05:30
|
|
|
thin_pool(block_manager::ptr bm);
|
|
|
|
thin_pool(block_manager::ptr bm,
|
|
|
|
sector_t data_block_size,
|
|
|
|
block_address nr_data_blocks);
|
2011-10-28 16:51:58 +05:30
|
|
|
~thin_pool();
|
2011-06-23 19:17:08 +05:30
|
|
|
|
2011-07-22 20:39:56 +05:30
|
|
|
void create_thin(thin_dev_t dev);
|
|
|
|
void create_snap(thin_dev_t dev, thin_dev_t origin);
|
|
|
|
void del(thin_dev_t);
|
2020-05-31 17:44:42 +05:30
|
|
|
void commit();
|
2011-06-23 19:17:08 +05:30
|
|
|
|
|
|
|
void set_transaction_id(uint64_t id);
|
|
|
|
uint64_t get_transaction_id() const;
|
|
|
|
|
2020-06-02 16:37:13 +05:30
|
|
|
// handling metadata snapshot
|
|
|
|
void reserve_metadata_snap();
|
|
|
|
void release_metadata_snap();
|
2012-05-17 17:33:10 +05:30
|
|
|
block_address get_metadata_snap() const;
|
2011-06-23 19:17:08 +05:30
|
|
|
|
|
|
|
block_address alloc_data_block();
|
|
|
|
void free_data_block(block_address b);
|
|
|
|
|
|
|
|
// accessors
|
|
|
|
block_address get_nr_free_data_blocks() const;
|
|
|
|
sector_t get_data_block_size() const;
|
|
|
|
block_address get_data_dev_size() const;
|
2020-05-31 17:44:42 +05:30
|
|
|
uint32_t get_time() const;
|
2011-06-23 19:17:08 +05:30
|
|
|
|
2011-07-22 20:39:56 +05:30
|
|
|
thin::ptr open_thin(thin_dev_t);
|
2020-06-02 10:13:55 +05:30
|
|
|
void close_thin(thin::ptr td);
|
2011-06-23 19:17:08 +05:30
|
|
|
|
|
|
|
private:
|
|
|
|
friend class thin;
|
2020-05-31 17:44:42 +05:30
|
|
|
typedef std::map<thin_dev_t, thin::ptr> device_map;
|
|
|
|
|
2011-07-22 20:39:56 +05:30
|
|
|
bool device_exists(thin_dev_t dev) const;
|
2020-05-31 17:44:42 +05:30
|
|
|
thin::ptr create_device(thin_dev_t dev);
|
|
|
|
thin::ptr open_device(thin_dev_t dev);
|
|
|
|
void close_device(thin::ptr device);
|
2020-05-31 20:28:59 +05:30
|
|
|
void set_snapshot_details(thin::ptr snap, thin_dev_t origin);
|
2020-05-31 17:44:42 +05:30
|
|
|
void write_changed_details();
|
2011-06-23 19:17:08 +05:30
|
|
|
|
2011-10-28 16:55:06 +05:30
|
|
|
metadata::ptr md_;
|
2020-05-31 17:44:42 +05:30
|
|
|
device_map thin_devices_;
|
2011-06-23 19:17:08 +05:30
|
|
|
};
|
2020-06-01 22:46:38 +05:30
|
|
|
|
|
|
|
void process_read(thin::ptr td, thin_pool::ptr tp, sector_t offset);
|
|
|
|
void process_write(thin::ptr td, thin_pool::ptr tp, sector_t offset);
|
|
|
|
void process_discard(thin::ptr td, thin_pool::ptr tp, sector_t offset);
|
2011-06-23 19:17:08 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
#endif
|