]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: move journal tag decode helpers to shared location
authorJason Dillaman <dillaman@redhat.com>
Tue, 18 Oct 2016 02:44:55 +0000 (22:44 -0400)
committerJason Dillaman <dillaman@redhat.com>
Mon, 31 Oct 2016 14:57:14 +0000 (10:57 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/CMakeLists.txt
src/librbd/Journal.cc
src/librbd/journal/Utils.cc [new file with mode: 0644]
src/librbd/journal/Utils.h [new file with mode: 0644]

index 68f3f461c7e1ad69039127f633a7676c6c5b6360..7f2d863c18fa774e3a4395d1cb0188c42cca3211 100644 (file)
@@ -1,6 +1,6 @@
 add_library(rbd_types STATIC
   journal/Types.cc
-  mirroring_watcher/Types.cc 
+  mirroring_watcher/Types.cc
   WatchNotifyTypes.cc)
 
 set(librbd_internal_srcs
@@ -22,9 +22,9 @@ set(librbd_internal_srcs
   Journal.cc
   LibrbdAdminSocketHook.cc
   LibrbdWriteback.cc
-  MirroringWatcher.cc 
+  MirroringWatcher.cc
   ObjectMap.cc
-  ObjectWatcher.cc 
+  ObjectWatcher.cc
   Operations.cc
   Utils.cc
   cache/ImageWriteback.cc
@@ -47,6 +47,7 @@ set(librbd_internal_srcs
   journal/CreateRequest.cc
   journal/Replay.cc
   journal/StandardPolicy.cc
+  journal/Utils.cc
   mirror/DisableRequest.cc
   mirror/EnableRequest.cc
   object_map/CreateRequest.cc
index a0ebe8f5a8f74bcbed817f552c234cd52431bcfe..999c26b9a9510b45f1be8f8e69aa083cbb8da1d6 100644 (file)
@@ -12,6 +12,7 @@
 #include "journal/Policy.h"
 #include "journal/ReplayEntry.h"
 #include "journal/Settings.h"
+#include "journal/Utils.h"
 #include "common/errno.h"
 #include "common/Timer.h"
 #include "common/WorkQueue.h"
 
 namespace librbd {
 
-namespace {
-
-struct C_DecodeTag : public Context {
-  CephContext *cct;
-  Mutex *lock;
-  uint64_t *tag_tid;
-  journal::TagData *tag_data;
-  Context *on_finish;
-
-  cls::journal::Tag tag;
-
-  C_DecodeTag(CephContext *cct, Mutex *lock, uint64_t *tag_tid,
-              journal::TagData *tag_data, Context *on_finish)
-    : cct(cct), lock(lock), tag_tid(tag_tid), tag_data(tag_data),
-      on_finish(on_finish) {
-  }
-
-  virtual void complete(int r) override {
-    on_finish->complete(process(r));
-    Context::complete(0);
-  }
-  virtual void finish(int r) override {
-  }
-
-  int process(int r) {
-    if (r < 0) {
-      lderr(cct) << this << " " << __func__ << ": "
-                 << "failed to allocate tag: " << cpp_strerror(r) << dendl;
-      return r;
-    }
-
-    Mutex::Locker locker(*lock);
-    *tag_tid = tag.tid;
-
-    bufferlist::iterator data_it = tag.data.begin();
-    r = decode(&data_it, tag_data);
-    if (r < 0) {
-      lderr(cct) << this << " " << __func__ << ": "
-                 << "failed to decode allocated tag" << dendl;
-      return r;
-    }
-
-    ldout(cct, 20) << this << " " << __func__ << ": "
-                   << "allocated journal tag: "
-                   << "tid=" << tag.tid << ", "
-                   << "data=" << *tag_data << dendl;
-    return 0;
-  }
-
-  static int decode(bufferlist::iterator *it,
-                    journal::TagData *tag_data) {
-    try {
-      ::decode(*tag_data, *it);
-    } catch (const buffer::error &err) {
-      return -EBADMSG;
-    }
-    return 0;
-  }
-
-};
-
-struct C_DecodeTags : public Context {
-  CephContext *cct;
-  Mutex *lock;
-  uint64_t *tag_tid;
-  journal::TagData *tag_data;
-  Context *on_finish;
-
-  ::journal::Journaler::Tags tags;
-
-  C_DecodeTags(CephContext *cct, Mutex *lock, uint64_t *tag_tid,
-               journal::TagData *tag_data, Context *on_finish)
-    : cct(cct), lock(lock), tag_tid(tag_tid), tag_data(tag_data),
-      on_finish(on_finish) {
-  }
-
-  virtual void complete(int r) {
-    on_finish->complete(process(r));
-    Context::complete(0);
-  }
-  virtual void finish(int r) override {
-  }
-
-  int process(int r) {
-    if (r < 0) {
-      lderr(cct) << this << " " << __func__ << ": "
-                 << "failed to retrieve journal tags: " << cpp_strerror(r)
-                 << dendl;
-      return r;
-    }
-
-    if (tags.empty()) {
-      lderr(cct) << this << " " << __func__ << ": "
-                 << "no journal tags retrieved" << dendl;
-      return -ENOENT;
-    }
-
-    Mutex::Locker locker(*lock);
-    *tag_tid = tags.back().tid;
-
-    bufferlist::iterator data_it = tags.back().data.begin();
-    r = C_DecodeTag::decode(&data_it, tag_data);
-    if (r < 0) {
-      lderr(cct) << this << " " << __func__ << ": "
-                 << "failed to decode journal tag" << dendl;
-      return r;
-    }
+using util::create_async_context_callback;
+using util::create_context_callback;
+using journal::util::C_DecodeTag;
+using journal::util::C_DecodeTags;
 
-    ldout(cct, 20) << this << " " << __func__ << ": "
-                   << "most recent journal tag: "
-                   << "tid=" << *tag_tid << ", "
-                   << "data=" << *tag_data << dendl;
-    return 0;
-  }
-};
+namespace {
 
 // TODO: once journaler is 100% async, remove separate threads and
 // reuse ImageCtx's thread pool
@@ -391,9 +283,6 @@ int allocate_journaler_tag(CephContext *cct, J *journaler,
 
 } // anonymous namespace
 
-using util::create_async_context_callback;
-using util::create_context_callback;
-
 // client id for local image
 template <typename I>
 const std::string Journal<I>::IMAGE_CLIENT_ID("");
diff --git a/src/librbd/journal/Utils.cc b/src/librbd/journal/Utils.cc
new file mode 100644 (file)
index 0000000..e1888f0
--- /dev/null
@@ -0,0 +1,85 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "librbd/journal/Utils.h"
+#include "common/dout.h"
+#include "common/errno.h"
+#include "librbd/journal/Types.h"
+
+#define dout_subsys ceph_subsys_rbd
+#undef dout_prefix
+#define dout_prefix *_dout << "librbd::journal::"
+
+namespace librbd {
+namespace journal {
+namespace util {
+
+int C_DecodeTag::decode(bufferlist::iterator *it, TagData *tag_data) {
+  try {
+    ::decode(*tag_data, *it);
+  } catch (const buffer::error &err) {
+    return -EBADMSG;
+  }
+  return 0;
+}
+
+int C_DecodeTag::process(int r) {
+  if (r < 0) {
+    lderr(cct) << "C_DecodeTag: " << this << " " << __func__ << ": "
+               << "failed to allocate tag: " << cpp_strerror(r)
+        << dendl;
+    return r;
+  }
+
+  Mutex::Locker locker(*lock);
+  *tag_tid = tag.tid;
+
+  bufferlist::iterator data_it = tag.data.begin();
+  r = decode(&data_it, tag_data);
+  if (r < 0) {
+    lderr(cct) << "C_DecodeTag: " << this << " " << __func__ << ": "
+               << "failed to decode allocated tag" << dendl;
+    return r;
+  }
+
+  ldout(cct, 20) << "C_DecodeTag: " << this << " " << __func__ << ": "
+                 << "allocated journal tag: "
+                 << "tid=" << tag.tid << ", "
+                 << "data=" << *tag_data << dendl;
+  return 0;
+}
+
+int C_DecodeTags::process(int r) {
+  if (r < 0) {
+    lderr(cct) << "C_DecodeTags: " << this << " " << __func__ << ": "
+               << "failed to retrieve journal tags: " << cpp_strerror(r)
+               << dendl;
+    return r;
+  }
+
+  if (tags.empty()) {
+    lderr(cct) << "C_DecodeTags: " << this << " " << __func__ << ": "
+               << "no journal tags retrieved" << dendl;
+    return -ENOENT;
+  }
+
+  Mutex::Locker locker(*lock);
+  *tag_tid = tags.back().tid;
+  bufferlist::iterator data_it = tags.back().data.begin();
+  r = C_DecodeTag::decode(&data_it, tag_data);
+  if (r < 0) {
+    lderr(cct) << "C_DecodeTags: " << this << " " << __func__ << ": "
+               << "failed to decode journal tag" << dendl;
+    return r;
+  }
+
+  ldout(cct, 20) << "C_DecodeTags: " << this << " " << __func__ << ": "
+                 << "most recent journal tag: "
+                 << "tid=" << *tag_tid << ", "
+                 << "data=" << *tag_data << dendl;
+  return 0;
+}
+
+} // namespace util
+} // namespace journal
+} // namespace librbd
diff --git a/src/librbd/journal/Utils.h b/src/librbd/journal/Utils.h
new file mode 100644 (file)
index 0000000..7ce4852
--- /dev/null
@@ -0,0 +1,81 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#ifndef CEPH_LIBRBD_JOURNAL_UTILS_H
+#define CEPH_LIBRBD_JOURNAL_UTILS_H
+
+#include "include/int_types.h"
+#include "include/Context.h"
+#include "cls/journal/cls_journal_types.h"
+#include <list>
+
+struct CephContext;
+struct Mutex;
+
+namespace librbd {
+namespace journal {
+
+struct TagData;
+
+namespace util {
+
+struct C_DecodeTag : public Context {
+  CephContext *cct;
+  Mutex *lock;
+  uint64_t *tag_tid;
+  TagData *tag_data;
+  Context *on_finish;
+
+  cls::journal::Tag tag;
+
+  C_DecodeTag(CephContext *cct, Mutex *lock, uint64_t *tag_tid,
+              TagData *tag_data, Context *on_finish)
+    : cct(cct), lock(lock), tag_tid(tag_tid), tag_data(tag_data),
+      on_finish(on_finish) {
+  }
+
+  virtual void complete(int r) override {
+    on_finish->complete(process(r));
+    Context::complete(0);
+  }
+  virtual void finish(int r) override {
+  }
+
+  int process(int r);
+
+  static int decode(bufferlist::iterator *it, TagData *tag_data);
+
+};
+
+struct C_DecodeTags : public Context {
+  typedef std::list<cls::journal::Tag> Tags;
+
+  CephContext *cct;
+  Mutex *lock;
+  uint64_t *tag_tid;
+  TagData *tag_data;
+  Context *on_finish;
+
+  Tags tags;
+
+  C_DecodeTags(CephContext *cct, Mutex *lock, uint64_t *tag_tid,
+               TagData *tag_data, Context *on_finish)
+    : cct(cct), lock(lock), tag_tid(tag_tid), tag_data(tag_data),
+      on_finish(on_finish) {
+  }
+
+  virtual void complete(int r) {
+    on_finish->complete(process(r));
+    Context::complete(0);
+  }
+  virtual void finish(int r) override {
+  }
+
+  int process(int r);
+};
+
+} // namespace util
+} // namespace journal
+} // namespace librbd
+
+#endif // CEPH_LIBRBD_JOURNAL_UTILS_H