]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add namespace to rgw_pool
authorYehuda Sadeh <yehuda@redhat.com>
Fri, 16 Dec 2016 02:14:58 +0000 (18:14 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Thu, 9 Mar 2017 17:18:54 +0000 (09:18 -0800)
add a namespace field to the rgw_pool struct

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_common.cc
src/rgw/rgw_common.h

index cc104c685728e3d351e2e104f027f6e559918aac..834ff51ecefb46dd7f7789f007ef1f476c52a398 100644 (file)
@@ -1435,6 +1435,74 @@ bool RGWUserCaps::is_valid_cap_type(const string& tp)
   return false;
 }
 
+static ssize_t unescape_str(const string& s, ssize_t ofs, char esc_char, char special_char, string *dest)
+{
+  const char *src = s.c_str();
+  char dest_buf[s.size() + 1];
+  char *destp = dest_buf;
+  bool esc = false;
+
+  dest_buf[0] = '\0';
+
+  for (size_t i = ofs; i < s.size(); i++) {
+    char c = src[i];
+    if (!esc && c == esc_char) {
+      esc = true;
+      continue;
+    }
+    if (!esc && c == special_char) {
+      *destp = '\0';
+      *dest = dest_buf;
+      return (ssize_t)i + 1;
+    }
+    *destp++ = c;
+    esc = false;
+  }
+  *destp = '\0';
+  *dest = dest_buf;
+  return string::npos;
+}
+
+static void escape_str(const string& s, char esc_char, char special_char, string *dest)
+{
+  const char *src = s.c_str();
+  char dest_buf[s.size() * 2 + 1];
+  char *destp = dest_buf;
+  
+  for (size_t i = 0; i < s.size(); i++) {
+    char c = src[i];
+    if (c == esc_char || c == special_char) {
+      *destp++ = esc_char;
+    }
+    *destp++ = c;
+  }
+  *destp++ = '\0';
+  *dest = dest_buf;
+}
+
+void rgw_pool::from_str(const string& s)
+{
+  ssize_t pos = unescape_str(s, 0, '\\', ':', &name);
+  if (pos != string::npos) {
+    pos = unescape_str(s, pos, '\\', ':', &ns);
+    /* ignore return; if pos != string::npos it means that we had a colon
+     * in the middle of ns that wasn't escaped, we're going to stop there
+     */
+  }
+}
+
+string rgw_pool::to_str() const
+{
+  string esc_name;
+  escape_str(name, '\\', ':', &esc_name);
+  if (ns.empty()) {
+    return esc_name;
+  }
+  string esc_ns;
+  escape_str(ns, '\\', ':', &esc_ns);
+  return esc_name + ":" + esc_ns;
+}
+
 void rgw_raw_obj::decode_from_rgw_obj(bufferlist::iterator& bl)
 {
   rgw_obj old_obj;
index 4317de9ff54030e3e6c2cef941216352cc2fc224..2aa20009bf83523450e4d3681807bfde0c8d5f14 100644 (file)
@@ -736,17 +736,20 @@ WRITE_CLASS_ENCODER(RGWUserInfo)
 
 struct rgw_pool {
   string name;
+  string ns;
 
   rgw_pool() {}
-  rgw_pool(const rgw_pool& _p) : name(_p.name) {}
-  rgw_pool(const string& _name) : name(_name) {}
-
-  const string& to_str() const {
-    return name;
+  rgw_pool(const rgw_pool& _p) : name(_p.name), ns(_p.ns) {}
+  rgw_pool(const string& _s) {
+    from_str(_s);
   }
+  rgw_pool(const string& _name, const string& _ns) : name(_name), ns(_ns) {}
+
+  string to_str() const;
+  void from_str(const string& s);
 
-  void init(const string& _name) {
-    name = _name;
+  void init(const string& _s) {
+    from_str(_s);
   }
 
   bool empty() const {
@@ -754,12 +757,17 @@ struct rgw_pool {
   }
 
   int compare(const rgw_pool& p) const {
-    return name.compare(p.name);
+    int r = name.compare(p.name);
+    if (r != 0) {
+      return r;
+    }
+    return ns.compare(p.ns);
   }
 
   void encode(bufferlist& bl) const {
      ENCODE_START(10, 10, bl);
     ::encode(name, bl);
+    ::encode(ns, bl);
     ENCODE_FINISH(bl);
   }
 
@@ -780,6 +788,8 @@ struct rgw_pool {
      * version. Anything older than 10 needs to be treated as old rgw_bucket
      */
 
+    } else {
+      ::decode(ns, bl);
     }
 
     DECODE_FINISH(bl);
@@ -791,6 +801,13 @@ struct rgw_pool {
   bool operator!=(const rgw_pool& p) const {
     return !(*this == p);
   }
+  bool operator<(const rgw_pool& p) const {
+    int r = name.compare(p.name);
+    if (r == 0) {
+      return (ns.compare(p.ns) < 0);
+    }
+    return (r < 0);
+  }
 };
 WRITE_CLASS_ENCODER(rgw_pool)
 
@@ -828,7 +845,7 @@ struct rgw_data_placement_target {
 };
 
 inline ostream& operator<<(ostream& out, const rgw_pool& p) {
-  out << p.name;
+  out << p.to_str();
   return out;
 }