crush/CrushWrapper: add parse_loc_[multi]map helpers

Signed-off-by: Sage Weil <sage@inktank.com>
This commit is contained in:
Sage Weil 2013-10-29 16:37:42 -07:00
parent 4ce6400a77
commit 8f48906db7
2 changed files with 51 additions and 0 deletions

View File

@ -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<string>& args,
std::map<string,string> *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<string>& args,
std::multimap<string,string> *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<string,string>& loc,
int *weight)
{

View File

@ -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<string>& args,
std::map<string,string> *ploc);
static int parse_loc_multimap(const std::vector<string>& args,
std::multimap<string,string> *ploc);
/**
* get an item's weight
*