]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
msg: add simplified messenger constructor
authorJosh Durgin <jdurgin@redhat.com>
Mon, 21 Sep 2015 22:20:53 +0000 (15:20 -0700)
committerLoic Dachary <ldachary@redhat.com>
Fri, 2 Oct 2015 19:53:02 +0000 (21:53 +0200)
Several callers create messengers using exactly the same parameters:

- reading the ms type from cct that is also passed in
- a default entity_name_t::CLIENT
- the default features

Additionally, the nonce should be randomized and not depend on
e.g. pid, as it does in several callers now. Clients running in
containers can easily have pid collisions, leading to hangs, so
randomize the nonce in this simplified constructor rather than
duplicating that logic in every caller.

Daemons have meaningful entity_name_ts, and monitors currently depend
on using 0 as a nonce, so make this simple constructer
client-specific.

Related: #13032
Signed-off-by: Josh Durgin <jdurgin@redhat.com>
(cherry picked from commit e3785b0b5fbff870adbd5f121021b671912386cf)

Conflicts:
   src/msg/Messenger.cc: Messenger::create only has 5 arguments in
   hammer. Since the last one is zero, it does not change the
   semantic.

src/msg/Messenger.cc
src/msg/Messenger.h

index b63950e0a624a1a15786da71303dd8537e018f5f..ea28808b2f4c242b034e9a55110e9e339ded0c29 100644 (file)
 #include "msg/xio/XioMessenger.h"
 #endif
 
+Messenger *Messenger::create_client_messenger(CephContext *cct, string lname)
+{
+  uint64_t nonce = 0;
+  get_random_bytes((char*)&nonce, sizeof(nonce));
+  return Messenger::create(cct, cct->_conf->ms_type, entity_name_t::CLIENT(),
+                          lname, nonce);
+}
+
 Messenger *Messenger::create(CephContext *cct, const string &type,
                             entity_name_t name, string lname,
                             uint64_t nonce)
index 429e5007e77832f62cf57a340c34b5de5a11fcf8..82f6c021c01749f2736ae5526111636a639e319a 100644 (file)
@@ -158,6 +158,21 @@ public:
                           string lname,
                            uint64_t nonce);
 
+  /**
+   * create a new messenger
+   *
+   * Create a new messenger instance.
+   * Same as the above, but a slightly simpler interface for clients:
+   * - Generate a random nonce
+   * - use the default feature bits
+   * - get the messenger type from cct
+   * - use the client entity_type
+   *
+   * @param cct context
+   * @param lname logical name of the messenger in this process (e.g., "client")
+   */
+  static Messenger *create_client_messenger(CephContext *cct, string lname);
+
   /**
    * @defgroup Accessors
    * @{