]> git.apps.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)
committerLoic Dachary <ldachary@redhat.com>
Sun, 30 Aug 2015 15:55:59 +0000 (17:55 +0200)
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>
(cherry picked from commit 20bd490bebf9be3553d4e25322c9544b0b090086)

src/rgw/rgw_common.h
src/rgw/rgw_orphan.cc
src/rgw/rgw_rados.cc

index 53f75455c715af6c30390bb21c22da407d622cda..c9c455fe6e06a72dbd0b8a4830bdb4800ca928d7 100644 (file)
@@ -1316,36 +1316,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 9e3298153cd0dba28b9fd4fd8816714d6830a2a0..9a415eb9112888bc4a753a4fde6bce4cf55de7c5 100644 (file)
@@ -2466,8 +2466,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;
       }
@@ -2528,7 +2534,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++;
     }