From 5df28ecec6b91fd27d50e1923091cad2086143f6 Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Tue, 8 Nov 2011 09:45:44 -0800 Subject: [PATCH] OSDMap,CrushWrapper: const cleanup on OSDMap The osd's cached maps are not actually modified once cached. Marking these methods const (which they should be) allows us to make OSDMapRef shared_ptr. Signed-off-by: Samuel Just --- src/crush/CrushWrapper.h | 6 ++-- src/crush/mapper.c | 12 ++++---- src/crush/mapper.h | 6 ++-- src/osd/OSDMap.cc | 2 +- src/osd/OSDMap.h | 62 ++++++++++++++++++++-------------------- 5 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index d278715854b65..0e57779ca4a25 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -171,7 +171,7 @@ public: /*** devices ***/ - int get_max_devices() { + int get_max_devices() const { if (!crush) return 0; return crush->max_devices; } @@ -382,12 +382,12 @@ public: crush->max_devices = m; } - int find_rule(int ruleset, int type, int size) { + int find_rule(int ruleset, int type, int size) const { if (!crush) return -1; return crush_find_rule(crush, ruleset, type, size); } void do_rule(int rule, int x, vector& out, int maxout, int forcefeed, - vector<__u32>& weight) { + const vector<__u32>& weight) const { int rawout[maxout]; int numrep = crush_do_rule(crush, rule, x, rawout, maxout, forcefeed, &weight[0]); diff --git a/src/crush/mapper.c b/src/crush/mapper.c index 8235ca2e15006..75656e1e0aec3 100644 --- a/src/crush/mapper.c +++ b/src/crush/mapper.c @@ -32,7 +32,7 @@ * @type: storage ruleset type (user defined) * @size: output set size */ -int crush_find_rule(struct crush_map *map, int ruleset, int type, int size) +int crush_find_rule(const struct crush_map *map, int ruleset, int type, int size) { __u32 i; @@ -262,7 +262,7 @@ static int crush_bucket_choose(struct crush_bucket *in, int x, int r) * true if device is marked "out" (failed, fully offloaded) * of the cluster */ -static int is_out(struct crush_map *map, __u32 *weight, int item, int x) +static int is_out(const struct crush_map *map, const __u32 *weight, int item, int x) { if (weight[item] >= 0x10000) return 0; @@ -287,9 +287,9 @@ static int is_out(struct crush_map *map, __u32 *weight, int item, int x) * @recurse_to_leaf: true if we want one device under each item of given type * @out2: second output vector for leaf items (if @recurse_to_leaf) */ -static int crush_choose(struct crush_map *map, +static int crush_choose(const struct crush_map *map, struct crush_bucket *bucket, - __u32 *weight, + const __u32 *weight, int x, int numrep, int type, int *out, int outpos, int firstn, int recurse_to_leaf, @@ -456,9 +456,9 @@ reject: * @result_max: maximum result size * @force: force initial replica choice; -1 for none */ -int crush_do_rule(struct crush_map *map, +int crush_do_rule(const struct crush_map *map, int ruleno, int x, int *result, int result_max, - int force, __u32 *weight) + int force, const __u32 *weight) { int result_len; int force_context[CRUSH_MAX_DEPTH]; diff --git a/src/crush/mapper.h b/src/crush/mapper.h index a0e2a6757b221..9322ab8bccd84 100644 --- a/src/crush/mapper.h +++ b/src/crush/mapper.h @@ -10,11 +10,11 @@ #include "crush.h" -extern int crush_find_rule(struct crush_map *map, int ruleset, int type, int size); -extern int crush_do_rule(struct crush_map *map, +extern int crush_find_rule(const struct crush_map *map, int ruleset, int type, int size); +extern int crush_do_rule(const struct crush_map *map, int ruleno, int x, int *result, int result_max, int forcefeed, /* -1 for none */ - __u32 *weights); + const __u32 *weights); #endif diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index 00171c7ba53bc..46aaf59f89af9 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -251,7 +251,7 @@ void OSDMap::Incremental::decode(bufferlist::iterator &p) // ---------------------------------- // OSDMap -bool OSDMap::is_blacklisted(const entity_addr_t& a) +bool OSDMap::is_blacklisted(const entity_addr_t& a) const { if (blacklist.empty()) return false; diff --git a/src/osd/OSDMap.h b/src/osd/OSDMap.h index 6c13faf438b17..c383ba8a9025f 100644 --- a/src/osd/OSDMap.h +++ b/src/osd/OSDMap.h @@ -214,7 +214,7 @@ private: const utime_t& get_created() const { return created; } const utime_t& get_modified() const { return modified; } - bool is_blacklisted(const entity_addr_t& a); + bool is_blacklisted(const entity_addr_t& a) const; string get_cluster_snapshot() const { if (cluster_snapshot_epoch == epoch) @@ -232,7 +232,7 @@ private: } int calc_num_osds(); - void get_all_osds(set& ls) { + void get_all_osds(set& ls) const { for (int i=0; i pg - ceph_object_layout file_to_object_layout(object_t oid, ceph_file_layout& layout) { + ceph_object_layout file_to_object_layout(object_t oid, ceph_file_layout& layout) const { return make_object_layout(oid, layout.fl_pg_pool, layout.fl_pg_preferred); } - ceph_object_layout make_object_layout(object_t oid, int pg_pool, int preferred=-1) { + ceph_object_layout make_object_layout(object_t oid, int pg_pool, int preferred=-1) const { object_locator_t loc(pg_pool); loc.preferred = preferred; @@ -435,7 +435,7 @@ public: return ol; } - int get_pg_num(int pg_pool) + int get_pg_num(int pg_pool) const { const pg_pool_t *pool = get_pg_pool(pg_pool); return pool->get_pg_num(); @@ -443,7 +443,7 @@ public: // pg -> (osd list) private: - int _pg_to_osds(const pg_pool_t& pool, pg_t pg, vector& osds) { + int _pg_to_osds(const pg_pool_t& pool, pg_t pg, vector& osds) const { // map to osds[] ps_t pps = pool.raw_pg_to_pps(pg); // placement ps unsigned size = pool.get_size(); @@ -464,7 +464,7 @@ private: } // pg -> (up osd list) - void _raw_to_up_osds(pg_t pg, vector& raw, vector& up) { + void _raw_to_up_osds(pg_t pg, vector& raw, vector& up) const { up.clear(); for (unsigned i=0; i& raw, vector& temp) { + bool _raw_to_temp_osds(const pg_pool_t& pool, pg_t pg, vector& raw, vector& temp) const { pg = pool.raw_pg_to_pg(pg); - map >::iterator p = pg_temp.find(pg); + map >::const_iterator p = pg_temp.find(pg); if (p != pg_temp.end()) { temp.clear(); for (unsigned i=0; isecond.size(); i++) { @@ -496,7 +496,7 @@ public: return _pg_to_osds(*pool, pg, raw); } - int pg_to_acting_osds(pg_t pg, vector& acting) { // list of osd addr's + int pg_to_acting_osds(pg_t pg, vector& acting) const { // list of osd addr's const pg_pool_t *pool = get_pg_pool(pg.pool()); if (!pool) return 0; @@ -516,7 +516,7 @@ public: _raw_to_up_osds(pg, raw, up); } - void pg_to_up_acting_osds(pg_t pg, vector& up, vector& acting) { + void pg_to_up_acting_osds(pg_t pg, vector& up, vector& acting) const { const pg_pool_t *pool = get_pg_pool(pg.pool()); if (!pool) return; @@ -534,17 +534,19 @@ public: } const map& get_pools() { return pools; } - const char *get_pool_name(int64_t p) { - if (pool_name.count(p)) - return pool_name[p].c_str(); + const char *get_pool_name(int64_t p) const { + map::const_iterator i = pool_name.find(p); + if (i != pool_name.end()) + return i->second.c_str(); return 0; } bool have_pg_pool(int64_t p) const { return pools.count(p); } - const pg_pool_t* get_pg_pool(int64_t p) { - if (pools.count(p)) - return &pools[p]; + const pg_pool_t* get_pg_pool(int64_t p) const { + map::const_iterator i = pools.find(p); + if (i != pools.end()) + return &i->second; return NULL; } unsigned get_pg_size(pg_t pg) const { @@ -552,17 +554,15 @@ public: assert(p != pools.end()); return p->second.get_size(); } - int get_pg_type(pg_t pg) { + int get_pg_type(pg_t pg) const { assert(pools.count(pg.pool())); - pg_pool_t &pool = pools[pg.pool()]; - return pool.get_type(); + return pools.find(pg.pool())->second.get_type(); } - pg_t raw_pg_to_pg(pg_t pg) { + pg_t raw_pg_to_pg(pg_t pg) const { assert(pools.count(pg.pool())); - pg_pool_t &pool = pools[pg.pool()]; - return pool.raw_pg_to_pg(pg); + return pools.find(pg.pool())->second.raw_pg_to_pg(pg); } // pg -> primary osd @@ -662,7 +662,7 @@ public: }; -typedef std::tr1::shared_ptr OSDMapRef; +typedef std::tr1::shared_ptr OSDMapRef; inline ostream& operator<<(ostream& out, const OSDMap& m) { m.print_summary(out); -- 2.39.5