mirror of
https://github.com/ceph/ceph
synced 2025-03-11 02:39:05 +00:00
librbd: allow force promotions to create necessary orphan snapshot
The rbd-mirror daemon needs to accept the RPC request to create an orphan snapshot so that it knows to shut-down the replayer. Signed-off-by: Jason Dillaman <dillaman@redhat.com>
This commit is contained in:
parent
3e7642617a
commit
5af1578d10
src
cls/rbd
librbd
tools/rbd_mirror/image_replayer
@ -584,6 +584,12 @@ struct MirrorSnapshotNamespace {
|
||||
state == MIRROR_SNAPSHOT_STATE_NON_PRIMARY_DEMOTED);
|
||||
}
|
||||
|
||||
inline bool is_orphan() const {
|
||||
return (is_non_primary() &&
|
||||
primary_mirror_uuid.empty() &&
|
||||
primary_snap_id == CEPH_NOSNAP);
|
||||
}
|
||||
|
||||
void encode(bufferlist& bl) const;
|
||||
void decode(bufferlist::const_iterator& it);
|
||||
|
||||
|
@ -777,8 +777,16 @@ bool ImageWatcher<I>::handle_payload(const SnapCreatePayload &payload,
|
||||
std::shared_lock l{m_image_ctx.owner_lock};
|
||||
if (m_image_ctx.exclusive_lock != nullptr) {
|
||||
int r;
|
||||
if (m_image_ctx.exclusive_lock->accept_request(
|
||||
exclusive_lock::OPERATION_REQUEST_TYPE_GENERAL, &r)) {
|
||||
auto request_type = exclusive_lock::OPERATION_REQUEST_TYPE_GENERAL;
|
||||
|
||||
// rbd-mirror needs to accept forced promotion orphan snap create requests
|
||||
auto mirror_ns = boost::get<cls::rbd::MirrorSnapshotNamespace>(
|
||||
&payload.snap_namespace);
|
||||
if (mirror_ns != nullptr && mirror_ns->is_orphan()) {
|
||||
request_type = exclusive_lock::OPERATION_REQUEST_TYPE_FORCE_PROMOTION;
|
||||
}
|
||||
|
||||
if (m_image_ctx.exclusive_lock->accept_request(request_type, &r)) {
|
||||
ldout(m_image_ctx.cct, 10) << this << " remote snap_create request: "
|
||||
<< payload.snap_name << dendl;
|
||||
|
||||
|
@ -10,6 +10,7 @@ namespace exclusive_lock {
|
||||
enum OperationRequestType {
|
||||
OPERATION_REQUEST_TYPE_GENERAL = 0,
|
||||
OPERATION_REQUEST_TYPE_TRASH_SNAP_REMOVE = 1,
|
||||
OPERATION_REQUEST_TYPE_FORCE_PROMOTION = 2,
|
||||
};
|
||||
|
||||
struct Policy {
|
||||
|
@ -122,6 +122,7 @@ void CreateNonPrimaryRequest<I>::create_snapshot() {
|
||||
cls::rbd::MIRROR_SNAPSHOT_STATE_NON_PRIMARY), {},
|
||||
m_primary_mirror_uuid, m_primary_snap_id};
|
||||
ns.snap_seqs = m_snap_seqs;
|
||||
ns.complete = is_orphan();
|
||||
ldout(cct, 20) << "ns=" << ns << dendl;
|
||||
|
||||
auto ctx = create_context_callback<
|
||||
@ -160,6 +161,7 @@ void CreateNonPrimaryRequest<I>::write_image_state() {
|
||||
|
||||
if (is_orphan()) {
|
||||
finish(0);
|
||||
return;
|
||||
}
|
||||
|
||||
CephContext *cct = m_image_ctx->cct;
|
||||
|
@ -43,6 +43,8 @@ void PromoteRequest<I>::send() {
|
||||
return;
|
||||
}
|
||||
|
||||
ldout(cct, 20) << "requires_orphan=" << requires_orphan << ", "
|
||||
<< "rollback_snap_id=" << m_rollback_snap_id << dendl;
|
||||
create_orphan_snapshot();
|
||||
}
|
||||
|
||||
@ -233,6 +235,7 @@ void PromoteRequest<I>::handle_acquire_exclusive_lock(int r) {
|
||||
r = m_image_ctx->exclusive_lock->get_unlocked_op_error();
|
||||
locker.unlock();
|
||||
finish(r);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,11 +62,13 @@ struct MirrorExclusiveLockPolicy : public librbd::exclusive_lock::Policy {
|
||||
|
||||
bool accept_blocked_request(
|
||||
librbd::exclusive_lock::OperationRequestType request_type) override {
|
||||
if (request_type ==
|
||||
librbd::exclusive_lock::OPERATION_REQUEST_TYPE_TRASH_SNAP_REMOVE) {
|
||||
switch (request_type) {
|
||||
case librbd::exclusive_lock::OPERATION_REQUEST_TYPE_TRASH_SNAP_REMOVE:
|
||||
case librbd::exclusive_lock::OPERATION_REQUEST_TYPE_FORCE_PROMOTION:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user