]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
tools/cephfs: s/Mutex/ceph::mutex/
authorKefu Chai <kchai@redhat.com>
Sun, 7 Jul 2019 04:44:47 +0000 (12:44 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 3 Aug 2019 03:27:20 +0000 (11:27 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/tools/cephfs/Dumper.cc
src/tools/cephfs/MDSUtility.cc
src/tools/cephfs/MDSUtility.h
src/tools/cephfs/Resetter.cc

index 6b7584978918eeee6445b9a7e6141fbe6bbe65b0..fbfa6ae8fff52600756be66c8f46b6cccb3fa515 100644 (file)
@@ -67,9 +67,9 @@ int Dumper::init(mds_role_t role_, const std::string &type)
 int Dumper::recover_journal(Journaler *journaler)
 {
   C_SaferCond cond;
-  lock.Lock();
+  lock.lock();
   journaler->recover(&cond);
-  lock.Unlock();
+  lock.unlock();
   const int r = cond.wait();
 
   if (r < 0) { // Error
@@ -155,10 +155,10 @@ int Dumper::dump(const char *dump_file)
       const uint32_t read_size = std::min<uint64_t>(chunk_size, end - pos);
 
       C_SaferCond cond;
-      lock.Lock();
+      lock.lock();
       filer.read(ino, &journaler.get_layout(), CEPH_NOSNAP,
                  pos, read_size, &bl, 0, &cond);
-      lock.Unlock();
+      lock.unlock();
       r = cond.wait();
       if (r < 0) {
         derr << "Error " << r << " (" << cpp_strerror(r) << ") reading "
@@ -339,11 +339,11 @@ int Dumper::undump(const char *dump_file, bool force)
 
   cout << "writing header " << oid << std::endl;
   C_SaferCond header_cond;
-  lock.Lock();
+  lock.lock();
   objecter->write_full(oid, oloc, snapc, hbl,
                       ceph::real_clock::now(), 0,
                       &header_cond);
-  lock.Unlock();
+  lock.unlock();
 
   r = header_cond.wait();
   if (r != 0) {
@@ -373,10 +373,10 @@ int Dumper::undump(const char *dump_file, bool force)
     }
     C_SaferCond purge_cond;
     cout << "Purging " << purge_count << " objects from " << last_obj << std::endl;
-    lock.Lock();
+    lock.lock();
     filer.purge_range(ino, &h.layout, snapc, last_obj, purge_count,
                      ceph::real_clock::now(), 0, &purge_cond);
-    lock.Unlock();
+    lock.unlock();
     purge_cond.wait();
   }
   /* When the length is zero, zero the last object 
@@ -388,9 +388,9 @@ int Dumper::undump(const char *dump_file, bool force)
     C_SaferCond zero_cond;
     cout << "Zeroing " << len << " bytes in the last object." << std::endl;
     
-    lock.Lock();
+    lock.lock();
     filer.zero(ino, &h.layout, snapc, h.write_pos, len, ceph::real_clock::now(), 0, &zero_cond);
-    lock.Unlock();
+    lock.unlock();
     zero_cond.wait();
   }
 
@@ -407,10 +407,10 @@ int Dumper::undump(const char *dump_file, bool force)
     // Write
     cout << " writing " << pos << "~" << l << std::endl;
     C_SaferCond write_cond;
-    lock.Lock();
+    lock.lock();
     filer.write(ino, &h.layout, snapc, pos, l, j,
                ceph::real_clock::now(), 0, &write_cond);
-    lock.Unlock();
+    lock.unlock();
 
     r = write_cond.wait();
     if (r != 0) {
index 6e71d21a29ca9ba9a65d987043631ea1f69d6041..839b4aea0502d25bea0d20be00670367d58e7049 100644 (file)
@@ -21,7 +21,6 @@
 MDSUtility::MDSUtility() :
   Dispatcher(g_ceph_context),
   objecter(NULL),
-  lock("MDSUtility::lock"),
   finisher(g_ceph_context, "MDSUtility", "fn_mds_utility"),
   waiting_for_mds_map(NULL),
   inited(false)
@@ -91,22 +90,22 @@ int MDSUtility::init()
   objecter->wait_for_osd_map();
 
   // Prepare to receive MDS map and request it
-  Mutex init_lock("MDSUtility:init");
-  Cond cond;
+  ceph::mutex init_lock = ceph::make_mutex("MDSUtility:init");
+  ceph::condition_variable cond;
   bool done = false;
   ceph_assert(!fsmap->get_epoch());
-  lock.Lock();
-  waiting_for_mds_map = new C_SafeCond(&init_lock, &cond, &done, NULL);
-  lock.Unlock();
+  lock.lock();
+  waiting_for_mds_map = new C_SafeCond(init_lock, cond, &done, NULL);
+  lock.unlock();
   monc->sub_want("fsmap", 0, CEPH_SUBSCRIBE_ONETIME);
   monc->renew_subs();
 
   // Wait for MDS map
   dout(4) << "waiting for MDS map..." << dendl;
-  init_lock.Lock();
-  while (!done)
-    cond.Wait(init_lock);
-  init_lock.Unlock();
+  {
+    std::unique_lock locker{init_lock};
+    cond.wait(locker, [&done] { return done; });
+  }
   dout(4) << "Got MDS map " << fsmap->get_epoch() << dendl;
 
   finisher.start();
@@ -120,9 +119,9 @@ void MDSUtility::shutdown()
 {
   finisher.stop();
 
-  lock.Lock();
+  lock.lock();
   objecter->shutdown();
-  lock.Unlock();
+  lock.unlock();
   monc->shutdown();
   messenger->shutdown();
   messenger->wait();
@@ -131,7 +130,7 @@ void MDSUtility::shutdown()
 
 bool MDSUtility::ms_dispatch(Message *m)
 {
-   Mutex::Locker locker(lock);
+  std::lock_guard locker{lock};
    switch (m->get_type()) {
    case CEPH_MSG_FS_MAP:
      handle_fs_map((MFSMap*)m);
index 8ffc32f7a5c1585197bacc22eb9d31f5be8a4961..e5097ec48fe25dd7d90a550885b259e09c3c88c3 100644 (file)
@@ -36,7 +36,7 @@ protected:
   Messenger *messenger;
   MonClient *monc;
 
-  Mutex lock;
+  ceph::mutex lock = ceph::make_mutex("MDSUtility::lock");
   Finisher finisher;
 
   Context *waiting_for_mds_map;
index 8ab134f8d61235bff7e0be3f2e82dfa48a43aec7..278a48767cdfd0f73090e5532b2a4eeb5780a788 100644 (file)
@@ -71,8 +71,8 @@ int Resetter::init(mds_role_t role_, const std::string &type, bool hard)
 
 int Resetter::reset()
 {
-  Mutex mylock("Resetter::reset::lock");
-  Cond cond;
+  ceph::mutex mylock = ceph::make_mutex("Resetter::reset::lock");
+  ceph::condition_variable cond;
   bool done;
   int r;
 
@@ -83,16 +83,14 @@ int Resetter::reset()
       fs->mds_map.get_metadata_pool(),
       CEPH_FS_ONDISK_MAGIC,
       objecter, 0, 0, &finisher);
-
-  lock.Lock();
-  journaler.recover(new C_SafeCond(&mylock, &cond, &done, &r));
-  lock.Unlock();
-
-  mylock.Lock();
-  while (!done)
-    cond.Wait(mylock);
-  mylock.Unlock();
-
+  {
+    std::lock_guard locker{lock};
+    journaler.recover(new C_SafeCond(mylock, cond, &done, &r));
+  }
+  {
+    std::unique_lock locker{mylock};
+    cond.wait(locker, [&done] { return done; });
+  }
   if (r != 0) {
     if (r == -ENOENT) {
       cerr << "journal does not exist on-disk. Did you set a bad rank?"
@@ -106,7 +104,7 @@ int Resetter::reset()
     }
   }
 
-  lock.Lock();
+  lock.lock();
   uint64_t old_start = journaler.get_read_pos();
   uint64_t old_end = journaler.get_write_pos();
   uint64_t old_len = old_end - old_start;
@@ -123,15 +121,13 @@ int Resetter::reset()
   journaler.set_writeable();
 
   cout << "writing journal head" << std::endl;
-  journaler.write_head(new C_SafeCond(&mylock, &cond, &done, &r));
-  lock.Unlock();
-
-  mylock.Lock();
-  while (!done)
-    cond.Wait(mylock);
-  mylock.Unlock();
-
-  Mutex::Locker l(lock);
+  journaler.write_head(new C_SafeCond(mylock, cond, &done, &r));
+  lock.unlock();
+  {
+    std::unique_lock locker{mylock};
+    cond.wait(locker, [&done] { return done; });
+  }
+  std::lock_guard l{lock};
   if (r != 0) {
     return r;
   }
@@ -163,7 +159,7 @@ int Resetter::reset_hard()
 
   C_SaferCond cond;
   {
-    Mutex::Locker l(lock);
+    std::lock_guard l{lock};
     journaler.write_head(&cond);
   }
   
@@ -175,7 +171,7 @@ int Resetter::reset_hard()
   
   if (is_mdlog) // reset event is specific for mdlog journal
   {
-    Mutex::Locker l(lock);
+    std::lock_guard l{lock};
     r = _write_reset_event(&journaler);
     if (r != 0) {
       derr << "Error writing EResetJournal: " << cpp_strerror(r) << dendl;