]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: list_objects() sets namespace appropriately
authorYehuda Sadeh <yehuda@redhat.com>
Sat, 2 May 2015 23:34:09 +0000 (16:34 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Mon, 29 Jun 2015 22:09:02 +0000 (15:09 -0700)
list_objects() now uses parse_raw_oid(), so that it can set the correct
namespace. It only affects users of the function that want to get all
objects in bucket, regardless to the namespace associated with it. This
makes it so that the orphan code actually works now with namespaced
objects, and with special named objects (namely, start with underscore).

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

index 1e6eaf3b46042826cf4826cdca7d831167641f40..f0be1b77e6b42b1a7d3cb8bdc8a3e32137e590d0 100644 (file)
@@ -1327,36 +1327,23 @@ public:
    * part of the given namespace, it returns false.
    */
   static bool translate_raw_obj_to_obj_in_ns(string& obj, string& instance, string& ns) {
-    if (ns.empty()) {
-      if (obj[0] != '_')
-        return true;
-
-      if (obj.size() >= 2 && obj[1] == '_') {
-        obj = obj.substr(1);
+    if (obj[0] != '_') {
+      if (ns.empty()) {
         return true;
       }
-
       return false;
     }
 
-    if (obj[0] != '_' || obj.size() < 3) // for namespace, min size would be 3: _x_
-      return false;
-
-    int pos = obj.find('_', 1);
-    if (pos <= 1) // if it starts with __, it's not in our namespace
-      return false;
-
-    string obj_ns = obj.substr(1, pos - 1);
-    parse_ns_field(obj_ns, instance);
-    if (obj_ns.compare(ns) != 0)
-        return false;
+    string obj_ns;
+    bool ret = parse_raw_oid(obj, &obj, &instance, &obj_ns);
+    if (!ret) {
+      return ret;
+    }
 
-    obj = obj.substr(pos + 1);
-    return true;
+    return (ns == obj_ns);
   }
 
   static bool parse_raw_oid(const string& oid, string *obj_name, string *obj_instance, string *obj_ns) {
-    obj_name->clear();
     obj_instance->clear();
     obj_ns->clear();
     if (oid[0] != '_') {
index da73e5767737ec7f3572d3574493c1481f24239e..9e8e5b8f88e2e3395f5aa01f81c7695df1c5eae9 100644 (file)
@@ -447,21 +447,9 @@ int RGWOrphanSearch::build_linked_oids_for_bucket(const string& bucket_instance_
         ldout(store->ctx(), 20) << "obj entry: " << entry.key.name << " [" << entry.key.instance << "]" << dendl;
       }
 
-      /*
-       * this is a bit confusing, but the list operation isn't going to return the namespace, for
-       * the object, but it will return the instance. So we need to decode the namespace out of the
-       * object key. The problem is that the list_op is mainly used to list objects in a specific
-       * namespace, but we want to list all, that's why we have the special handling.
-       */
-      string obj_name;
-      string obj_instance;
-      string obj_ns;
-      rgw_obj::parse_raw_oid(entry.key.name, &obj_name, &obj_instance, &obj_ns);
       ldout(store->ctx(), 20) << __func__ << ": entry.key.name=" << entry.key.name << " entry.key.instance=" << entry.key.instance << " entry.ns=" << entry.ns << dendl;
-      ldout(store->ctx(), 20) << __func__ << ": obj_name=" << obj_name << " obj_instance=" << obj_instance << " obj_ns=" << obj_ns << dendl;
-      rgw_obj_key key(obj_name, entry.key.instance);
-      rgw_obj obj(bucket_info.bucket, key);
-      obj.set_ns(obj_ns);
+      rgw_obj obj(bucket_info.bucket, entry.key);
+      obj.set_ns(entry.ns);
 
       RGWRados::Object op_target(store, bucket_info, obj_ctx, obj);
 
index ebb58936c4aa9f6dd8e63d21bb316e9636b411de..eba32ab53cb20d905c69366c4ce25054764cacb8 100644 (file)
@@ -2475,8 +2475,14 @@ int RGWRados::Bucket::List::list_objects(int max, vector<RGWObjEnt> *result,
       RGWObjEnt& entry = eiter->second;
       rgw_obj_key key = obj;
       string instance;
+      string ns;
 
-      bool check_ns = rgw_obj::translate_raw_obj_to_obj_in_ns(obj.name, instance, params.ns);
+      bool valid = rgw_obj::parse_raw_oid(obj.name, &obj.name, &instance, &ns);
+      if (!valid) {
+        ldout(cct, 0) << "ERROR: could not parse object name: " << obj.name << dendl;
+        continue;
+      }
+      bool check_ns = (ns == params.ns);
       if (!params.list_versions && !entry.is_visible()) {
         continue;
       }
@@ -2542,7 +2548,7 @@ int RGWRados::Bucket::List::list_objects(int max, vector<RGWObjEnt> *result,
 
       RGWObjEnt ent = eiter->second;
       ent.key = obj;
-      ent.ns = params.ns;
+      ent.ns = ns;
       result->push_back(ent);
       count++;
     }