]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crush/CrushWrapper: add parse_loc_[multi]map helpers
authorSage Weil <sage@inktank.com>
Tue, 29 Oct 2013 23:37:42 +0000 (16:37 -0700)
committerSage Weil <sage@inktank.com>
Mon, 23 Dec 2013 23:18:31 +0000 (15:18 -0800)
Signed-off-by: Sage Weil <sage@inktank.com>
src/crush/CrushWrapper.cc
src/crush/CrushWrapper.h

index ae1ece1a74a6fab9096e94574e85ac5f3353ac69..95ec2e6977aa87feaab99cf46ddb2df0666b11ea 100644 (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)
 {
index 9931fae1e7f40f5122025e52edb3e10763baa2d5..a4c9dd002272cb0ef8ccaa078a176780b50faef6 100644 (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
    *