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 <dillaman@redhat.com>
This commit is contained in:
Jason Dillaman 2016-03-21 20:12:55 -04:00
parent 2afb2c31ed
commit 38cf63d55c
3 changed files with 13 additions and 5 deletions

View File

@ -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;
}

View File

@ -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<NotifyMessage *> &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)));

View File

@ -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);