From: Mykola Golub Date: Thu, 22 Apr 2021 06:14:25 +0000 (+0100) Subject: cls/rgw: look for plane entries in non-ascii plain namespace too X-Git-Tag: v14.2.22~7^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=44e43e8afd79f6f515feaeb809f8a0316ac9d1b1;p=ceph.git cls/rgw: look for plane entries in non-ascii plain namespace too Fixes: https://tracker.ceph.com/issues/50415 Signed-off-by: Mykola Golub (cherry picked from commit 7cf30e943276ff66f0eff9f0c088c597b1f9e066) Conflicts: src/cls/rgw/cls_rgw.cc (trivial: indentation, 'start_after_key' vs 'start_key', iterator declaration) --- diff --git a/src/cls/rgw/cls_rgw.cc b/src/cls/rgw/cls_rgw.cc index 741d8c571906..73a57312cb20 100644 --- a/src/cls/rgw/cls_rgw.cc +++ b/src/cls/rgw/cls_rgw.cc @@ -35,6 +35,9 @@ static std::string bucket_index_prefixes[] = { "", /* special handling for the o /* this must be the last index */ "9999_",}; +static const std::string BI_PREFIX_END = string(1, BI_PREFIX_CHAR) + + bucket_index_prefixes[BI_BUCKET_LAST_INDEX]; + static bool bi_is_objs_index(const string& s) { return ((unsigned char)s[0] != BI_PREFIX_CHAR); } @@ -2322,29 +2325,29 @@ static int rgw_bi_put_op(cls_method_context_t hctx, bufferlist *in, bufferlist * return 0; } -static int list_plain_entries(cls_method_context_t hctx, const string& name, const string& marker, uint32_t max, - list *entries, bool *pmore) +static int list_plain_entries(cls_method_context_t hctx, + const string& filter, + const string& start_after_key, + const string& end_key, + uint32_t max, + list *entries, + bool *end_key_reached, + bool *pmore) { - string filter = name; - string start_key = marker; - - string end_key; // stop listing at bi_log_prefix - bi_log_prefix(end_key); - int count = 0; map keys; - int ret = cls_cxx_map_get_vals(hctx, start_key, filter, max, &keys, pmore); + int ret = cls_cxx_map_get_vals(hctx, start_after_key, filter, max, &keys, + pmore); if (ret < 0) { return ret; } - map::iterator iter; - for (iter = keys.begin(); iter != keys.end(); ++iter) { - if (iter->first >= end_key) { - /* past the end of plain namespace */ - if (pmore) { - *pmore = false; - } + *end_key_reached = false; + + for (auto iter = keys.begin(); iter != keys.end(); ++iter) { + if (!end_key.empty() && iter->first >= end_key) { + *end_key_reached = true; + *pmore = true; return count; } @@ -2363,13 +2366,12 @@ static int list_plain_entries(cls_method_context_t hctx, const string& name, con return -EIO; } - CLS_LOG(20, "%s(): entry.idx=%s e.key.name=%s", __func__, escape_str(entry.idx).c_str(), escape_str(e.key.name).c_str()); + CLS_LOG(20, "%s(): entry.idx=%s e.key.name=%s", __func__, + escape_str(entry.idx).c_str(), escape_str(e.key.name).c_str()); - if (!name.empty() && e.key.name != name) { + if (!filter.empty() && e.key.name != filter) { /* we are skipping the rest of the entries */ - if (pmore) { - *pmore = false; - } + *pmore = false; return count; } @@ -2378,12 +2380,54 @@ static int list_plain_entries(cls_method_context_t hctx, const string& name, con if (count >= (int)max) { return count; } - start_key = entry.idx; } return count; } +static int list_plain_entries(cls_method_context_t hctx, + const string& name, + const string& marker, + uint32_t max, + list *entries, + bool *pmore) { + string start_after_key = marker; + string end_key; + bi_log_prefix(end_key); + int r; + bool end_key_reached; + bool more; + + if (start_after_key < end_key) { + // listing ascii plain namespace + int r = list_plain_entries(hctx, name, start_after_key, end_key, max, + entries, &end_key_reached, &more); + if (r < 0) { + return r; + } + if (r >= (int)max || !end_key_reached || !more) { + if (pmore) { + *pmore = more; + } + return r; + } + start_after_key = BI_PREFIX_END; + max = max - r; + } + + // listing non-ascii plain namespace + r = list_plain_entries(hctx, name, start_after_key, {}, max, entries, + &end_key_reached, &more); + if (r < 0) { + return r; + } + if (pmore) { + *pmore = more; + } + + return r; +} + static int list_instance_entries(cls_method_context_t hctx, const string& name, const string& marker, uint32_t max, list *entries, bool *pmore) {