]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore/BlueFS: use std::mutex et al
authorSage Weil <sage@redhat.com>
Wed, 27 Jan 2016 18:43:38 +0000 (13:43 -0500)
committerSage Weil <sage@redhat.com>
Wed, 27 Jan 2016 18:55:42 +0000 (13:55 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/os/bluestore/BlueFS.cc
src/os/bluestore/BlueFS.h

index e637ac7b736da6df6b2e1b28c400ad1e14f5eb8a..562d477b6c953bc30f7d633cb71a8f802dad5063 100644 (file)
@@ -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<std::mutex> 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<std::mutex> l(lock);
   assert(id < block_all.size());
   uint64_t r = 0;
   interval_set<uint64_t>& 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<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;
@@ -149,7 +148,7 @@ void BlueFS::get_usage(vector<pair<uint64_t,uint64_t>> *usage)
 
 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;
@@ -291,7 +290,7 @@ void BlueFS::umount()
 
 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;
@@ -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<std::mutex> 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<std::mutex> l(lock);
   dout(10) << __func__ << " " << dirname << "/" << filename << dendl;
   map<string,DirRef>::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<std::mutex> l(lock);
   dout(10) << __func__ << " " << dirname << "/" << filename
           << (random ? " (random)":" (sequential)") << dendl;
   map<string,DirRef>::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<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);
@@ -1392,7 +1391,7 @@ int BlueFS::rename(
 
 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()) {
@@ -1406,7 +1405,7 @@ int BlueFS::mkdir(const string& dirname)
 
 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()) {
@@ -1425,7 +1424,7 @@ int BlueFS::rmdir(const string& dirname)
 
 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;
@@ -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<std::mutex> l(lock);
   dout(10) << __func__ << " " << dirname << "/" << filename << dendl;
   map<string,DirRef>::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<std::mutex> l(lock);
   dout(10) << __func__ << " " << dirname << "/" << filename << dendl;
   map<string,DirRef>::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<std::mutex> 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<string> *ls)
 {
-  Mutex::Locker l(lock);
+  std::lock_guard<std::mutex> l(lock);
   dout(10) << __func__ << " " << dirname << dendl;
   if (dirname.size() == 0) {
     // list dirs
@@ -1539,7 +1538,7 @@ int BlueFS::readdir(const string& dirname, vector<string> *ls)
 
 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()) {
index 474a63a97b682e0be6a0aa7c47fe62d53b97a349..0ade7a9ec30d522d265f3e5f06af99ee0da075fb 100644 (file)
@@ -3,9 +3,9 @@
 #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"
 
@@ -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<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) {
@@ -156,8 +155,7 @@ public:
   };
 
 private:
-  Mutex lock;
-  Cond cond;
+  std::mutex lock;
 
   // cache
   map<string, DirRef> dir_map;                    ///< dirname -> Dir
@@ -277,7 +275,7 @@ public:
     bool random = false);
 
   void close_writer(FileWriter *h) {
-    Mutex::Locker l(lock);
+    std::lock_guard<std::mutex> 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<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,
@@ -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<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);
   }