]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephfs-journal-tool: wait prezero ops before destroying journal 21610/head
authorYan, Zheng <zyan@redhat.com>
Tue, 24 Apr 2018 07:59:37 +0000 (15:59 +0800)
committerYan, Zheng <zyan@redhat.com>
Wed, 25 Apr 2018 06:58:35 +0000 (14:58 +0800)
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
src/osdc/Journaler.cc
src/osdc/Journaler.h
src/tools/cephfs/Resetter.cc

index 9ac942baa6a3e12592eda283294e5fad0604736d..63cf435e4c056663ff880abd1e5e8b8c30686498 100644 (file)
@@ -848,6 +848,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);
   }
@@ -857,6 +864,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 4caa65fdad08a823dd767326e3ae02a382d2cdab..0b8caa09ac7d7176d8089404899851e89ec5cd13 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 cbc9a353ce1bacec0cc853ab0e9f88134d5820ff..9573e6a6239e1b1f529ee40070078f6e2aa9c57c 100644 (file)
@@ -200,12 +200,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;
 }