WIP on cache tools
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
#include "persistent-data/math_utils.h"
|
||||
#include "thin-provisioning/file_utils.h"
|
||||
|
||||
#include <linux/fs.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
using namespace base;
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
persistent_data::block_address
|
||||
thin_provisioning::get_nr_blocks(string const &path)
|
||||
{
|
||||
using namespace persistent_data;
|
||||
|
||||
struct stat info;
|
||||
block_address nr_blocks;
|
||||
|
||||
int r = ::stat(path.c_str(), &info);
|
||||
if (r)
|
||||
throw runtime_error("Couldn't stat dev path");
|
||||
|
||||
if (S_ISREG(info.st_mode) && info.st_size)
|
||||
nr_blocks = div_up<block_address>(info.st_size, MD_BLOCK_SIZE);
|
||||
|
||||
else if (S_ISBLK(info.st_mode)) {
|
||||
// To get the size of a block device we need to
|
||||
// open it, and then make an ioctl call.
|
||||
int fd = ::open(path.c_str(), O_RDONLY);
|
||||
if (fd < 0)
|
||||
throw runtime_error("couldn't open block device to ascertain size");
|
||||
|
||||
r = ::ioctl(fd, BLKGETSIZE64, &nr_blocks);
|
||||
if (r) {
|
||||
::close(fd);
|
||||
throw runtime_error("ioctl BLKGETSIZE64 failed");
|
||||
}
|
||||
::close(fd);
|
||||
nr_blocks = div_down<block_address>(nr_blocks, MD_BLOCK_SIZE);
|
||||
} else
|
||||
// FIXME: needs a better message
|
||||
throw runtime_error("bad path");
|
||||
|
||||
return nr_blocks;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
@@ -1,14 +0,0 @@
|
||||
#ifndef THIN_FILE_UTILS_H
|
||||
#define THIN_FILE_UTILS_H
|
||||
|
||||
#include "persistent-data/block.h"
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace thin_provisioning {
|
||||
persistent_data::block_address get_nr_blocks(string const &path);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
#endif
|
||||
@@ -17,9 +17,9 @@
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "thin-provisioning/device_tree.h"
|
||||
#include "thin-provisioning/file_utils.h"
|
||||
#include "thin-provisioning/metadata.h"
|
||||
|
||||
#include "persistent-data/file_utils.h"
|
||||
#include "persistent-data/math_utils.h"
|
||||
#include "persistent-data/space-maps/core.h"
|
||||
#include "persistent-data/space-maps/disk.h"
|
||||
@@ -40,15 +40,6 @@ namespace {
|
||||
|
||||
unsigned const METADATA_CACHE_SIZE = 1024;
|
||||
|
||||
block_manager<>::ptr open_bm(string const &dev_path, bool writeable) {
|
||||
block_address nr_blocks = get_nr_blocks(dev_path);
|
||||
block_io<>::mode m = writeable ?
|
||||
block_io<>::READ_WRITE :
|
||||
block_io<>::READ_ONLY;
|
||||
|
||||
return block_manager<>::ptr(new block_manager<>(dev_path, nr_blocks, 1, m));
|
||||
}
|
||||
|
||||
transaction_manager::ptr
|
||||
open_tm(block_manager<>::ptr bm) {
|
||||
space_map::ptr sm(new core_map(bm->get_nr_blocks()));
|
||||
@@ -90,7 +81,7 @@ metadata::metadata(std::string const &dev_path, open_type ot,
|
||||
{
|
||||
switch (ot) {
|
||||
case OPEN:
|
||||
tm_ = open_tm(open_bm(dev_path, false));
|
||||
tm_ = open_tm(open_bm(dev_path, block_io<>::READ_ONLY));
|
||||
sb_ = read_superblock(tm_->get_bm());
|
||||
|
||||
if (sb_.version_ != 1)
|
||||
@@ -115,7 +106,7 @@ metadata::metadata(std::string const &dev_path, open_type ot,
|
||||
break;
|
||||
|
||||
case CREATE:
|
||||
tm_ = open_tm(open_bm(dev_path, true));
|
||||
tm_ = open_tm(open_bm(dev_path, block_io<>::READ_WRITE));
|
||||
space_map::ptr core = tm_->get_sm();
|
||||
metadata_sm_ = create_metadata_sm(tm_, tm_->get_bm()->get_nr_blocks());
|
||||
copy_space_maps(metadata_sm_, core);
|
||||
@@ -143,7 +134,7 @@ metadata::metadata(std::string const &dev_path, open_type ot,
|
||||
|
||||
metadata::metadata(std::string const &dev_path, block_address metadata_snap)
|
||||
{
|
||||
tm_ = open_tm(open_bm(dev_path, false));
|
||||
tm_ = open_tm(open_bm(dev_path, block_io<>::READ_ONLY));
|
||||
sb_ = read_superblock(tm_->get_bm(), metadata_snap);
|
||||
|
||||
// We don't open the metadata sm for a held root
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
// with thin-provisioning-tools. If not, see
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "thin-provisioning/file_utils.h"
|
||||
#include "persistent-data/file_utils.h"
|
||||
#include "thin-provisioning/metadata.h"
|
||||
#include "thin-provisioning/metadata_checker.h"
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
#include "base/error_state.h"
|
||||
#include "base/nested_output.h"
|
||||
#include "persistent-data/space-maps/core.h"
|
||||
#include "persistent-data/file_utils.h"
|
||||
#include "thin-provisioning/device_tree.h"
|
||||
#include "thin-provisioning/file_utils.h"
|
||||
#include "thin-provisioning/mapping_tree.h"
|
||||
#include "thin-provisioning/superblock.h"
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@ struct flags {
|
||||
};
|
||||
|
||||
namespace {
|
||||
int dump(string const &path, ostream *out, string const &format, struct flags &flags,
|
||||
block_address metadata_snap = 0) {
|
||||
int dump_(string const &path, ostream &out, string const &format, struct flags &flags,
|
||||
block_address metadata_snap) {
|
||||
try {
|
||||
metadata::ptr md(new metadata(path, metadata_snap));
|
||||
emitter::ptr e;
|
||||
@@ -56,9 +56,9 @@ namespace {
|
||||
}
|
||||
|
||||
if (format == "xml")
|
||||
e = create_xml_emitter(*out);
|
||||
e = create_xml_emitter(out);
|
||||
else if (format == "human_readable")
|
||||
e = create_human_readable_emitter(*out);
|
||||
e = create_human_readable_emitter(out);
|
||||
else {
|
||||
cerr << "unknown format '" << format << "'" << endl;
|
||||
exit(1);
|
||||
@@ -74,6 +74,15 @@ namespace {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dump(string const &path, char const *output, string const &format, struct flags &flags,
|
||||
block_address metadata_snap = 0) {
|
||||
if (output) {
|
||||
ofstream out(output);
|
||||
return dump_(path, out, format, flags, metadata_snap);
|
||||
} else
|
||||
return dump_(path, cout, format, flags, metadata_snap);
|
||||
}
|
||||
|
||||
void usage(ostream &out, string const &cmd) {
|
||||
out << "Usage: " << cmd << " [options] {device|file}" << endl
|
||||
<< "Options:" << endl
|
||||
@@ -154,5 +163,5 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
return dump(argv[optind], output ? new ofstream(output) : &cout, format, flags, metadata_snap);
|
||||
return dump(argv[optind], output, format, flags, metadata_snap);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "persistent-data/data-structures/btree_damage_visitor.h"
|
||||
#include "persistent-data/run.h"
|
||||
#include "persistent-data/space-maps/core.h"
|
||||
#include "thin-provisioning/file_utils.h"
|
||||
#include "persistent-data/file_utils.h"
|
||||
#include "thin-provisioning/superblock.h"
|
||||
#include "thin-provisioning/mapping_tree.h"
|
||||
#include "thin-provisioning/rmap_visitor.h"
|
||||
|
||||
Reference in New Issue
Block a user