From dba721f199fa225572a44b4619bf0da9310f7c9d Mon Sep 17 00:00:00 2001 From: John Spray Date: Tue, 6 May 2014 13:12:36 +0100 Subject: [PATCH] osdc: Add Journaler.erase 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 --- src/osdc/Journaler.cc | 37 +++++++++++++++++++++++++++++++++++++ src/osdc/Journaler.h | 7 +++++++ 2 files changed, 44 insertions(+) diff --git a/src/osdc/Journaler.cc b/src/osdc/Journaler.cc index d8bfeb5447533..912bcfd9b5d63 100644 --- a/src/osdc/Journaler.cc +++ b/src/osdc/Journaler.cc @@ -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. diff --git a/src/osdc/Journaler.h b/src/osdc/Journaler.h index 670b4ad611c83..20b576ce8ffee 100644 --- a/src/osdc/Journaler.h +++ b/src/osdc/Journaler.h @@ -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); -- 2.39.5