From: Sage Weil Date: Wed, 2 Sep 2015 02:26:01 +0000 (-0400) Subject: mds/SessionMap: move Session method definitions together X-Git-Tag: v10.0.0~123^2~14 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fa43c6f28caaf4711e733f46f2cfc6d2a61f1784;p=ceph.git mds/SessionMap: move Session method definitions together Signed-off-by: Sage Weil --- diff --git a/src/mds/SessionMap.cc b/src/mds/SessionMap.cc index cde0ba0d38dd..e36945c31b72 100644 --- a/src/mds/SessionMap.cc +++ b/src/mds/SessionMap.cc @@ -545,27 +545,6 @@ void SessionMap::wipe_ino_prealloc() projected = ++version; } -/** - * Calculate the length of the `requests` member list, - * because elist does not have a size() method. - * - * O(N) runtime. This would be const, but elist doesn't - * have const iterators. - */ -size_t Session::get_request_count() -{ - size_t result = 0; - - elist::iterator p = requests.begin( - member_offset(MDRequestImpl, item_session_request)); - while (!p.end()) { - ++result; - ++p; - } - - return result; -} - void SessionMap::add_session(Session *s) { dout(10) << __func__ << " s=" << s << " name=" << s->info.inst.name << dendl; @@ -606,85 +585,6 @@ void SessionMap::touch_session(Session *session) session->last_cap_renew = ceph_clock_now(g_ceph_context); } -/** - * Capped in response to a CEPH_MSG_CLIENT_CAPRELEASE message, - * with n_caps equal to the number of caps that were released - * in the message. Used to update state about how many caps a - * client has released since it was last instructed to RECALL_STATE. - */ -void Session::notify_cap_release(size_t n_caps) -{ - if (!recalled_at.is_zero()) { - recall_release_count += n_caps; - if (recall_release_count >= recall_count) { - recalled_at = utime_t(); - recall_count = 0; - recall_release_count = 0; - } - } -} - -/** - * Called when a CEPH_MSG_CLIENT_SESSION->CEPH_SESSION_RECALL_STATE - * message is sent to the client. Update our recall-related state - * in order to generate health metrics if the session doesn't see - * a commensurate number of calls to ::notify_cap_release - */ -void Session::notify_recall_sent(int const new_limit) -{ - if (recalled_at.is_zero()) { - // Entering recall phase, set up counters so we can later - // judge whether the client has respected the recall request - recalled_at = ceph_clock_now(g_ceph_context); - assert (new_limit < caps.size()); // Behaviour of Server::recall_client_state - recall_count = caps.size() - new_limit; - recall_release_count = 0; - } -} - -void Session::set_client_metadata(map const &meta) -{ - info.client_metadata = meta; - - _update_human_name(); -} - -/** - * Use client metadata to generate a somewhat-friendlier - * name for the client than its session ID. - * - * This is *not* guaranteed to be unique, and any machine - * consumers of session-related output should always use - * the session ID as a primary capacity and use this only - * as a presentation hint. - */ -void Session::_update_human_name() -{ - if (info.client_metadata.count("hostname")) { - // Happy path, refer to clients by hostname - human_name = info.client_metadata["hostname"]; - if (info.client_metadata.count("entity_id")) { - EntityName entity; - entity.set_id(info.client_metadata["entity_id"]); - if (!entity.has_default_id()) { - // When a non-default entity ID is set by the user, assume they - // would like to see it in references to the client - human_name += std::string(":") + entity.get_id(); - } - } - } else { - // Fallback, refer to clients by ID e.g. client.4567 - human_name = stringify(info.inst.name.num()); - } -} - -void Session::decode(bufferlist::iterator &p) -{ - info.decode(p); - - _update_human_name(); -} - void SessionMap::_mark_dirty(Session *s) { if (dirty_sessions.size() >= g_conf->mds_sessionmap_keys_per_op) { @@ -829,6 +729,109 @@ void SessionMap::save_if_dirty(const std::set &tgt_sessions, } } +// ================= +// Session + +/** + * Calculate the length of the `requests` member list, + * because elist does not have a size() method. + * + * O(N) runtime. This would be const, but elist doesn't + * have const iterators. + */ +size_t Session::get_request_count() +{ + size_t result = 0; + + elist::iterator p = requests.begin( + member_offset(MDRequestImpl, item_session_request)); + while (!p.end()) { + ++result; + ++p; + } + + return result; +} + +/** + * Capped in response to a CEPH_MSG_CLIENT_CAPRELEASE message, + * with n_caps equal to the number of caps that were released + * in the message. Used to update state about how many caps a + * client has released since it was last instructed to RECALL_STATE. + */ +void Session::notify_cap_release(size_t n_caps) +{ + if (!recalled_at.is_zero()) { + recall_release_count += n_caps; + if (recall_release_count >= recall_count) { + recalled_at = utime_t(); + recall_count = 0; + recall_release_count = 0; + } + } +} + +/** + * Called when a CEPH_MSG_CLIENT_SESSION->CEPH_SESSION_RECALL_STATE + * message is sent to the client. Update our recall-related state + * in order to generate health metrics if the session doesn't see + * a commensurate number of calls to ::notify_cap_release + */ +void Session::notify_recall_sent(int const new_limit) +{ + if (recalled_at.is_zero()) { + // Entering recall phase, set up counters so we can later + // judge whether the client has respected the recall request + recalled_at = ceph_clock_now(g_ceph_context); + assert (new_limit < caps.size()); // Behaviour of Server::recall_client_state + recall_count = caps.size() - new_limit; + recall_release_count = 0; + } +} + +void Session::set_client_metadata(map const &meta) +{ + info.client_metadata = meta; + + _update_human_name(); +} + +/** + * Use client metadata to generate a somewhat-friendlier + * name for the client than its session ID. + * + * This is *not* guaranteed to be unique, and any machine + * consumers of session-related output should always use + * the session ID as a primary capacity and use this only + * as a presentation hint. + */ +void Session::_update_human_name() +{ + if (info.client_metadata.count("hostname")) { + // Happy path, refer to clients by hostname + human_name = info.client_metadata["hostname"]; + if (info.client_metadata.count("entity_id")) { + EntityName entity; + entity.set_id(info.client_metadata["entity_id"]); + if (!entity.has_default_id()) { + // When a non-default entity ID is set by the user, assume they + // would like to see it in references to the client + human_name += std::string(":") + entity.get_id(); + } + } + } else { + // Fallback, refer to clients by ID e.g. client.4567 + human_name = stringify(info.inst.name.num()); + } +} + +void Session::decode(bufferlist::iterator &p) +{ + info.decode(p); + + _update_human_name(); +} + bool Session::check_access(CInode *in, unsigned mask, int caller_uid, int caller_gid, int setattr_uid, int setattr_gid) { string path;