[all tools] Factor out open_bm() and open_tm.

Many duplicates of this code.
This commit is contained in:
Joe Thornber
2017-10-05 11:53:40 +01:00
parent 924a996fa7
commit 3c761e6822
11 changed files with 44 additions and 122 deletions

View File

@ -1,5 +1,6 @@
#include "persistent-data/math_utils.h"
#include "persistent-data/file_utils.h"
#include "persistent-data/space-maps/core.h"
#include <linux/fs.h>
#include <sys/ioctl.h>
@ -36,4 +37,23 @@ persistent_data::open_bm(std::string const &dev_path, block_manager<>::mode m, b
return block_manager<>::ptr(new block_manager<>(dev_path, nr_blocks, 1, m, excl));
}
block_manager<>::ptr
persistent_data::open_bm(std::string const &path) {
block_address nr_blocks = get_nr_metadata_blocks(path);
block_manager<>::mode m = block_manager<>::READ_ONLY;
return block_manager<>::ptr(new block_manager<>(path, nr_blocks, 1, m));
}
transaction_manager::ptr
persistent_data::open_tm(block_manager<>::ptr bm, block_address superblock_location) {
auto nr_blocks = bm->get_nr_blocks();
if (!nr_blocks)
throw runtime_error("Metadata is not large enough for superblock.");
space_map::ptr sm(new core_map(nr_blocks));
sm->inc(superblock_location);
transaction_manager::ptr tm(new transaction_manager(bm, sm));
return tm;
}
//----------------------------------------------------------------