]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/mds/SessionMap.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / mds / SessionMap.cc
index ae10833c71857b82cddbb23642fa5fe0be016109..b3a73e8797a274a3361ec6138cd79539995b2e17 100644 (file)
@@ -22,7 +22,7 @@
 #include "common/config.h"
 #include "common/errno.h"
 #include "common/DecayCounter.h"
-#include "include/assert.h"
+#include "include/ceph_assert.h"
 #include "include/stringify.h"
 
 #define dout_context g_ceph_context
@@ -38,7 +38,7 @@ class SessionMapIOContext : public MDSIOContextBase
     MDSRank *get_mds() override {return sessionmap->mds;}
   public:
     explicit SessionMapIOContext(SessionMap *sessionmap_) : sessionmap(sessionmap_) {
-      assert(sessionmap != NULL);
+      ceph_assert(sessionmap != NULL);
     }
 };
 };
@@ -125,9 +125,9 @@ public:
 void SessionMapStore::decode_header(
       bufferlist &header_bl)
 {
-  bufferlist::iterator q = header_bl.begin();
+  auto q = header_bl.cbegin();
   DECODE_START(1, q)
-  ::decode(version, q);
+  decode(version, q);
   DECODE_FINISH(q);
 }
 
@@ -135,7 +135,7 @@ void SessionMapStore::encode_header(
     bufferlist *header_bl)
 {
   ENCODE_START(1, 1, *header_bl);
-  ::encode(version, *header_bl);
+  encode(version, *header_bl);
   ENCODE_FINISH(*header_bl);
 }
 
@@ -161,7 +161,7 @@ void SessionMapStore::decode_values(std::map<std::string, bufferlist> &session_v
       s->set_state(Session::STATE_OPEN);
       s->set_load_avg_decay_rate(decay_rate);
     }
-    auto q = i->second.begin();
+    auto q = i->second.cbegin();
     s->decode(q);
   }
 }
@@ -240,7 +240,7 @@ void SessionMap::_load_finish(
     object_locator_t oloc(mds->mdsmap->get_metadata_pool());
     C_IO_SM_Load *c = new C_IO_SM_Load(this, false);
     ObjectOperation op;
-    op.omap_get_vals(last_key, "", g_conf->mds_sessionmap_keys_per_op,
+    op.omap_get_vals(last_key, "", g_conf()->mds_sessionmap_keys_per_op,
                     &c->session_vals, &c->more_session_vals, &c->values_r);
     mds->objecter->read(oid, oloc, op, CEPH_NOSNAP, NULL, 0,
         new C_OnFinisher(c, mds->finisher));
@@ -270,7 +270,7 @@ void SessionMap::_load_finish(
  * Populate session state from OMAP records in this
  * rank's sessionmap object.
  */
-void SessionMap::load(MDSInternalContextBase *onload)
+void SessionMap::load(MDSContext *onload)
 {
   dout(10) << "load" << dendl;
 
@@ -283,7 +283,7 @@ void SessionMap::load(MDSInternalContextBase *onload)
 
   ObjectOperation op;
   op.omap_get_header(&c->header_bl, &c->header_r);
-  op.omap_get_vals("", "", g_conf->mds_sessionmap_keys_per_op,
+  op.omap_get_vals("", "", g_conf()->mds_sessionmap_keys_per_op,
                   &c->session_vals, &c->more_session_vals, &c->values_r);
 
   mds->objecter->read(oid, oloc, op, CEPH_NOSNAP, NULL, 0, new C_OnFinisher(c, mds->finisher));
@@ -324,10 +324,10 @@ void SessionMap::load_legacy()
 
 void SessionMap::_load_legacy_finish(int r, bufferlist &bl)
 { 
-  bufferlist::iterator blp = bl.begin();
+  auto blp = bl.cbegin();
   if (r < 0) {
     derr << "_load_finish got " << cpp_strerror(r) << dendl;
-    assert(0 == "failed to load sessionmap");
+    ceph_abort_msg("failed to load sessionmap");
   }
   dump();
   decode_legacy(blp);  // note: this sets last_cap_renew = now()
@@ -373,12 +373,12 @@ public:
 };
 }
 
-void SessionMap::save(MDSInternalContextBase *onsave, version_t needv)
+void SessionMap::save(MDSContext *onsave, version_t needv)
 {
   dout(10) << __func__ << ": needv " << needv << ", v " << version << dendl;
  
   if (needv && committing >= needv) {
-    assert(committing > committed);
+    ceph_assert(committing > committed);
     commit_waiters[committing].push_back(onsave);
     return;
   }
@@ -474,7 +474,7 @@ void SessionMap::_save_finish(version_t v)
 /**
  * Deserialize sessions, and update by_state index
  */
-void SessionMap::decode_legacy(bufferlist::iterator &p)
+void SessionMap::decode_legacy(bufferlist::const_iterator &p)
 {
   // Populate `sessions`
   SessionMapStore::decode_legacy(p);
@@ -514,20 +514,20 @@ uint64_t SessionMap::set_state(Session *session, int s) {
   return session->get_state_seq();
 }
 
-void SessionMapStore::decode_legacy(bufferlist::iterator& p)
+void SessionMapStore::decode_legacy(bufferlist::const_iterator& p)
 {
   auto now = clock::now();
   uint64_t pre;
-  ::decode(pre, p);
+  decode(pre, p);
   if (pre == (uint64_t)-1) {
     DECODE_START_LEGACY_COMPAT_LEN(3, 3, 3, p);
-    assert(struct_v >= 2);
+    ceph_assert(struct_v >= 2);
     
-    ::decode(version, p);
+    decode(version, p);
     
     while (!p.end()) {
       entity_inst_t inst;
-      ::decode(inst.name, p);
+      decode(inst.name, p);
       Session *s = get_or_add_session(inst);
       if (s->is_closed()) {
         s->set_state(Session::STATE_OPEN);
@@ -543,7 +543,7 @@ void SessionMapStore::decode_legacy(bufferlist::iterator& p)
 
     // this is a meaningless upper bound.  can be ignored.
     __u32 n;
-    ::decode(n, p);
+    decode(n, p);
     
     while (n-- && !p.end()) {
       auto p2 = p;
@@ -622,7 +622,7 @@ void SessionMap::add_session(Session *s)
 {
   dout(10) << __func__ << " s=" << s << " name=" << s->info.inst.name << dendl;
 
-  assert(session_map.count(s->info.inst.name) == 0);
+  ceph_assert(session_map.count(s->info.inst.name) == 0);
   session_map[s->info.inst.name] = s;
   auto by_state_entry = by_state.find(s->state);
   if (by_state_entry == by_state.end())
@@ -659,7 +659,7 @@ void SessionMap::touch_session(Session *session)
 
   // Move to the back of the session list for this state (should
   // already be on a list courtesy of add_session and set_state)
-  assert(session->item_session_list.is_on_list());
+  ceph_assert(session->item_session_list.is_on_list());
   auto by_state_entry = by_state.find(session->state);
   if (by_state_entry == by_state.end())
     by_state_entry = by_state.emplace(session->state,
@@ -674,7 +674,7 @@ void SessionMap::_mark_dirty(Session *s)
   if (dirty_sessions.count(s->info.inst.name))
     return;
 
-  if (dirty_sessions.size() >= g_conf->mds_sessionmap_keys_per_op) {
+  if (dirty_sessions.size() >= g_conf()->mds_sessionmap_keys_per_op) {
     // Pre-empt the usual save() call from journal segment trim, in
     // order to avoid building up an oversized OMAP update operation
     // from too many sessions modified at once
@@ -722,9 +722,9 @@ version_t SessionMap::mark_projected(Session *s)
 
 namespace {
 class C_IO_SM_Save_One : public SessionMapIOContext {
-  MDSInternalContextBase *on_safe;
+  MDSContext *on_safe;
 public:
-  C_IO_SM_Save_One(SessionMap *cm, MDSInternalContextBase *on_safe_)
+  C_IO_SM_Save_One(SessionMap *cm, MDSContext *on_safe_)
     : SessionMapIOContext(cm), on_safe(on_safe_) {}
   void finish(int r) override {
     if (r != 0) {
@@ -743,7 +743,7 @@ public:
 void SessionMap::save_if_dirty(const std::set<entity_name_t> &tgt_sessions,
                                MDSGatherBuilder *gather_bld)
 {
-  assert(gather_bld != NULL);
+  ceph_assert(gather_bld != NULL);
 
   std::vector<entity_name_t> write_sessions;
 
@@ -782,14 +782,9 @@ void SessionMap::save_if_dirty(const std::set<entity_name_t> &tgt_sessions,
   dout(4) << __func__ << ": writing " << write_sessions.size() << dendl;
 
   // Batch writes into mds_sessionmap_keys_per_op
-  const uint32_t kpo = g_conf->mds_sessionmap_keys_per_op;
+  const uint32_t kpo = g_conf()->mds_sessionmap_keys_per_op;
   map<string, bufferlist> to_set;
   for (uint32_t i = 0; i < write_sessions.size(); ++i) {
-    // Start a new write transaction?
-    if (i % g_conf->mds_sessionmap_keys_per_op == 0) {
-      to_set.clear();
-    }
-
     const entity_name_t &session_id = write_sessions[i];
     Session *session = session_map[session_id];
     session->clear_dirty_completed_requests();
@@ -810,11 +805,12 @@ void SessionMap::save_if_dirty(const std::set<entity_name_t> &tgt_sessions,
         || i % kpo == kpo - 1) {
       ObjectOperation op;
       op.omap_set(to_set);
+      to_set.clear(); // clear to start a new transaction      
 
       SnapContext snapc;
       object_t oid = get_object_name();
       object_locator_t oloc(mds->mdsmap->get_metadata_pool());
-      MDSInternalContextBase *on_safe = gather_bld->new_sub();
+      MDSContext *on_safe = gather_bld->new_sub();
       mds->objecter->mutate(oid, oloc, op, snapc,
                            ceph::real_clock::now(), 0,
                            new C_OnFinisher(
@@ -859,8 +855,8 @@ size_t Session::get_request_count()
  */
 void Session::notify_cap_release(size_t n_caps)
 {
-  recall_caps.hit(ceph_clock_now(), -(double)n_caps);
-  release_caps.hit(ceph_clock_now(), n_caps);
+  recall_caps.hit(-(double)n_caps);
+  release_caps.hit(n_caps);
 }
 
 /**
@@ -886,8 +882,9 @@ uint64_t Session::notify_recall_sent(size_t new_limit)
    * session that is not releasing caps (i.e. allow the session counter to
    * throttle future RECALL messages).
    */
-  recall_caps_throttle.hit(ceph_clock_now(), count);
-  recall_caps.hit(ceph_clock_now(), count);
+  recall_caps_throttle.hit(count);
+  recall_caps_throttle2o.hit(count);
+  recall_caps.hit(count);
   return new_change;
 }
 
@@ -923,7 +920,7 @@ void Session::_update_human_name()
   }
 }
 
-void Session::decode(bufferlist::iterator &p)
+void Session::decode(bufferlist::const_iterator &p)
 {
   info.decode(p);
 
@@ -940,7 +937,7 @@ int Session::check_access(CInode *in, unsigned mask,
   if (!in->is_base())
     diri = in->get_projected_parent_dn()->get_dir()->get_inode();
   if (diri && diri->is_stray()){
-    path = std::string(boost::string_view(in->get_projected_inode()->stray_prior_path));
+    path = in->get_projected_inode()->stray_prior_path;
     dout(20) << __func__ << " stray_prior_path " << path << dendl;
   } else {
     in->make_path_string(path, true);
@@ -959,7 +956,8 @@ int Session::check_access(CInode *in, unsigned mask,
 
   if (!auth_caps.is_capable(path, in->inode.uid, in->inode.gid, in->inode.mode,
                            caller_uid, caller_gid, caller_gid_list, mask,
-                           new_uid, new_gid)) {
+                           new_uid, new_gid,
+                           socket_addr)) {
     return -EACCES;
   }
   return 0;
@@ -969,9 +967,9 @@ int Session::check_access(CInode *in, unsigned mask,
 void SessionMap::hit_session(Session *session) {
   uint64_t sessions = get_session_count_in_state(Session::STATE_OPEN) +
                       get_session_count_in_state(Session::STATE_STALE);
-  assert(sessions != 0);
+  ceph_assert(sessions != 0);
 
-  double total_load = total_load_avg.hit(ceph_clock_now(), total_load_avg_rate);
+  double total_load = total_load_avg.hit();
   double avg_load = total_load / sessions;
 
   logger->set(l_mdssm_total_load, (uint64_t)total_load);
@@ -980,61 +978,48 @@ void SessionMap::hit_session(Session *session) {
   session->hit_session();
 }
 
-void SessionMap::handle_conf_change(const struct md_config_t *conf,
+void SessionMap::handle_conf_change(const ConfigProxy &conf,
                                     const std::set <std::string> &changed)
 {
-
-  if (changed.count("mds_request_load_average_decay_rate")) {
-    auto d = g_conf->get_val<double>("mds_request_load_average_decay_rate");
-    dout(20) << __func__ << " decay rate changed to " << d << dendl;
-
-    decay_rate = d;
-    total_load_avg = DecayCounter(ceph_clock_now(), d);
-
-    auto it = by_state.find(Session::STATE_OPEN);
-    if (it != by_state.end()) {
+  auto apply_to_open_sessions = [this](auto f) {
+    if (auto it = by_state.find(Session::STATE_OPEN); it != by_state.end()) {
       for (const auto &session : *(it->second)) {
-        session->set_load_avg_decay_rate(d);
+        f(session);
       }
     }
-    it = by_state.find(Session::STATE_STALE);
-    if (it != by_state.end()) {
+    if (auto it = by_state.find(Session::STATE_STALE); it != by_state.end()) {
       for (const auto &session : *(it->second)) {
-        session->set_load_avg_decay_rate(d);
+        f(session);
       }
     }
+  };
+
+  if (changed.count("mds_request_load_average_decay_rate")) {
+    auto d = g_conf().get_val<double>("mds_request_load_average_decay_rate");
+    dout(20) << __func__ << " decay rate changed to " << d << dendl;
+
+    decay_rate = d;
+    total_load_avg = DecayCounter(d);
+
+    auto mut = [d](auto s) {
+      s->set_load_avg_decay_rate(d);
+    };
+    apply_to_open_sessions(mut);
   }
   if (changed.count("mds_recall_max_decay_rate")) {
-    auto d = g_conf->get_val<double>("mds_recall_max_decay_rate");
-    auto it = by_state.find(Session::STATE_OPEN);
-    if (it != by_state.end()) {
-      for (const auto &session : *(it->second)) {
-        session->recall_caps_throttle = DecayCounter(ceph_clock_now(), d);
-      }
-    }
-    it = by_state.find(Session::STATE_STALE);
-    if (it != by_state.end()) {
-      for (const auto &session : *(it->second)) {
-        session->recall_caps_throttle = DecayCounter(ceph_clock_now(), d);
-      }
-    }
+    auto d = g_conf().get_val<double>("mds_recall_max_decay_rate");
+    auto mut = [d](auto s) {
+      s->recall_caps_throttle = DecayCounter(d);
+    };
+    apply_to_open_sessions(mut);
   }
   if (changed.count("mds_recall_warning_decay_rate")) {
-    auto d = g_conf->get_val<double>("mds_recall_warning_decay_rate");
-    auto it = by_state.find(Session::STATE_OPEN);
-    if (it != by_state.end()) {
-      for (const auto &session : *(it->second)) {
-        session->recall_caps = DecayCounter(ceph_clock_now(), d);
-        session->release_caps = DecayCounter(ceph_clock_now(), d);
-      }
-    }
-    it = by_state.find(Session::STATE_STALE);
-    if (it != by_state.end()) {
-      for (const auto &session : *(it->second)) {
-        session->recall_caps = DecayCounter(ceph_clock_now(), d);
-        session->release_caps = DecayCounter(ceph_clock_now(), d);
-      }
-    }
+    auto d = g_conf().get_val<double>("mds_recall_warning_decay_rate");
+    auto mut = [d](auto s) {
+      s->recall_caps = DecayCounter(d);
+      s->release_caps = DecayCounter(d);
+    };
+    apply_to_open_sessions(mut);
   }
 }
 
@@ -1051,7 +1036,7 @@ int SessionFilter::parse(
     const std::vector<std::string> &args,
     std::stringstream *ss)
 {
-  assert(ss != NULL);
+  ceph_assert(ss != NULL);
 
   for (const auto &s : args) {
     dout(20) << __func__ << " parsing filter '" << s << "'" << dendl;
@@ -1095,9 +1080,9 @@ int SessionFilter::parse(
        * Strict boolean parser.  Allow true/false/0/1.
        * Anything else is -EINVAL.
        */
-      auto is_true = [](boost::string_view bstr, bool *out) -> bool
+      auto is_true = [](std::string_view bstr, bool *out) -> bool
       {
-        assert(out != nullptr);
+        ceph_assert(out != nullptr);
 
         if (bstr == "true" || bstr == "1") {
           *out = true;
@@ -1134,10 +1119,11 @@ bool SessionFilter::match(
   for (const auto &m : metadata) {
     const auto &k = m.first;
     const auto &v = m.second;
-    if (session.info.client_metadata.count(k) == 0) {
+    auto it = session.info.client_metadata.find(k);
+    if (it == session.info.client_metadata.end()) {
       return false;
     }
-    if (session.info.client_metadata.at(k) != v) {
+    if (it->second != v) {
       return false;
     }
   }
@@ -1166,10 +1152,10 @@ bool SessionFilter::match(
 
 std::ostream& operator<<(std::ostream &out, const Session &s)
 {
- if (s.get_human_name() == stringify(s.info.inst.name.num())) {
+ if (s.get_human_name() == stringify(s.get_client())) {
    out << s.get_human_name();
  } else {
-   out << s.get_human_name() << " (" << std::dec << s.info.inst.name.num() << ")";
+   out << s.get_human_name() << " (" << std::dec << s.get_client() << ")";
  }
  return out;
 }