From: Yehuda Sadeh Date: Sat, 2 May 2015 23:34:09 +0000 (-0700) Subject: rgw: list_objects() sets namespace appropriately X-Git-Tag: v9.0.3~76^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=20bd490bebf9be3553d4e25322c9544b0b090086;p=ceph.git rgw: list_objects() sets namespace appropriately 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 --- diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index 1e6eaf3b4604..f0be1b77e6b4 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -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] != '_') { diff --git a/src/rgw/rgw_orphan.cc b/src/rgw/rgw_orphan.cc index da73e5767737..9e8e5b8f88e2 100644 --- a/src/rgw/rgw_orphan.cc +++ b/src/rgw/rgw_orphan.cc @@ -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); diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index ebb58936c4aa..eba32ab53cb2 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -2475,8 +2475,14 @@ int RGWRados::Bucket::List::list_objects(int max, vector *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 *result, RGWObjEnt ent = eiter->second; ent.key = obj; - ent.ns = params.ns; + ent.ns = ns; result->push_back(ent); count++; }