From: Sage Weil Date: Tue, 29 Oct 2013 23:37:42 +0000 (-0700) Subject: crush/CrushWrapper: add parse_loc_[multi]map helpers X-Git-Tag: v0.75~37^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8f48906db7cee14bfa287365ceb4c86f9b203d94;p=ceph.git crush/CrushWrapper: add parse_loc_[multi]map helpers Signed-off-by: Sage Weil --- diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index ae1ece1a74a..95ec2e6977a 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -193,6 +193,44 @@ int CrushWrapper::remove_item_under(CephContext *cct, int item, int ancestor, bo return ret; } +int CrushWrapper::parse_loc_map(const std::vector& args, + std::map *ploc) +{ + ploc->clear(); + for (unsigned i = 0; i < args.size(); ++i) { + const char *s = args[i].c_str(); + const char *pos = strchr(s, '='); + if (!pos) + return -EINVAL; + string key(s, 0, pos-s); + string value(pos+1); + if (value.length()) + (*ploc)[key] = value; + else + return -EINVAL; + } + return 0; +} + +int CrushWrapper::parse_loc_multimap(const std::vector& args, + std::multimap *ploc) +{ + ploc->clear(); + for (unsigned i = 0; i < args.size(); ++i) { + const char *s = args[i].c_str(); + const char *pos = strchr(s, '='); + if (!pos) + return -EINVAL; + string key(s, 0, pos-s); + string value(pos+1); + if (value.length()) + ploc->insert(make_pair(key, value)); + else + return -EINVAL; + } + return 0; +} + bool CrushWrapper::check_item_loc(CephContext *cct, int item, const map& loc, int *weight) { diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index 9931fae1e7f..a4c9dd00227 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -472,6 +472,19 @@ private: public: int remove_item_under(CephContext *cct, int id, int ancestor, bool unlink_only); + /** + * parse a set of key/value pairs out of a string vector + * + * These are used to describe a location in the CRUSH hierarchy. + * + * @param args list of strings (each key= or key=value) + * @param ploc pointer to a resulting location map or multimap + */ + static int parse_loc_map(const std::vector& args, + std::map *ploc); + static int parse_loc_multimap(const std::vector& args, + std::multimap *ploc); + /** * get an item's weight *