[io_engine] Add exclusive flag to io_engine
This commit is contained in:
parent
df9f4d479d
commit
07f44e9c77
@ -75,9 +75,11 @@ aio_engine::~aio_engine()
|
|||||||
}
|
}
|
||||||
|
|
||||||
aio_engine::handle
|
aio_engine::handle
|
||||||
aio_engine::open_file(std::string const &path, mode m)
|
aio_engine::open_file(std::string const &path, mode m, sharing s)
|
||||||
{
|
{
|
||||||
int flags = (m == READ_ONLY) ? O_RDONLY : O_RDWR;
|
int flags = (m == READ_ONLY) ? O_RDONLY : O_RDWR;
|
||||||
|
if (s == EXCLUSIVE)
|
||||||
|
flags |= O_EXCL;
|
||||||
int fd = ::open(path.c_str(), O_DIRECT | flags);
|
int fd = ::open(path.c_str(), O_DIRECT | flags);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
ostringstream out;
|
ostringstream out;
|
||||||
|
@ -27,12 +27,17 @@ namespace bcache {
|
|||||||
WRITE
|
WRITE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum sharing {
|
||||||
|
EXCLUSIVE,
|
||||||
|
SHARED
|
||||||
|
};
|
||||||
|
|
||||||
io_engine() {}
|
io_engine() {}
|
||||||
virtual ~io_engine() {}
|
virtual ~io_engine() {}
|
||||||
|
|
||||||
using handle = unsigned;
|
using handle = unsigned;
|
||||||
|
|
||||||
virtual handle open_file(std::string const &path, mode m) = 0;
|
virtual handle open_file(std::string const &path, mode m, sharing s = EXCLUSIVE) = 0;
|
||||||
virtual void close_file(handle h) = 0;
|
virtual void close_file(handle h) = 0;
|
||||||
|
|
||||||
// returns false if there are insufficient resources to
|
// returns false if there are insufficient resources to
|
||||||
@ -79,8 +84,7 @@ namespace bcache {
|
|||||||
|
|
||||||
using handle = unsigned;
|
using handle = unsigned;
|
||||||
|
|
||||||
// FIXME: open exclusive?
|
virtual handle open_file(std::string const &path, mode m, sharing s = EXCLUSIVE);
|
||||||
virtual handle open_file(std::string const &path, mode m);
|
|
||||||
virtual void close_file(handle h);
|
virtual void close_file(handle h);
|
||||||
|
|
||||||
// Returns false if queueing the io failed
|
// Returns false if queueing the io failed
|
||||||
|
@ -33,7 +33,7 @@ using namespace testing;
|
|||||||
namespace {
|
namespace {
|
||||||
class io_engine_mock : public io_engine {
|
class io_engine_mock : public io_engine {
|
||||||
public:
|
public:
|
||||||
MOCK_METHOD2(open_file, handle(string const &, mode));
|
MOCK_METHOD3(open_file, handle(string const &, mode, sharing));
|
||||||
MOCK_METHOD1(close_file, void(handle));
|
MOCK_METHOD1(close_file, void(handle));
|
||||||
MOCK_METHOD6(issue_io, bool(handle, dir, sector_t, sector_t, void *, unsigned));
|
MOCK_METHOD6(issue_io, bool(handle, dir, sector_t, sector_t, void *, unsigned));
|
||||||
|
|
||||||
@ -51,9 +51,9 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<copier> make_copier() {
|
unique_ptr<copier> make_copier() {
|
||||||
EXPECT_CALL(engine_, open_file(src_file_, io_engine::READ_ONLY)).
|
EXPECT_CALL(engine_, open_file(src_file_, io_engine::READ_ONLY, io_engine::EXCLUSIVE)).
|
||||||
WillOnce(Return(SRC_HANDLE));
|
WillOnce(Return(SRC_HANDLE));
|
||||||
EXPECT_CALL(engine_, open_file(dest_file_, io_engine::READ_WRITE)).
|
EXPECT_CALL(engine_, open_file(dest_file_, io_engine::READ_WRITE, io_engine::EXCLUSIVE)).
|
||||||
WillOnce(Return(DEST_HANDLE));
|
WillOnce(Return(DEST_HANDLE));
|
||||||
|
|
||||||
EXPECT_CALL(engine_, close_file(SRC_HANDLE)).Times(1);
|
EXPECT_CALL(engine_, close_file(SRC_HANDLE)).Times(1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user