]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: fix bucket index listing count bug
authorJ. Eric Ivancich <ivancich@redhat.com>
Wed, 25 Aug 2021 13:50:29 +0000 (09:50 -0400)
committerJ. Eric Ivancich <ivancich@redhat.com>
Tue, 31 Aug 2021 15:01:24 +0000 (11:01 -0400)
Fix bugs surrounding calculation of number of entries returned and
whether the end of a listing range has been reached.

Signed-off-by: J. Eric Ivancich <ivancich@redhat.com>
src/cls/rgw/cls_rgw.cc

index 56f6cfe188d2fdca6ac83c36355762deb6b9fab4..5bd9813f6c4b15a4945d0c8b566ebdc300f8365d 100644 (file)
@@ -2599,6 +2599,7 @@ static int list_plain_entries_help(cls_method_context_t hctx,
              escape_str(e.key.name).c_str());
       // skip the rest of the entries
       more = false;
+      end_key_reached = true;
       return count;
     }
 
@@ -2623,8 +2624,17 @@ static int list_plain_entries_help(cls_method_context_t hctx,
   } // iter for loop
 
   return count;
-}
+} // list_plain_entries_help
 
+/*
+ * Lists plain entries in either or both regions, the region of those
+ * beginning with an ASCII character or a non-ASCII character, which
+ * surround the "ugly" namespace used by special entries for versioned
+ * buckets.
+ *
+ * The entries parameter is not cleared and additional entries are
+ * appended to it.
+ */
 static int list_plain_entries(cls_method_context_t hctx,
                               const std::string& name_filter,
                               const std::string& marker,
@@ -2633,9 +2643,9 @@ static int list_plain_entries(cls_method_context_t hctx,
                               bool* pmore,
                              const PlainEntriesRegion region = PlainEntriesRegion::Both)
 {
-  int r;
-  bool end_key_reached;
-  bool more;
+  int r = 0;
+  bool end_key_reached = false;
+  bool more = false;
   const size_t start_size = entries->size();
 
   if (region <= PlainEntriesRegion::Both && marker < BI_PREFIX_BEGIN) {
@@ -2647,10 +2657,11 @@ static int list_plain_entries(cls_method_context_t hctx,
     }
 
     // see if we're done for this call (there may be more for a later call)
-    if (r >= int(max) || !end_key_reached || (!more && region != PlainEntriesRegion::Both)) {
+    if (r >= int(max) || !end_key_reached || (!more && region == PlainEntriesRegion::Low)) {
       if (pmore) {
        *pmore = more;
       }
+
       return int(entries->size() - start_size);
     }
 
@@ -2661,8 +2672,8 @@ static int list_plain_entries(cls_method_context_t hctx,
     const std::string start_after_key = std::max(marker, BI_PREFIX_END);
 
     // listing non-ascii plain namespace
-    r = list_plain_entries_help(hctx, name_filter, start_after_key, {}, max, entries,
-                               end_key_reached, more);
+    r = list_plain_entries_help(hctx, name_filter, start_after_key, {}, max,
+                               entries, end_key_reached, more);
     if (r < 0) {
       return r;
     }
@@ -2891,10 +2902,12 @@ static int rgw_bi_list_op(cls_method_context_t hctx,
     return -EINVAL;
   }
 
+  constexpr uint32_t MAX_BI_LIST_ENTRIES = 1000;
+  const uint32_t max = std::min(op.max, MAX_BI_LIST_ENTRIES);
+
+
   int ret;
-  int count = 0;
-  constexpr int MAX_BI_LIST_ENTRIES = 1000;
-  const int32_t max = (op.max < MAX_BI_LIST_ENTRIES ? op.max : MAX_BI_LIST_ENTRIES);
+  uint32_t count = 0;
   bool more = false;
   rgw_cls_bi_list_ret op_ret;
 
@@ -2938,7 +2951,7 @@ static int rgw_bi_list_op(cls_method_context_t hctx,
       return ret;
     }
 
-    count = ret;
+    count += ret;
     CLS_LOG(20, "found %d non-ascii (high) plain entries", count);
   }
 
@@ -2951,7 +2964,7 @@ static int rgw_bi_list_op(cls_method_context_t hctx,
   encode(op_ret, *out);
 
   return 0;
-}
+} // rgw_bi_list_op
 
 
 int bi_log_record_decode(bufferlist& bl, rgw_bi_log_entry& e)