]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: include notifier's gid in notify
authorSage Weil <sage@redhat.com>
Tue, 7 Oct 2014 22:56:52 +0000 (15:56 -0700)
committerSage Weil <sage@redhat.com>
Thu, 4 Dec 2014 18:32:37 +0000 (10:32 -0800)
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 <sage@redhat.com>
src/include/rados/librados.h
src/include/rados/librados.hpp
src/librados/RadosClient.cc
src/librados/librados.cc
src/messages/MWatchNotify.h
src/osd/ReplicatedPG.cc
src/osd/Watch.cc
src/osd/Watch.h
src/test/librados/watch_notify.cc

index 3e4a2673e45eef326a65c581a4dd381b96280e80..0e8047827dad080e6dd22298f6325e1fe9be2555 100644 (file)
@@ -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);
 
index 20eec5bc5e8343d9d870632e0bb86502cbe126ae..b79bd73e4578e4eefb11c6233c17ea7cf1d4773c 100644 (file)
@@ -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;
   };
 
index b19c1e5b02057720e2ad41772958a00cd581eb7b..ffe600b22cbdf273bcd1a52df0af72af250235ce 100644 (file)
@@ -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();
index aad5eaac781e898e1aed2874a265dd4a47056967..8077d28cd7a58cda91ef3db3a53dec93c7831f25 100644 (file)
@@ -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());
   }
 };
 
index bc6bacb711ebc4eb35ccaddc2f6625a91479d55d..aa82140739f8e8db0d197627009dd661720c58dc 100644 (file)
@@ -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"; }
index d0dea52df1ef490a99e3a25d0e4af674dc73124b..896bd0d1a6876930a9b88848ae2f11a55a8572b3 100644 (file)
@@ -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,
index 4dfc8346f6616a46187bb75af3a17050139d9cfc..125a93b20fb2d8cfd86735a4c4ed12ac591b2be3 100644 (file)
@@ -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());
 }
 
index 00bcc638f6495bc48ffe9dbf4a13bafbf0e839af..b6142a59d628b8f4e3a9ef74284ce4984da17a5b 100644 (file)
@@ -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,
index 0a2636cfcc70acaf367512c10799d8ab9ca681ae..3ed93676739f4f0ec138ab0646f34f1dd0c3ef88 100644 (file)
@@ -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;