Make sure socket_addr is populated when connection is set.
Signed-off-by: Sage Weil <sage@redhat.com>
// It doesn't go into a SessionMap instance until it sends an explicit
// request to open a session (initial state of Session is `closed`)
if (!s) {
- s = new Session;
+ s = new Session(con);
s->info.auth_name = name;
s->info.inst.addr = con->get_peer_addr();
s->info.inst.name = n;
dout(10) << " new session " << s << " for " << s->info.inst << " con " << con << dendl;
con->set_priv(RefCountedPtr{s, false});
- s->connection = con;
if (mds_rank) {
mds_rank->kick_waiters_for_any_client_connection();
}
if (s) {
if (s->connection != con) {
dout(10) << " session connection " << s->connection << " -> " << con << dendl;
- s->connection = con;
+ s->set_connection(con);
// send out any queued messages
while (!s->preopen_out_queue.empty()) {
while (n-- && !p.end()) {
auto p2 = p;
- Session *s = new Session;
+ Session *s = new Session(nullptr);
s->info.decode(p);
if (session_map.count(s->info.inst.name)) {
// eager client connected too fast! aie.
MDSAuthCaps auth_caps;
ConnectionRef connection;
+ entity_addr_t socket_addr;
xlist<Session*>::item item_session_list;
list<Message*> preopen_out_queue; ///< messages for client, queued before they connect
const vector<uint64_t> *gid_list, int new_uid, int new_gid);
- Session() :
+ Session(Connection *con) :
state(STATE_CLOSED), state_seq(0), importing_count(0),
recall_count(0), recall_release_count(0),
auth_caps(g_ceph_context),
lease_seq(0),
completed_requests_dirty(false),
num_trim_flushes_warnings(0),
- num_trim_requests_warnings(0) { }
+ num_trim_requests_warnings(0) {
+ if (con) {
+ set_connection(con);
+ }
+ }
~Session() override {
if (state == STATE_CLOSED) {
item_session_list.remove_myself();
}
}
+ void set_connection(Connection *con) {
+ connection = con;
+ socket_addr = con->get_peer_socket_addr();
+ }
+
void clear() {
pending_prealloc_inos.clear();
info.clear_meta();
if (session_map_entry != session_map.end()) {
s = session_map_entry->second;
} else {
- s = session_map[i.name] = new Session;
+ s = session_map[i.name] = new Session(nullptr);
s->info.inst = i;
s->last_cap_renew = ceph_clock_now();
if (logger) {
SessionFilter filter;
std::stringstream ss;
filter.parse({"id=123"}, &ss);
- Session *a = new Session();;
- Session *b = new Session();;
+ Session *a = new Session(nullptr);;
+ Session *b = new Session(nullptr);;
a->info.inst.name.parse("client.123");
b->info.inst.name.parse("client.456");
SessionFilter filter;
std::stringstream ss;
filter.parse({"state=closing"}, &ss);
- Session *a = new Session();
+ Session *a = new Session(nullptr);
a->set_state(Session::STATE_CLOSING);
- Session *b = new Session();
+ Session *b = new Session(nullptr);
b->set_state(Session::STATE_OPENING);
ASSERT_TRUE(filter.match(*a, [](client_t c) -> bool {return false;}));
SessionFilter filter;
std::stringstream ss;
filter.parse({"auth_name=rhubarb"}, &ss);
- Session *a = new Session();
+ Session *a = new Session(nullptr);
a->info.auth_name.set_id("rhubarb");
- Session *b = new Session();
+ Session *b = new Session(nullptr);
b->info.auth_name.set_id("custard");
ASSERT_TRUE(filter.match(*a, [](client_t c) -> bool {return false;}));
int r = filter.parse({"client_metadata.root=/rhubarb"}, &ss);
ASSERT_EQ(r, 0);
client_metadata_t meta;
- Session *a = new Session();
+ Session *a = new Session(nullptr);
meta.kv_map = {{"root", "/rhubarb"}};
a->set_client_metadata(meta);
- Session *b = new Session();
+ Session *b = new Session(nullptr);
meta.kv_map = {{"root", "/custard"}};
b->set_client_metadata(meta);
std::stringstream ss;
int r = filter.parse({"reconnecting=true"}, &ss);
ASSERT_EQ(r, 0);
- Session *a = new Session();
+ Session *a = new Session(nullptr);
ASSERT_TRUE(filter.match(*a, [](client_t c) -> bool {return true;}));
ASSERT_FALSE(filter.match(*a, [](client_t c) -> bool {return false;}));