#define dout_prefix *_dout << "bluefs "
BlueFS::BlueFS()
- : lock("BlueFS::lock"),
- ino_last(0),
+ : ino_last(0),
log_seq(0),
log_writer(NULL)
{
void BlueFS::add_block_extent(unsigned id, uint64_t offset, uint64_t length)
{
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
dout(1) << __func__ << " bdev " << id << " " << offset << "~" << length
<< dendl;
assert(id < bdev.size());
uint64_t BlueFS::get_total(unsigned id)
{
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
assert(id < block_all.size());
uint64_t r = 0;
interval_set<uint64_t>& p = block_all[id];
uint64_t BlueFS::get_free(unsigned id)
{
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
assert(id < alloc.size());
return alloc[id]->get_free();
}
void BlueFS::get_usage(vector<pair<uint64_t,uint64_t>> *usage)
{
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
usage->resize(bdev.size());
for (unsigned id = 0; id < bdev.size(); ++id) {
uint64_t total = 0;
int BlueFS::get_block_extents(unsigned id, interval_set<uint64_t> *extents)
{
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
dout(10) << __func__ << " bdev " << id << dendl;
if (id >= block_all.size())
return -EINVAL;
int BlueFS::fsck()
{
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
dout(1) << __func__ << dendl;
// hrm, i think we check everything on mount...
return 0;
void BlueFS::sync_metadata()
{
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
if (log_t.empty()) {
dout(10) << __func__ << " - no pending log events" << dendl;
return;
FileWriter **h,
bool overwrite)
{
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
dout(10) << __func__ << " " << dirname << "/" << filename << dendl;
map<string,DirRef>::iterator p = dir_map.find(dirname);
DirRef dir;
FileReader **h,
bool random)
{
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
dout(10) << __func__ << " " << dirname << "/" << filename
<< (random ? " (random)":" (sequential)") << dendl;
map<string,DirRef>::iterator p = dir_map.find(dirname);
const string& old_dirname, const string& old_filename,
const string& new_dirname, const string& new_filename)
{
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
dout(10) << __func__ << " " << old_dirname << "/" << old_filename
<< " -> " << new_dirname << "/" << new_filename << dendl;
map<string,DirRef>::iterator p = dir_map.find(old_dirname);
int BlueFS::mkdir(const string& dirname)
{
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
dout(10) << __func__ << " " << dirname << dendl;
map<string,DirRef>::iterator p = dir_map.find(dirname);
if (p != dir_map.end()) {
int BlueFS::rmdir(const string& dirname)
{
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
dout(10) << __func__ << " " << dirname << dendl;
map<string,DirRef>::iterator p = dir_map.find(dirname);
if (p == dir_map.end()) {
bool BlueFS::dir_exists(const string& dirname)
{
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
map<string,DirRef>::iterator p = dir_map.find(dirname);
bool exists = p != dir_map.end();
dout(10) << __func__ << " " << dirname << " = " << (int)exists << dendl;
int BlueFS::stat(const string& dirname, const string& filename,
uint64_t *size, utime_t *mtime)
{
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
dout(10) << __func__ << " " << dirname << "/" << filename << dendl;
map<string,DirRef>::iterator p = dir_map.find(dirname);
if (p == dir_map.end()) {
int BlueFS::lock_file(const string& dirname, const string& filename,
FileLock **plock)
{
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
dout(10) << __func__ << " " << dirname << "/" << filename << dendl;
map<string,DirRef>::iterator p = dir_map.find(dirname);
if (p == dir_map.end()) {
int BlueFS::unlock_file(FileLock *fl)
{
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
dout(10) << __func__ << " " << fl << " on " << fl->file->fnode << dendl;
assert(fl->file->locked);
fl->file->locked = false;
int BlueFS::readdir(const string& dirname, vector<string> *ls)
{
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
dout(10) << __func__ << " " << dirname << dendl;
if (dirname.size() == 0) {
// list dirs
int BlueFS::unlink(const string& dirname, const string& filename)
{
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
dout(10) << __func__ << " " << dirname << "/" << filename << dendl;
map<string,DirRef>::iterator p = dir_map.find(dirname);
if (p == dir_map.end()) {
#ifndef CEPH_OS_BLUESTORE_BLUEFS_H
#define CEPH_OS_BLUESTORE_BLUEFS_H
+#include <mutex>
+
#include "bluefs_types.h"
-#include "common/Mutex.h"
-#include "common/Cond.h"
#include "common/RefCountedObj.h"
#include "BlockDevice.h"
bufferlist buffer; ///< new data to write (at end of file)
bufferlist tail_block; ///< existing partial block at end of file, if any
- Mutex lock;
+ std::mutex lock;
vector<IOContext*> iocv; ///< one for each bdev
FileWriter(FileRef f, unsigned num_bdev)
: file(f),
- pos(0),
- lock("BlueFS::FileWriter::lock") {
+ pos(0) {
file->num_writers.inc();
iocv.resize(num_bdev);
for (unsigned i = 0; i < num_bdev; ++i) {
};
private:
- Mutex lock;
- Cond cond;
+ std::mutex lock;
// cache
map<string, DirRef> dir_map; ///< dirname -> Dir
bool random = false);
void close_writer(FileWriter *h) {
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
_close_writer(h);
}
uint64_t *offset, uint32_t *length);
void flush(FileWriter *h) {
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
_flush(h, false);
}
void flush_range(FileWriter *h, uint64_t offset, uint64_t length) {
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
_flush_range(h, offset, length);
}
void fsync(FileWriter *h) {
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
_fsync(h);
}
int read(FileReader *h, FileReaderBuffer *buf, uint64_t offset, size_t len,
return _read_random(h, offset, len, out);
}
void invalidate_cache(FileRef f, uint64_t offset, uint64_t len) {
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
_invalidate_cache(f, offset, len);
}
int preallocate(FileRef f, uint64_t offset, uint64_t len) {
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
return _preallocate(f, offset, len);
}
int truncate(FileWriter *h, uint64_t offset) {
- Mutex::Locker l(lock);
+ std::lock_guard<std::mutex> l(lock);
return _truncate(h, offset);
}