]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: Fix all uses of Session and get_caps.
authorGreg Farnum <gregf@hq.newdream.net>
Thu, 25 Mar 2010 17:43:04 +0000 (10:43 -0700)
committerGreg Farnum <gregf@hq.newdream.net>
Thu, 25 Mar 2010 18:03:11 +0000 (11:03 -0700)
They now use MonSession and get_service()->caps, respectively.

src/messages/MForward.h
src/messages/PaxosServiceMessage.h
src/mon/AuthMonitor.cc
src/mon/LogMonitor.cc
src/mon/MDSMonitor.cc
src/mon/Monitor.cc
src/mon/Monitor.h
src/mon/OSDMonitor.cc
src/mon/PGMonitor.cc

index 036a7086722b3b861b8e22a60e6491aa9d408877..45823ad6a49d8143a3a2a51531eb2d402c80e047 100644 (file)
@@ -27,21 +27,13 @@ struct MForward : public Message {
   PaxosServiceMessage *msg;
   entity_inst_t client;
   MonCaps client_caps;
-  bool has_caps;
   
-  MForward() : Message(MSG_FORWARD), msg(NULL), has_caps(false) {}
+  MForward() : Message(MSG_FORWARD), msg(NULL) {}
   //the message needs to have caps filled in!
   MForward(PaxosServiceMessage *m) :
     Message(MSG_FORWARD), msg(m) {
     client = m->get_source_inst();
-    if (m->caps) {
-      client_caps = *m->caps;
-      has_caps = true;
-    } else {
-      has_caps = false;
-      generic_dout(10) << "creating MForward without caps on message " 
-                      << m << dendl;
-    }
+    client_caps = m->get_session()->caps;
   }
 
   ~MForward() {
@@ -50,7 +42,6 @@ struct MForward : public Message {
   
   void encode_payload() {
     ::encode(client, payload);
-    ::encode(has_caps, payload);
     ::encode(client_caps, payload);
     encode_message(msg, payload);
   }
@@ -58,15 +49,8 @@ struct MForward : public Message {
   void decode_payload() {
     bufferlist::iterator p = payload.begin();
     ::decode(client, p);
-    ::decode(has_caps, p);
     ::decode(client_caps, p);
     msg = (PaxosServiceMessage *)decode_message(p);
-    if (has_caps) msg->caps = &client_caps;
-    else {
-      msg->caps = NULL;
-      generic_dout(10) << "Decoding MForward without any caps!" << dendl;
-    }
-    generic_dout(20) << "MForward decoded! " << *msg << client_caps << dendl;
   }
 
   const char *get_type_name() { return "forward"; }
index 7d6003d2a26caac160819509dfc2192c7e4943c7..1b670bfa483dcb6308624643dc85662305c39ce8 100644 (file)
@@ -46,8 +46,8 @@ class PaxosServiceMessage : public Message {
    * very long-lived -- it will still only last as long as the Session would
    * normally.
    */
-  Session *get_session() {
-    Session *session = (Session *)get_connection()->get_priv();
+  MonSession *get_session() {
+    MonSession *session = (MonSession *)get_connection()->get_priv();
     session->put();
     return session;
   }
index 84ae71461d1bef7f6caf7e11b861ec2206f0e79d..f770701f6679753bf7e7f6a46e775353f70325f2 100644 (file)
@@ -354,7 +354,7 @@ bool AuthMonitor::prep_auth(MAuth *m, bool paxos_writable)
 {
   dout(0) << "prep_auth() blob_size=" << m->get_auth_payload().length() << dendl;
 
-  Session *s = (Session *)m->get_connection()->get_priv();
+  MonSession *s = (MonSession *)m->get_connection()->get_priv();
   if (!s) {
     dout(10) << "no session, dropping" << dendl;
     delete m;
index aed7e1ebb6140e8aefe296b871c1e48a20412638..1cd6722bf562a8c083072ebca51e92cd1a634bdd 100644 (file)
@@ -230,9 +230,9 @@ bool LogMonitor::preprocess_log(MLog *m)
 {
   dout(10) << "preprocess_log " << *m << " from " << m->get_orig_source() << dendl;
 
-  if (!m->caps->check_privileges(PAXOS_LOG, MON_CAP_X)) {
+  if (!m->get_session()->caps.check_privileges(PAXOS_LOG, MON_CAP_X)) {
     dout(0) << "Received MLog from entity with insufficient privileges "
-           << m->caps << dendl;
+           << m->get_session()->caps << dendl;
     return true; //no reply expected
   }
   
index 67d0088a0ed39c684d817348701fe321a639395d..01abfb75068812c3f13f8e69566683a520e386f2 100644 (file)
@@ -159,9 +159,9 @@ bool MDSMonitor::preprocess_beacon(MMDSBeacon *m)
   MDSMap::mds_info_t info;
 
   //check privileges, ignore if fails
-  if ( !m->caps->check_privileges(PAXOS_MDSMAP, MON_CAP_X)) {
+  if ( !m->get_session()->caps.check_privileges(PAXOS_MDSMAP, MON_CAP_X)) {
     dout(0) << "received MMDSBeacon from entity with insufficient privileges "
-           << *m->caps << dendl;
+           << m->get_session()->caps << dendl;
     goto out;
   }
 
@@ -249,9 +249,9 @@ bool MDSMonitor::preprocess_offload_targets(MMDSLoadTargets* m)
   dout(10) << "preprocess_offload_targets " << *m << " from " << m->get_orig_source() << dendl;
 
   //check privileges, ignore message if fails
-  if(!m->caps->check_privileges(PAXOS_MDSMAP, MON_CAP_X)) {
+  if(!m->get_session()->caps.check_privileges(PAXOS_MDSMAP, MON_CAP_X)) {
     dout(0) << "got MMDSLoadTargets from entity with insufficient caps "
-           << *m->caps << dendl;
+           << m->get_session()->caps << dendl;
     return true;
   }
 
index 67a0073196bced3bf4ddab9bbcc8083ff3649373..b85602141c2e9ff49202e48f63df0144a42b1df1 100644 (file)
@@ -124,7 +124,7 @@ Monitor::~Monitor()
     delete *p;
   for (vector<Paxos*>::iterator p = paxos.begin(); p != paxos.end(); p++)
     delete *p;
-  //clean out SessionMap's subscriptions
+  //clean out MonSessionMap's subscriptions
   for (map<nstring, xlist<Subscription*> >::iterator i
         = session_map.subs.begin();
        i != session_map.subs.end();
@@ -133,7 +133,7 @@ Monitor::~Monitor()
       session_map.remove_sub(i->second.front());
     }
   }
-  //clean out SessionMap's sessions
+  //clean out MonSessionMap's sessions
   while (!session_map.sessions.empty()) {
     session_map.remove_session(session_map.sessions.front());
   }
@@ -263,7 +263,7 @@ void Monitor::handle_command(MMonCommand *m)
     return;
   }
 
-  if (!m->caps->check_privileges(PAXOS_MONMAP, MON_CAP_ALL)) {
+  if (!m->get_session()->caps.check_privileges(PAXOS_MONMAP, MON_CAP_ALL)) {
     string rs="Access denied";
     reply_command((MMonCommand *)m, -EACCES, rs, 0);
   }
@@ -346,9 +346,9 @@ void Monitor::reply_command(MMonCommand *m, int rc, const string &rs, bufferlist
 void Monitor::forward_request_leader(PaxosServiceMessage *req)
 {
   int mon = get_leader();
-  Session *session = 0;
+  MonSession *session = 0;
   if (req->get_connection())
-    session = (Session *)req->get_connection()->get_priv();
+    session = (MonSession *)req->get_connection()->get_priv();
   if (req->session_mon >= 0) {
     dout(10) << "forward_request won't double fwd request " << *req << dendl;
     delete req;
@@ -367,7 +367,7 @@ void Monitor::forward_request_leader(PaxosServiceMessage *req)
     
     //encode forward message and insert into routed_requests
     encode_message(req, rr->request_bl);
-    rr->session = (Session *)session->get();
+    rr->session = (MonSession *)session->get();
     routed_requests[rr->tid] = rr;
 
     session->routed_request_tids.insert(rr->tid);
@@ -388,7 +388,7 @@ void Monitor::handle_forward(MForward *m)
 {
   dout(10) << "received forwarded message from " << m->msg->get_source_inst()
           << " via " << m->get_source_inst() << dendl;
-  Session *session = (Session *)m->get_connection()->get_priv();
+  MonSession *session = (MonSession *)m->get_connection()->get_priv();
   assert(session);
 
   if (!session->caps.check_privileges(PAXOS_MONMAP, MON_CAP_X)) {
@@ -396,7 +396,7 @@ void Monitor::handle_forward(MForward *m)
            << session->caps << dendl;
   } else {
 
-    Session *s = new Session(m->msg->get_source_inst());
+    MonSession *s = new MonSession(m->msg->get_source_inst());
     s->caps = m->client_caps;
     Connection *c = new Connection;
     c->set_priv(s);
@@ -444,7 +444,7 @@ void Monitor::send_reply(PaxosServiceMessage *req, Message *reply, entity_inst_t
 
 void Monitor::handle_route(MRoute *m)
 {
-  Session *session = (Session *)m->get_connection()->get_priv();
+  MonSession *session = (MonSession *)m->get_connection()->get_priv();
   //check privileges
   if (session && !session->caps.check_privileges(PAXOS_MONMAP, MON_CAP_X)) {
     dout(0) << "MRoute received from entity without appropriate perms! "
@@ -492,7 +492,7 @@ void Monitor::resend_routed_requests()
   }  
 }
 
-void Monitor::remove_session(Session *s)
+void Monitor::remove_session(MonSession *s)
 {
   dout(10) << "remove_session " << s << " " << s->inst << dendl;
   assert(!s->closed);
@@ -516,7 +516,7 @@ void Monitor::handle_observe(MMonObserve *m)
   //check that there are perms. Send a response back if they aren't sufficient,
   //and delete the message (if it's not deleted for us, which happens when
   //we own the connection to the requested observer).
-  if (!m->caps->check_privileges(PAXOS_MONMAP, MON_CAP_X)) {
+  if (!m->get_session()->caps.check_privileges(PAXOS_MONMAP, MON_CAP_X)) {
     bool delete_m = false;
     if (m->session_mon) delete_m = true;
     send_reply(m, m);
@@ -563,14 +563,14 @@ bool Monitor::_ms_dispatch(Message *m)
   bool ret = true;
 
   Connection *connection = m->get_connection();
-  Session *s = NULL;
+  MonSession *s = NULL;
   bool reuse_caps = false;
   MonCaps caps;
   EntityName entity_name;
   bool src_is_mon;
 
   if (connection) {
-    s = (Session *)connection->get_priv();
+    s = (MonSession *)connection->get_priv();
     if (s && s->closed) {
       caps = s->caps;
       reuse_caps = true;
@@ -619,7 +619,6 @@ bool Monitor::_ms_dispatch(Message *m)
       break;
 
     case MSG_MON_COMMAND:
-      fill_caps(m);
       handle_command((MMonCommand*)m);
       break;
 
@@ -633,19 +632,16 @@ bool Monitor::_ms_dispatch(Message *m)
     case MSG_OSD_BOOT:
     case MSG_OSD_ALIVE:
     case MSG_OSD_PGTEMP:
-      fill_caps(m);
       paxos_service[PAXOS_OSDMAP]->dispatch((PaxosServiceMessage*)m);
       break;
 
     case MSG_REMOVE_SNAPS:
-      fill_caps(m);
       paxos_service[PAXOS_OSDMAP]->dispatch((PaxosServiceMessage*)m);
       break;
 
       // MDSs
     case MSG_MDS_BEACON:
     case MSG_MDS_OFFLOAD_TARGETS:
-      fill_caps(m);
       paxos_service[PAXOS_MDSMAP]->dispatch((PaxosServiceMessage*)m);
       break;
 
@@ -653,7 +649,6 @@ bool Monitor::_ms_dispatch(Message *m)
     case MSG_MON_GLOBAL_ID:
     case CEPH_MSG_AUTH:
       /* no need to check caps here */
-      fill_caps(m);
       paxos_service[PAXOS_AUTH]->dispatch((PaxosServiceMessage*)m);
       break;
 
@@ -661,18 +656,15 @@ bool Monitor::_ms_dispatch(Message *m)
     case CEPH_MSG_STATFS:
     case MSG_PGSTATS:
     case MSG_GETPOOLSTATS:
-      fill_caps(m);
       paxos_service[PAXOS_PGMAP]->dispatch((PaxosServiceMessage*)m);
       break;
 
     case MSG_POOLOP:
-      fill_caps(m);
       paxos_service[PAXOS_OSDMAP]->dispatch((PaxosServiceMessage*)m);
       break;
 
       // log
     case MSG_LOG:
-      fill_caps(m);
       paxos_service[PAXOS_LOG]->dispatch((PaxosServiceMessage*)m);
       break;
 
@@ -708,7 +700,6 @@ bool Monitor::_ms_dispatch(Message *m)
       break;
 
     case MSG_MON_OBSERVE:
-      fill_caps(m);
       handle_observe((MMonObserve *)m);
       break;
 
@@ -742,30 +733,13 @@ bool Monitor::_ms_dispatch(Message *m)
   return ret;
 }
 
-//if we can, fill in the PaxosServiceMessage's caps field.
-void Monitor::fill_caps(Message *m)
-{
-  PaxosServiceMessage *msg = (PaxosServiceMessage *) m;
-  if (msg->caps) return; //already filled in!
-  Session *s = NULL;
-  if (m->get_connection()) {
-    s = (Session *) m->get_connection()->get_priv();
-    if (s) {
-      msg->caps = &s->caps;
-      s->put();
-    }
-  } else { //it has to be a monitor if the Connection's not set
-    msg->caps = mon_caps;
-  }
-}
-
 void Monitor::handle_subscribe(MMonSubscribe *m)
 {
   dout(10) << "handle_subscribe " << *m << dendl;
   
   bool reply = false;
 
-  Session *s = (Session *)m->get_connection()->get_priv();
+  MonSession *s = (MonSession *)m->get_connection()->get_priv();
   if (!s) {
     dout(10) << " no session, dropping" << dendl;
     delete m;
@@ -809,7 +783,7 @@ bool Monitor::ms_handle_reset(Connection *con)
   if (con->get_peer_type() == CEPH_ENTITY_TYPE_MON)
     return false;
 
-  Session *s = (Session *)con->get_priv();
+  MonSession *s = (MonSession *)con->get_priv();
   if (!s)
     return false;
 
@@ -909,9 +883,9 @@ void Monitor::tick()
   
   // trim sessions
   utime_t now = g_clock.now();
-  xlist<Session*>::iterator p = session_map.sessions.begin();
+  xlist<MonSession*>::iterator p = session_map.sessions.begin();
   while (!p.end()) {
-    Session *s = *p;
+    MonSession *s = *p;
     ++p;
     
     // don't trim monitors
@@ -995,9 +969,9 @@ int Monitor::mkfs(bufferlist& osdmapbl)
 
 void Monitor::handle_class(MClass *m)
 {
-  if (!m->caps->check_privileges(PAXOS_OSDMAP, MON_CAP_X)) {
+  if (!m->get_session()->caps.check_privileges(PAXOS_OSDMAP, MON_CAP_X)) {
     dout(0) << "MClass received from entity without sufficient privileges "
-           << m->caps << dendl;
+           << m->get_session()->caps << dendl;
     delete m;
     return;
   }
index 6c9c0f260bed5a0f69b8bf57ea111ed86aa91802..b851b916f75696ca17b56dceffa91771a824b751 100644 (file)
@@ -140,7 +140,7 @@ public:
 
 
   // -- sessions --
-  SessionMap session_map;
+  MonSessionMap session_map;
 
   void check_subs();
   void check_sub(Subscription *sub);
@@ -163,7 +163,7 @@ public:
   struct RoutedRequest {
     __u64 tid;
     bufferlist request_bl;
-    Session *session;
+    MonSession *session;
 
     ~RoutedRequest() {
       if (session)
@@ -181,7 +181,7 @@ public:
     send_reply(req, reply, req->get_orig_source_inst());
   }
   void resend_routed_requests();
-  void remove_session(Session *s);
+  void remove_session(MonSession *s);
 
   void inject_args(const entity_inst_t& inst, string& args, version_t version) {
     vector<string> a(1);
@@ -216,8 +216,6 @@ public:
     lock.Unlock();
     return ret;
   }
-  //fill in caps field if possible
-  void fill_caps(Message *m);
   //mon_caps is used for un-connected messages from monitors
   MonCaps * mon_caps;
   bool ms_get_authorizer(int dest_type, AuthAuthorizer **authorizer, bool force_new);
index c65055c200a88d7456edf0ca54f17c4ccc21f49e..8204eaa9e4de3de26e3b0decdb0562bff110d31a 100644 (file)
@@ -179,7 +179,7 @@ void OSDMonitor::committed()
   // tell any osd
   int r = osdmap.get_any_up_osd();
   if (r >= 0) {
-    Session *s = mon->session_map.get_random_osd_session();
+    MonSession *s = mon->session_map.get_random_osd_session();
     if (s) {
       dout(10) << "committed, telling random " << s->inst << " all about it" << dendl;
       MOSDMap *m = build_incremental(osdmap.get_epoch() - 1);  // whatev, they'll request more if they need it
@@ -297,9 +297,9 @@ bool OSDMonitor::preprocess_failure(MOSDFailure *m)
   }
 
   //check permissions
-  if (!m->caps->check_privileges(PAXOS_OSDMAP, MON_CAP_X)) {
+  if (!m->get_session()->caps.check_privileges(PAXOS_OSDMAP, MON_CAP_X)) {
     dout(0) << "got MOSDFailure from entity with insufficient caps "
-           << *m->caps << dendl;
+           << m->get_session()->caps << dendl;
     goto didit;
   }
 
@@ -393,9 +393,9 @@ bool OSDMonitor::preprocess_boot(MOSDBoot *m)
   }
 
   //check permissions, ignore if failed (no response expected)
-  if (!m->caps->check_privileges(PAXOS_OSDMAP, MON_CAP_X)) {
+  if (!m->get_session()->caps.check_privileges(PAXOS_OSDMAP, MON_CAP_X)) {
     dout(0) << "got preprocess_boot message from entity with insufficient caps"
-           << *m->caps << dendl;
+           << m->get_session()->caps << dendl;
     delete m;
     return true;
   }
@@ -504,9 +504,9 @@ void OSDMonitor::_booted(MOSDBoot *m, bool logit)
 bool OSDMonitor::preprocess_alive(MOSDAlive *m)
 {
   //check permissions, ignore if failed
-  if (!m->caps->check_privileges(PAXOS_OSDMAP, MON_CAP_X)) {
+  if (!m->get_session()->caps.check_privileges(PAXOS_OSDMAP, MON_CAP_X)) {
     dout(0) << "attempt to send MOSDAlive from entity with insufficient privileges:"
-           << *m->caps << dendl;
+           << m->get_session()->caps << dendl;
     return true;
   }
   int from = m->get_orig_source().num();
@@ -556,9 +556,9 @@ bool OSDMonitor::preprocess_pgtemp(MOSDPGTemp *m)
   dout(10) << "preprocess_pgtemp " << *m << dendl;
 
   //check caps
-  if (!m->caps->check_privileges(PAXOS_OSDMAP, MON_CAP_X)) {
+  if (!m->get_session()->caps.check_privileges(PAXOS_OSDMAP, MON_CAP_X)) {
     dout(0) << "attempt to send MOSDPGTemp from entity with insufficient caps "
-           << *m->caps << dendl;
+           << m->get_session()->caps << dendl;
     return true;
   }
   vector<int> empty;
@@ -597,9 +597,9 @@ bool OSDMonitor::preprocess_remove_snaps(MRemoveSnaps *m)
   dout(7) << "preprocess_remove_snaps " << *m << dendl;
 
   //check privilege, ignore if failed
-  if (!m->caps->check_privileges(PAXOS_OSDMAP, MON_CAP_RW)) {
+  if (!m->get_session()->caps.check_privileges(PAXOS_OSDMAP, MON_CAP_RW)) {
     dout(0) << "got preprocess_remove_snaps from entity with insufficient caps "
-           << *m->caps << dendl;
+           << m->get_session()->caps << dendl;
     delete m;
     return true;
   }
@@ -1035,21 +1035,22 @@ int OSDMonitor::prepare_new_pool(MPoolOp *m)
   dout(10) << "prepare_new_pool from "
           << (m->get_connection()) << dendl;
   if (m->auid) {
-    if(m->caps->check_privileges(PAXOS_OSDMAP, MON_CAP_W, m->auid)) {
+    if(m->get_session()->
+       caps.check_privileges(PAXOS_OSDMAP, MON_CAP_W, m->auid)) {
       return prepare_new_pool(m->name, m->auid);
     } else {
       dout(5) << "attempt to create new pool without sufficient auid privileges!"
              << "message: " << *m  << std::endl
-             << "caps: " << *m->caps << dendl;
+             << "caps: " << m->get_session()->caps << dendl;
       return -EPERM;
     }
   } else {
-    if (m->caps->check_privileges(PAXOS_OSDMAP, MON_CAP_W)) {
-      return prepare_new_pool(m->name, m->caps->auid);
+    if (m->get_session()->caps.check_privileges(PAXOS_OSDMAP, MON_CAP_W)) {
+      return prepare_new_pool(m->name, m->get_session()->caps.auid);
     } else {
       dout(5) << "attempt to create new pool without sufficient caps!"
              << "message: " << *m  << std::endl
-             << "caps: " << *m->caps << dendl;
+             << "caps: " << m->get_session()->caps << dendl;
       return -EPERM;
     }
   }
@@ -1446,10 +1447,12 @@ bool OSDMonitor::prepare_pool_op_delete (MPoolOp *m)
 bool OSDMonitor::prepare_pool_op_auid (MPoolOp *m)
 {
   //check that current user can write to new auid
-  if(m->caps->check_privileges(PAXOS_OSDMAP, MON_CAP_W, m->auid)) {
+  if(m->get_session()->
+     caps.check_privileges(PAXOS_OSDMAP, MON_CAP_W, m->auid)) {
     //check that current user can write to old auid
     int old_auid = osdmap.get_pg_pool(m->pool)->v.auid;
-    if(m->caps->check_privileges(PAXOS_OSDMAP, MON_CAP_W, old_auid)) {
+    if(m->get_session()->
+       caps.check_privileges(PAXOS_OSDMAP, MON_CAP_W, old_auid)) {
       //update pg_pool_t with new auid
       pending_inc.new_pools[m->pool] = *(osdmap.get_pg_pool(m->pool));
       pending_inc.new_pools[m->pool].v.auid = m->auid;
index 53acb3bae7991ada296a749865a98321ac40a090..1af1c41123d2e7d4a71ba67bc53c7042eb067fd7 100644 (file)
@@ -191,9 +191,9 @@ void PGMonitor::committed()
 void PGMonitor::handle_statfs(MStatfs *statfs)
 {
   //check caps
-  if(!statfs->caps->check_privileges(PAXOS_PGMAP, MON_CAP_R)) {
+  if(!statfs->get_session()->caps.check_privileges(PAXOS_PGMAP, MON_CAP_R)) {
     dout(0) << "MStatfs received from entity with insufficient privileges "
-           << *statfs->caps << dendl;
+           << statfs->get_session()->caps << dendl;
     goto out;
   }
   MStatfsReply *reply;
@@ -224,9 +224,9 @@ bool PGMonitor::preprocess_getpoolstats(MGetPoolStats *m)
 {
   MGetPoolStatsReply *reply;
 
-  if (!m->caps->check_privileges(PAXOS_PGMAP, MON_CAP_R)) {
+  if (!m->get_session()->caps.check_privileges(PAXOS_PGMAP, MON_CAP_R)) {
     dout(0) << "MGetPoolStats received from entity with insufficient caps "
-           << *m->caps << dendl;
+           << m->get_session()->caps << dendl;
     goto out;
   }
 
@@ -262,9 +262,9 @@ bool PGMonitor::preprocess_pg_stats(MPGStats *stats)
   int from = stats->get_orig_source().num();
   MPGStatsAck *ack;
   //check caps
-  if (!stats->caps->check_privileges(PAXOS_PGMAP, MON_CAP_R)) {
+  if (!stats->get_session()->caps.check_privileges(PAXOS_PGMAP, MON_CAP_R)) {
     dout(0) << "MPGStats received from entity with insufficient privileges "
-           << *stats->caps << dendl;
+           << stats->get_session()->caps << dendl;
     goto out;
   }
   // first, just see if they need a new osdmap.  but