From b3025914374ddde29d3bb0e70214ac86288e5075 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Tue, 27 Aug 2024 23:07:00 -0400 Subject: [PATCH] mds: use Journaler getters To access the Journaler::Header safely. Signed-off-by: Patrick Donnelly --- src/mds/PurgeQueue.cc | 8 +++++--- src/osdc/Journaler.h | 15 +++++++++++++-- src/tools/cephfs/Dumper.cc | 24 +++++++++++++----------- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/mds/PurgeQueue.cc b/src/mds/PurgeQueue.cc index 639c7e85277a6..594e8db87f862 100644 --- a/src/mds/PurgeQueue.cc +++ b/src/mds/PurgeQueue.cc @@ -225,9 +225,10 @@ void PurgeQueue::open(Context *completion) // Journaler only guarantees entries before head write_pos have been // fully flushed. Before appending new entries, we need to find and // drop any partial written entry. - if (journaler.last_committed.write_pos < journaler.get_write_pos()) { + auto&& last_committed = journaler.get_last_committed(); + if (last_committed.write_pos < journaler.get_write_pos()) { dout(4) << "recovering write_pos" << dendl; - journaler.set_read_pos(journaler.last_committed.write_pos); + journaler.set_read_pos(last_committed.write_pos); _recover(); return; } @@ -281,7 +282,8 @@ void PurgeQueue::_recover() if (journaler.get_read_pos() == journaler.get_write_pos()) { dout(4) << "write_pos recovered" << dendl; // restore original read_pos - journaler.set_read_pos(journaler.last_committed.expire_pos); + auto&& last_committed = journaler.get_last_committed(); + journaler.set_read_pos(last_committed.expire_pos); journaler.set_writeable(); recovered = true; finish_contexts(g_ceph_context, waiting_for_recovery); diff --git a/src/osdc/Journaler.h b/src/osdc/Journaler.h index 4e2db0c97b7dc..5e1677de7c04d 100644 --- a/src/osdc/Journaler.h +++ b/src/osdc/Journaler.h @@ -217,10 +217,9 @@ public: return stream_format; } - Header last_committed; - private: // me + Header last_committed; CephContext *cct; mutable ceph::mutex lock; const std::string name; @@ -528,6 +527,18 @@ public: // Synchronous getters // =================== + + Header get_last_committed() const { + ceph_assert(!ceph_mutex_is_locked_by_me(lock)); + lock_guard l(lock); + return last_committed; + } + Header get_last_written() const { + ceph_assert(!ceph_mutex_is_locked_by_me(lock)); + lock_guard l(lock); + return last_written; + } + uint64_t get_layout_period() const { ceph_assert(!ceph_mutex_is_locked_by_me(lock)); lock_guard l(lock); diff --git a/src/tools/cephfs/Dumper.cc b/src/tools/cephfs/Dumper.cc index 2253ebc6cb7c7..b9f66360d66d7 100644 --- a/src/tools/cephfs/Dumper.cc +++ b/src/tools/cephfs/Dumper.cc @@ -112,6 +112,7 @@ int Dumper::dump(const char *dump_file) fsid.print(fsid_str); char buf[HEADER_LEN]; memset(buf, 0, sizeof(buf)); + auto&& last_committed = journaler.get_last_committed(); snprintf(buf, HEADER_LEN, "Ceph mds%d journal dump\n start offset %llu (0x%llx)\n\ length %llu (0x%llx)\n write_pos %llu (0x%llx)\n format %llu\n\ trimmed_pos %llu (0x%llx)\n stripe_unit %lu (0x%lx)\n stripe_count %lu (0x%lx)\n\ @@ -119,12 +120,12 @@ int Dumper::dump(const char *dump_file) role.rank, (unsigned long long)start, (unsigned long long)start, (unsigned long long)len, (unsigned long long)len, - (unsigned long long)journaler.last_committed.write_pos, (unsigned long long)journaler.last_committed.write_pos, - (unsigned long long)journaler.last_committed.stream_format, - (unsigned long long)journaler.last_committed.trimmed_pos, (unsigned long long)journaler.last_committed.trimmed_pos, - (unsigned long)journaler.last_committed.layout.stripe_unit, (unsigned long)journaler.last_committed.layout.stripe_unit, - (unsigned long)journaler.last_committed.layout.stripe_count, (unsigned long)journaler.last_committed.layout.stripe_count, - (unsigned long)journaler.last_committed.layout.object_size, (unsigned long)journaler.last_committed.layout.object_size, + (unsigned long long)last_committed.write_pos, (unsigned long long)last_committed.write_pos, + (unsigned long long)last_committed.stream_format, + (unsigned long long)last_committed.trimmed_pos, (unsigned long long)last_committed.trimmed_pos, + (unsigned long)last_committed.layout.stripe_unit, (unsigned long)last_committed.layout.stripe_unit, + (unsigned long)last_committed.layout.stripe_count, (unsigned long)last_committed.layout.stripe_count, + (unsigned long)last_committed.layout.object_size, (unsigned long)last_committed.layout.object_size, fsid_str, 4); r = safe_write(fd, buf, sizeof(buf)); @@ -156,8 +157,8 @@ int Dumper::dump(const char *dump_file) C_SaferCond cond; lock.lock(); - filer.read(ino, &journaler.get_layout(), CEPH_NOSNAP, - pos, read_size, &bl, 0, &cond); + auto&& layout = journaler.get_layout(); + filer.read(ino, &layout, CEPH_NOSNAP, pos, read_size, &bl, 0, &cond); lock.unlock(); r = cond.wait(); if (r < 0) { @@ -264,9 +265,10 @@ int Dumper::undump(const char *dump_file, bool force) } if (recovered == 0) { - stripe_unit = journaler.last_committed.layout.stripe_unit; - stripe_count = journaler.last_committed.layout.stripe_count; - object_size = journaler.last_committed.layout.object_size; + auto&& last_committed = journaler.get_last_committed(); + stripe_unit = last_committed.layout.stripe_unit; + stripe_count = last_committed.layout.stripe_count; + object_size = last_committed.layout.object_size; } else { // try to get layout from dump file header, if failed set layout to default if (strstr(buf, "stripe_unit")) { -- 2.39.5