]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephfs-journal-tool: wait prezero ops before destroying journal 21874/head
authorYan, Zheng <zyan@redhat.com>
Tue, 24 Apr 2018 07:59:37 +0000 (15:59 +0800)
committerPrashant D <pdhange@redhat.com>
Tue, 8 May 2018 03:05:05 +0000 (23:05 -0400)
There still can be pending prezero requests after Journal::flush()
return. We should wait until all prezero requests are done, then
destroy the on-stack journaler.

Signed-off-by: "Yan, Zheng" <zyan@redhat.com>
Fixes: http://tracker.ceph.com/issues/20549
(cherry picked from commit 9299a1ceb607199d2ea09662ee1ef280a7b9f920)

src/osdc/Journaler.cc
src/osdc/Journaler.h
src/tools/cephfs/Resetter.cc

index 94386101a1d34326216d4ed0fbada085c692d2a5..8ca0c4b27188eddf8db2856db60ebb1fcb3bade4 100644 (file)
@@ -853,6 +853,13 @@ void Journaler::_finish_prezero(int r, uint64_t start, uint64_t len)
     if (waiting_for_zero_pos > flush_pos) {
       _do_flush(waiting_for_zero_pos - flush_pos);
     }
+
+    if (prezero_pos == prezeroing_pos &&
+       !waitfor_prezero.empty()) {
+      list<Context*> ls;
+      ls.swap(waitfor_prezero);
+      finish_contexts(cct, ls, 0);
+    }
   } else {
     pending_zero.insert(start, len);
   }
@@ -862,6 +869,17 @@ void Journaler::_finish_prezero(int r, uint64_t start, uint64_t len)
                 << dendl;
 }
 
+void Journaler::wait_for_prezero(Context *onfinish)
+{
+  assert(onfinish);
+  lock_guard l(lock);
+
+  if (prezero_pos == prezeroing_pos) {
+    finisher->queue(onfinish, 0);
+    return;
+  }
+  waitfor_prezero.push_back(wrap_finisher(onfinish));
+}
 
 
 /***************** READING *******************/
index d65419a652be45bdf675bf799f81ca3306484bb8..521752017529ee33a1f2e525418285d574683890 100644 (file)
@@ -312,6 +312,8 @@ private:
 
   uint64_t waiting_for_zero_pos;
   interval_set<uint64_t> pending_zero;  // non-contig bits we've zeroed
+  list<Context*> waitfor_prezero;
+
   std::map<uint64_t, uint64_t> pending_safe; // flush_pos -> safe_pos
   // when safe through given offset
   std::map<uint64_t, std::list<Context*> > waitfor_safe;
@@ -459,6 +461,7 @@ public:
   void flush(Context *onsafe = 0);
   void wait_for_readable(Context *onfinish);
   bool have_waiter() const;
+  void wait_for_prezero(Context *onfinish);
 
   // Synchronous setters
   // ===================
index 58465c2ffc79ed3458afe2d90a5cf1f58ddee8cf..7741db44352b3a1e7a56f98085940b939d2a679f 100644 (file)
@@ -170,12 +170,25 @@ int Resetter::_write_reset_event(Journaler *journaler)
 
   bufferlist bl;
   le->encode_with_header(bl, CEPH_FEATURES_SUPPORTED_DEFAULT);
-  
+
   cout << "writing EResetJournal entry" << std::endl;
-  C_SaferCond cond;
   journaler->append_entry(bl);
-  journaler->flush(&cond);
 
-  return cond.wait();
+  int ret;
+  {
+    C_SaferCond cond;
+    journaler->flush(&cond);
+    ret = cond.wait();
+    if (ret < 0)
+      return ret;
+  }
+  {
+    // wait until all journal prezero ops are done
+    C_SaferCond cond;
+    journaler->wait_for_prezero(&cond);
+    cond.wait();
+  }
+
+  return ret;
 }