]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rgw: fix bug with (un)ordered bucket listing and marker w/ namespace
authorJ. Eric Ivancich <ivancich@redhat.com>
Fri, 31 Jan 2020 20:01:40 +0000 (15:01 -0500)
committerJ. Eric Ivancich <ivancich@redhat.com>
Wed, 19 Feb 2020 19:33:18 +0000 (14:33 -0500)
When listing without specifying a namespace, the returned entries
could be in one or more namespaces. The marker used to continue the
listing may therefore contain a namespace, and that needs to be
preserved. This fixes a bug in both ordered and unordered listings
where it was not preserved.

Signed-off-by: J. Eric Ivancich <ivancich@redhat.com>
src/rgw/rgw_common.h
src/rgw/rgw_rados.cc

index 07745d6adc3d5991307b0c0370c17b0b6bf2dead..8d840731fe07eca6a77647cbfc700f6992b2813f 100644 (file)
@@ -1371,6 +1371,14 @@ struct rgw_obj_key {
     return instance;
   }
 
+  void set_ns(const std::string& _ns) {
+    ns = _ns;
+  }
+
+  const std::string& get_ns() const {
+    return ns;
+  }
+
   string get_index_key_name() const {
     if (ns.empty()) {
       if (name.size() < 1 || name[0] != '_') {
index 85f20574257f93b52c122766ef58240565b4570d..de678164c21d95bacf41369b2294d4b5c9192767 100644 (file)
@@ -1746,21 +1746,23 @@ int RGWRados::Bucket::List::list_objects_ordered(
 
   result->clear();
 
+  // use a local marker; either the marker will have a previous entry
+  // or it will be empty; either way it's OK to copy
   rgw_obj_key marker_obj(params.marker.name,
                         params.marker.instance,
-                        params.ns);
+                        params.marker.ns);
   rgw_obj_index_key cur_marker;
   marker_obj.get_index_key(&cur_marker);
 
   rgw_obj_key end_marker_obj(params.end_marker.name,
                             params.end_marker.instance,
-                             params.ns);
+                            params.end_marker.ns);
   rgw_obj_index_key cur_end_marker;
   end_marker_obj.get_index_key(&cur_end_marker);
   const bool cur_end_marker_valid = !params.end_marker.empty();
 
   rgw_obj_key prefix_obj(params.prefix);
-  prefix_obj.ns = params.ns;
+  prefix_obj.set_ns(params.ns);
   string cur_prefix = prefix_obj.get_index_key_name();
   string after_delim_s; /* needed in !params.delim.empty() AND later */
 
@@ -1858,8 +1860,8 @@ int RGWRados::Bucket::List::list_objects_ordered(
       }
 
       if (count < max) {
-        params.marker = index_key;
-        next_marker = index_key;
+       params.marker = index_key;
+       next_marker = index_key;
       }
 
       if (params.filter &&
@@ -2038,21 +2040,23 @@ int RGWRados::Bucket::List::list_objects_unordered(int64_t max_p,
 
   result->clear();
 
+  // use a local marker; either the marker will have a previous entry
+  // or it will be empty; either way it's OK to copy
   rgw_obj_key marker_obj(params.marker.name,
                         params.marker.instance,
-                        params.ns);
+                        params.marker.ns);
   rgw_obj_index_key cur_marker;
   marker_obj.get_index_key(&cur_marker);
 
   rgw_obj_key end_marker_obj(params.end_marker.name,
                             params.end_marker.instance,
-                             params.ns);
+                            params.end_marker.ns);
   rgw_obj_index_key cur_end_marker;
   end_marker_obj.get_index_key(&cur_end_marker);
   const bool cur_end_marker_valid = !params.end_marker.empty();
 
   rgw_obj_key prefix_obj(params.prefix);
-  prefix_obj.ns = params.ns;
+  prefix_obj.set_ns(params.ns);
   string cur_prefix = prefix_obj.get_index_key_name();
 
   while (truncated && count <= max) {
@@ -2078,6 +2082,11 @@ int RGWRados::Bucket::List::list_objects_unordered(int64_t max_p,
       rgw_obj_index_key index_key = entry.key;
       rgw_obj_key obj(index_key);
 
+      if (count < max) {
+       params.marker.set(index_key);
+       next_marker.set(index_key);
+      }
+
       /* note that parse_raw_oid() here will not set the correct
        * object's instance, as rgw_obj_index_key encodes that
        * separately. We don't need to set the instance because it's
@@ -2105,11 +2114,6 @@ int RGWRados::Bucket::List::list_objects_unordered(int64_t max_p,
        continue;
       }
 
-      if (count < max) {
-       params.marker.set(index_key);
-        next_marker.set(index_key);
-      }
-
       if (params.filter && !params.filter->filter(obj.name, index_key.name))
         continue;