add_library(rbd_types STATIC
journal/Types.cc
- mirroring_watcher/Types.cc
+ mirroring_watcher/Types.cc
WatchNotifyTypes.cc)
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
journal/CreateRequest.cc
journal/Replay.cc
journal/StandardPolicy.cc
+ journal/Utils.cc
mirror/DisableRequest.cc
mirror/EnableRequest.cc
object_map/CreateRequest.cc
#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
} // 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("");
--- /dev/null
+// -*- 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
--- /dev/null
+// -*- 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