Introduce a mode enum to block_io<>
This commit is contained in:
parent
2b86309961
commit
779f8e1fd4
@ -82,8 +82,12 @@ namespace persistent_data {
|
||||
class block_io : private boost::noncopyable {
|
||||
public:
|
||||
typedef boost::shared_ptr<block_io> ptr;
|
||||
enum mode {
|
||||
READ_ONLY,
|
||||
READ_WRITE,
|
||||
};
|
||||
|
||||
block_io(std::string const &path, block_address nr_blocks, bool writeable = false);
|
||||
block_io(std::string const &path, block_address nr_blocks, mode m);
|
||||
~block_io();
|
||||
|
||||
block_address get_nr_blocks() const {
|
||||
@ -96,6 +100,7 @@ namespace persistent_data {
|
||||
private:
|
||||
int fd_;
|
||||
block_address nr_blocks_;
|
||||
mode mode_;
|
||||
bool writeable_;
|
||||
};
|
||||
|
||||
@ -107,7 +112,7 @@ namespace persistent_data {
|
||||
block_manager(std::string const &path,
|
||||
block_address nr_blocks,
|
||||
unsigned max_concurrent_locks,
|
||||
bool writeable = false);
|
||||
typename block_io<BlockSize>::mode m);
|
||||
|
||||
class validator {
|
||||
public:
|
||||
|
@ -36,12 +36,28 @@ using namespace std;
|
||||
//----------------------------------------------------------------
|
||||
|
||||
template <uint32_t BlockSize>
|
||||
block_io<BlockSize>::block_io(std::string const &path, block_address nr_blocks, bool writeable)
|
||||
block_io<BlockSize>::block_io(std::string const &path, block_address nr_blocks, mode m)
|
||||
: nr_blocks_(nr_blocks),
|
||||
writeable_(writeable)
|
||||
mode_(m)
|
||||
{
|
||||
int fd_mode = O_DIRECT | O_SYNC;
|
||||
|
||||
switch (m) {
|
||||
case READ_ONLY:
|
||||
fd_mode |= O_RDONLY;
|
||||
break;
|
||||
|
||||
case READ_WRITE:
|
||||
fd_mode |= O_RDWR;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw runtime_error("unsupported mode");
|
||||
break;
|
||||
}
|
||||
|
||||
// fd_ = ::open(path.c_str(), writeable ? (O_RDWR | O_CREAT) : O_RDONLY, 0666);
|
||||
fd_ = ::open(path.c_str(), O_DIRECT | O_SYNC | (writeable ? O_RDWR : O_RDONLY), 0666);
|
||||
fd_ = ::open(path.c_str(), fd_mode, 0666);
|
||||
if (fd_ < 0)
|
||||
throw std::runtime_error("couldn't open file");
|
||||
}
|
||||
@ -237,8 +253,8 @@ template <uint32_t BlockSize>
|
||||
block_manager<BlockSize>::block_manager(std::string const &path,
|
||||
block_address nr_blocks,
|
||||
unsigned max_concurrent_blocks,
|
||||
bool writeable)
|
||||
: io_(new block_io<BlockSize>(path, nr_blocks, writeable)),
|
||||
typename block_io<BlockSize>::mode mode)
|
||||
: io_(new block_io<BlockSize>(path, nr_blocks, mode)),
|
||||
cache_(max(64u, max_concurrent_blocks)),
|
||||
tracker_(0, nr_blocks)
|
||||
{
|
||||
|
@ -91,7 +91,11 @@ namespace {
|
||||
transaction_manager::ptr
|
||||
open_tm(string const &dev_path, bool writeable) {
|
||||
block_address nr_blocks = get_nr_blocks(dev_path);
|
||||
block_manager<>::ptr bm(new block_manager<>(dev_path, nr_blocks, 1, writeable));
|
||||
typename block_io<>::mode m = writeable ?
|
||||
block_io<>::READ_WRITE :
|
||||
block_io<>::READ_ONLY;
|
||||
|
||||
block_manager<>::ptr bm(new block_manager<>(dev_path, nr_blocks, 1, m));
|
||||
space_map::ptr sm(new core_map(nr_blocks));
|
||||
sm->inc(SUPERBLOCK_LOCATION);
|
||||
transaction_manager::ptr tm(new transaction_manager(bm, sm));
|
||||
|
Loading…
Reference in New Issue
Block a user