]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds/SessionMap: make Session::connection private
authorSage Weil <sage@redhat.com>
Thu, 9 Aug 2018 19:09:39 +0000 (14:09 -0500)
committerSage Weil <sage@redhat.com>
Sun, 12 Aug 2018 22:03:20 +0000 (17:03 -0500)
Ensure all setters go through set_connection()

Signed-off-by: Sage Weil <sage@redhat.com>
src/mds/CInode.cc
src/mds/Locker.cc
src/mds/MDCache.cc
src/mds/MDSDaemon.cc
src/mds/MDSRank.cc
src/mds/Migrator.cc
src/mds/Server.cc
src/mds/SessionMap.h
src/mds/journal.cc

index ad87cec5a369a605950899690c1fb964f58ddbe2..7504a4616abd023db75289dff0d30c2be567f401 100644 (file)
@@ -3209,9 +3209,11 @@ int CInode::get_caps_allowed_for_client(Session *session, mempool_inode *file_i)
 
   if (!is_dir()) {
     if ((file_i->inline_data.version != CEPH_INLINE_NONE &&
-        !session->connection->has_feature(CEPH_FEATURE_MDS_INLINE_DATA)) ||
+        !session->get_connection()->has_feature(
+          CEPH_FEATURE_MDS_INLINE_DATA)) ||
        (!file_i->layout.pool_ns.empty() &&
-        !session->connection->has_feature(CEPH_FEATURE_FS_FILE_LAYOUT_V2)))
+        !session->get_connection()->has_feature(
+          CEPH_FEATURE_FS_FILE_LAYOUT_V2)))
       allowed &= ~(CEPH_CAP_FILE_RD | CEPH_CAP_FILE_WR);
   }
   return allowed;
@@ -3622,7 +3624,7 @@ int CInode::encode_inodestat(bufferlist& bl, Session *session,
     ENCODE_FINISH(bl);
   }
   else {
-    assert(session->connection);
+    assert(session->get_connection());
 
     encode(oi->ino, bl);
     encode(snapid, bl);
@@ -3655,22 +3657,22 @@ int CInode::encode_inodestat(bufferlist& bl, Session *session,
     encode(file_i->rstat.rctime, bl);
     dirfragtree.encode(bl);
     encode(symlink, bl);
-    if (session->connection->has_feature(CEPH_FEATURE_DIRLAYOUTHASH)) {
+    if (session->get_connection()->has_feature(CEPH_FEATURE_DIRLAYOUTHASH)) {
       encode(file_i->dir_layout, bl);
     }
     encode(xbl, bl);
-    if (session->connection->has_feature(CEPH_FEATURE_MDS_INLINE_DATA)) {
+    if (session->get_connection()->has_feature(CEPH_FEATURE_MDS_INLINE_DATA)) {
       encode(inline_version, bl);
       encode(inline_data, bl);
     }
-    if (session->connection->has_feature(CEPH_FEATURE_MDS_QUOTA)) {
+    if (session->get_connection()->has_feature(CEPH_FEATURE_MDS_QUOTA)) {
       mempool_inode *policy_i = ppolicy ? pi : oi;
       encode(policy_i->quota, bl);
     }
-    if (session->connection->has_feature(CEPH_FEATURE_FS_FILE_LAYOUT_V2)) {
+    if (session->get_connection()->has_feature(CEPH_FEATURE_FS_FILE_LAYOUT_V2)) {
       encode(layout.pool_ns, bl);
     }
-    if (session->connection->has_feature(CEPH_FEATURE_FS_BTIME)) {
+    if (session->get_connection()->has_feature(CEPH_FEATURE_FS_BTIME)) {
       encode(any_i->btime, bl);
       encode(any_i->change_attr, bl);
     }
index dee0587b2be5024b9aedea62113d5f06a64dbf74..2eb5471b98e3b936cc26e035a04658445246f7e3 100644 (file)
@@ -2027,8 +2027,9 @@ bool Locker::issue_caps(CInode *in, Capability *only_cap)
 
     Session *session = mds->get_session(it->first);
     if (in->inode.inline_data.version != CEPH_INLINE_NONE &&
-       !(session && session->connection &&
-         session->connection->has_feature(CEPH_FEATURE_MDS_INLINE_DATA)))
+       !(session &&
+         session->get_connection() &&
+         session->get_connection()->has_feature(CEPH_FEATURE_MDS_INLINE_DATA)))
       allowed &= ~(CEPH_CAP_FILE_RD | CEPH_CAP_FILE_WR);
 
     int pending = cap->pending();
index dd57feeed80f0c4f58786d0d52ae24124decff81..ad3ffcd2bf9bc9fafaa7edab9cd2af2fa77b12b9 100644 (file)
@@ -2038,8 +2038,9 @@ void MDCache::broadcast_quota_to_client(CInode *in, client_t exclude_ct)
 
   for (auto &p : in->client_caps) {
     Session *session = mds->get_session(p.first);
-    if (!session || !session->connection ||
-        !session->connection->has_feature(CEPH_FEATURE_MDS_QUOTA))
+    if (!session ||
+       !session->get_connection() ||
+        !session->get_connection()->has_feature(CEPH_FEATURE_MDS_QUOTA))
       continue;
 
     Capability *cap = &p.second;
@@ -2079,7 +2080,7 @@ update:
     msg->ino = in->ino();
     msg->rstat = i->rstat;
     msg->quota = i->quota;
-    mds->send_message_client_counted(msg, session->connection);
+    mds->send_message_client_counted(msg, session->get_connection());
   }
   for (const auto &it : in->get_replicas()) {
     MGatherCaps *msg = new MGatherCaps;
index 1228f63a8dfba1afe3311e631dece1c52e827f23..98c524556d763535fdc0f895189fffb5cb20e8c6 100644 (file)
@@ -584,7 +584,7 @@ void MDSDaemon::send_command_reply(MCommand *m, MDSRank *mds_rank,
     // This session only existed to issue commands, so terminate it
     // as soon as we can.
     assert(session->is_closed());
-    session->connection->mark_disposable();
+    session->get_connection()->mark_disposable();
   }
   priv.reset();
 
@@ -1362,7 +1362,8 @@ bool MDSDaemon::ms_verify_authorizer(Connection *con, int peer_type,
         mds_rank->kick_waiters_for_any_client_connection();
       }
     } else {
-      dout(10) << " existing session " << s << " for " << s->info.inst << " existing con " << s->connection
+      dout(10) << " existing session " << s << " for " << s->info.inst
+              << " existing con " << s->get_connection()
               << ", new/authorizing con " << con << dendl;
       con->set_priv(RefCountedPtr{s});
 
@@ -1424,8 +1425,9 @@ void MDSDaemon::ms_handle_accept(Connection *con)
   auto s = static_cast<Session *>(priv.get());
   dout(10) << "ms_handle_accept " << con->get_peer_addr() << " con " << con << " session " << s << dendl;
   if (s) {
-    if (s->connection != con) {
-      dout(10) << " session connection " << s->connection << " -> " << con << dendl;
+    if (s->get_connection() != con) {
+      dout(10) << " session connection " << s->get_connection()
+              << " -> " << con << dendl;
       s->set_connection(con);
 
       // send out any queued messages
index fb65a117130f0b7f210c58784f909007dff8fcce..3b9e713d9c3ba0deb14cf7d083610008d4d298e8 100644 (file)
@@ -910,19 +910,22 @@ Session *MDSRank::get_session(Message *m)
     if (session->is_closed()) {
       Session *imported_session = sessionmap.get_session(session->info.inst.name);
       if (imported_session && imported_session != session) {
-        dout(10) << __func__ << " replacing connection bootstrap session " << session << " with imported session " << imported_session << dendl;
+        dout(10) << __func__ << " replacing connection bootstrap session "
+                << session << " with imported session " << imported_session
+                << dendl;
         imported_session->info.auth_name = session->info.auth_name;
         //assert(session->info.auth_name == imported_session->info.auth_name);
         assert(session->info.inst == imported_session->info.inst);
-        imported_session->set_connection(session->connection);
+        imported_session->set_connection(session->get_connection().get());
         // send out any queued messages
         while (!session->preopen_out_queue.empty()) {
-          imported_session->connection->send_message(session->preopen_out_queue.front());
+          imported_session->get_connection()->send_message(
+           session->preopen_out_queue.front());
           session->preopen_out_queue.pop_front();
         }
         imported_session->auth_caps = session->auth_caps;
         assert(session->get_nref() == 1);
-        imported_session->connection->set_priv(imported_session->get());
+        imported_session->get_connection()->set_priv(imported_session->get());
         session = imported_session;
       }
     }
@@ -1033,8 +1036,8 @@ void MDSRank::send_message_client_counted(Message *m, Session *session)
   version_t seq = session->inc_push_seq();
   dout(10) << "send_message_client_counted " << session->info.inst.name << " seq "
           << seq << " " << *m << dendl;
-  if (session->connection) {
-    session->connection->send_message(m);
+  if (session->get_connection()) {
+    session->get_connection()->send_message(m);
   } else {
     session->preopen_out_queue.push_back(m);
   }
@@ -1043,8 +1046,8 @@ void MDSRank::send_message_client_counted(Message *m, Session *session)
 void MDSRank::send_message_client(Message *m, Session *session)
 {
   dout(10) << "send_message_client " << session->info.inst << " " << *m << dendl;
-  if (session->connection) {
-    session->connection->send_message(m);
+  if (session->get_connection()) {
+    session->get_connection()->send_message(m);
   } else {
     session->preopen_out_queue.push_back(m);
   }
@@ -3025,7 +3028,7 @@ void MDSRank::bcast_mds_map()
   for (set<Session*>::const_iterator p = clients.begin();
        p != clients.end();
        ++p)
-    (*p)->connection->send_message(new MMDSMap(monc->get_fsid(), mdsmap));
+    (*p)->get_connection()->send_message(new MMDSMap(monc->get_fsid(), mdsmap));
   last_client_mdsmap_bcast = mdsmap->get_epoch();
 }
 
index df19531a7e0c5ffd2bb601384be731ba5b0d16da..4fc8db4f6cb92ab2483b1139c44efd3240233b4b 100644 (file)
@@ -3103,7 +3103,7 @@ void Migrator::finish_import_inode_caps(CInode *in, mds_rank_t peer, bool auth_c
     // For non-auth caps, ask exporter mds to send cap export messages to
     // clients who haven't opened sessions. The cap export messages will
     // make clients open sessions.
-    if (auth_cap || session->connection == nullptr) {
+    if (auth_cap || !session->get_connection()) {
       Capability::Import& im = import_map[it.first];
       im.cap_id = cap->get_cap_id();
       im.mseq = auth_cap ? it.second.mseq : cap->get_mseq();
index 2d743b23174e2d5ce4bd7a8e63c3f6b9dc99e174..38708165542173d21a316f816a2122dbbd417894 100644 (file)
@@ -511,8 +511,8 @@ void Server::flush_client_sessions(set<client_t>& client_set, MDSGatherBuilder&
     Session *session = mds->sessionmap.get_session(entity_name_t::CLIENT(p->v));
     assert(session);
     if (!session->is_open() ||
-       !session->connection.get() ||
-       !session->connection->has_feature(CEPH_FEATURE_EXPORT_PEER))
+       !session->get_connection() ||
+       !session->get_connection()->has_feature(CEPH_FEATURE_EXPORT_PEER))
       continue;
     version_t seq = session->wait_for_flush(gather.new_sub());
     mds->send_message_client(new MClientSession(CEPH_SESSION_FLUSHMSG, seq), session);
@@ -551,13 +551,13 @@ void Server::_session_logged(Session *session, uint64_t state_seq, bool open, ve
     assert(session->is_opening());
     mds->sessionmap.set_state(session, Session::STATE_OPEN);
     mds->sessionmap.touch_session(session);
-    assert(session->connection != NULL);
+    assert(session->get_connection());
     MClientSession *reply = new MClientSession(CEPH_SESSION_OPEN);
     if (session->info.has_feature(CEPHFS_FEATURE_MIMIC))
       reply->supported_features = supported_features;
-    session->connection->send_message(reply);
+    session->get_connection()->send_message(reply);
     if (mdcache->is_readonly())
-      session->connection->send_message(new MClientSession(CEPH_SESSION_FORCE_RO));
+      session->get_connection()->send_message(new MClientSession(CEPH_SESSION_FORCE_RO));
   } else if (session->is_closing() ||
             session->is_killing()) {
     // kill any lingering capabilities, leases, requests
@@ -590,10 +590,10 @@ void Server::_session_logged(Session *session, uint64_t state_seq, bool open, ve
       // ms_handle_remote_reset() and realize they had in fact closed.
       // do this *before* sending the message to avoid a possible
       // race.
-      if (session->connection != NULL) {
+      if (session->get_connection()) {
         // Conditional because terminate_sessions will indiscrimately
         // put sessions in CLOSING whether they ever had a conn or not.
-        session->connection->mark_disposable();
+        session->get_connection()->mark_disposable();
       }
 
       // reset session
@@ -603,9 +603,9 @@ void Server::_session_logged(Session *session, uint64_t state_seq, bool open, ve
       mds->sessionmap.remove_session(session);
     } else if (session->is_killing()) {
       // destroy session, close connection
-      if (session->connection != NULL) {
-       session->connection->mark_down();
-       session->connection->set_priv(NULL);
+      if (session->get_connection()) {
+       session->get_connection()->mark_down();
+       session->get_connection()->set_priv(NULL);
       }
       mds->sessionmap.remove_session(session);
     } else {
@@ -1103,18 +1103,18 @@ void Server::infer_supported_features(Session *session, client_metadata_t& clien
     // user space client
     if (it->second.compare(0, 16, "ceph version 12.") == 0)
       supported = CEPHFS_FEATURE_LUMINOUS;
-    else if (session->connection->has_feature(CEPH_FEATURE_FS_CHANGE_ATTR))
+    else if (session->get_connection()->has_feature(CEPH_FEATURE_FS_CHANGE_ATTR))
       supported = CEPHFS_FEATURE_KRAKEN;
   } else {
     it = client_metadata.find("kernel_version");
     if (it != client_metadata.end()) {
       // kernel client
-      if (session->connection->has_feature(CEPH_FEATURE_NEW_OSDOP_ENCODING))
+      if (session->get_connection()->has_feature(CEPH_FEATURE_NEW_OSDOP_ENCODING))
        supported = CEPHFS_FEATURE_LUMINOUS;
     }
   }
   if (supported == -1 &&
-      session->connection->has_feature(CEPH_FEATURE_FS_FILE_LAYOUT_V2))
+      session->get_connection()->has_feature(CEPH_FEATURE_FS_FILE_LAYOUT_V2))
     supported = CEPHFS_FEATURE_JEWEL;
 
   if (supported >= 0) {
@@ -2834,7 +2834,7 @@ CInode* Server::prepare_new_inode(MDRequestRef& mdr, CDir *dir, inodeno_t useino
   }
 
   if (!mds->mdsmap->get_inline_data_enabled() ||
-      !mdr->session->connection->has_feature(CEPH_FEATURE_MDS_INLINE_DATA))
+      !mdr->session->get_connection()->has_feature(CEPH_FEATURE_MDS_INLINE_DATA))
     in->inode.inline_data.version = CEPH_INLINE_NONE;
 
   mdcache->add_inode(in);  // add
@@ -3516,7 +3516,7 @@ void Server::handle_client_open(MDRequestRef& mdr)
   }
 
   if (cur->inode.inline_data.version != CEPH_INLINE_NONE &&
-      !mdr->session->connection->has_feature(CEPH_FEATURE_MDS_INLINE_DATA)) {
+      !mdr->session->get_connection()->has_feature(CEPH_FEATURE_MDS_INLINE_DATA)) {
     dout(7) << "old client cannot open inline data file " << *cur << dendl;
     respond_to_request(mdr, -EPERM);
     return;
index 04b6f483d9e968d10ef1f578ac5dce15c56a172d..10e87a713e121125f104ed234ed082790e4ef145 100644 (file)
@@ -138,7 +138,9 @@ public:
 
   MDSAuthCaps auth_caps;
 
+protected:
   ConnectionRef connection;
+public:
   entity_addr_t socket_addr;
   xlist<Session*>::item item_session_list;
 
@@ -353,6 +355,9 @@ public:
     connection = con;
     socket_addr = con->get_peer_socket_addr();
   }
+  const ConnectionRef& get_connection() const {
+    return connection;
+  }
 
   void clear() {
     pending_prealloc_inos.clear();
index 58939570d7d98410104008b54cd33f286944433b..222bba3b1bd05ffd5225e441596455ac71b1e19e 100644 (file)
@@ -1682,7 +1682,7 @@ void ESession::replay(MDSRank *mds)
     } else {
       session = mds->sessionmap.get_session(client_inst.name);
       if (session) { // there always should be a session, but there's a bug
-       if (session->connection == NULL) {
+       if (session->get_connection() == NULL) {
          dout(10) << " removed session " << session->info.inst << dendl;
          mds->sessionmap.remove_session(session);
           session = NULL;