]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osdc: Add Journaler.erase
authorJohn Spray <john.spray@inktank.com>
Tue, 6 May 2014 12:12:36 +0000 (13:12 +0100)
committerJohn Spray <john.spray@inktank.com>
Tue, 20 May 2014 13:07:50 +0000 (14:07 +0100)
This is used in subsequent commits to delete journals
that are no longer needed, such as after rewriting
a journal in a different format.

Signed-off-by: John Spray <john.spray@inktank.com>
src/osdc/Journaler.cc
src/osdc/Journaler.h

index d8bfeb5447533e26c024e920eeb0d15aebbe1333..912bcfd9b5d630711ec9eb138b77eed291ebb639 100644 (file)
@@ -915,7 +915,44 @@ bool Journaler::is_readable()
   return r;
 }
 
+class Journaler::C_EraseFinish : public Context {
+  Journaler *journaler;
+  Context *completion;
+  public:
+  C_EraseFinish(Journaler *j, Context *c) : journaler(j), completion(c) {}
+  void finish(int r) {
+    journaler->_erase_finish(r, completion);
+  }
+};
 
+/**
+ * Entirely erase the journal, including header.  For use when you
+ * have already made a copy of the journal somewhere else.
+ */
+void Journaler::erase(Context *completion)
+{
+  // Async delete the journal data
+  uint64_t first = trimmed_pos / get_layout_period();
+  uint64_t num = (write_pos - trimmed_pos) / get_layout_period() + 1;
+  filer.purge_range(ino, &layout, SnapContext(), first, num, ceph_clock_now(cct), 0,
+      new C_EraseFinish(this, completion));
+
+  // We will not start the operation to delete the header until _erase_finish has
+  // seen the data deletion succeed: otherwise if there was an error deleting data
+  // we might prematurely delete the header thereby lose our reference to the data.
+}
+
+void Journaler::_erase_finish(int data_result, Context *completion)
+{
+  if (data_result == 0) {
+    // Async delete the journal header
+    filer.purge_range(ino, &layout, SnapContext(), 0, 1, ceph_clock_now(cct), 0,
+        completion);
+  } else {
+    lderr(cct) << "Failed to delete journal " << ino << " data: " << cpp_strerror(data_result) << dendl;
+    completion->complete(data_result);
+  }
+}
 
 /* try_read_entry(bl)
  *  read entry into bl if it's ready.
index 670b4ad611c83842f6183c27cf1185a140a97f40..20b576ce8ffee9ad878748356135eafad4a3a7b2 100644 (file)
@@ -367,6 +367,13 @@ public:
     waiting_for_zero = false;
   }
 
+  void erase(Context *completion);
+private:
+  void _erase_finish(int data_result, Context *completion);
+  class C_EraseFinish;
+  friend class C_EraseFinish;
+
+public:
   void create(ceph_file_layout *layout);
   void recover(Context *onfinish);
   void reread_head(Context *onfinish);