]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: convert stringstream to CachedStackStringStream 36957/head
authorPatrick Donnelly <pdonnell@redhat.com>
Wed, 2 Sep 2020 23:51:50 +0000 (16:51 -0700)
committerPatrick Donnelly <pdonnell@redhat.com>
Fri, 18 Sep 2020 01:54:55 +0000 (18:54 -0700)
This is a simple performance refactor.

Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
23 files changed:
src/common/DecayCounter.h
src/common/StackStringStream.h
src/common/cmdparse.cc
src/common/cmdparse.h
src/mds/Beacon.cc
src/mds/CDir.cc
src/mds/FSMap.cc
src/mds/Locker.cc
src/mds/MDBalancer.cc
src/mds/MDCache.cc
src/mds/MDSCacheObject.cc
src/mds/MDSDaemon.cc
src/mds/MDSMap.cc
src/mds/MDSRank.cc
src/mds/OpenFileTable.cc
src/mds/ScrubStack.cc
src/mds/Server.cc
src/mds/SessionMap.cc
src/mds/SessionMap.h
src/mds/SnapServer.cc
src/mds/cephfs_features.cc
src/mds/journal.cc
src/mds/mdstypes.h

index 2202b596e2adc02b8396659a556cc18600d762b1..9455ecc5a33d67e36f2e34343a61aa5cf23997af 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "include/buffer.h"
 #include "common/Formatter.h"
+#include "common/StackStringStream.h"
 #include "common/ceph_time.h"
 
 #include <cmath>
@@ -125,11 +126,11 @@ inline void decode(DecayCounter &c, ceph::buffer::list::const_iterator &p) {
 }
 
 inline std::ostream& operator<<(std::ostream& out, const DecayCounter& d) {
-  std::ostringstream oss;
-  oss.precision(2);
+  CachedStackStringStream css;
+  css->precision(2);
   double val = d.get();
-  oss << "[C " << std::scientific << val << "]";
-  return out << oss.str();
+  *css << "[C " << std::scientific << val << "]";
+  return out << css->strv();
 }
 
 #endif
index 046e37d7acd0aa139162e0f1c0dd32d715d1c2b8..8bd70fc1a110ad85be632de8ca5d47bc6f08e7ac 100644 (file)
@@ -108,6 +108,9 @@ public:
   std::string_view strv() const {
     return ssb.strv();
   }
+  std::string str() const {
+    return std::string(ssb.strv());
+  }
 
 private:
   StackStringBuf<SIZE> ssb;
index 6dbbb3925dd2b45d2e1bcf1e20839897651da685..b8cf316340de5c8b0e685eee7c56ae03b018ffbd 100644 (file)
@@ -289,7 +289,7 @@ void cmdmap_dump(const cmdmap_t &cmdmap, Formatter *f)
  * false, ss is valid */
 
 bool
-cmdmap_from_json(const vector<string>& cmd, cmdmap_t *mapp, stringstream &ss)
+cmdmap_from_json(const vector<string>& cmd, cmdmap_t *mapp, std::ostream& ss)
 {
   json_spirit::mValue v;
 
index 2f9e85acf9052e1e07a476a08e58f6b33cf904d4..112c24930532188ca35c5f62c9bf4a793f791cb4 100644 (file)
@@ -40,7 +40,7 @@ void dump_cmddesc_to_json(ceph::Formatter *jf,
                          const std::string& perm,
                          uint64_t flags);
 bool cmdmap_from_json(const std::vector<std::string>& cmd, cmdmap_t *mapp,
-                     std::stringstream &ss);
+                     std::ostream& ss);
 void cmdmap_dump(const cmdmap_t &cmdmap, ceph::Formatter *f);
 void handle_bad_get(CephContext *cct, const std::string& k, const char *name);
 
index 9953324d80c1433bb1541057119c6aed19dc077a..89654759187ace4338b4bfafc7a428a37e38eab9 100644 (file)
@@ -307,11 +307,11 @@ void Beacon::notify_health(MDSRank const *mds)
   // Indicates MDS is not trimming promptly
   {
     if (mds->mdlog->get_num_segments() > (size_t)(g_conf()->mds_log_max_segments * g_conf().get_val<double>("mds_log_warn_factor"))) {
-      std::ostringstream oss;
-      oss << "Behind on trimming (" << mds->mdlog->get_num_segments()
+      CachedStackStringStream css;
+      *css << "Behind on trimming (" << mds->mdlog->get_num_segments()
         << "/" << g_conf()->mds_log_max_segments << ")";
 
-      MDSHealthMetric m(MDS_HEALTH_TRIM, HEALTH_WARN, oss.str());
+      MDSHealthMetric m(MDS_HEALTH_TRIM, HEALTH_WARN, css->strv());
       m.metadata["num_segments"] = stringify(mds->mdlog->get_num_segments());
       m.metadata["max_segments"] = stringify(g_conf()->mds_log_max_segments);
       health.metrics.push_back(m);
@@ -336,9 +336,9 @@ void Beacon::notify_health(MDSRank const *mds)
         continue;
       }
 
-      std::ostringstream oss;
-      oss << "Client " << s->get_human_name() << " failing to respond to capability release";
-      MDSHealthMetric m(MDS_HEALTH_CLIENT_LATE_RELEASE, HEALTH_WARN, oss.str());
+      CachedStackStringStream css;
+      *css << "Client " << s->get_human_name() << " failing to respond to capability release";
+      MDSHealthMetric m(MDS_HEALTH_CLIENT_LATE_RELEASE, HEALTH_WARN, css->strv());
       m.metadata["client_id"] = stringify(client.v);
       late_cap_metrics.emplace_back(std::move(m));
     }
@@ -347,10 +347,10 @@ void Beacon::notify_health(MDSRank const *mds)
       auto&& m = late_cap_metrics;
       health.metrics.insert(std::end(health.metrics), std::cbegin(m), std::cend(m));
     } else {
-      std::ostringstream oss;
-      oss << "Many clients (" << late_cap_metrics.size()
+      CachedStackStringStream css;
+      *css << "Many clients (" << late_cap_metrics.size()
           << ") failing to respond to capability release";
-      MDSHealthMetric m(MDS_HEALTH_CLIENT_LATE_RELEASE_MANY, HEALTH_WARN, oss.str());
+      MDSHealthMetric m(MDS_HEALTH_CLIENT_LATE_RELEASE_MANY, HEALTH_WARN, css->strv());
       m.metadata["client_count"] = stringify(late_cap_metrics.size());
       health.metrics.push_back(std::move(m));
     }
@@ -377,9 +377,9 @@ void Beacon::notify_health(MDSRank const *mds)
         dout(2) << "Session " << *session <<
              " is not releasing caps fast enough. Recalled caps at " << recall_caps
           << " > " << recall_warning_threshold << " (mds_recall_warning_threshold)." << dendl;
-        std::ostringstream oss;
-        oss << "Client " << session->get_human_name() << " failing to respond to cache pressure";
-        MDSHealthMetric m(MDS_HEALTH_CLIENT_RECALL, HEALTH_WARN, oss.str());
+        CachedStackStringStream css;
+        *css << "Client " << session->get_human_name() << " failing to respond to cache pressure";
+        MDSHealthMetric m(MDS_HEALTH_CLIENT_RECALL, HEALTH_WARN, css->strv());
         m.metadata["client_id"] = stringify(session->get_client());
         late_recall_metrics.emplace_back(std::move(m));
       }
@@ -387,9 +387,9 @@ void Beacon::notify_health(MDSRank const *mds)
           session->get_num_completed_requests() >= max_completed_requests) ||
          (session->get_num_trim_flushes_warnings() > 0 &&
           session->get_num_completed_flushes() >= max_completed_flushes)) {
-       std::ostringstream oss;
-       oss << "Client " << session->get_human_name() << " failing to advance its oldest client/flush tid. ";
-       MDSHealthMetric m(MDS_HEALTH_CLIENT_OLDEST_TID, HEALTH_WARN, oss.str());
+       CachedStackStringStream css;
+       *css << "Client " << session->get_human_name() << " failing to advance its oldest client/flush tid. ";
+       MDSHealthMetric m(MDS_HEALTH_CLIENT_OLDEST_TID, HEALTH_WARN, css->strv());
        m.metadata["client_id"] = stringify(session->get_client());
        large_completed_requests_metrics.emplace_back(std::move(m));
       }
@@ -399,10 +399,10 @@ void Beacon::notify_health(MDSRank const *mds)
       auto&& m = late_recall_metrics;
       health.metrics.insert(std::end(health.metrics), std::cbegin(m), std::cend(m));
     } else {
-      std::ostringstream oss;
-      oss << "Many clients (" << late_recall_metrics.size()
+      CachedStackStringStream css;
+      *css << "Many clients (" << late_recall_metrics.size()
           << ") failing to respond to cache pressure";
-      MDSHealthMetric m(MDS_HEALTH_CLIENT_RECALL_MANY, HEALTH_WARN, oss.str());
+      MDSHealthMetric m(MDS_HEALTH_CLIENT_RECALL_MANY, HEALTH_WARN, css->strv());
       m.metadata["client_count"] = stringify(late_recall_metrics.size());
       health.metrics.push_back(m);
       late_recall_metrics.clear();
@@ -412,10 +412,10 @@ void Beacon::notify_health(MDSRank const *mds)
       auto&& m = large_completed_requests_metrics;
       health.metrics.insert(std::end(health.metrics), std::cbegin(m), std::cend(m));
     } else {
-      std::ostringstream oss;
-      oss << "Many clients (" << large_completed_requests_metrics.size()
+      CachedStackStringStream css;
+      *css << "Many clients (" << large_completed_requests_metrics.size()
        << ") failing to advance their oldest client/flush tid";
-      MDSHealthMetric m(MDS_HEALTH_CLIENT_OLDEST_TID_MANY, HEALTH_WARN, oss.str());
+      MDSHealthMetric m(MDS_HEALTH_CLIENT_OLDEST_TID_MANY, HEALTH_WARN, css->strv());
       m.metadata["client_count"] = stringify(large_completed_requests_metrics.size());
       health.metrics.push_back(m);
       large_completed_requests_metrics.clear();
@@ -427,10 +427,10 @@ void Beacon::notify_health(MDSRank const *mds)
     int slow = mds->get_mds_slow_req_count();
     if (slow) {
       dout(20) << slow << " slow request found" << dendl;
-      std::ostringstream oss;
-      oss << slow << " slow requests are blocked > " << g_conf()->mds_op_complaint_time << " secs";
+      CachedStackStringStream css;
+      *css << slow << " slow requests are blocked > " << g_conf()->mds_op_complaint_time << " secs";
 
-      MDSHealthMetric m(MDS_HEALTH_SLOW_REQUEST, HEALTH_WARN, oss.str());
+      MDSHealthMetric m(MDS_HEALTH_SLOW_REQUEST, HEALTH_WARN, css->strv());
       health.metrics.push_back(m);
     }
   }
@@ -446,11 +446,11 @@ void Beacon::notify_health(MDSRank const *mds)
       dout(20) << count << " slow metadata IOs found" << dendl;
 
       auto oldest_secs = std::chrono::duration<double>(now - oldest).count();
-      std::ostringstream oss;
-      oss << count << " slow metadata IOs are blocked > " << complaint_time
+      CachedStackStringStream css;
+      *css << count << " slow metadata IOs are blocked > " << complaint_time
          << " secs, oldest blocked for " << (int64_t)oldest_secs << " secs";
 
-      MDSHealthMetric m(MDS_HEALTH_SLOW_METADATA_IO, HEALTH_WARN, oss.str());
+      MDSHealthMetric m(MDS_HEALTH_SLOW_METADATA_IO, HEALTH_WARN, css->strv());
       health.metrics.push_back(m);
     }
   }
@@ -464,13 +464,13 @@ void Beacon::notify_health(MDSRank const *mds)
 
   // Report if we have significantly exceeded our cache size limit
   if (mds->mdcache->cache_overfull()) {
-    std::ostringstream oss;
-    oss << "MDS cache is too large (" << bytes2str(mds->mdcache->cache_size())
+    CachedStackStringStream css;
+    *css << "MDS cache is too large (" << bytes2str(mds->mdcache->cache_size())
         << "/" << bytes2str(mds->mdcache->cache_limit_memory()) << "); "
         << mds->mdcache->num_inodes_with_caps << " inodes in use by clients, "
         << mds->mdcache->get_num_strays() << " stray files";
 
-    MDSHealthMetric m(MDS_HEALTH_CACHE_OVERSIZED, HEALTH_WARN, oss.str());
+    MDSHealthMetric m(MDS_HEALTH_CACHE_OVERSIZED, HEALTH_WARN, css->strv());
     health.metrics.push_back(m);
   }
 }
index 7061de14442e9b498667ff1e5b6ac680e9eed882..78fcdb5b6038d380206a91c4904369c0fa132e7f 100755 (executable)
@@ -1910,9 +1910,9 @@ CDentry *CDir::_load_dentry(
       }
     }
   } else {
-    std::ostringstream oss;
-    oss << "Invalid tag char '" << type << "' pos " << pos;
-    throw buffer::malformed_input(oss.str());
+    CachedStackStringStream css;
+    *css << "Invalid tag char '" << type << "' pos " << pos;
+    throw buffer::malformed_input(css->str());
   }
 
   return dn;
index 797325d6e874ed3f00e0a944d98315b91dcfd352..708f2c13ec53100dd8a06ba239f0907d63231087 100644 (file)
@@ -29,9 +29,7 @@
 using std::list;
 using std::pair;
 using std::ostream;
-using std::ostringstream;
 using std::string;
-using std::stringstream;
 
 using ceph::bufferlist;
 using ceph::Formatter;
@@ -483,9 +481,9 @@ void FSMap::get_health(list<pair<health_status_t,string> >& summary,
   }
 
   if (standby_count_wanted) {
-    std::ostringstream oss;
-    oss << "insufficient standby daemons available: have " << standby_daemons.size() << "; want " << standby_count_wanted << " more";
-    summary.push_back(make_pair(HEALTH_WARN, oss.str()));
+    CachedStackStringStream css;
+    *css << "insufficient standby daemons available: have " << standby_daemons.size() << "; want " << standby_count_wanted << " more";
+    summary.push_back(make_pair(HEALTH_WARN, css->str()));
   }
 }
 
@@ -524,10 +522,10 @@ void FSMap::get_health_checks(health_check_map_t *checks) const
       health_check_t& fscheck = checks->get_or_add(
         "FS_WITH_FAILED_MDS", HEALTH_WARN,
         "%num% filesystem%plurals% %hasorhave% a failed mds daemon", 1);
-      ostringstream ss;
-      ss << "fs " << fs->mds_map.fs_name << " has " << stuck_failed.size()
+      CachedStackStringStream css;
+      *css << "fs " << fs->mds_map.fs_name << " has " << stuck_failed.size()
          << " failed mds" << (stuck_failed.size() > 1 ? "s" : "");
-      fscheck.detail.push_back(ss.str()); }
+      fscheck.detail.push_back(css->str()); }
 
     checks->merge(fschecks);
     standby_count_wanted = std::max(
@@ -537,12 +535,12 @@ void FSMap::get_health_checks(health_check_map_t *checks) const
 
   // MDS_INSUFFICIENT_STANDBY
   if (standby_count_wanted) {
-    std::ostringstream oss, dss;
-    oss << "insufficient standby MDS daemons available";
-    auto& d = checks->get_or_add("MDS_INSUFFICIENT_STANDBY", HEALTH_WARN, oss.str(), 1);
-    dss << "have " << standby_daemons.size() << "; want " << standby_count_wanted
-       << " more";
-    d.detail.push_back(dss.str());
+    CachedStackStringStream css1, css2;
+    *css1 << "insufficient standby MDS daemons available";
+    auto& d = checks->get_or_add("MDS_INSUFFICIENT_STANDBY", HEALTH_WARN, css1->str(), 1);
+    *css2 << "have " << standby_daemons.size() << "; want " << standby_count_wanted
+         << " more";
+    d.detail.push_back(css2->str());
   }
 }
 
index 0bd17826563bcb838411023d19848e5ccea9348c..8d2740ad7eead28cf96288669c04b7b23ba9ff7d 100644 (file)
@@ -2453,8 +2453,8 @@ void Locker::revoke_stale_cap(CInode *in, client_t client)
     return;
 
   if (cap->revoking() & CEPH_CAP_ANY_WR) {
-    std::stringstream ss;
-    mds->evict_client(client.v, false, g_conf()->mds_session_blocklist_on_timeout, ss, nullptr);
+    CachedStackStringStream css;
+    mds->evict_client(client.v, false, g_conf()->mds_session_blocklist_on_timeout, *css, nullptr);
     return;
   }
 
@@ -3162,13 +3162,13 @@ void Locker::handle_client_caps(const cref_t<MClientCaps> &m)
       if (session->get_num_completed_flushes() >=
          (g_conf()->mds_max_completed_flushes << session->get_num_trim_flushes_warnings())) {
        session->inc_num_trim_flushes_warnings();
-       stringstream ss;
-       ss << "client." << session->get_client() << " does not advance its oldest_flush_tid ("
-          << m->get_oldest_flush_tid() << "), "
-          << session->get_num_completed_flushes()
-          << " completed flushes recorded in session";
-       mds->clog->warn() << ss.str();
-       dout(20) << __func__ << " " << ss.str() << dendl;
+       CachedStackStringStream css;
+       *css << "client." << session->get_client() << " does not advance its oldest_flush_tid ("
+            << m->get_oldest_flush_tid() << "), "
+            << session->get_num_completed_flushes()
+            << " completed flushes recorded in session";
+       mds->clog->warn() << css->strv();
+       dout(20) << __func__ << " " << css->strv() << dendl;
       }
     }
   }
@@ -4145,12 +4145,12 @@ void Locker::caps_tick()
     // exponential backoff of warning intervals
     if (age > mds->mdsmap->get_session_timeout() * (1 << cap->get_num_revoke_warnings())) {
       cap->inc_num_revoke_warnings();
-      stringstream ss;
-      ss << "client." << cap->get_client() << " isn't responding to mclientcaps(revoke), ino "
-        << cap->get_inode()->ino() << " pending " << ccap_string(cap->pending())
-        << " issued " << ccap_string(cap->issued()) << ", sent " << age << " seconds ago";
-      mds->clog->warn() << ss.str();
-      dout(20) << __func__ << " " << ss.str() << dendl;
+      CachedStackStringStream css;
+      *css << "client." << cap->get_client() << " isn't responding to mclientcaps(revoke), ino "
+          << cap->get_inode()->ino() << " pending " << ccap_string(cap->pending())
+          << " issued " << ccap_string(cap->issued()) << ", sent " << age << " seconds ago";
+      mds->clog->warn() << css->strv();
+      dout(20) << __func__ << " " << css->strv() << dendl;
     } else {
       dout(20) << __func__ << " silencing log message (backoff) for " << "client." << cap->get_client() << "." << cap->get_inode()->ino() << dendl;
     }
index 0c8ec4965bcf6535256a1f98bb4085189355d8b5..2fd700228cb18c95a9171e1de40b6a6baa7af958 100644 (file)
@@ -1400,7 +1400,7 @@ int MDBalancer::dump_loads(Formatter *f) const
   f->open_object_section("mds_load");
   {
 
-    auto dump_mds_load = [f](mds_load_t& load) {
+    auto dump_mds_load = [f](const mds_load_t& load) {
       f->dump_float("request_rate", load.req_rate);
       f->dump_float("cache_hit_rate", load.cache_hit_rate);
       f->dump_float("queue_length", load.queue_len);
@@ -1415,34 +1415,36 @@ int MDBalancer::dump_loads(Formatter *f) const
       f->close_section();
     };
 
-    for (auto p : mds_load) {
-      stringstream name;
-      name << "mds." << p.first;
-      f->open_object_section(name.str().c_str());
-      dump_mds_load(p.second);
+    for (const auto& [rank, load] : mds_load) {
+      CachedStackStringStream css;
+      *css << "mds." << rank;
+      f->open_object_section(css->strv());
+      dump_mds_load(load);
       f->close_section();
     }
   }
   f->close_section(); // mds_load
 
   f->open_object_section("mds_meta_load");
-  for (auto p : mds_meta_load) {
-    stringstream name;
-    name << "mds." << p.first;
-    f->dump_float(name.str().c_str(), p.second);
+  for (auto& [rank, mload] : mds_meta_load) {
+    CachedStackStringStream css;
+    *css << "mds." << rank;
+    f->dump_float(css->strv(), mload);
   }
   f->close_section(); // mds_meta_load
 
   f->open_object_section("mds_import_map");
-  for (auto p : mds_import_map) {
-    stringstream name1;
-    name1 << "mds." << p.first;
-    f->open_array_section(name1.str().c_str());
-    for (auto q : p.second) {
+  for (auto& [rank, imports] : mds_import_map) {
+    {
+      CachedStackStringStream css;
+      *css << "mds." << rank;
+      f->open_array_section(css->strv());
+    }
+    for (auto& [rank_from, mload] : imports) {
       f->open_object_section("from");
-      stringstream name2;
-      name2 << "mds." << q.first;
-      f->dump_float(name2.str().c_str(), q.second);
+      CachedStackStringStream css;
+      *css << "mds." << rank_from;
+      f->dump_float(css->strv(), mload);
       f->close_section();
     }
     f->close_section(); // mds.? array
index 7ceb51645eef54f03770b2b15fec9bc9d45a5779..860c39f4a5cd6926c67b5c28f69ea6d7b373bac4 100644 (file)
@@ -509,9 +509,9 @@ void MDCache::create_mydir_hierarchy(MDSGather *gather)
   for (int i = 0; i < NUM_STRAY; ++i) {
     CInode *stray = create_system_inode(MDS_INO_STRAY(mds->get_nodeid(), i), S_IFDIR);
     CDir *straydir = stray->get_or_open_dirfrag(this, frag_t());
-    stringstream name;
-    name << "stray" << i;
-    CDentry *sdn = mydir->add_primary_dentry(name.str(), stray);
+    CachedStackStringStream css;
+    *css << "stray" << i;
+    CDentry *sdn = mydir->add_primary_dentry(css->str(), stray);
     sdn->_mark_dirty(mds->mdlog->get_current_segment());
 
     stray->_get_inode()->dirstat = straydir->get_fnode()->fragstat;
@@ -801,16 +801,16 @@ void MDCache::populate_mydir()
   // open or create stray
   uint64_t num_strays = 0;
   for (int i = 0; i < NUM_STRAY; ++i) {
-    stringstream name;
-    name << "stray" << i;
-    CDentry *straydn = mydir->lookup(name.str());
+    CachedStackStringStream css;
+    *css << "stray" << i;
+    CDentry *straydn = mydir->lookup(css->str());
 
     // allow for older fs's with stray instead of stray0
     if (straydn == NULL && i == 0)
       straydn = mydir->lookup("stray");
 
     if (!straydn || !straydn->get_linkage()->get_inode()) {
-      _create_system_file(mydir, name.str().c_str(), create_system_inode(MDS_INO_STRAY(mds->get_nodeid(), i), S_IFDIR),
+      _create_system_file(mydir, css->strv(), create_system_inode(MDS_INO_STRAY(mds->get_nodeid(), i), S_IFDIR),
                          new C_MDS_RetryOpenRoot(this));
       return;
     }
@@ -5825,11 +5825,11 @@ void MDCache::export_remaining_imported_caps()
 {
   dout(10) << "export_remaining_imported_caps" << dendl;
 
-  stringstream warn_str;
+  CachedStackStringStream css;
 
   int count = 0;
   for (auto p = cap_imports.begin(); p != cap_imports.end(); ++p) {
-    warn_str << " ino " << p->first << "\n";
+    *css << " ino " << p->first << "\n";
     for (auto q = p->second.begin(); q != p->second.end(); ++q) {
       Session *session = mds->sessionmap.get_session(entity_name_t::CLIENT(q->first.v));
       if (session) {
@@ -5854,9 +5854,9 @@ void MDCache::export_remaining_imported_caps()
   cap_imports.clear();
   cap_reconnect_waiters.clear();
 
-  if (warn_str.peek() != EOF) {
-    mds->clog->warn() << "failed to reconnect caps for missing inodes:";
-    mds->clog->warn(warn_str);
+  if (css->strv().length()) {
+    mds->clog->warn() << "failed to reconnect caps for missing inodes:"
+                      << css->strv();
   }
 }
 
@@ -6023,16 +6023,16 @@ void MDCache::open_snaprealms()
   if (!reconnected_snaprealms.empty()) {
     dout(5) << "open_snaprealms has unconnected snaprealm:" << dendl;
     for (auto& p : reconnected_snaprealms) {
-      stringstream warn_str;
-      warn_str << " " << p.first << " {";
+      CachedStackStringStream css;
+      *css << " " << p.first << " {";
       bool first = true;
       for (auto& q : p.second) {
         if (!first)
-          warn_str << ", ";
-        warn_str << "client." << q.first << "/" << q.second;
+          *css << ", ";
+        *css << "client." << q.first << "/" << q.second;
       }
-      warn_str << "}";
-      dout(5) << warn_str.str() << dendl;
+      *css << "}";
+      dout(5) << css->strv() << dendl;
     }
   }
   ceph_assert(rejoin_waiters.empty());
@@ -12732,10 +12732,10 @@ int MDCache::dump_cache(std::string_view fn, Formatter *f)
 
   if (threshold && cache_size() > threshold) {
     if (f) {
-      std::stringstream ss;
-      ss << "cache usage exceeds dump threshold";
+      CachedStackStringStream css;
+      *css << "cache usage exceeds dump threshold";
       f->open_object_section("result");
-      f->dump_string("error", ss.str());
+      f->dump_string("error", css->strv());
       f->close_section();
     } else {
       derr << "cache usage exceeds dump threshold" << dendl;
@@ -12774,26 +12774,26 @@ int MDCache::dump_cache(std::string_view fn, Formatter *f)
       f->close_section();
       return 1;
     } 
-    ostringstream ss;
-    ss << *in << std::endl;
-    std::string s = ss.str();
-    r = safe_write(fd, s.c_str(), s.length());
+    CachedStackStringStream css;
+    *css << *in << std::endl;
+    auto sv = css->strv();
+    r = safe_write(fd, sv.data(), sv.size());
     if (r < 0)
       return r;
     auto&& dfs = in->get_dirfrags();
     for (auto &dir : dfs) {
-      ostringstream tt;
-      tt << " " << *dir << std::endl;
-      std::string t = tt.str();
-      r = safe_write(fd, t.c_str(), t.length());
+      CachedStackStringStream css2;
+      *css2 << " " << *dir << std::endl;
+      auto sv = css2->strv();
+      r = safe_write(fd, sv.data(), sv.size());
       if (r < 0)
         return r;
       for (auto &p : dir->items) {
        CDentry *dn = p.second;
-        ostringstream uu;
-        uu << "  " << *dn << std::endl;
-        std::string u = uu.str();
-        r = safe_write(fd, u.c_str(), u.length());
+        CachedStackStringStream css3;
+        *css3 << "  " << *dn << std::endl;
+        auto sv = css3->strv();
+        r = safe_write(fd, sv.data(), sv.size());
         if (r < 0)
           return r;
       }
index 8398e80c56c2c98da972c508e91ebfdf2c8635b4..b36352c33555dbfcdacf7643925189179b2757f0 100644 (file)
@@ -37,9 +37,9 @@ void MDSCacheObject::dump(ceph::Formatter *f) const
   {
     f->open_object_section("replicas");
     for (const auto &it : get_replicas()) {
-      std::ostringstream rank_str;
-      rank_str << it.first;
-      f->dump_int(rank_str.str().c_str(), it.second);
+      CachedStackStringStream css;
+      *css << it.first;
+      f->dump_int(css->strv(), it.second);
     }
     f->close_section();
   }
@@ -63,7 +63,7 @@ void MDSCacheObject::dump(ceph::Formatter *f) const
 #ifdef MDS_REF_SET
     f->open_object_section("pins");
     for(const auto& p : ref_map) {
-      f->dump_int(pin_name(p.first).data(), p.second);
+      f->dump_int(pin_name(p.first), p.second);
     }
     f->close_section();
 #endif
index faa15feeaa25db7badcd9ba235df76485da639b2..93ef295c60602ce641be53fcf94dfb0bf327cf1c 100644 (file)
@@ -139,7 +139,8 @@ void MDSDaemon::asok_command(
 
   int r = -ENOSYS;
   bufferlist outbl;
-  stringstream ss;
+  CachedStackStringStream css;
+  auto& ss = *css;
   if (command == "status") {
     dump_status(f);
     r = 0;
@@ -595,8 +596,8 @@ void MDSDaemon::handle_command(const cref_t<MCommand> &m)
 
   int r = 0;
   cmdmap_t cmdmap;
-  std::stringstream ss;
-  std::string outs;
+  CachedStackStringStream css;
+  auto& ss = *css;
   bufferlist outbl;
 
   // If someone is using a closed session for sending commands (e.g.
@@ -625,16 +626,14 @@ void MDSDaemon::handle_command(const cref_t<MCommand> &m)
   } else if (m->cmd.empty()) {
     r = -EINVAL;
     ss << "no command given";
-    outs = ss.str();
   } else if (!TOPNSPC::common::cmdmap_from_json(m->cmd, &cmdmap, ss)) {
     r = -EINVAL;
-    outs = ss.str();
   } else {
     cct->get_admin_socket()->queue_tell_command(m);
     return;
   }
 
-  auto reply = make_message<MCommandReply>(r, outs);
+  auto reply = make_message<MCommandReply>(r, ss.str());
   reply->set_tid(m->get_tid());
   reply->set_data(outbl);
   m->get_connection()->send_message2(reply);
index 95d10c9aebb27d4d5d652caeec769ef424f97bee..e655922a63fdd0db0fcfeeb555482c61180bf4e0 100644 (file)
@@ -29,7 +29,6 @@ using std::ostream;
 using std::pair;
 using std::string;
 using std::set;
-using std::stringstream;
 
 using ceph::bufferlist;
 using ceph::Formatter;
@@ -331,35 +330,35 @@ void MDSMap::get_health(list<pair<health_status_t,string> >& summary,
                        list<pair<health_status_t,string> > *detail) const
 {
   if (!failed.empty()) {
-    std::ostringstream oss;
-    oss << "mds rank"
+    CachedStackStringStream css;
+    *css << "mds rank"
        << ((failed.size() > 1) ? "s ":" ")
        << failed
        << ((failed.size() > 1) ? " have":" has")
        << " failed";
-    summary.push_back(make_pair(HEALTH_ERR, oss.str()));
+    summary.push_back(make_pair(HEALTH_ERR, css->str()));
     if (detail) {
-      for (set<mds_rank_t>::const_iterator p = failed.begin(); p != failed.end(); ++p) {
-       std::ostringstream oss;
-       oss << "mds." << *p << " has failed";
-       detail->push_back(make_pair(HEALTH_ERR, oss.str()));
+      for (const auto& r : failed) {
+        CachedStackStringStream css;
+       *css << "mds." << r << " has failed";
+       detail->push_back(make_pair(HEALTH_ERR, css->str()));
       }
     }
   }
 
   if (!damaged.empty()) {
-    std::ostringstream oss;
-    oss << "mds rank"
-       << ((damaged.size() > 1) ? "s ":" ")
-       << damaged
-       << ((damaged.size() > 1) ? " are":" is")
-       << " damaged";
-    summary.push_back(make_pair(HEALTH_ERR, oss.str()));
+    CachedStackStringStream css;
+    *css << "mds rank"
+        << ((damaged.size() > 1) ? "s ":" ")
+        << damaged
+        << ((damaged.size() > 1) ? " are":" is")
+        << " damaged";
+    summary.push_back(make_pair(HEALTH_ERR, css->str()));
     if (detail) {
-      for (set<mds_rank_t>::const_iterator p = damaged.begin(); p != damaged.end(); ++p) {
-       std::ostringstream oss;
-       oss << "mds." << *p << " is damaged";
-       detail->push_back(make_pair(HEALTH_ERR, oss.str()));
+      for (const auto& r : damaged) {
+        CachedStackStringStream css;
+       *css << "mds." << r << " is damaged";
+       detail->push_back(make_pair(HEALTH_ERR, css->str()));
       }
     }
   }
@@ -373,36 +372,36 @@ void MDSMap::get_health(list<pair<health_status_t,string> >& summary,
          continue;
        mds_gid_t gid = up.find(i)->second;
        const auto& info = mds_info.at(gid);
-       stringstream ss;
+        CachedStackStringStream css;
        if (is_resolve(i))
-         ss << "mds." << info.name << " at " << info.addrs
+         *css << "mds." << info.name << " at " << info.addrs
             << " rank " << i << " is resolving";
        if (is_replay(i))
-         ss << "mds." << info.name << " at " << info.addrs
+         *css << "mds." << info.name << " at " << info.addrs
             << " rank " << i << " is replaying journal";
        if (is_rejoin(i))
-         ss << "mds." << info.name << " at " << info.addrs
+         *css << "mds." << info.name << " at " << info.addrs
             << " rank " << i << " is rejoining";
        if (is_reconnect(i))
-         ss << "mds." << info.name << " at " << info.addrs
+         *css << "mds." << info.name << " at " << info.addrs
             << " rank " << i << " is reconnecting to clients";
-       if (ss.str().length())
-         detail->push_back(make_pair(HEALTH_WARN, ss.str()));
+       if (css->strv().length())
+         detail->push_back(make_pair(HEALTH_WARN, css->str()));
       }
     }
   }
 
   {
-  stringstream ss;
-  ss << fs_name << " max_mds " << max_mds;
-  summary.push_back(make_pair(HEALTH_WARN, ss.str()));
+    CachedStackStringStream css;
+    *css << fs_name << " max_mds " << max_mds;
+    summary.push_back(make_pair(HEALTH_WARN, css->str()));
   }
 
   if ((mds_rank_t)up.size() < max_mds) {
-    stringstream ss;
-    ss << fs_name << " has " << up.size()
-       << " active MDS(s), but has max_mds of " << max_mds;
-    summary.push_back(make_pair(HEALTH_WARN, ss.str()));
+    CachedStackStringStream css;
+    *css << fs_name << " has " << up.size()
+         << " active MDS(s), but has max_mds of " << max_mds;
+    summary.push_back(make_pair(HEALTH_WARN, css->str()));
   }
 
   set<string> laggy;
@@ -411,27 +410,27 @@ void MDSMap::get_health(list<pair<health_status_t,string> >& summary,
     if (info.laggy()) {
       laggy.insert(info.name);
       if (detail) {
-       std::ostringstream oss;
-       oss << "mds." << info.name << " at " << info.addrs
+        CachedStackStringStream css;
+       *css << "mds." << info.name << " at " << info.addrs
            << " is laggy/unresponsive";
-       detail->push_back(make_pair(HEALTH_WARN, oss.str()));
+       detail->push_back(make_pair(HEALTH_WARN, css->str()));
       }
     }
   }
 
   if (!laggy.empty()) {
-    std::ostringstream oss;
-    oss << "mds " << laggy
-       << ((laggy.size() > 1) ? " are":" is")
-       << " laggy";
-    summary.push_back(make_pair(HEALTH_WARN, oss.str()));
+    CachedStackStringStream css;
+    *css << "mds " << laggy
+        << ((laggy.size() > 1) ? " are":" is")
+        << " laggy";
+    summary.push_back(make_pair(HEALTH_WARN, css->str()));
   }
 
   if (get_max_mds() > 1 &&
       was_snaps_ever_allowed() && !allows_multimds_snaps()) {
-    std::ostringstream oss;
-    oss << "multi-active mds while there are snapshots possibly created by pre-mimic MDS";
-    summary.push_back(make_pair(HEALTH_WARN, oss.str()));
+    CachedStackStringStream css;
+    *css << "multi-active mds while there are snapshots possibly created by pre-mimic MDS";
+    summary.push_back(make_pair(HEALTH_WARN, css->str()));
   }
 }
 
@@ -442,10 +441,10 @@ void MDSMap::get_health_checks(health_check_map_t *checks) const
     health_check_t& check = checks->get_or_add("MDS_DAMAGE", HEALTH_ERR,
                                               "%num% mds daemon%plurals% damaged",
                                               damaged.size());
-    for (auto p : damaged) {
-      std::ostringstream oss;
-      oss << "fs " << fs_name << " mds." << p << " is damaged";
-      check.detail.push_back(oss.str());
+    for (const auto& p : damaged) {
+      CachedStackStringStream css;
+      *css << "fs " << fs_name << " mds." << p << " is damaged";
+      check.detail.push_back(css->str());
     }
   }
 
@@ -454,9 +453,9 @@ void MDSMap::get_health_checks(health_check_map_t *checks) const
     health_check_t& fscheck = checks->get_or_add(
       "FS_DEGRADED", HEALTH_WARN,
       "%num% filesystem%plurals% %isorare% degraded", 1);
-    std::ostringstream ss;
-    ss << "fs " << fs_name << " is degraded";
-    fscheck.detail.push_back(ss.str());
+    CachedStackStringStream css;
+    *css << "fs " << fs_name << " is degraded";
+    fscheck.detail.push_back(css->str());
 
     list<string> detail;
     for (mds_rank_t i = mds_rank_t(0); i< get_max_mds(); i++) {
@@ -464,19 +463,19 @@ void MDSMap::get_health_checks(health_check_map_t *checks) const
        continue;
       mds_gid_t gid = up.find(i)->second;
       const auto& info = mds_info.at(gid);
-      stringstream ss;
-      ss << "fs " << fs_name << " mds." << info.name << " at "
+      CachedStackStringStream css;
+      *css << "fs " << fs_name << " mds." << info.name << " at "
         << info.addrs << " rank " << i;
       if (is_resolve(i))
-       ss << " is resolving";
+       *css << " is resolving";
       if (is_replay(i))
-       ss << " is replaying journal";
+       *css << " is replaying journal";
       if (is_rejoin(i))
-       ss << " is rejoining";
+       *css << " is rejoining";
       if (is_reconnect(i))
-       ss << " is reconnecting to clients";
-      if (ss.str().length())
-       detail.push_back(ss.str());
+       *css << " is reconnecting to clients";
+      if (css->strv().length())
+       detail.push_back(css->str());
     }
   }
 
@@ -485,10 +484,10 @@ void MDSMap::get_health_checks(health_check_map_t *checks) const
     health_check_t& check = checks->add(
       "MDS_UP_LESS_THAN_MAX", HEALTH_WARN,
       "%num% filesystem%plurals% %isorare% online with fewer MDS than max_mds", 1);
-    stringstream ss;
-    ss << "fs " << fs_name << " has " << get_num_in_mds()
-       << " MDS online, but wants " << get_max_mds();
-    check.detail.push_back(ss.str());
+    CachedStackStringStream css;
+    *css << "fs " << fs_name << " has " << get_num_in_mds()
+         << " MDS online, but wants " << get_max_mds();
+    check.detail.push_back(css->str());
   }
 
   // MDS_ALL_DOWN
@@ -496,9 +495,9 @@ void MDSMap::get_health_checks(health_check_map_t *checks) const
     health_check_t &check = checks->add(
       "MDS_ALL_DOWN", HEALTH_ERR,
       "%num% filesystem%plurals% %isorare% offline", 1);
-    stringstream ss;
-    ss << "fs " << fs_name << " is offline because no MDS is active for it.";
-    check.detail.push_back(ss.str());
+    CachedStackStringStream css;
+    *css << "fs " << fs_name << " is offline because no MDS is active for it.";
+    check.detail.push_back(css->str());
   }
 
   if (get_max_mds() > 1 &&
@@ -506,18 +505,18 @@ void MDSMap::get_health_checks(health_check_map_t *checks) const
     health_check_t &check = checks->add(
       "MULTIMDS_WITH_OLDSNAPS", HEALTH_ERR,
       "%num% filesystem%plurals% %isorare% multi-active mds with old snapshots", 1);
-    stringstream ss;
-    ss << "multi-active mds while there are snapshots possibly created by pre-mimic MDS";
-    check.detail.push_back(ss.str());
+    CachedStackStringStream css;
+    *css << "multi-active mds while there are snapshots possibly created by pre-mimic MDS";
+    check.detail.push_back(css->str());
   }
 
   if (get_inline_data_enabled()) {
     health_check_t &check = checks->add(
       "FS_INLINE_DATA_DEPRECATED", HEALTH_WARN,
       "%num% filesystem%plurals% with deprecated feature inline_data", 1);
-    stringstream ss;
-    ss << "fs " << fs_name << " has deprecated feature inline_data enabled.";
-    check.detail.push_back(ss.str());
+    CachedStackStringStream css;
+    *css << "fs " << fs_name << " has deprecated feature inline_data enabled.";
+    check.detail.push_back(css->str());
   }
 }
 
@@ -611,9 +610,9 @@ void MDSMap::mds_info_t::decode(bufferlist::const_iterator& bl)
 std::string MDSMap::mds_info_t::human_name() const
 {
   // Like "daemon mds.myhost restarted", "Activating daemon mds.myhost"
-  std::ostringstream out;
-  out << "daemon mds." << name;
-  return out.str();
+  CachedStackStringStream css;
+  *css << "daemon mds." << name;
+  return css->str();
 }
 
 void MDSMap::encode(bufferlist& bl, uint64_t features) const
index 6f61d1d5f519fbd2fb0da0201327ee3b489a3abb..3fcfc887955729c67ba81cc32251db1ae91f0b8c 100644 (file)
@@ -688,11 +688,11 @@ void MDSRank::set_mdsmap_multimds_snaps_allowed()
   if (already_sent)
     return;
 
-  stringstream ss;
-  ss << "{\"prefix\":\"fs set\", \"fs_name\":\"" <<  mdsmap->get_fs_name() << "\", ";
-  ss << "\"var\":\"allow_multimds_snaps\", \"val\":\"true\", ";
-  ss << "\"confirm\":\"--yes-i-am-really-a-mds\"}";
-  std::vector<std::string> cmd = {ss.str()};
+  CachedStackStringStream css;
+  *css << "{\"prefix\":\"fs set\", \"fs_name\":\"" <<  mdsmap->get_fs_name() << "\", ";
+  *css << "\"var\":\"allow_multimds_snaps\", \"val\":\"true\", ";
+  *css << "\"confirm\":\"--yes-i-am-really-a-mds\"}";
+  std::vector<std::string> cmd = {css->str()};
 
   dout(0) << __func__ << ": sending mon command: " << cmd[0] << dendl;
 
@@ -2169,9 +2169,9 @@ void MDSRank::stopping_start()
 
     C_GatherBuilder gather(g_ceph_context, new C_MDSInternalNoop);
     for (const auto &s : victims) {
-      std::stringstream ss;
+      CachedStackStringStream css;
       evict_client(s->get_client().v, false,
-                   g_conf()->mds_session_blocklist_on_evict, ss, gather.new_sub());
+                   g_conf()->mds_session_blocklist_on_evict, *css, gather.new_sub());
     }
     gather.activate();
   }
@@ -2517,31 +2517,31 @@ void MDSRankDispatcher::handle_asok_command(
   std::function<void(int,const std::string&,bufferlist&)> on_finish)
 {
   int r = 0;
-  stringstream ss;
+  CachedStackStringStream css;
   bufferlist outbl;
   if (command == "dump_ops_in_flight" ||
       command == "ops") {
     if (!op_tracker.dump_ops_in_flight(f)) {
-      ss << "op_tracker disabled; set mds_enable_op_tracker=true to enable";
+      *css << "op_tracker disabled; set mds_enable_op_tracker=true to enable";
     }
   } else if (command == "dump_blocked_ops") {
     if (!op_tracker.dump_ops_in_flight(f, true)) {
-      ss << "op_tracker disabled; set mds_enable_op_tracker=true to enable";
+      *css << "op_tracker disabled; set mds_enable_op_tracker=true to enable";
     }
   } else if (command == "dump_historic_ops") {
     if (!op_tracker.dump_historic_ops(f)) {
-      ss << "op_tracker disabled; set mds_enable_op_tracker=true to enable";
+      *css << "op_tracker disabled; set mds_enable_op_tracker=true to enable";
     }
   } else if (command == "dump_historic_ops_by_duration") {
     if (!op_tracker.dump_historic_ops(f, true)) {
-      ss << "op_tracker disabled; set mds_enable_op_tracker=true to enable";
+      *css << "op_tracker disabled; set mds_enable_op_tracker=true to enable";
     }
   } else if (command == "osdmap barrier") {
     int64_t target_epoch = 0;
     bool got_val = cmd_getval(cmdmap, "target_epoch", target_epoch);
 
     if (!got_val) {
-      ss << "no target epoch given";
+      *css << "no target epoch given";
       r = -EINVAL;
       goto out;
     }
@@ -2561,7 +2561,7 @@ void MDSRankDispatcher::handle_asok_command(
     cmd_getval(cmdmap, "filters", filter_args);
 
     SessionFilter filter;
-    r = filter.parse(filter_args, &ss);
+    r = filter.parse(filter_args, css.get());
     if (r != 0) {
       goto out;
     }
@@ -2573,7 +2573,7 @@ void MDSRankDispatcher::handle_asok_command(
     cmd_getval(cmdmap, "filters", filter_args);
 
     SessionFilter filter;
-    r = filter.parse(filter_args, &ss);
+    r = filter.parse(filter_args, css.get());
     if (r != 0) {
       r = -EINVAL;
       goto out;
@@ -2583,15 +2583,15 @@ void MDSRankDispatcher::handle_asok_command(
   } else if (command == "session kill") {
     std::string client_id;
     if (!cmd_getval(cmdmap, "client_id", client_id)) {
-      ss << "Invalid client_id specified";
+      *css << "Invalid client_id specified";
       r = -ENOENT;
       goto out;
     }
     std::lock_guard l(mds_lock);
     bool evicted = evict_client(strtol(client_id.c_str(), 0, 10), true,
-        g_conf()->mds_session_blocklist_on_evict, ss);
+        g_conf()->mds_session_blocklist_on_evict, *css);
     if (!evicted) {
-      dout(15) << ss.str() << dendl;
+      dout(15) << css->strv() << dendl;
       r = -ENOENT;
     }
   } else if (command == "session config" ||
@@ -2605,7 +2605,7 @@ void MDSRankDispatcher::handle_asok_command(
     bool got_value = cmd_getval(cmdmap, "value", value);
 
     std::lock_guard l(mds_lock);
-    r = config_client(client_id, !got_value, option, value, ss);
+    r = config_client(client_id, !got_value, option, value, *css);
   } else if (command == "scrub start" ||
             command == "scrub_start") {
     string path;
@@ -2617,7 +2617,7 @@ void MDSRankDispatcher::handle_asok_command(
 
     /* Multiple MDS scrub is not currently supported. See also: https://tracker.ceph.com/issues/12274 */
     if (mdsmap->get_max_mds() > 1) {
-      ss << "Scrub is not currently supported for multiple active MDS. Please reduce max_mds to 1 and then scrub.";
+      *css << "Scrub is not currently supported for multiple active MDS. Please reduce max_mds to 1 and then scrub.";
       r = -EINVAL;
       goto out;
     }
@@ -2687,13 +2687,13 @@ void MDSRankDispatcher::handle_asok_command(
   } else if (command == "export dir") {
     string path;
     if(!cmd_getval(cmdmap, "path", path)) {
-      ss << "malformed path";
+      *css << "malformed path";
       r = -EINVAL;
       goto out;
     }
     int64_t rank;
     if(!cmd_getval(cmdmap, "rank", rank)) {
-      ss << "malformed rank";
+      *css << "malformed rank";
       r = -EINVAL;
       goto out;
     }
@@ -2725,7 +2725,7 @@ void MDSRankDispatcher::handle_asok_command(
     std::lock_guard l(mds_lock);
     mdcache->cache_status(f);
   } else if (command == "dump tree") {
-    command_dump_tree(cmdmap, ss, f);
+    command_dump_tree(cmdmap, *css, f);
   } else if (command == "dump loads") {
     std::lock_guard l(mds_lock);
     r = balancer->dump_loads(f);
@@ -2738,7 +2738,7 @@ void MDSRankDispatcher::handle_asok_command(
        snapserver->dump(f);
       } else {
        r = -EXDEV;
-       ss << "Not snapserver";
+       *css << "Not snapserver";
       }
     } else {
       r = snapclient->dump_cache(f);
@@ -2747,15 +2747,15 @@ void MDSRankDispatcher::handle_asok_command(
     std::lock_guard l(mds_lock);
     mdcache->force_readonly();
   } else if (command == "dirfrag split") {
-    command_dirfrag_split(cmdmap, ss);
+    command_dirfrag_split(cmdmap, *css);
   } else if (command == "dirfrag merge") {
-    command_dirfrag_merge(cmdmap, ss);
+    command_dirfrag_merge(cmdmap, *css);
   } else if (command == "dirfrag ls") {
-    command_dirfrag_ls(cmdmap, ss, f);
+    command_dirfrag_ls(cmdmap, *css, f);
   } else if (command == "openfiles ls") {
     command_openfiles_ls(f);
   } else if (command == "dump inode") {
-    command_dump_inode(f, cmdmap, ss);
+    command_dump_inode(f, cmdmap, *css);
   } else if (command == "damage ls") {
     std::lock_guard l(mds_lock);
     damage_table.dump(f);
@@ -2771,7 +2771,7 @@ void MDSRankDispatcher::handle_asok_command(
     r = -ENOSYS;
   }
 out:
-  on_finish(r, ss.str(), outbl);
+  on_finish(r, css->str(), outbl);
 }
 
 /**
@@ -2817,9 +2817,9 @@ void MDSRankDispatcher::evict_clients(
                                             on_finish(r, {}, bl);
                                           }));
   for (const auto s : victims) {
-    std::stringstream ss;
+    CachedStackStringStream css;
     evict_client(s->get_client().v, false,
-                 g_conf()->mds_session_blocklist_on_evict, ss, gather.new_sub());
+                 g_conf()->mds_session_blocklist_on_evict, *css, gather.new_sub());
   }
   gather.activate();
 }
@@ -2919,16 +2919,16 @@ void MDSRank::command_flush_journal(Formatter *f) {
   ceph_assert(f != NULL);
 
   C_SaferCond cond;
-  std::stringstream ss;
+  CachedStackStringStream css;
   {
     std::lock_guard locker(mds_lock);
-    C_Flush_Journal *flush_journal = new C_Flush_Journal(mdcache, mdlog, this, &ss, &cond);
+    C_Flush_Journal *flush_journal = new C_Flush_Journal(mdcache, mdlog, this, css.get(), &cond);
     flush_journal->send();
   }
   int r = cond.wait();
 
   f->open_object_section("result");
-  f->dump_string("message", ss.str());
+  f->dump_string("message", css->strv());
   f->dump_int("return_code", r);
   f->close_section();
 }
@@ -3475,13 +3475,12 @@ bool MDSRank::evict_client(int64_t session_id,
   }
 
   dout(4) << "Preparing blocklist command... (wait=" << wait << ")" << dendl;
-  stringstream ss;
-  ss << "{\"prefix\":\"osd blocklist\", \"blocklistop\":\"add\",";
-  ss << "\"addr\":\"";
-  ss << addr;
-  ss << "\"}";
-  std::string tmp = ss.str();
-  std::vector<std::string> cmd = {tmp};
+  CachedStackStringStream css;
+  *css << "{\"prefix\":\"osd blocklist\", \"blocklistop\":\"add\",";
+  *css << "\"addr\":\"";
+  *css << addr;
+  *css << "\"}";
+  std::vector<std::string> cmd = {css->str()};
 
   auto kill_client_session = [this, session_id, wait, on_killed](){
     ceph_assert(ceph_mutex_is_locked_by_me(mds_lock));
index 930b4d88d6a504e1a67e190fac15ec564180dfe5..aaad09ae056a77964574cab8d064cd38f1f29940 100644 (file)
@@ -777,9 +777,9 @@ void OpenFileTable::_load_finish(int op_r, int header_r, int values_r,
       } else {
        decode(magic, p);
        if (magic != CEPH_FS_ONDISK_MAGIC) {
-         std::ostringstream oss;
-         oss << "invalid magic '" << magic << "'";
-         throw buffer::malformed_input(oss.str());
+         CachedStackStringStream css;
+         *css << "invalid magic '" << magic << "'";
+         throw buffer::malformed_input(css->str());
        }
 
        DECODE_START(1, p);
@@ -790,14 +790,14 @@ void OpenFileTable::_load_finish(int op_r, int header_r, int values_r,
       }
 
       if (num_objs > MAX_OBJECTS) {
-         std::ostringstream oss;
-         oss << "invalid object count '" << num_objs << "'";
-         throw buffer::malformed_input(oss.str());
+         CachedStackStringStream css;
+         *css << "invalid object count '" << num_objs << "'";
+         throw buffer::malformed_input(css->str());
       }
       if (jstate > JOURNAL_FINISH) {
-         std::ostringstream oss;
-         oss << "invalid journal state '" << jstate << "'";
-         throw buffer::malformed_input(oss.str());
+         CachedStackStringStream css;
+         *css << "invalid journal state '" << jstate << "'";
+         throw buffer::malformed_input(css->str());
       }
 
       if (version > omap_version) {
index e28fc305bdce79ba2e08be3889f610c8b916cc6b..b2e426757a47c40b9530ef8fd8fdbbfcd476f458 100644 (file)
@@ -467,9 +467,9 @@ void ScrubStack::_validate_inode_done(CInode *in, int r,
     // Put the verbose JSON output into the MDS log for later inspection
     JSONFormatter f;
     result.dump(&f);
-    std::ostringstream out;
-    f.flush(out);
-    derr << __func__ << " scrub error on inode " << *in << ": " << out.str()
+    CachedStackStringStream css;
+    f.flush(*css);
+    derr << __func__ << " scrub error on inode " << *in << ": " << css->strv()
          << dendl;
   } else {
     dout(10) << __func__ << " scrub passed on inode " << *in << dendl;
@@ -583,33 +583,33 @@ void ScrubStack::scrub_status(Formatter *f) {
 
   f->open_object_section("result");
 
-  std::stringstream ss;
+  CachedStackStringStream css;
   bool have_more = false;
 
   if (state == STATE_IDLE) {
-    ss << "no active scrubs running";
+    *css << "no active scrubs running";
   } else if (state == STATE_RUNNING) {
     if (clear_inode_stack) {
-      ss << "ABORTING";
+      *css << "ABORTING";
     } else {
-      ss << "scrub active";
+      *css << "scrub active";
     }
-    ss << " (" << stack_size << " inodes in the stack)";
+    *css << " (" << stack_size << " inodes in the stack)";
   } else {
     if (state == STATE_PAUSING || state == STATE_PAUSED) {
       have_more = true;
-      ss << state;
+      *css << state;
     }
     if (clear_inode_stack) {
       if (have_more) {
-        ss << "+";
+        *css << "+";
       }
-      ss << "ABORTING";
+      *css << "ABORTING";
     }
 
-    ss << " (" << stack_size << " inodes in the stack)";
+    *css << " (" << stack_size << " inodes in the stack)";
   }
-  f->dump_string("status", ss.str());
+  f->dump_string("status", css->strv());
 
   f->open_object_section("scrubs");
   for (auto &inode : scrub_origins) {
@@ -621,26 +621,26 @@ void ScrubStack::scrub_status(Formatter *f) {
 
     f->dump_string("path", scrub_inode_path(inode));
 
-    std::stringstream optss;
+    CachedStackStringStream optcss;
     if (header->get_recursive()) {
-      optss << "recursive";
+      *optcss << "recursive";
       have_more = true;
     }
     if (header->get_repair()) {
       if (have_more) {
-        optss << ",";
+        *optcss << ",";
       }
-      optss << "repair";
+      *optcss << "repair";
       have_more = true;
     }
     if (header->get_force()) {
       if (have_more) {
-        optss << ",";
+        *optcss << ",";
       }
-      optss << "force";
+      *optcss << "force";
     }
 
-    f->dump_string("options", optss.str());
+    f->dump_string("options", optcss->strv());
     f->close_section(); // scrub id
   }
   f->close_section(); // scrubs
index 6b534930b19d04ed6ce123f7a3ff42c57abce7aa..061b1bc17f6b0bc34622ead70369563495773df8 100644 (file)
@@ -475,8 +475,8 @@ void Server::finish_reclaim_session(Session *session, const ref_t<MClientReclaim
     if (blocklisted || !g_conf()->mds_session_blocklist_on_evict) {
       kill_session(target, send_reply);
     } else {
-      std::stringstream ss;
-      mds->evict_client(target->get_client().v, false, true, ss, send_reply);
+      CachedStackStringStream css;
+      mds->evict_client(target->get_client().v, false, true, *css, send_reply);
     }
   } else if (reply) {
     mds->send_message_client(reply, session);
@@ -632,9 +632,9 @@ void Server::handle_client_session(const cref_t<MClientSession> &m)
       feature_bitset_t missing_features = required_client_features;
       missing_features -= client_metadata.features;
       if (!missing_features.empty()) {
-       stringstream ss;
-       ss << "missing required features '" << missing_features << "'";
-       send_reject_message(ss.str());
+       CachedStackStringStream css;
+       *css << "missing required features '" << missing_features << "'";
+       send_reject_message(css->strv());
        mds->clog->warn() << "client session (" << session->info.inst
                           << ") lacks required features " << missing_features
                           << "; client supports " << client_metadata.features;
@@ -646,22 +646,22 @@ void Server::handle_client_session(const cref_t<MClientSession> &m)
       // root is actually within the caps of the session
       if (auto it = client_metadata.find("root"); it != client_metadata.end()) {
        auto claimed_root = it->second;
-       stringstream ss;
+       CachedStackStringStream css;
        bool denied = false;
        // claimed_root has a leading "/" which we strip before passing
        // into caps check
        if (claimed_root.empty() || claimed_root[0] != '/') {
          denied = true;
-         ss << "invalue root '" << claimed_root << "'";
+         *css << "invalue root '" << claimed_root << "'";
        } else if (!session->auth_caps.path_capable(claimed_root.substr(1))) {
          denied = true;
-         ss << "non-allowable root '" << claimed_root << "'";
+         *css << "non-allowable root '" << claimed_root << "'";
        }
 
        if (denied) {
          // Tell the client we're rejecting their open
-         send_reject_message(ss.str());
-         mds->clog->warn() << "client session with " << ss.str()
+         send_reject_message(css->strv());
+         mds->clog->warn() << "client session with " << css->strv()
                            << " denied (" << session->info.inst << ")";
          session->clear();
          break;
@@ -1163,8 +1163,8 @@ void Server::find_idle_sessions()
             << " last renewed caps " << last_cap_renew_span << "s ago" << dendl;
 
     if (g_conf()->mds_session_blocklist_on_timeout) {
-      std::stringstream ss;
-      mds->evict_client(session->get_client().v, false, true, ss, nullptr);
+      CachedStackStringStream css;
+      mds->evict_client(session->get_client().v, false, true, *css, nullptr);
     } else {
       kill_session(session, NULL);
     }
@@ -1185,10 +1185,10 @@ void Server::evict_cap_revoke_non_responders() {
     dout(1) << __func__ << ": evicting cap revoke non-responder client id "
             << client << dendl;
 
-    std::stringstream ss;
+    CachedStackStringStream css;
     bool evicted = mds->evict_client(client.v, false,
                                      g_conf()->mds_session_blocklist_on_evict,
-                                     ss, nullptr);
+                                     *css, nullptr);
     if (evicted && logger) {
       logger->inc(l_mdss_cap_revoke_eviction);
     }
@@ -1421,9 +1421,9 @@ void Server::handle_client_reconnect(const cref_t<MClientReconnect> &m)
       feature_bitset_t missing_features = required_client_features;
       missing_features -= session->info.client_metadata.features;
       if (!missing_features.empty()) {
-       stringstream ss;
-       ss << "missing required features '" << missing_features << "'";
-       error_str = ss.str();
+       CachedStackStringStream css;
+       *css << "missing required features '" << missing_features << "'";
+       error_str = css->strv();
       }
     }
 
@@ -1571,9 +1571,9 @@ void Server::update_required_client_features()
 
        mds->clog->warn() << "evicting session " << *session << ", missing required features '"
                          << missing_features << "'";
-       std::stringstream ss;
+       CachedStackStringStream css;
        mds->evict_client(session->get_client().v, false,
-                         g_conf()->mds_session_blocklist_on_evict, ss);
+                         g_conf()->mds_session_blocklist_on_evict, *css);
       }
     }
   }
@@ -1670,8 +1670,8 @@ void Server::reconnect_tick()
                      << " seconds during MDS startup";
 
     if (g_conf()->mds_session_blocklist_on_timeout) {
-      std::stringstream ss;
-      mds->evict_client(session->get_client().v, false, true, ss,
+      CachedStackStringStream css;
+      mds->evict_client(session->get_client().v, false, true, *css,
                        gather.new_sub());
     } else {
       kill_session(session, NULL, true);
@@ -2383,13 +2383,13 @@ void Server::handle_client_request(const cref_t<MClientRequest> &req)
       if (session->get_num_completed_requests() >=
          (g_conf()->mds_max_completed_requests << session->get_num_trim_requests_warnings())) {
        session->inc_num_trim_requests_warnings();
-       stringstream ss;
-       ss << "client." << session->get_client() << " does not advance its oldest_client_tid ("
+       CachedStackStringStream css;
+       *css << "client." << session->get_client() << " does not advance its oldest_client_tid ("
           << req->get_oldest_client_tid() << "), "
           << session->get_num_completed_requests()
           << " completed requests recorded in session\n";
-       mds->clog->warn() << ss.str();
-       dout(20) << __func__ << " " << ss.str() << dendl;
+       mds->clog->warn() << css->strv();
+       dout(20) << __func__ << " " << css->strv() << dendl;
       }
     }
   }
index 9d5bd569ec33c1be6f5bba864da59a2362713f1e..167ca3efd0a88826df5f874fe5844239edf69afe 100644 (file)
@@ -420,15 +420,15 @@ void SessionMap::save(MDSContext *onsave, version_t needv)
        session->is_killing()) {
       dout(20) << "  " << name << dendl;
       // Serialize K
-      std::ostringstream k;
-      k << name;
+      CachedStackStringStream css;
+      *css << name;
 
       // Serialize V
       bufferlist bl;
       session->info.encode(bl, mds->mdsmap->get_up_features());
 
       // Add to RADOS op
-      to_set[k.str()] = bl;
+      to_set[std::string(css->strv())] = bl;
 
       session->clear_dirty_completed_requests();
     } else {
@@ -444,9 +444,9 @@ void SessionMap::save(MDSContext *onsave, version_t needv)
   for(std::set<entity_name_t>::const_iterator i = null_sessions.begin();
       i != null_sessions.end(); ++i) {
     dout(20) << "  " << *i << dendl;
-    std::ostringstream k;
-    k << *i;
-    to_remove.insert(k.str());
+    CachedStackStringStream css;
+    *css << *i;
+    to_remove.insert(css->str());
   }
   if (!to_remove.empty()) {
     op.omap_rm_keys(to_remove);
@@ -855,15 +855,15 @@ void SessionMap::save_if_dirty(const std::set<entity_name_t> &tgt_sessions,
     session->clear_dirty_completed_requests();
 
     // Serialize K
-    std::ostringstream k;
-    k << session_id;
+    CachedStackStringStream css;
+    *css << session_id;
 
     // Serialize V
     bufferlist bl;
     session->info.encode(bl, mds->mdsmap->get_up_features());
 
     // Add to RADOS op
-    to_set[k.str()] = bl;
+    to_set[css->str()] = bl;
 
     // Complete this write transaction?
     if (i == write_sessions.size() - 1
@@ -1099,7 +1099,7 @@ void SessionMap::update_average_session_age() {
 
 int SessionFilter::parse(
     const std::vector<std::string> &args,
-    std::stringstream *ss)
+    std::ostream *ss)
 {
   ceph_assert(ss != NULL);
 
index ffa7973a2415b78710a0af0187968d0a992185e5..02be9ba594680e0506638d217f2aeca9af42fdde 100644 (file)
@@ -499,7 +499,7 @@ public:
   bool match(
       const Session &session,
       std::function<bool(client_t)> is_reconnecting) const;
-  int parse(const std::vector<std::string> &args, std::stringstream *ss);
+  int parse(const std::vector<std::string> &args, std::ostream *ss);
   void set_reconnecting(bool v)
   {
     reconnecting.first = true;
index f6881d8ec1ed59c78e4b6abf8fd7699d6c57bd15..f1648003585d689ac984dacc41bd746743114b99 100644 (file)
@@ -418,9 +418,9 @@ void SnapServer::dump(Formatter *f) const
 
   f->open_object_section("need_to_purge");
   for (map<int, set<snapid_t> >::const_iterator i = need_to_purge.begin(); i != need_to_purge.end(); ++i) {
-    stringstream pool_id;
-    pool_id << i->first;
-    f->open_array_section(pool_id.str().c_str());
+    CachedStackStringStream css;
+    *css << i->first;
+    f->open_array_section(css->strv());
     for (set<snapid_t>::const_iterator s = i->second.begin(); s != i->second.end(); ++s) {
       f->dump_unsigned("snapid", s->val);
     }
index dcec2c46aa3bacafe711060d465d864fac844dc3..d458fe8f345e8164f678a0505bbcba715b4b74c3 100644 (file)
@@ -44,19 +44,19 @@ int cephfs_feature_from_name(std::string_view name)
 
 std::string cephfs_stringify_features(const feature_bitset_t& features)
 {
-  std::ostringstream ss;
+  CachedStackStringStream css;
   bool first = true;
-  ss << "{";
+  *css << "{";
   for (size_t i = 0; i < feature_names.size(); ++i) {
     if (!features.test(i))
       continue;
     if (!first)
-      ss << ",";
-    ss << i << "=" << cephfs_feature_name(i);
+      *css << ",";
+    *css << i << "=" << cephfs_feature_name(i);
     first = false;
   }
-  ss << "}";
-  return ss.str();
+  *css << "}";
+  return css->str();
 }
 
 void cephfs_dump_features(ceph::Formatter *f, const feature_bitset_t& features)
index 535e522c970c74276486fc173f2d1f8aea2c0638..5f0dfe381c8bc5190f256cbaec142f32d23fcc43 100644 (file)
@@ -573,9 +573,9 @@ void EMetaBlob::fullbit::update_inode(MDSRank *mds, CInode *in)
        !in->get_inode()->layout.is_valid()) {
       dout(0) << "EMetaBlob.replay invalid layout on ino " << *in
               << ": " << in->get_inode()->layout << dendl;
-      std::ostringstream oss;
-      oss << "Invalid layout for inode " << in->ino() << " in journal";
-      mds->clog->error() << oss.str();
+      CachedStackStringStream css;
+      *css << "Invalid layout for inode " << in->ino() << " in journal";
+      mds->clog->error() << css->strv();
       mds->damaged();
       ceph_abort();  // Should be unreachable because damaged() calls respawn()
     }
@@ -1241,11 +1241,11 @@ void EMetaBlob::replay(MDSRank *mds, LogSegment *logseg, MDPeerUpdate *peerup)
        if (!dn->get_linkage()->is_null()) {
          if (dn->get_linkage()->is_primary()) {
            unlinked[dn->get_linkage()->get_inode()] = dir;
-           stringstream ss;
-           ss << "EMetaBlob.replay FIXME had dentry linked to wrong inode " << *dn
+           CachedStackStringStream css;
+           *css << "EMetaBlob.replay FIXME had dentry linked to wrong inode " << *dn
               << " " << *dn->get_linkage()->get_inode() << " should be " << in->ino();
-           dout(0) << ss.str() << dendl;
-           mds->clog->warn(ss);
+           dout(0) << css->strv() << dendl;
+           mds->clog->warn() << css->strv();
          }
          dir->unlink_inode(dn, false);
        }
@@ -1265,11 +1265,11 @@ void EMetaBlob::replay(MDSRank *mds, LogSegment *logseg, MDPeerUpdate *peerup)
          if (!dn->get_linkage()->is_null()) { // note: might be remote.  as with stray reintegration.
            if (dn->get_linkage()->is_primary()) {
              unlinked[dn->get_linkage()->get_inode()] = dir;
-             stringstream ss;
-             ss << "EMetaBlob.replay FIXME had dentry linked to wrong inode " << *dn
+             CachedStackStringStream css;
+             *css << "EMetaBlob.replay FIXME had dentry linked to wrong inode " << *dn
                 << " " << *dn->get_linkage()->get_inode() << " should be " << in->ino();
-             dout(0) << ss.str() << dendl;
-             mds->clog->warn(ss);
+             dout(0) << css->strv() << dendl;
+             mds->clog->warn() << css->strv();
            }
            dir->unlink_inode(dn, false);
          }
@@ -1312,10 +1312,10 @@ void EMetaBlob::replay(MDSRank *mds, LogSegment *logseg, MDPeerUpdate *peerup)
          dout(10) << "EMetaBlob.replay unlinking " << *dn << dendl;
          if (dn->get_linkage()->is_primary()) {
            unlinked[dn->get_linkage()->get_inode()] = dir;
-           stringstream ss;
-           ss << "EMetaBlob.replay FIXME had dentry linked to wrong inode " << *dn
+           CachedStackStringStream css;
+           *css << "EMetaBlob.replay FIXME had dentry linked to wrong inode " << *dn
               << " " << *dn->get_linkage()->get_inode() << " should be remote " << rb.ino;
-           dout(0) << ss.str() << dendl;
+           dout(0) << css->strv() << dendl;
          }
          dir->unlink_inode(dn, false);
        }
index 7ffc39ffb33da29fd25f3a454b514d3cf424595f..9c4104fa6b963d9ad3c2d661c777dc5cf15f6193 100644 (file)
@@ -14,6 +14,7 @@
 #include "common/config.h"
 #include "common/Clock.h"
 #include "common/DecayCounter.h"
+#include "common/StackStringStream.h"
 #include "common/entity_name.h"
 
 #include "include/Context.h"
@@ -1365,9 +1366,9 @@ struct dentry_key_t {
     } else {
       snprintf(b, sizeof(b), "%s", "head");
     }
-    std::ostringstream oss;
-    oss << name << "_" << b;
-    key = oss.str();
+    CachedStackStringStream css;
+    *css << name << "_" << b;
+    key = css->strv();
   }
   static void decode_helper(ceph::buffer::list::const_iterator& bl, std::string& nm,
                            snapid_t& sn) {
@@ -1782,8 +1783,8 @@ inline void decode(dirfrag_load_vec_t& c, ceph::buffer::list::const_iterator &p)
 
 inline std::ostream& operator<<(std::ostream& out, const dirfrag_load_vec_t& dl)
 {
-  std::ostringstream ss;
-  ss << std::setprecision(1) << std::fixed
+  CachedStackStringStream css;
+  *css << std::setprecision(1) << std::fixed
      << "[pop"
         " IRD:" << dl.vec[0]
      << " IWR:" << dl.vec[1]
@@ -1791,7 +1792,7 @@ inline std::ostream& operator<<(std::ostream& out, const dirfrag_load_vec_t& dl)
      << " FET:" << dl.vec[3]
      << " STR:" << dl.vec[4]
      << " *LOAD:" << dl.meta_load() << "]";
-  return out << ss.str() << std::endl;
+  return out << css->strv() << std::endl;
 }
 
 struct mds_load_t {