]> git.proxmox.com Git - ceph.git/blame - ceph/src/tools/rbd_mirror/MirrorStatusWatcher.cc
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / tools / rbd_mirror / MirrorStatusWatcher.cc
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#include "MirrorStatusWatcher.h"
5#include "common/debug.h"
6#include "common/errno.h"
7#include "cls/rbd/cls_rbd_client.h"
8#include "librbd/Utils.h"
9
10#define dout_context g_ceph_context
11#define dout_subsys ceph_subsys_rbd_mirror
12#undef dout_prefix
13#define dout_prefix *_dout << "rbd::mirror::MirrorStatusWatcher: " \
14 << this << " " << __func__ << ": "
15
16namespace rbd {
17namespace mirror {
18
19using librbd::util::create_rados_callback;
20
21template <typename I>
22MirrorStatusWatcher<I>::MirrorStatusWatcher(librados::IoCtx &io_ctx,
23 ContextWQ *work_queue)
24 : Watcher(io_ctx, work_queue, RBD_MIRRORING) {
25}
26
27template <typename I>
28MirrorStatusWatcher<I>::~MirrorStatusWatcher() {
29}
30
31template <typename I>
32void MirrorStatusWatcher<I>::init(Context *on_finish) {
33 dout(20) << dendl;
34
35 on_finish = new FunctionContext(
36 [this, on_finish] (int r) {
37 if (r < 0) {
38 derr << "error removing down statuses: " << cpp_strerror(r) << dendl;
39 on_finish->complete(r);
40 return;
41 }
42 register_watch(on_finish);
43 });
44
45 librados::ObjectWriteOperation op;
46 librbd::cls_client::mirror_image_status_remove_down(&op);
47 librados::AioCompletion *aio_comp = create_rados_callback(on_finish);
48
49 int r = m_ioctx.aio_operate(RBD_MIRRORING, aio_comp, &op);
50 assert(r == 0);
51 aio_comp->release();
52}
53
54template <typename I>
55void MirrorStatusWatcher<I>::shut_down(Context *on_finish) {
56 dout(20) << dendl;
57
58 unregister_watch(on_finish);
59}
60
61template <typename I>
62void MirrorStatusWatcher<I>::handle_notify(uint64_t notify_id, uint64_t handle,
63 uint64_t notifier_id,
64 bufferlist &bl) {
65 dout(20) << dendl;
66
67 bufferlist out;
68 acknowledge_notify(notify_id, handle, out);
69}
70
71} // namespace mirror
72} // namespace rbd
73
74template class rbd::mirror::MirrorStatusWatcher<librbd::ImageCtx>;