[file_utils] rename get_nr_blocks() -> get_nr_metadata_blocks() and introduce get_nr_blocks()
This commit is contained in:
parent
c8276a41f7
commit
8676198e76
@ -8,11 +8,13 @@
|
||||
#include <unistd.h>
|
||||
|
||||
using namespace base;
|
||||
using namespace bcache;
|
||||
using namespace persistent_data;
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
persistent_data::block_address
|
||||
persistent_data::get_nr_blocks(string const &path)
|
||||
block_address
|
||||
persistent_data::get_nr_blocks(string const &path, block_address block_size)
|
||||
{
|
||||
using namespace persistent_data;
|
||||
|
||||
@ -24,7 +26,7 @@ persistent_data::get_nr_blocks(string const &path)
|
||||
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);
|
||||
nr_blocks = div_down<block_address>(info.st_size, block_size);
|
||||
|
||||
else if (S_ISBLK(info.st_mode)) {
|
||||
// To get the size of a block device we need to
|
||||
@ -39,7 +41,7 @@ persistent_data::get_nr_blocks(string const &path)
|
||||
throw runtime_error("ioctl BLKGETSIZE64 failed");
|
||||
}
|
||||
::close(fd);
|
||||
nr_blocks = div_down<block_address>(nr_blocks, MD_BLOCK_SIZE);
|
||||
nr_blocks = div_down<block_address>(nr_blocks, block_size);
|
||||
} else
|
||||
// FIXME: needs a better message
|
||||
throw runtime_error("bad path");
|
||||
@ -47,10 +49,16 @@ persistent_data::get_nr_blocks(string const &path)
|
||||
return nr_blocks;
|
||||
}
|
||||
|
||||
block_address
|
||||
persistent_data::get_nr_metadata_blocks(string const &path)
|
||||
{
|
||||
return get_nr_blocks(path, MD_BLOCK_SIZE);
|
||||
}
|
||||
|
||||
persistent_data::block_manager<>::ptr
|
||||
persistent_data::open_bm(std::string const &dev_path, block_manager<>::mode m, bool excl)
|
||||
{
|
||||
block_address nr_blocks = get_nr_blocks(dev_path);
|
||||
block_address nr_blocks = get_nr_metadata_blocks(dev_path);
|
||||
return block_manager<>::ptr(new block_manager<>(dev_path, nr_blocks, 1, m, excl));
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,9 @@
|
||||
|
||||
// FIXME: move to a different unit
|
||||
namespace persistent_data {
|
||||
persistent_data::block_address get_nr_blocks(string const &path);
|
||||
block_address get_nr_blocks(string const &path, block_address block_size);
|
||||
block_address get_nr_metadata_blocks(string const &path);
|
||||
|
||||
block_manager<>::ptr open_bm(std::string const &dev_path,
|
||||
block_manager<>::mode m, bool excl = true);
|
||||
|
||||
|
@ -43,7 +43,7 @@ using namespace thin_provisioning;
|
||||
namespace {
|
||||
block_manager<>::ptr
|
||||
open_bm(string const &path) {
|
||||
block_address nr_blocks = get_nr_blocks(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));
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ using namespace thin_provisioning;
|
||||
namespace {
|
||||
block_manager<>::ptr
|
||||
open_bm(string const &path) {
|
||||
block_address nr_blocks = get_nr_blocks(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));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user