From: Sage Weil Date: Wed, 27 Jan 2016 18:43:38 +0000 (-0500) Subject: os/bluestore/BlueFS: use std::mutex et al X-Git-Tag: v10.0.4~101^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b62318ea16d5830bb2b23b1a95ca39a5310fac34;p=ceph.git os/bluestore/BlueFS: use std::mutex et al Signed-off-by: Sage Weil --- diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc index e637ac7b736d..562d477b6c95 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -15,8 +15,7 @@ #define dout_prefix *_dout << "bluefs " BlueFS::BlueFS() - : lock("BlueFS::lock"), - ino_last(0), + : ino_last(0), log_seq(0), log_writer(NULL) { @@ -65,7 +64,7 @@ uint64_t BlueFS::get_block_device_size(unsigned id) void BlueFS::add_block_extent(unsigned id, uint64_t offset, uint64_t length) { - Mutex::Locker l(lock); + std::lock_guard l(lock); dout(1) << __func__ << " bdev " << id << " " << offset << "~" << length << dendl; assert(id < bdev.size()); @@ -107,7 +106,7 @@ int BlueFS::reclaim_blocks(unsigned id, uint64_t want, uint64_t BlueFS::get_total(unsigned id) { - Mutex::Locker l(lock); + std::lock_guard l(lock); assert(id < block_all.size()); uint64_t r = 0; interval_set& p = block_all[id]; @@ -119,14 +118,14 @@ uint64_t BlueFS::get_total(unsigned id) uint64_t BlueFS::get_free(unsigned id) { - Mutex::Locker l(lock); + std::lock_guard l(lock); assert(id < alloc.size()); return alloc[id]->get_free(); } void BlueFS::get_usage(vector> *usage) { - Mutex::Locker l(lock); + std::lock_guard l(lock); usage->resize(bdev.size()); for (unsigned id = 0; id < bdev.size(); ++id) { uint64_t total = 0; @@ -149,7 +148,7 @@ void BlueFS::get_usage(vector> *usage) int BlueFS::get_block_extents(unsigned id, interval_set *extents) { - Mutex::Locker l(lock); + std::lock_guard l(lock); dout(10) << __func__ << " bdev " << id << dendl; if (id >= block_all.size()) return -EINVAL; @@ -291,7 +290,7 @@ void BlueFS::umount() int BlueFS::fsck() { - Mutex::Locker l(lock); + std::lock_guard l(lock); dout(1) << __func__ << dendl; // hrm, i think we check everything on mount... return 0; @@ -1204,7 +1203,7 @@ int BlueFS::_preallocate(FileRef f, uint64_t off, uint64_t len) void BlueFS::sync_metadata() { - Mutex::Locker l(lock); + std::lock_guard l(lock); if (log_t.empty()) { dout(10) << __func__ << " - no pending log events" << dendl; return; @@ -1230,7 +1229,7 @@ int BlueFS::open_for_write( FileWriter **h, bool overwrite) { - Mutex::Locker l(lock); + std::lock_guard l(lock); dout(10) << __func__ << " " << dirname << "/" << filename << dendl; map::iterator p = dir_map.find(dirname); DirRef dir; @@ -1316,7 +1315,7 @@ int BlueFS::open_for_read( FileReader **h, bool random) { - Mutex::Locker l(lock); + std::lock_guard l(lock); dout(10) << __func__ << " " << dirname << "/" << filename << (random ? " (random)":" (sequential)") << dendl; map::iterator p = dir_map.find(dirname); @@ -1345,7 +1344,7 @@ int BlueFS::rename( const string& old_dirname, const string& old_filename, const string& new_dirname, const string& new_filename) { - Mutex::Locker l(lock); + std::lock_guard l(lock); dout(10) << __func__ << " " << old_dirname << "/" << old_filename << " -> " << new_dirname << "/" << new_filename << dendl; map::iterator p = dir_map.find(old_dirname); @@ -1392,7 +1391,7 @@ int BlueFS::rename( int BlueFS::mkdir(const string& dirname) { - Mutex::Locker l(lock); + std::lock_guard l(lock); dout(10) << __func__ << " " << dirname << dendl; map::iterator p = dir_map.find(dirname); if (p != dir_map.end()) { @@ -1406,7 +1405,7 @@ int BlueFS::mkdir(const string& dirname) int BlueFS::rmdir(const string& dirname) { - Mutex::Locker l(lock); + std::lock_guard l(lock); dout(10) << __func__ << " " << dirname << dendl; map::iterator p = dir_map.find(dirname); if (p == dir_map.end()) { @@ -1425,7 +1424,7 @@ int BlueFS::rmdir(const string& dirname) bool BlueFS::dir_exists(const string& dirname) { - Mutex::Locker l(lock); + std::lock_guard l(lock); map::iterator p = dir_map.find(dirname); bool exists = p != dir_map.end(); dout(10) << __func__ << " " << dirname << " = " << (int)exists << dendl; @@ -1435,7 +1434,7 @@ bool BlueFS::dir_exists(const string& dirname) int BlueFS::stat(const string& dirname, const string& filename, uint64_t *size, utime_t *mtime) { - Mutex::Locker l(lock); + std::lock_guard l(lock); dout(10) << __func__ << " " << dirname << "/" << filename << dendl; map::iterator p = dir_map.find(dirname); if (p == dir_map.end()) { @@ -1463,7 +1462,7 @@ int BlueFS::stat(const string& dirname, const string& filename, int BlueFS::lock_file(const string& dirname, const string& filename, FileLock **plock) { - Mutex::Locker l(lock); + std::lock_guard l(lock); dout(10) << __func__ << " " << dirname << "/" << filename << dendl; map::iterator p = dir_map.find(dirname); if (p == dir_map.end()) { @@ -1501,7 +1500,7 @@ int BlueFS::lock_file(const string& dirname, const string& filename, int BlueFS::unlock_file(FileLock *fl) { - Mutex::Locker l(lock); + std::lock_guard l(lock); dout(10) << __func__ << " " << fl << " on " << fl->file->fnode << dendl; assert(fl->file->locked); fl->file->locked = false; @@ -1511,7 +1510,7 @@ int BlueFS::unlock_file(FileLock *fl) int BlueFS::readdir(const string& dirname, vector *ls) { - Mutex::Locker l(lock); + std::lock_guard l(lock); dout(10) << __func__ << " " << dirname << dendl; if (dirname.size() == 0) { // list dirs @@ -1539,7 +1538,7 @@ int BlueFS::readdir(const string& dirname, vector *ls) int BlueFS::unlink(const string& dirname, const string& filename) { - Mutex::Locker l(lock); + std::lock_guard l(lock); dout(10) << __func__ << " " << dirname << "/" << filename << dendl; map::iterator p = dir_map.find(dirname); if (p == dir_map.end()) { diff --git a/src/os/bluestore/BlueFS.h b/src/os/bluestore/BlueFS.h index 474a63a97b68..0ade7a9ec30d 100644 --- a/src/os/bluestore/BlueFS.h +++ b/src/os/bluestore/BlueFS.h @@ -3,9 +3,9 @@ #ifndef CEPH_OS_BLUESTORE_BLUEFS_H #define CEPH_OS_BLUESTORE_BLUEFS_H +#include + #include "bluefs_types.h" -#include "common/Mutex.h" -#include "common/Cond.h" #include "common/RefCountedObj.h" #include "BlockDevice.h" @@ -75,13 +75,12 @@ public: 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 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) { @@ -156,8 +155,7 @@ public: }; private: - Mutex lock; - Cond cond; + std::mutex lock; // cache map dir_map; ///< dirname -> Dir @@ -277,7 +275,7 @@ public: bool random = false); void close_writer(FileWriter *h) { - Mutex::Locker l(lock); + std::lock_guard l(lock); _close_writer(h); } @@ -316,15 +314,15 @@ public: uint64_t *offset, uint32_t *length); void flush(FileWriter *h) { - Mutex::Locker l(lock); + std::lock_guard l(lock); _flush(h, false); } void flush_range(FileWriter *h, uint64_t offset, uint64_t length) { - Mutex::Locker l(lock); + std::lock_guard l(lock); _flush_range(h, offset, length); } void fsync(FileWriter *h) { - Mutex::Locker l(lock); + std::lock_guard l(lock); _fsync(h); } int read(FileReader *h, FileReaderBuffer *buf, uint64_t offset, size_t len, @@ -342,15 +340,15 @@ public: 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 l(lock); _invalidate_cache(f, offset, len); } int preallocate(FileRef f, uint64_t offset, uint64_t len) { - Mutex::Locker l(lock); + std::lock_guard l(lock); return _preallocate(f, offset, len); } int truncate(FileWriter *h, uint64_t offset) { - Mutex::Locker l(lock); + std::lock_guard l(lock); return _truncate(h, offset); }