-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rbd-mirror: load/update/remove image map state machines
Signed-off-by: Venky Shankar <vshankar@redhat.com>
- Loading branch information
Showing
7 changed files
with
481 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- | ||
// vim: ts=8 sw=2 smarttab | ||
|
||
#include "common/debug.h" | ||
#include "common/errno.h" | ||
|
||
#include "librbd/Utils.h" | ||
#include "include/rbd_types.h" | ||
#include "cls/rbd/cls_rbd_client.h" | ||
|
||
#include "LoadRequest.h" | ||
|
||
#define dout_context g_ceph_context | ||
#define dout_subsys ceph_subsys_rbd_mirror | ||
#undef dout_prefix | ||
#define dout_prefix *_dout << "rbd::mirror::image_map::LoadRequest: " \ | ||
<< this << " " << __func__ | ||
|
||
namespace rbd { | ||
namespace mirror { | ||
namespace image_map { | ||
|
||
static const uint32_t MAX_RETURN = 1024; | ||
|
||
using librbd::util::create_rados_callback; | ||
|
||
template<typename I> | ||
LoadRequest<I>::LoadRequest(librados::IoCtx &ioctx, | ||
std::map<std::string, cls::rbd::MirrorImageMap> *image_map, | ||
Context *on_finish) | ||
: m_ioctx(ioctx), | ||
m_image_map(image_map), | ||
m_on_finish(on_finish) { | ||
} | ||
|
||
template<typename I> | ||
void LoadRequest<I>::send() { | ||
dout(20) << dendl; | ||
|
||
image_map_list(); | ||
} | ||
|
||
template<typename I> | ||
void LoadRequest<I>::image_map_list() { | ||
dout(20) << dendl; | ||
|
||
librados::ObjectReadOperation op; | ||
librbd::cls_client::mirror_image_map_list_start( | ||
&op, m_start_after, MAX_RETURN); | ||
|
||
librados::AioCompletion *aio_comp = create_rados_callback< | ||
LoadRequest, | ||
&LoadRequest::handle_image_map_list>(this); | ||
m_out_bl.clear(); | ||
int r = m_ioctx.aio_operate(RBD_MIRROR_LEADER, aio_comp, &op, &m_out_bl); | ||
assert(r == 0); | ||
aio_comp->release(); | ||
} | ||
|
||
template<typename I> | ||
void LoadRequest<I>::handle_image_map_list(int r) { | ||
dout(20) << ": r=" << r << dendl; | ||
|
||
std::map<std::string, cls::rbd::MirrorImageMap> image_map; | ||
if (r == 0) { | ||
bufferlist::iterator it = m_out_bl.begin(); | ||
r = librbd::cls_client::mirror_image_map_list_finish(&it, &image_map); | ||
} | ||
|
||
if (r < 0) { | ||
derr << ": failed to get image map: " << cpp_strerror(r) << dendl; | ||
finish(r); | ||
return; | ||
} | ||
|
||
m_image_map->insert(image_map.begin(), image_map.end()); | ||
|
||
if (!image_map.empty()) { | ||
m_start_after = image_map.rbegin()->first; | ||
image_map_list(); | ||
return; | ||
} | ||
|
||
finish(0); | ||
} | ||
|
||
template<typename I> | ||
void LoadRequest<I>::finish(int r) { | ||
dout(20) << ": r=" << r << dendl; | ||
|
||
m_on_finish->complete(r); | ||
delete this; | ||
} | ||
|
||
} // namespace image_map | ||
} // namespace mirror | ||
} // namespace rbd | ||
|
||
template class rbd::mirror::image_map::LoadRequest<librbd::ImageCtx>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- | ||
// vim: ts=8 sw=2 smarttab | ||
|
||
#ifndef CEPH_RBD_MIRROR_IMAGE_MAP_LOAD_REQUEST_H | ||
#define CEPH_RBD_MIRROR_IMAGE_MAP_LOAD_REQUEST_H | ||
|
||
#include "cls/rbd/cls_rbd_types.h" | ||
#include "include/rados/librados.hpp" | ||
|
||
class Context; | ||
|
||
namespace librbd { class ImageCtx; } | ||
|
||
namespace rbd { | ||
namespace mirror { | ||
namespace image_map { | ||
|
||
template<typename ImageCtxT = librbd::ImageCtx> | ||
class LoadRequest { | ||
public: | ||
static LoadRequest *create(librados::IoCtx &ioctx, | ||
std::map<std::string, cls::rbd::MirrorImageMap> *image_map, | ||
Context *on_finish) { | ||
return new LoadRequest(ioctx, image_map, on_finish); | ||
} | ||
|
||
void send(); | ||
|
||
private: | ||
/** | ||
* @verbatim | ||
* | ||
* <start> | ||
* | . . . . . . . . | ||
* v v . MAX_RETURN | ||
* IMAGE_MAP_LIST. . . . . . . | ||
* | | ||
* v | ||
* <finish> | ||
* | ||
* @endverbatim | ||
*/ | ||
LoadRequest(librados::IoCtx &ioctx, | ||
std::map<std::string, cls::rbd::MirrorImageMap> *image_map, | ||
Context *on_finish); | ||
|
||
librados::IoCtx &m_ioctx; | ||
std::map<std::string, cls::rbd::MirrorImageMap> *m_image_map; | ||
Context *m_on_finish; | ||
|
||
bufferlist m_out_bl; | ||
std::string m_start_after; | ||
|
||
void image_map_list(); | ||
void handle_image_map_list(int r); | ||
|
||
void finish(int r); | ||
}; | ||
|
||
} // namespace image_map | ||
} // namespace mirror | ||
} // namespace rbd | ||
|
||
#endif // CEPH_RBD_MIRROR_IMAGE_MAP_LOAD_REQUEST_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- | ||
// vim: ts=8 sw=2 smarttab | ||
|
||
#include "common/debug.h" | ||
#include "common/errno.h" | ||
|
||
#include "librbd/Utils.h" | ||
#include "include/rbd_types.h" | ||
#include "cls/rbd/cls_rbd_client.h" | ||
|
||
#include "RemoveRequest.h" | ||
|
||
#define dout_context g_ceph_context | ||
#define dout_subsys ceph_subsys_rbd_mirror | ||
#undef dout_prefix | ||
#define dout_prefix *_dout << "rbd::mirror::image_map::RemoveRequest: " \ | ||
<< this << " " << __func__ | ||
|
||
namespace rbd { | ||
namespace mirror { | ||
namespace image_map { | ||
|
||
using librbd::util::create_rados_callback; | ||
|
||
static const uint32_t MAX_REMOVE = 1024; | ||
|
||
template <typename I> | ||
RemoveRequest<I>::RemoveRequest(librados::IoCtx &ioctx, | ||
std::set<std::string> &&global_image_ids, Context *on_finish) | ||
: m_ioctx(ioctx), | ||
m_global_image_ids(std::move(global_image_ids)), | ||
m_on_finish(on_finish) { | ||
} | ||
|
||
template <typename I> | ||
void RemoveRequest<I>::send() { | ||
dout(20) << dendl; | ||
|
||
remove_image_map(); | ||
} | ||
|
||
template <typename I> | ||
void RemoveRequest<I>::remove_image_map() { | ||
dout(20) << dendl; | ||
|
||
if (m_global_image_ids.empty()) { | ||
finish(0); | ||
return; | ||
} | ||
|
||
uint32_t count = min(MAX_REMOVE, (uint32_t)m_global_image_ids.size()); | ||
auto first = m_global_image_ids.begin(); | ||
auto last = m_global_image_ids.begin(); | ||
std::advance(last, count); | ||
|
||
m_remove_batch.clear(); | ||
m_remove_batch.insert(first, last); | ||
m_global_image_ids.erase(first, last); | ||
|
||
librados::ObjectWriteOperation op; | ||
librbd::cls_client::mirror_image_map_remove(&op, m_remove_batch); | ||
librados::AioCompletion *aio_comp = create_rados_callback< | ||
RemoveRequest, &RemoveRequest::handle_remove_image_map>(this); | ||
|
||
int r = m_ioctx.aio_operate(RBD_MIRROR_LEADER, aio_comp, &op); | ||
assert(r == 0); | ||
} | ||
|
||
template <typename I> | ||
void RemoveRequest<I>::handle_remove_image_map(int r) { | ||
dout(20) << ": r=" << r << dendl; | ||
|
||
if (r < 0) { | ||
derr << ": failed to remove image map: " << cpp_strerror(r) << dendl; | ||
finish(r); | ||
return; | ||
} | ||
|
||
remove_image_map(); | ||
} | ||
|
||
template <typename I> | ||
void RemoveRequest<I>::finish(int r) { | ||
dout(20) << ": r=" << r << dendl; | ||
|
||
m_on_finish->complete(r); | ||
delete this; | ||
} | ||
|
||
} // namespace image_map | ||
} // namespace mirror | ||
} // namespace rbd | ||
|
||
template class rbd::mirror::image_map::RemoveRequest<librbd::ImageCtx>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- | ||
// vim: ts=8 sw=2 smarttab | ||
|
||
#ifndef CEPH_RBD_MIRROR_IMAGE_MAP_REMOVE_REQUEST_H | ||
#define CEPH_RBD_MIRROR_IMAGE_MAP_REMOVE_REQUEST_H | ||
|
||
#include <set> | ||
|
||
#include "include/rados/librados.hpp" | ||
|
||
class Context; | ||
|
||
namespace librbd { class ImageCtx; } | ||
|
||
namespace rbd { | ||
namespace mirror { | ||
namespace image_map { | ||
|
||
template<typename ImageCtxT = librbd::ImageCtx> | ||
class RemoveRequest { | ||
public: | ||
static RemoveRequest *create(librados::IoCtx &ioctx, | ||
std::set<std::string> &&global_image_ids, Context *on_finish) { | ||
return new RemoveRequest(ioctx, std::move(global_image_ids), on_finish); | ||
} | ||
|
||
void send(); | ||
|
||
private: | ||
/** | ||
* @verbatim | ||
* | ||
* <start> | ||
* | . . . . . . . . | ||
* v v . MAX_REMOVE | ||
* REMOVE_IMAGE_MAP. . . . . . . | ||
* | | ||
* v | ||
* <finish> | ||
* | ||
* @endverbatim | ||
*/ | ||
RemoveRequest(librados::IoCtx &ioctx, | ||
std::set<std::string> &&global_image_ids, Context *on_finish); | ||
|
||
librados::IoCtx &m_ioctx; | ||
std::set<std::string> &&m_global_image_ids; | ||
Context *m_on_finish; | ||
|
||
std::set<std::string> m_remove_batch; | ||
|
||
void remove_image_map(); | ||
void handle_remove_image_map(int r); | ||
|
||
void finish(int r); | ||
}; | ||
|
||
} // namespace image_map | ||
} // namespace mirror | ||
} // namespace rbd | ||
|
||
#endif // CEPH_RBD_MIRROR_IMAGE_MAP_REMOVE_REQUEST_H |
Oops, something went wrong.