[io_engine] Add exclusive flag to io_engine
This commit is contained in:
@@ -75,9 +75,11 @@ aio_engine::~aio_engine()
|
||||
}
|
||||
|
||||
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;
|
||||
if (s == EXCLUSIVE)
|
||||
flags |= O_EXCL;
|
||||
int fd = ::open(path.c_str(), O_DIRECT | flags);
|
||||
if (fd < 0) {
|
||||
ostringstream out;
|
||||
|
||||
@@ -27,12 +27,17 @@ namespace bcache {
|
||||
WRITE
|
||||
};
|
||||
|
||||
enum sharing {
|
||||
EXCLUSIVE,
|
||||
SHARED
|
||||
};
|
||||
|
||||
io_engine() {}
|
||||
virtual ~io_engine() {}
|
||||
|
||||
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;
|
||||
|
||||
// returns false if there are insufficient resources to
|
||||
@@ -79,8 +84,7 @@ namespace bcache {
|
||||
|
||||
using handle = unsigned;
|
||||
|
||||
// FIXME: open exclusive?
|
||||
virtual handle open_file(std::string const &path, mode m);
|
||||
virtual handle open_file(std::string const &path, mode m, sharing s = EXCLUSIVE);
|
||||
virtual void close_file(handle h);
|
||||
|
||||
// Returns false if queueing the io failed
|
||||
|
||||
Reference in New Issue
Block a user