]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mds: use Journaler getters
authorPatrick Donnelly <pdonnell@redhat.com>
Wed, 28 Aug 2024 03:07:00 +0000 (23:07 -0400)
committerPatrick Donnelly <pdonnell@redhat.com>
Wed, 25 Sep 2024 19:42:26 +0000 (15:42 -0400)
To access the Journaler::Header safely.

Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
src/mds/PurgeQueue.cc
src/osdc/Journaler.h
src/tools/cephfs/Dumper.cc

index 639c7e85277a60b9d81fd67b4754d459a5e76118..594e8db87f862403167d0dc6f7640ca93fbbe96f 100644 (file)
@@ -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);
index 4e2db0c97b7dcab72a7e2244ed75523db65e63cf..5e1677de7c04d7eb0968b8c4849f27ba2b1d2aef 100644 (file)
@@ -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);
index 2253ebc6cb7c75705065547cc843f6dbb2770076..b9f66360d66d7c35b20c0af3effeea73295da848 100644 (file)
@@ -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")) {