]>
Commit | Line | Data |
---|---|---|
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 "common/dout.h" | |
5 | #include "common/errno.h" | |
6 | #include "common/Timer.h" | |
7c673cae | 7 | #include "journal/Settings.h" |
11fdf7f2 | 8 | #include "include/ceph_assert.h" |
7c673cae FG |
9 | #include "librbd/Utils.h" |
10 | #include "librbd/journal/RemoveRequest.h" | |
11 | ||
12 | #define dout_subsys ceph_subsys_rbd | |
13 | #undef dout_prefix | |
14 | #define dout_prefix *_dout << "librbd::Journal::RemoveRequest: " | |
15 | ||
16 | namespace librbd { | |
17 | ||
18 | using util::create_context_callback; | |
19 | ||
20 | namespace journal { | |
21 | ||
22 | template<typename I> | |
23 | RemoveRequest<I>::RemoveRequest(IoCtx &ioctx, const std::string &image_id, | |
24 | const std::string &client_id, | |
25 | ContextWQ *op_work_queue, | |
26 | Context *on_finish) | |
27 | : m_ioctx(ioctx), m_image_id(image_id), m_image_client_id(client_id), | |
28 | m_op_work_queue(op_work_queue), m_on_finish(on_finish) { | |
29 | m_cct = reinterpret_cast<CephContext *>(m_ioctx.cct()); | |
30 | } | |
31 | ||
32 | template<typename I> | |
33 | void RemoveRequest<I>::send() { | |
34 | ldout(m_cct, 20) << this << " " << __func__ << dendl; | |
35 | ||
36 | stat_journal(); | |
37 | } | |
38 | ||
39 | template<typename I> | |
40 | void RemoveRequest<I>::stat_journal() { | |
41 | ldout(m_cct, 20) << this << " " << __func__ << dendl; | |
42 | ||
43 | ImageCtx::get_timer_instance(m_cct, &m_timer, &m_timer_lock); | |
9f95a23c TL |
44 | m_journaler = new Journaler(m_op_work_queue, m_timer, m_timer_lock, m_ioctx, |
45 | m_image_id, m_image_client_id, {}, nullptr); | |
7c673cae FG |
46 | |
47 | using klass = RemoveRequest<I>; | |
48 | Context *ctx = create_context_callback<klass, &klass::handle_stat_journal>(this); | |
49 | ||
50 | m_journaler->exists(ctx); | |
51 | } | |
52 | ||
53 | template<typename I> | |
54 | Context *RemoveRequest<I>::handle_stat_journal(int *result) { | |
55 | ldout(m_cct, 20) << __func__ << ": r=" << *result << dendl; | |
56 | ||
57 | if ((*result < 0) && (*result != -ENOENT)) { | |
58 | lderr(m_cct) << "failed to stat journal header: " << cpp_strerror(*result) << dendl; | |
59 | shut_down_journaler(*result); | |
60 | return nullptr; | |
61 | } | |
62 | ||
63 | if (*result == -ENOENT) { | |
64 | shut_down_journaler(0); | |
65 | return nullptr; | |
66 | } | |
67 | ||
68 | init_journaler(); | |
69 | return nullptr; | |
70 | } | |
71 | ||
72 | template<typename I> | |
73 | void RemoveRequest<I>::init_journaler() { | |
74 | ldout(m_cct, 20) << this << " " << __func__ << dendl; | |
75 | ||
76 | using klass = RemoveRequest<I>; | |
77 | Context *ctx = create_context_callback<klass, &klass::handle_init_journaler>(this); | |
78 | ||
79 | m_journaler->init(ctx); | |
80 | } | |
81 | ||
82 | template<typename I> | |
83 | Context *RemoveRequest<I>::handle_init_journaler(int *result) { | |
84 | ldout(m_cct, 20) << __func__ << ": r=" << *result << dendl; | |
85 | ||
86 | if ((*result < 0) && (*result != -ENOENT)) { | |
87 | lderr(m_cct) << "failed to init journaler: " << cpp_strerror(*result) << dendl; | |
88 | shut_down_journaler(*result); | |
89 | return nullptr; | |
90 | } | |
91 | ||
92 | remove_journal(); | |
93 | return nullptr; | |
94 | } | |
95 | ||
96 | template<typename I> | |
97 | void RemoveRequest<I>::remove_journal() { | |
98 | ldout(m_cct, 20) << this << " " << __func__ << dendl; | |
99 | ||
100 | using klass = RemoveRequest<I>; | |
101 | Context *ctx = create_context_callback<klass, &klass::handle_remove_journal>(this); | |
102 | ||
103 | m_journaler->remove(true, ctx); | |
104 | } | |
105 | ||
106 | template<typename I> | |
107 | Context *RemoveRequest<I>::handle_remove_journal(int *result) { | |
108 | ldout(m_cct, 20) << __func__ << ": r=" << *result << dendl; | |
109 | ||
110 | if (*result < 0) { | |
111 | lderr(m_cct) << "failed to remove journal: " << cpp_strerror(*result) << dendl; | |
112 | } | |
113 | ||
114 | shut_down_journaler(*result); | |
115 | return nullptr; | |
116 | } | |
117 | ||
118 | template<typename I> | |
119 | void RemoveRequest<I>::shut_down_journaler(int r) { | |
120 | ldout(m_cct, 20) << this << " " << __func__ << dendl; | |
121 | ||
122 | m_r_saved = r; | |
123 | ||
124 | using klass = RemoveRequest<I>; | |
125 | Context *ctx = create_context_callback<klass, &klass::handle_journaler_shutdown>(this); | |
126 | ||
127 | m_journaler->shut_down(ctx); | |
128 | } | |
129 | ||
130 | template<typename I> | |
131 | Context *RemoveRequest<I>::handle_journaler_shutdown(int *result) { | |
132 | ldout(m_cct, 20) << __func__ << ": r=" << *result << dendl; | |
133 | ||
134 | if (*result < 0) { | |
135 | lderr(m_cct) << "failed to shut down journaler: " << cpp_strerror(*result) << dendl; | |
136 | } | |
137 | ||
138 | delete m_journaler; | |
139 | ||
140 | if (m_r_saved == 0) { | |
141 | ldout(m_cct, 20) << "done." << dendl; | |
142 | } | |
143 | ||
144 | m_on_finish->complete(m_r_saved); | |
145 | delete this; | |
146 | ||
147 | return nullptr; | |
148 | } | |
149 | ||
150 | } // namespace journal | |
151 | } // namespace librbd | |
152 | ||
153 | template class librbd::journal::RemoveRequest<librbd::ImageCtx>; |