]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
monmaptool: use generic MonMap::print methods
authorSage Weil <sage@newdream.net>
Sun, 11 Oct 2009 04:34:40 +0000 (21:34 -0700)
committerSage Weil <sage@newdream.net>
Sun, 11 Oct 2009 04:34:40 +0000 (21:34 -0700)
src/mon/MonMap.cc
src/mon/MonMap.h
src/monmaptool.cc

index bc7711e88864704b365f09dab5285ce83734b8d0..551c3fda4d57b3cd42a8b6df6aa65c35c605c699 100644 (file)
@@ -26,3 +26,21 @@ int MonMap::read(const char *fn)
   decode(bl);
   return 0;
 }
+
+void MonMap::print_summary(ostream& out)
+{
+  out << "e" << epoch << ": "
+      << mon_inst.size() << " mons at";
+  for (unsigned i = 0; i<mon_inst.size(); i++)
+    out << " " << mon_inst[i].addr;
+}
+void MonMap::print(ostream& out)
+{
+  out << "epoch " << epoch << "\n";
+  out << "fsid " << fsid << "\n";
+  out << "last_changed " << last_changed << "\n";
+  for (unsigned i=0; i<mon_inst.size(); i++) {
+    out << "\t" << mon_inst[i] << "\n";
+  }
+}
index 24f4ef0f17be64d2aa09e636af9514effbe9fbdd..8b6b43e040be0c58354baa8c601c6f9aecb4ecb9 100644 (file)
@@ -116,6 +116,8 @@ class MonMap {
   int write(const char *fn);
   int read(const char *fn);
 
+  void print(ostream& out);
+  void print_summary(ostream& out);
 };
 
 inline void encode(MonMap &m, bufferlist &bl) {
@@ -125,4 +127,9 @@ inline void decode(MonMap &m, bufferlist::iterator &p) {
   m.decode(p);
 }
 
+inline ostream& operator<<(ostream& out, MonMap& m) {
+  m.print_summary(out);
+  return out;
+}
+
 #endif
index 50b86c75ec23880fdb42092c127019d775c80772..e42008a557b7935842062fc3c8b6233be0e8d5ce 100644 (file)
@@ -32,15 +32,6 @@ void usage()
   exit(1);
 }
 
-void printmap(const char *me, MonMap *m)
-{
-  cout << me << ": monmap: epoch " << m->epoch << std::endl
-       << me << ": monmap: fsid " << m->fsid << std::endl;
-  for (unsigned i=0; i<m->mon_inst.size(); i++)
-    cout << me << ": monmap:  " //<< "mon" << i << " " 
-        << m->mon_inst[i] << std::endl;
-}
-
 int main(int argc, const char **argv)
 {
   vector<const char*> args;
@@ -131,7 +122,7 @@ int main(int argc, const char **argv)
     monmap.epoch++;
 
   if (print) 
-    printmap(me, &monmap);
+    monmap.print(cout);
 
   if (modified) {
     // write it out