Skip to content

Commit

Permalink
Merge pull request ceph#12047 from rzarzynski/wip-rgw-17931
Browse files Browse the repository at this point in the history
rgw: add support for the prefix parameter in account listing of Swift API
  • Loading branch information
mattbenjamin authored Nov 29, 2016
2 parents 515c14c + 1d7e94b commit 27c1462
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/rgw/rgw_rest_swift.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

int RGWListBuckets_ObjStore_SWIFT::get_params()
{
prefix = s->info.args.get("prefix");
marker = s->info.args.get("marker");
end_marker = s->info.args.get("end_marker");

Expand Down Expand Up @@ -145,7 +146,7 @@ void RGWListBuckets_ObjStore_SWIFT::send_response_begin(bool has_buckets)
set_req_state_err(s, op_ret);
}

if (!g_conf->rgw_swift_enforce_content_length) {
if (! s->cct->_conf->rgw_swift_enforce_content_length) {
/* Adding account stats in the header to keep align with Swift API */
dump_account_metadata(s,
buckets_count,
Expand All @@ -170,22 +171,28 @@ void RGWListBuckets_ObjStore_SWIFT::send_response_begin(bool has_buckets)

void RGWListBuckets_ObjStore_SWIFT::send_response_data(RGWUserBuckets& buckets)
{
map<string, RGWBucketEnt>& m = buckets.get_buckets();
map<string, RGWBucketEnt>::iterator iter;

if (!sent_data)
if (! sent_data) {
return;
}

/* Take care of the prefix parameter of Swift API. There is no business
* in applying the filter earlier as we really need to go through all
* entries regardless of it (the headers like X-Account-Container-Count
* aren't affected by specifying prefix). */
const std::map<std::string, RGWBucketEnt>& m = buckets.get_buckets();
for (auto iter = m.lower_bound(prefix);
iter != m.end() && boost::algorithm::starts_with(iter->first, prefix);
++iter) {
const RGWBucketEnt& obj = iter->second;

for (iter = m.begin(); iter != m.end(); ++iter) {
RGWBucketEnt obj = iter->second;
s->formatter->open_object_section("container");
s->formatter->dump_string("name", obj.bucket.name);
if (need_stats) {
s->formatter->dump_int("count", obj.count);
s->formatter->dump_int("bytes", obj.size);
}
s->formatter->close_section();
if (!g_conf->rgw_swift_enforce_content_length) {
if (! s->cct->_conf->rgw_swift_enforce_content_length) {
rgw_flush_formatter(s, s->formatter);
}
}
Expand All @@ -197,7 +204,7 @@ void RGWListBuckets_ObjStore_SWIFT::send_response_end()
s->formatter->close_section();
}

if (g_conf->rgw_swift_enforce_content_length) {
if (s->cct->_conf->rgw_swift_enforce_content_length) {
/* Adding account stats in the header to keep align with Swift API */
dump_account_metadata(s,
buckets_count,
Expand All @@ -211,7 +218,7 @@ void RGWListBuckets_ObjStore_SWIFT::send_response_end()
end_header(s, NULL, NULL, s->formatter->get_len(), true);
}

if (sent_data || g_conf->rgw_swift_enforce_content_length) {
if (sent_data || s->cct->_conf->rgw_swift_enforce_content_length) {
rgw_flush_formatter_and_reset(s, s->formatter);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/rgw/rgw_rest_swift.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class RGWGetObj_ObjStore_SWIFT : public RGWGetObj_ObjStore {

class RGWListBuckets_ObjStore_SWIFT : public RGWListBuckets_ObjStore {
bool need_stats;
std::string prefix;

uint64_t get_default_max() const override {
return 0;
Expand Down

0 comments on commit 27c1462

Please sign in to comment.