Skip to content

Commit

Permalink
rgw: list_objects() sets namespace appropriately
Browse files Browse the repository at this point in the history
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 20bd490)
  • Loading branch information
yehudasa authored and ldachary committed Aug 30, 2015
1 parent 1c37072 commit 0082036
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 37 deletions.
29 changes: 8 additions & 21 deletions src/rgw/rgw_common.h
Expand Up @@ -1316,36 +1316,23 @@ class rgw_obj {
* 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] != '_') {
Expand Down
16 changes: 2 additions & 14 deletions src/rgw/rgw_orphan.cc
Expand Up @@ -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);

Expand Down
10 changes: 8 additions & 2 deletions src/rgw/rgw_rados.cc
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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++;
}
Expand Down

0 comments on commit 0082036

Please sign in to comment.