From: Sage Weil Date: Tue, 7 Oct 2014 22:56:52 +0000 (-0700) Subject: librados: include notifier's gid in notify X-Git-Tag: v0.91~151 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8b409d498e96918bd7970fe4880b46e0949d4460;p=ceph.git librados: include notifier's gid in notify The notify replies include the identify of everyone who acked the notify. For symmetry, inform the notified client who sent the notify. Fixes: #9198 Signed-off-by: Sage Weil --- diff --git a/src/include/rados/librados.h b/src/include/rados/librados.h index 3e4a2673e45e..0e8047827dad 100644 --- a/src/include/rados/librados.h +++ b/src/include/rados/librados.h @@ -1879,12 +1879,14 @@ typedef void (*rados_watchcb_t)(uint8_t opcode, uint64_t ver, void *arg); * - arg opaque user-defined value provided to rados_watch2() * - notify_id an id for this notify event * - handle the watcher handle we are notifying + * - notifier_id the unique client id for the notifier * - data payload from the notifier * - datalen length of payload buffer */ typedef void (*rados_watchcb2_t)(void *arg, uint64_t notify_id, uint64_t handle, + uint64_t notifier_id, void *data, size_t data_len); diff --git a/src/include/rados/librados.hpp b/src/include/rados/librados.hpp index 20eec5bc5e83..b79bd73e4578 100644 --- a/src/include/rados/librados.hpp +++ b/src/include/rados/librados.hpp @@ -158,10 +158,12 @@ namespace librados /** * @param notify_id unique id for this notify event * @param cookie the watcher we are notifying + * @param notifier_id the unique client id of the notifier * @param bl opaque notify payload (from the notifier) */ virtual void handle_notify(uint64_t notify_id, uint64_t cookie, + uint64_t notifier_id, bufferlist& bl) = 0; }; diff --git a/src/librados/RadosClient.cc b/src/librados/RadosClient.cc index b19c1e5b0205..ffe600b22cbd 100644 --- a/src/librados/RadosClient.cc +++ b/src/librados/RadosClient.cc @@ -739,7 +739,8 @@ void librados::RadosClient::do_watch_notify(MWatchNotify *m) bufferlist empty; wc->io_ctx_impl->notify_ack(wc->oid, m->notify_id, m->cookie, empty); } else if (wc->watch_ctx2) { - wc->watch_ctx2->handle_notify(m->notify_id, m->cookie, m->bl); + wc->watch_ctx2->handle_notify(m->notify_id, m->cookie, + m->notifier_gid, m->bl); // user needs to explicitly ack (and may have already!) } lock.Lock(); diff --git a/src/librados/librados.cc b/src/librados/librados.cc index aad5eaac781e..8077d28cd7a5 100644 --- a/src/librados/librados.cc +++ b/src/librados/librados.cc @@ -3775,8 +3775,9 @@ struct C_WatchCB2 : public librados::WatchCtx2 { C_WatchCB2(rados_watchcb2_t _wcb, void *_arg) : wcb(_wcb), arg(_arg) {} void handle_notify(uint64_t notify_id, uint64_t cookie, + uint64_t notifier_gid, bufferlist& bl) { - wcb(arg, notify_id, cookie, bl.c_str(), bl.length()); + wcb(arg, notify_id, cookie, notifier_gid, bl.c_str(), bl.length()); } }; diff --git a/src/messages/MWatchNotify.h b/src/messages/MWatchNotify.h index bc6bacb711eb..aa82140739f8 100644 --- a/src/messages/MWatchNotify.h +++ b/src/messages/MWatchNotify.h @@ -20,7 +20,7 @@ class MWatchNotify : public Message { - static const int HEAD_VERSION = 2; + static const int HEAD_VERSION = 3; static const int COMPAT_VERSION = 1; public: @@ -30,6 +30,7 @@ class MWatchNotify : public Message { uint8_t opcode; ///< always WATCH_NOTIFY bufferlist bl; ///< notify payload (osd->client) int32_t return_code; ///< notify result (osd->client) + uint64_t notifier_gid; ///< who sent the notify MWatchNotify() : Message(CEPH_MSG_WATCH_NOTIFY, HEAD_VERSION, COMPAT_VERSION) { } @@ -40,7 +41,8 @@ class MWatchNotify : public Message { notify_id(i), opcode(o), bl(b), - return_code(0) { } + return_code(0), + notifier_gid(0) { } private: ~MWatchNotify() {} @@ -59,6 +61,10 @@ public: ::decode(return_code, p); else return_code = 0; + if (header.version >= 3) + ::decode(notifier_gid, p); + else + notifier_gid = 0; } void encode_payload(uint64_t features) { uint8_t msg_ver = 1; @@ -69,6 +75,7 @@ public: ::encode(notify_id, payload); ::encode(bl, payload); ::encode(return_code, payload); + ::encode(notifier_gid, payload); } const char *get_type_name() const { return "watch-notify"; } diff --git a/src/osd/ReplicatedPG.cc b/src/osd/ReplicatedPG.cc index d0dea52df1ef..896bd0d1a687 100644 --- a/src/osd/ReplicatedPG.cc +++ b/src/osd/ReplicatedPG.cc @@ -5403,6 +5403,7 @@ void ReplicatedPG::do_osd_op_effects(OpContext *ctx) NotifyRef notif( Notify::makeNotifyRef( conn, + ctx->reqid.name.num(), ctx->obc->watchers.size(), p->bl, p->timeout, diff --git a/src/osd/Watch.cc b/src/osd/Watch.cc index 4dfc8346f661..125a93b20fb2 100644 --- a/src/osd/Watch.cc +++ b/src/osd/Watch.cc @@ -28,6 +28,7 @@ static ostream& _prefix( Notify::Notify( ConnectionRef client, + uint64_t client_gid, unsigned num_watchers, bufferlist &payload, uint32_t timeout, @@ -35,7 +36,7 @@ Notify::Notify( uint64_t notify_id, uint64_t version, OSDService *osd) - : client(client), + : client(client), client_gid(client_gid), in_progress_watchers(num_watchers), complete(false), discarded(false), @@ -51,6 +52,7 @@ Notify::Notify( NotifyRef Notify::makeNotifyRef( ConnectionRef client, + uint64_t client_gid, unsigned num_watchers, bufferlist &payload, uint32_t timeout, @@ -60,7 +62,7 @@ NotifyRef Notify::makeNotifyRef( OSDService *osd) { NotifyRef ret( new Notify( - client, num_watchers, + client, client_gid, num_watchers, payload, timeout, cookie, notify_id, version, osd)); @@ -188,6 +190,7 @@ void Notify::maybe_complete_notify() bufferlist empty; MWatchNotify *reply(new MWatchNotify(cookie, version, notify_id, WATCH_NOTIFY, empty)); + reply->notifier_gid = client_gid; reply->set_data(bl); if (timed_out) reply->return_code = -ETIMEDOUT; @@ -428,6 +431,7 @@ void Watch::send_notify(NotifyRef notif) MWatchNotify *notify_msg = new MWatchNotify( cookie, notif->version, notif->notify_id, WATCH_NOTIFY, notif->payload); + notify_msg->notifier_gid = notif->client_gid; osd->send_message_osd_client(notify_msg, conn.get()); } diff --git a/src/osd/Watch.h b/src/osd/Watch.h index 00bcc638f649..b6142a59d628 100644 --- a/src/osd/Watch.h +++ b/src/osd/Watch.h @@ -55,6 +55,7 @@ class Notify { friend class Watch; WNotifyRef self; ConnectionRef client; + uint64_t client_gid; unsigned in_progress_watchers; bool complete; bool discarded; @@ -87,6 +88,7 @@ class Notify { Notify( ConnectionRef client, + uint64_t client_gid, unsigned num_watchers, bufferlist &payload, uint32_t timeout, @@ -114,6 +116,7 @@ public: } static NotifyRef makeNotifyRef( ConnectionRef client, + uint64_t client_gid, unsigned num_watchers, bufferlist &payload, uint32_t timeout, diff --git a/src/test/librados/watch_notify.cc b/src/test/librados/watch_notify.cc index 0a2636cfcc70..3ed93676739f 100644 --- a/src/test/librados/watch_notify.cc +++ b/src/test/librados/watch_notify.cc @@ -45,11 +45,13 @@ const char *notify_oid = 0; static void watch_notify2_test_cb(void *arg, uint64_t notify_id, uint64_t handle, + uint64_t notifier_gid, void *data, size_t data_len) { - std::cout << __func__ << " notify_id " << notify_id + std::cout << __func__ << " from " << notifier_gid << " notify_id " << notify_id << " handle " << handle << std::endl; + assert(notifier_gid > 0); notify_bl.clear(); notify_bl.append((char*)data, data_len); if (notify_sleep) @@ -61,7 +63,8 @@ IoCtx *notify_ioctx; class WatchNotifyTestCtx2 : public WatchCtx2 { public: - void handle_notify(uint64_t notify_id, uint64_t cookie, bufferlist& bl) + void handle_notify(uint64_t notify_id, uint64_t cookie, uint64_t notifier_gid, + bufferlist& bl) { std::cout << __func__ << std::endl; notify_bl = bl;