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>
#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, 0);
+}
+
Messenger *Messenger::create(CephContext *cct, const string &type,
entity_name_t name, string lname,
uint64_t nonce, uint64_t features)
uint64_t nonce,
uint64_t features = 0);
+ /**
+ * 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
* @{