From 38cf63d55c2e8de0efd63ea0acf4c61907af6a71 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Mon, 21 Mar 2016 20:12:55 -0400 Subject: [PATCH] librbd: optional 'force' parameter for request lock payload This will be used when force promoting an image to primary -- when rbd-mirror receives the forced request, it will immediately abort playback. Signed-off-by: Jason Dillaman --- src/librbd/ImageWatcher.cc | 4 ++-- src/librbd/WatchNotifyTypes.cc | 9 +++++++-- src/librbd/WatchNotifyTypes.h | 5 ++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/librbd/ImageWatcher.cc b/src/librbd/ImageWatcher.cc index 8bb16c4e1b5..9579723b227 100644 --- a/src/librbd/ImageWatcher.cc +++ b/src/librbd/ImageWatcher.cc @@ -408,7 +408,7 @@ void ImageWatcher::notify_request_lock() { ldout(m_image_ctx.cct, 10) << this << " notify request lock" << dendl; bufferlist bl; - ::encode(NotifyMessage(RequestLockPayload(get_client_id())), bl); + ::encode(NotifyMessage(RequestLockPayload(get_client_id(), false)), bl); notify_lock_owner(std::move(bl), create_context_callback< ImageWatcher, &ImageWatcher::handle_request_lock>(this)); } @@ -616,7 +616,7 @@ bool ImageWatcher::handle_payload(const RequestLockPayload &payload, ldout(m_image_ctx.cct, 10) << this << " queuing release of exclusive lock" << dendl; - m_image_ctx.get_exclusive_lock_policy()->lock_requested(false); + m_image_ctx.get_exclusive_lock_policy()->lock_requested(payload.force); } return true; } diff --git a/src/librbd/WatchNotifyTypes.cc b/src/librbd/WatchNotifyTypes.cc index a40cdc7e29c..65c334ae855 100644 --- a/src/librbd/WatchNotifyTypes.cc +++ b/src/librbd/WatchNotifyTypes.cc @@ -131,18 +131,23 @@ void ReleasedLockPayload::dump(Formatter *f) const { void RequestLockPayload::encode(bufferlist &bl) const { ::encode(client_id, bl); + ::encode(force, bl); } void RequestLockPayload::decode(__u8 version, bufferlist::iterator &iter) { if (version >= 2) { ::decode(client_id, iter); } + if (version >= 3) { + ::decode(force, iter); + } } void RequestLockPayload::dump(Formatter *f) const { f->open_object_section("client_id"); client_id.dump(f); f->close_section(); + f->dump_bool("force", force); } void HeaderUpdatePayload::encode(bufferlist &bl) const { @@ -270,7 +275,7 @@ bool NotifyMessage::check_for_refresh() const { } void NotifyMessage::encode(bufferlist& bl) const { - ENCODE_START(2, 1, bl); + ENCODE_START(3, 1, bl); boost::apply_visitor(EncodePayloadVisitor(bl), payload); ENCODE_FINISH(bl); } @@ -344,7 +349,7 @@ void NotifyMessage::dump(Formatter *f) const { void NotifyMessage::generate_test_instances(std::list &o) { o.push_back(new NotifyMessage(AcquiredLockPayload(ClientId(1, 2)))); o.push_back(new NotifyMessage(ReleasedLockPayload(ClientId(1, 2)))); - o.push_back(new NotifyMessage(RequestLockPayload(ClientId(1, 2)))); + o.push_back(new NotifyMessage(RequestLockPayload(ClientId(1, 2), true))); o.push_back(new NotifyMessage(HeaderUpdatePayload())); o.push_back(new NotifyMessage(AsyncProgressPayload(AsyncRequestId(ClientId(0, 1), 2), 3, 4))); o.push_back(new NotifyMessage(AsyncCompletePayload(AsyncRequestId(ClientId(0, 1), 2), 3))); diff --git a/src/librbd/WatchNotifyTypes.h b/src/librbd/WatchNotifyTypes.h index a587b231d66..813ff5fd49c 100644 --- a/src/librbd/WatchNotifyTypes.h +++ b/src/librbd/WatchNotifyTypes.h @@ -123,9 +123,12 @@ struct RequestLockPayload { static const bool CHECK_FOR_REFRESH = true; ClientId client_id; + bool force = false; RequestLockPayload() {} - RequestLockPayload(const ClientId &client_id_) : client_id(client_id_) {} + RequestLockPayload(const ClientId &client_id_, bool force_) + : client_id(client_id_), force(force_) { + } void encode(bufferlist &bl) const; void decode(__u8 version, bufferlist::iterator &iter);