]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
OSDMap: const cleanup
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Tue, 19 Oct 2010 17:20:21 +0000 (10:20 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 22 Oct 2010 00:31:58 +0000 (17:31 -0700)
Signed-off-by: Colin McCabe <colinm@hq.newdream.net>
src/messages/MOSDPing.h
src/messages/MOSDScrub.h
src/messages/MPGStats.h
src/osd/OSDMap.cc
src/osd/OSDMap.h

index 07f763319c7a95da66960a9e9db642fc41418981..f27122bea66f66fbd6204761e6dd2e2f547d33af 100644 (file)
@@ -28,7 +28,7 @@ class MOSDPing : public Message {
   bool ack;
   osd_peer_stat_t peer_stat;
 
-  MOSDPing(ceph_fsid_t& f, epoch_t e, epoch_t pe, osd_peer_stat_t& ps, bool a=false) : 
+  MOSDPing(const ceph_fsid_t& f, epoch_t e, epoch_t pe, osd_peer_stat_t& ps, bool a=false) : 
     Message(MSG_OSD_PING), fsid(f), map_epoch(e), peer_as_of_epoch(pe), ack(a), peer_stat(ps) { }
   MOSDPing() {}
 private:
index d3c3eafbf298d2804b941d08b79416b479b79dbb..ec81e73016c9ea7faf1d920f94ebc8fb68fe01f8 100644 (file)
@@ -28,10 +28,10 @@ struct MOSDScrub : public Message {
   bool repair;
 
   MOSDScrub() {}
-  MOSDScrub(ceph_fsid_t& f, bool r) :
+  MOSDScrub(const ceph_fsid_t& f, bool r) :
     Message(MSG_OSD_SCRUB),
     fsid(f), repair(r) {}
-  MOSDScrub(ceph_fsid_t& f, vector<pg_t>& pgs, bool r) :
+  MOSDScrub(const ceph_fsid_t& f, vector<pg_t>& pgs, bool r) :
     Message(MSG_OSD_SCRUB),
     fsid(f), scrub_pgs(pgs), repair(r) {}
 private:
index 883ecc322c9c78119da3ff752c03c711527eee94..22248d736c09ba34f8cc2cc663b8c50a258baa5e 100644 (file)
@@ -27,7 +27,7 @@ public:
   utime_t had_map_for;
   
   MPGStats() : PaxosServiceMessage(MSG_PGSTATS, 0) {}
-  MPGStats(ceph_fsid_t& f, epoch_t e, utime_t had) : 
+  MPGStats(const ceph_fsid_t& f, epoch_t e, utime_t had) : 
     PaxosServiceMessage(MSG_PGSTATS, e), fsid(f), epoch(e), had_map_for(had) {}
 
 private:
index 8631a89b3a491fca5a9c2912c26612d014cb8294..9f4bc2c504c67f585b67b14799df6aec9bb7b4ab 100644 (file)
@@ -18,7 +18,7 @@
 
 
 
-void OSDMap::print(ostream& out)
+void OSDMap::print(ostream& out) const
 {
   out << "epoch " << get_epoch() << "\n"
       << "fsid " << get_fsid() << "\n"
@@ -38,11 +38,15 @@ void OSDMap::print(ostream& out)
     out << " pauserec";
   out << "\n" << std::endl;
  
-  for (map<int,pg_pool_t>::iterator p = pools.begin(); p != pools.end(); p++) {
+  for (map<int,pg_pool_t>::const_iterator p = pools.begin(); p != pools.end(); ++p) {
+    std::string name("<unknown>");
+    map<int32_t,string>::const_iterator pni = pool_name.find(p->first);
+    if (pni != pool_name.end())
+      name = pni->second;
     out << "pg_pool " << p->first
-       << " '" << pool_name[p->first]
+       << " '" << name
        << "' " << p->second << "\n";
-    for (map<snapid_t,pool_snap_info_t>::iterator q = p->second.snaps.begin();
+    for (map<snapid_t,pool_snap_info_t>::const_iterator q = p->second.snaps.begin();
         q != p->second.snaps.end();
         q++)
       out << "\tsnap " << q->second.snapid << " '" << q->second.name << "' " << q->second.stamp << "\n";
@@ -59,7 +63,7 @@ void OSDMap::print(ostream& out)
       if (is_in(i))
        out << " weight " << get_weightf(i);
       out << (is_up(i) ? " up  ":" down");
-      osd_info_t& info = get_info(i);
+      const osd_info_t& info(get_info(i));
       out << info << " ";
       if (is_up(i))
        out << get_addr(i) << " " << get_hb_addr(i);
@@ -68,12 +72,12 @@ void OSDMap::print(ostream& out)
   }
   out << std::endl;
 
-  for (map<pg_t,vector<int> >::iterator p = pg_temp.begin();
+  for (map<pg_t,vector<int> >::const_iterator p = pg_temp.begin();
        p != pg_temp.end();
        p++)
     out << "pg_temp " << p->first << " " << p->second << "\n";
   
-  for (hash_map<entity_addr_t,utime_t>::iterator p = blacklist.begin();
+  for (hash_map<entity_addr_t,utime_t>::const_iterator p = blacklist.begin();
        p != blacklist.end();
        p++)
     out << "blacklist " << p->first << " expires " << p->second << "\n";
@@ -81,7 +85,7 @@ void OSDMap::print(ostream& out)
   // ignore pg_swap_primary
 }
 
-void OSDMap::print_summary(ostream& out)
+void OSDMap::print_summary(ostream& out) const
 {
   out << "e" << get_epoch() << ": "
       << get_num_osds() << " osds: "
index a743594d2c8d0f70626e2df615a532d423369112..df888b83d17426caa0cd7a606960ca34eed8ad0d 100644 (file)
@@ -290,7 +290,7 @@ private:
   }
 
   // map info
-  ceph_fsid_t& get_fsid() { return fsid; }
+  const ceph_fsid_t& get_fsid() const { return fsid; }
   void set_fsid(ceph_fsid_t& f) { fsid = f; }
 
   epoch_t get_epoch() const { return epoch; }
@@ -343,7 +343,7 @@ private:
     calc_num_osds();
   }
 
-  int get_num_osds() {
+  int get_num_osds() const {
     return num_osd;
   }
   int calc_num_osds() {
@@ -359,14 +359,14 @@ private:
       if (exists(i))
        ls.insert(i);
   }
-  int get_num_up_osds() {
+  int get_num_up_osds() const {
     int n = 0;
     for (int i=0; i<max_osd; i++)
       if (osd_state[i] & CEPH_OSD_EXISTS &&
          osd_state[i] & CEPH_OSD_UP) n++;
     return n;
   }
-  int get_num_in_osds() {
+  int get_num_in_osds() const {
     int n = 0;
     for (int i=0; i<max_osd; i++)
       if (osd_state[i] & CEPH_OSD_EXISTS &&
@@ -396,11 +396,11 @@ private:
     if (w)
       osd_state[o] |= CEPH_OSD_EXISTS;
   }
-  unsigned get_weight(int o) {
+  unsigned get_weight(int o) const {
     assert(o < max_osd);
     return osd_weight[o];
   }
-  float get_weightf(int o) {
+  float get_weightf(int o) const {
     return (float)get_weight(o) / (float)CEPH_OSD_IN;
   }
   void adjust_osd_weights(map<int,double>& weights, Incremental& inc) {
@@ -415,14 +415,26 @@ private:
 
 
 
-  bool exists(int osd) {
+  bool exists(int osd) const {
     //assert(osd >= 0);
     return osd >= 0 && osd < max_osd && (osd_state[osd] & CEPH_OSD_EXISTS);
   }
-  bool is_up(int osd) { return exists(osd) && osd_state[osd] & CEPH_OSD_UP; }
-  bool is_down(int osd) { return !exists(osd) || !is_up(osd); }
-  bool is_out(int osd) { return !exists(osd) || get_weight(osd) == CEPH_OSD_OUT; }
-  bool is_in(int osd) { return exists(osd) && !is_out(osd); }
+
+  bool is_up(int osd) const {
+    return exists(osd) && osd_state[osd] & CEPH_OSD_UP;
+  }
+
+  bool is_down(int osd) const {
+    return !exists(osd) || !is_up(osd);
+  }
+
+  bool is_out(int osd) const {
+    return !exists(osd) || get_weight(osd) == CEPH_OSD_OUT;
+  }
+
+  bool is_in(int osd) const {
+    return exists(osd) && !is_out(osd);
+  }
   
   int identify_osd(const entity_addr_t& addr) const {
     for (unsigned i=0; i<osd_addr.size(); i++)
@@ -442,17 +454,17 @@ private:
   bool have_inst(int osd) {
     return exists(osd) && is_up(osd); 
   }
-  const entity_addr_t &get_addr(int osd) {
+  const entity_addr_t &get_addr(int osd) const {
     assert(exists(osd));
     return osd_addr[osd];
   }
-  const entity_addr_t &get_cluster_addr(int osd) {
+  const entity_addr_t &get_cluster_addr(int osd) const {
     assert(exists(osd));
     if (osd_cluster_addr[osd] == entity_addr_t())
       return get_addr(osd);
     return osd_cluster_addr[osd];
   }
-  const entity_addr_t &get_hb_addr(int osd) {
+  const entity_addr_t &get_hb_addr(int osd) const {
     assert(exists(osd));
     return osd_hb_addr[osd];
   }
@@ -486,7 +498,7 @@ private:
     assert(exists(osd));
     return osd_info[osd].down_at;
   }
-  osd_info_t& get_info(int osd) {
+  const osd_info_t& get_info(int osd) const {
     assert(osd < max_osd);
     return osd_info[osd];
   }
@@ -1011,12 +1023,12 @@ private:
   static void build_simple_crush_map(CrushWrapper& crush, map<int, const char*>& poolsets, int num_osd, int num_dom=0);
 
 
-  void print(ostream& out);
-  void print_summary(ostream& out);
+  void print(ostream& out) const;
+  void print_summary(ostream& out) const;
 
 };
 
-inline ostream& operator<<(ostream& out, OSDMap& m) {
+inline ostream& operator<<(ostream& out, const OSDMap& m) {
   m.print_summary(out);
   return out;
 }