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 TRANSACTION_MANAGER_H
|
|
|
|
#define TRANSACTION_MANAGER_H
|
|
|
|
|
|
|
|
#include "block.h"
|
|
|
|
#include "space_map.h"
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace persistent_data {
|
2011-07-22 20:39:56 +05:30
|
|
|
class transaction_manager : boost::noncopyable {
|
2011-06-23 19:17:08 +05:30
|
|
|
public:
|
2020-04-30 19:32:43 +05:30
|
|
|
typedef std::shared_ptr<transaction_manager> ptr;
|
2020-04-30 19:00:01 +05:30
|
|
|
typedef block_manager::read_ref read_ref;
|
|
|
|
typedef block_manager::write_ref write_ref;
|
2014-07-25 19:16:51 +05:30
|
|
|
typedef bcache::validator::ptr validator;
|
2011-06-23 19:17:08 +05:30
|
|
|
|
2011-07-14 20:01:00 +05:30
|
|
|
// If the space map is persistent, then the caller should
|
|
|
|
// hold onto a reference and remember to call sm_->commit()
|
|
|
|
// and update the superblock before dropping the superblock
|
|
|
|
// reference.
|
2020-04-30 19:00:01 +05:30
|
|
|
transaction_manager(block_manager::ptr bm,
|
2011-06-23 19:17:08 +05:30
|
|
|
space_map::ptr sm);
|
|
|
|
~transaction_manager();
|
|
|
|
|
2020-08-16 13:30:04 +05:30
|
|
|
void commit();
|
|
|
|
|
2011-07-14 20:01:00 +05:30
|
|
|
// Drop the superblock reference to commit
|
|
|
|
write_ref begin(block_address superblock, validator v);
|
|
|
|
write_ref new_block(validator v);
|
2011-06-23 19:17:08 +05:30
|
|
|
|
2011-07-14 20:01:00 +05:30
|
|
|
// shadowing returns a new write_ref, and a boolean which
|
|
|
|
// indicates whether the children should be incremented.
|
|
|
|
std::pair<write_ref, bool> shadow(block_address orig, validator v);
|
2011-06-23 19:17:08 +05:30
|
|
|
|
|
|
|
read_ref read_lock(block_address b);
|
2011-07-14 20:01:00 +05:30
|
|
|
read_ref read_lock(block_address b, validator v);
|
2011-06-23 19:17:08 +05:30
|
|
|
|
2011-07-14 20:01:00 +05:30
|
|
|
space_map::ptr get_sm() {
|
|
|
|
return sm_;
|
|
|
|
}
|
2011-06-23 19:17:08 +05:30
|
|
|
|
2011-10-28 20:58:24 +05:30
|
|
|
void set_sm(space_map::ptr sm) {
|
|
|
|
sm_ = sm;
|
|
|
|
}
|
|
|
|
|
2020-04-30 19:00:01 +05:30
|
|
|
block_manager::ptr get_bm() {
|
2011-07-22 20:39:56 +05:30
|
|
|
return bm_;
|
|
|
|
}
|
|
|
|
|
2014-07-25 21:02:59 +05:30
|
|
|
void prefetch(block_address b) {
|
|
|
|
bm_->prefetch(b);
|
|
|
|
}
|
|
|
|
|
2020-08-12 09:07:39 +05:30
|
|
|
// mark a block as shadowed,
|
|
|
|
// for the purpose of in-place modification
|
|
|
|
void mark_shadowed(block_address b) {
|
|
|
|
add_shadow(b);
|
|
|
|
}
|
|
|
|
|
2011-06-23 19:17:08 +05:30
|
|
|
private:
|
|
|
|
void add_shadow(block_address b);
|
2011-07-14 20:01:00 +05:30
|
|
|
void remove_shadow(block_address b);
|
|
|
|
bool is_shadow(block_address b) const;
|
2011-06-23 19:17:08 +05:30
|
|
|
void wipe_shadow_table();
|
|
|
|
|
2020-04-30 19:00:01 +05:30
|
|
|
block_manager::ptr bm_;
|
2011-06-23 19:17:08 +05:30
|
|
|
space_map::ptr sm_;
|
|
|
|
|
|
|
|
std::set<block_address> shadows_;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------
|
|
|
|
|
|
|
|
#endif
|