mirror of
https://github.com/ceph/ceph
synced 2025-03-25 11:48:05 +00:00
crush/CrushWrapper: add parse_loc_[multi]map helpers
Signed-off-by: Sage Weil <sage@inktank.com>
This commit is contained in:
parent
4ce6400a77
commit
8f48906db7
@ -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)
|
||||
{
|
||||
|
@ -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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user