From 8d914f0e00bb29db34a94f1d1789ad56ac9823b1 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 4 Nov 2011 11:41:43 -0700 Subject: [PATCH] rgw: list system buckets through rados api --- src/rgw/rgw_rados.cc | 67 +++++++++++++++++++++++++++++++++++++------- src/rgw/rgw_rados.h | 7 +++++ 2 files changed, 64 insertions(+), 10 deletions(-) diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index f5177dbd8d19b..c0ddef0913a6f 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -354,8 +354,15 @@ int RGWRados::list_objects(rgw_bucket& bucket, int max, string& prefix, string& do { std::map ent_map; - int r = cls_bucket_list(bucket, cur_marker, max - count, ent_map, + int r; + + if (bucket_is_system(bucket)) { + r = pool_list(bucket, cur_marker, max - count, ent_map, + &truncated, &cur_marker); + } else { + r = cls_bucket_list(bucket, cur_marker, max - count, ent_map, &truncated, &cur_marker); + } if (r < 0) return r; @@ -2026,12 +2033,52 @@ int RGWRados::distribute(bufferlist& bl) return r; } +int RGWRados::pool_list(rgw_bucket& bucket, string start, uint32_t num, map& m, + bool *is_truncated, string *last_entry) +{ + librados::IoCtx io_ctx; + int r = open_bucket_ctx(bucket, io_ctx); + if (r < 0) + return r; + + librados::ObjectIterator iter = io_ctx.objects_begin(); + while (iter != io_ctx.objects_end()) { + const std::string& oid = *iter; + if (oid.compare(start) >= 0) + break; + + ++iter; + } + if (iter == io_ctx.objects_end()) + return -ENOENT; + + uint32_t i; + + for (i = 0; i < num && iter != io_ctx.objects_end(); ++i, ++iter) { + RGWObjEnt e; + const string &oid = *iter; + + // fill it in with initial values; we may correct later + e.name = *iter; + m[e.name] = e; + dout(0) << " got " << e.name << dendl; + } + + if (m.size()) { + *last_entry = m.rbegin()->first; + } + if (is_truncated) + *is_truncated = (iter != io_ctx.objects_end()); + + return m.size(); +} + int RGWRados::cls_rgw_init_index(rgw_bucket& bucket, string& oid) { - if (bucket.marker.empty()) { - if (bucket.name[0] == '.') - return 0; + if (bucket_is_system(bucket)) + return 0; + if (bucket.marker.empty()) { dout(0) << "ERROR: empty marker for cls_rgw bucket operation" << dendl; return -EIO; } @@ -2049,10 +2096,10 @@ int RGWRados::cls_rgw_init_index(rgw_bucket& bucket, string& oid) int RGWRados::cls_obj_prepare_op(rgw_bucket& bucket, uint8_t op, string& tag, string& name, string& locator) { - if (bucket.marker.empty()) { - if (bucket.name[0] == '.') - return 0; + if (bucket_is_system(bucket)) + return 0; + if (bucket.marker.empty()) { dout(0) << "ERROR: empty marker for cls_rgw bucket operation" << dendl; return -EIO; } @@ -2078,10 +2125,10 @@ int RGWRados::cls_obj_prepare_op(rgw_bucket& bucket, uint8_t op, string& tag, int RGWRados::cls_obj_complete_op(rgw_bucket& bucket, uint8_t op, string& tag, uint64_t epoch, RGWObjEnt& ent, RGWObjCategory category) { - if (bucket.marker.empty()) { - if (bucket.name[0] == '.') - return 0; + if (bucket_is_system(bucket)) + return 0; + if (bucket.marker.empty()) { dout(0) << "ERROR: empty marker for cls_rgw bucket operation" << dendl; return -EIO; } diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index ee526f154bd55..111adb2adcb10 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -355,6 +355,13 @@ public: RGWObjEnt& object, bufferlist& suggested_updates); + bool bucket_is_system(rgw_bucket& bucket) { + return (bucket.name[0] == '.'); + } + + int pool_list(rgw_bucket& bucket, string start, uint32_t num, map& m, + bool *is_truncated, string *last_entry); + }; #endif -- 2.39.5