From de29be73c043c0cd49b4d35a160ddd3910d423e8 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Mon, 9 May 2016 18:17:49 -0400 Subject: [PATCH] librbd: Journal no longer requires AioCompletion for IO events Signed-off-by: Jason Dillaman (cherry picked from commit 82587a31f1d8ba1765f164391796753cf97a1878) --- src/librbd/AioImageRequest.cc | 10 +++----- src/librbd/Journal.cc | 20 ++++++--------- src/librbd/Journal.h | 17 +++++-------- src/test/librbd/journal/test_Replay.cc | 4 +-- src/test/librbd/test_mock_Journal.cc | 35 +++++++++++++++----------- 5 files changed, 41 insertions(+), 45 deletions(-) diff --git a/src/librbd/AioImageRequest.cc b/src/librbd/AioImageRequest.cc index 5a1904b8cb30c..4739b08da931f 100644 --- a/src/librbd/AioImageRequest.cc +++ b/src/librbd/AioImageRequest.cc @@ -318,9 +318,8 @@ uint64_t AioImageWrite::append_journal_event( bufferlist bl; bl.append(m_buf, m_len); - uint64_t tid = m_image_ctx.journal->append_write_event(m_aio_comp, m_off, - m_len, bl, requests, - synchronous); + uint64_t tid = m_image_ctx.journal->append_write_event(m_off, m_len, bl, + requests, synchronous); if (m_image_ctx.object_cacher == NULL) { m_aio_comp->associate_journal_event(tid); } @@ -378,8 +377,7 @@ void AioImageWrite::update_stats(size_t length) { uint64_t AioImageDiscard::append_journal_event( const AioObjectRequests &requests, bool synchronous) { journal::EventEntry event_entry(journal::AioDiscardEvent(m_off, m_len)); - uint64_t tid = m_image_ctx.journal->append_io_event(m_aio_comp, - std::move(event_entry), + uint64_t tid = m_image_ctx.journal->append_io_event(std::move(event_entry), requests, m_off, m_len, synchronous); m_aio_comp->associate_journal_event(tid); @@ -452,7 +450,7 @@ void AioImageFlush::send_request() { if (journaling) { // in-flight ops are flushed prior to closing the journal uint64_t journal_tid = m_image_ctx.journal->append_io_event( - m_aio_comp, journal::EventEntry(journal::AioFlushEvent()), + journal::EventEntry(journal::AioFlushEvent()), AioObjectRequests(), 0, 0, false); C_FlushJournalCommit *ctx = new C_FlushJournalCommit(m_image_ctx, diff --git a/src/librbd/Journal.cc b/src/librbd/Journal.cc index ebd1f246eef0c..855ea3d2882de 100644 --- a/src/librbd/Journal.cc +++ b/src/librbd/Journal.cc @@ -2,7 +2,6 @@ // vim: ts=8 sw=2 smarttab #include "librbd/Journal.h" -#include "librbd/AioCompletion.h" #include "librbd/AioImageRequestWQ.h" #include "librbd/AioObjectRequest.h" #include "librbd/ExclusiveLock.h" @@ -802,8 +801,7 @@ void Journal::flush_commit_position(Context *on_finish) { } template -uint64_t Journal::append_write_event(AioCompletion *aio_comp, - uint64_t offset, size_t length, +uint64_t Journal::append_write_event(uint64_t offset, size_t length, const bufferlist &bl, const AioObjectRequests &requests, bool flush_entry) { @@ -833,13 +831,12 @@ uint64_t Journal::append_write_event(AioCompletion *aio_comp, bytes_remaining -= event_length; } while (bytes_remaining > 0); - return append_io_events(aio_comp, journal::EVENT_TYPE_AIO_WRITE, bufferlists, - requests, offset, length, flush_entry); + return append_io_events(journal::EVENT_TYPE_AIO_WRITE, bufferlists, requests, + offset, length, flush_entry); } template -uint64_t Journal::append_io_event(AioCompletion *aio_comp, - journal::EventEntry &&event_entry, +uint64_t Journal::append_io_event(journal::EventEntry &&event_entry, const AioObjectRequests &requests, uint64_t offset, size_t length, bool flush_entry) { @@ -847,13 +844,12 @@ uint64_t Journal::append_io_event(AioCompletion *aio_comp, bufferlist bl; ::encode(event_entry, bl); - return append_io_events(aio_comp, event_entry.get_event_type(), {bl}, - requests, offset, length, flush_entry); + return append_io_events(event_entry.get_event_type(), {bl}, requests, offset, + length, flush_entry); } template -uint64_t Journal::append_io_events(AioCompletion *aio_comp, - journal::EventType event_type, +uint64_t Journal::append_io_events(journal::EventType event_type, const Bufferlists &bufferlists, const AioObjectRequests &requests, uint64_t offset, size_t length, @@ -875,7 +871,7 @@ uint64_t Journal::append_io_events(AioCompletion *aio_comp, assert(bl.length() <= m_max_append_size); futures.push_back(m_journaler->append(m_tag_tid, bl)); } - m_events[tid] = Event(futures, aio_comp, requests, offset, length); + m_events[tid] = Event(futures, requests, offset, length); } CephContext *cct = m_image_ctx.cct; diff --git a/src/librbd/Journal.h b/src/librbd/Journal.h index 48fe9a2e00723..3d36b28b40249 100644 --- a/src/librbd/Journal.h +++ b/src/librbd/Journal.h @@ -30,7 +30,6 @@ class Journaler; namespace librbd { -class AioCompletion; class AioObjectRequest; class ImageCtx; @@ -129,13 +128,11 @@ public: void flush_commit_position(Context *on_finish); - uint64_t append_write_event(AioCompletion *aio_comp, - uint64_t offset, size_t length, + uint64_t append_write_event(uint64_t offset, size_t length, const bufferlist &bl, const AioObjectRequests &requests, bool flush_entry); - uint64_t append_io_event(AioCompletion *aio_comp, - journal::EventEntry &&event_entry, + uint64_t append_io_event(journal::EventEntry &&event_entry, const AioObjectRequests &requests, uint64_t offset, size_t length, bool flush_entry); @@ -176,7 +173,6 @@ private: struct Event { Futures futures; - AioCompletion *aio_comp = nullptr; AioObjectRequests aio_object_requests; Contexts on_safe_contexts; ExtentInterval pending_extents; @@ -186,9 +182,9 @@ private: Event() { } - Event(const Futures &_futures, AioCompletion *_aio_comp, - const AioObjectRequests &_requests, uint64_t offset, size_t length) - : futures(_futures), aio_comp(_aio_comp), aio_object_requests(_requests) { + Event(const Futures &_futures, const AioObjectRequests &_requests, + uint64_t offset, size_t length) + : futures(_futures), aio_object_requests(_requests) { if (length > 0) { pending_extents.insert(offset, length); } @@ -290,8 +286,7 @@ private: journal::Replay *m_journal_replay; - uint64_t append_io_events(AioCompletion *aio_comp, - journal::EventType event_type, + uint64_t append_io_events(journal::EventType event_type, const Bufferlists &bufferlists, const AioObjectRequests &requests, uint64_t offset, size_t length, bool flush_entry); diff --git a/src/test/librbd/journal/test_Replay.cc b/src/test/librbd/journal/test_Replay.cc index f7e20f71c5a28..cbde9ae72bdf6 100644 --- a/src/test/librbd/journal/test_Replay.cc +++ b/src/test/librbd/journal/test_Replay.cc @@ -47,8 +47,8 @@ public: librbd::Journal<>::AioObjectRequests requests; { RWLock::RLocker owner_locker(ictx->owner_lock); - ictx->journal->append_io_event(NULL, std::move(event_entry), requests, 0, - 0, true); + ictx->journal->append_io_event(std::move(event_entry), requests, 0, 0, + true); } } diff --git a/src/test/librbd/test_mock_Journal.cc b/src/test/librbd/test_mock_Journal.cc index 53a6fa8632d05..1a912a7abe8a1 100644 --- a/src/test/librbd/test_mock_Journal.cc +++ b/src/test/librbd/test_mock_Journal.cc @@ -9,6 +9,8 @@ #include "common/Mutex.h" #include "cls/journal/cls_journal_types.h" #include "journal/Journaler.h" +#include "librbd/AioCompletion.h" +#include "librbd/AioObjectRequest.h" #include "librbd/Journal.h" #include "librbd/Utils.h" #include "librbd/journal/Replay.h" @@ -296,10 +298,15 @@ public: uint64_t when_append_io_event(MockJournalImageCtx &mock_image_ctx, MockJournal &mock_journal, - AioCompletion *aio_comp = nullptr) { + AioObjectRequest *object_request = nullptr) { RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + MockJournal::AioObjectRequests object_requests; + if (object_request != nullptr) { + object_requests.push_back(object_request); + } return mock_journal.append_io_event( - aio_comp, journal::EventEntry{journal::AioFlushEvent{}}, {}, 0, 0, false); + journal::EventEntry{journal::AioFlushEvent{}}, object_requests, 0, 0, + false); } void save_commit_context(Context *ctx) { @@ -878,21 +885,21 @@ TEST_F(TestMockJournal, EventCommitError) { close_journal(mock_journal, mock_journaler); }; - AioCompletion *comp = new AioCompletion(); - comp->get(); + C_SaferCond object_request_ctx; + AioObjectRemove *object_request = new AioObjectRemove( + ictx, "oid", 0, {}, &object_request_ctx); ::journal::MockFuture mock_future; Context *on_journal_safe; expect_append_journaler(mock_journaler); expect_wait_future(mock_future, &on_journal_safe); - ASSERT_EQ(1U, when_append_io_event(mock_image_ctx, mock_journal, comp)); + ASSERT_EQ(1U, when_append_io_event(mock_image_ctx, mock_journal, + object_request)); // commit the event in the journal w/o waiting writeback expect_future_committed(mock_journaler); on_journal_safe->complete(-EINVAL); - ASSERT_EQ(0, comp->wait_for_complete()); - ASSERT_EQ(-EINVAL, comp->get_return_value()); - comp->put(); + ASSERT_EQ(-EINVAL, object_request_ctx.wait()); // cache should receive the error after attempting writeback expect_future_is_valid(mock_future); @@ -917,14 +924,16 @@ TEST_F(TestMockJournal, EventCommitErrorWithPendingWriteback) { close_journal(mock_journal, mock_journaler); }; - AioCompletion *comp = new AioCompletion(); - comp->get(); + C_SaferCond object_request_ctx; + AioObjectRemove *object_request = new AioObjectRemove( + ictx, "oid", 0, {}, &object_request_ctx); ::journal::MockFuture mock_future; Context *on_journal_safe; expect_append_journaler(mock_journaler); expect_wait_future(mock_future, &on_journal_safe); - ASSERT_EQ(1U, when_append_io_event(mock_image_ctx, mock_journal, comp)); + ASSERT_EQ(1U, when_append_io_event(mock_image_ctx, mock_journal, + object_request)); expect_future_is_valid(mock_future); C_SaferCond flush_ctx; @@ -933,9 +942,7 @@ TEST_F(TestMockJournal, EventCommitErrorWithPendingWriteback) { // commit the event in the journal w/ waiting cache writeback expect_future_committed(mock_journaler); on_journal_safe->complete(-EINVAL); - ASSERT_EQ(0, comp->wait_for_complete()); - ASSERT_EQ(-EINVAL, comp->get_return_value()); - comp->put(); + ASSERT_EQ(-EINVAL, object_request_ctx.wait()); // cache should receive the error if waiting ASSERT_EQ(-EINVAL, flush_ctx.wait()); -- 2.39.5