From edc6659bb3f1b397812d6e658748a840d66f27be Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 10 Jun 2011 15:01:04 -0700 Subject: [PATCH] rgw: list bucket display the correct objects owners --- src/rgw/rgw_acl.h | 5 +++++ src/rgw/rgw_common.h | 2 ++ src/rgw/rgw_rados.cc | 25 ++++++++++++++++++++----- src/rgw/rgw_rest.h | 1 - src/rgw/rgw_rest_s3.cc | 2 +- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/rgw/rgw_acl.h b/src/rgw/rgw_acl.h index a9608ba974c3f..f479f34102c8a 100644 --- a/src/rgw/rgw_acl.h +++ b/src/rgw/rgw_acl.h @@ -329,6 +329,11 @@ public: ::decode(owner, bl); ::decode(acl, bl); } + void decode_owner(bufferlist::iterator& bl) { // sometimes we only need that, should be faster + __u8 struct_v; + ::decode(struct_v, bl); + ::decode(owner, bl); + } void to_xml(ostream& out) { out << ""; owner.to_xml(out); diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index c525616f3ee22..aafc099ff83e2 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -365,6 +365,8 @@ struct req_state { /** Store basic data on an object */ struct RGWObjEnt { std::string name; + std::string owner; + std::string owner_display_name; size_t size; time_t mtime; // two md5 digests and a terminator diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 71adf7f71e50b..74457313dced6 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -3,6 +3,7 @@ #include "rgw_access.h" #include "rgw_rados.h" +#include "rgw_acl.h" #include "include/rados/librados.hpp" using namespace librados; @@ -200,14 +201,28 @@ int RGWRados::list_objects(string& id, string& bucket, int max, string& prefix, continue; obj.size = s; - bufferlist bl; obj.etag[0] = '\0'; - if (io_ctx.getxattr(*p, RGW_ATTR_ETAG, bl) >= 0) { - strncpy(obj.etag, bl.c_str(), sizeof(obj.etag)); - obj.etag[sizeof(obj.etag)-1] = '\0'; + map attrset; + if (io_ctx.getxattrs(*p, attrset) >= 0) { + map::iterator iter = attrset.find(RGW_ATTR_ETAG); + if (iter != attrset.end()) { + bufferlist& bl = iter->second; + strncpy(obj.etag, bl.c_str(), sizeof(obj.etag)); + obj.etag[sizeof(obj.etag)-1] = '\0'; + } + iter = attrset.find(RGW_ATTR_ACL); + if (iter != attrset.end()) { + bufferlist& bl = iter->second; + bufferlist::iterator i = bl.begin(); + RGWAccessControlPolicy policy; + policy.decode_owner(i); + ACLOwner& owner = policy.get_owner(); + obj.owner = owner.get_id(); + obj.owner_display_name = owner.get_display_name(); + } } + bufferlist bl; if (get_content_type) { - bl.clear(); obj.content_type = ""; if (io_ctx.getxattr(*p, RGW_ATTR_CONTENT_TYPE, bl) >= 0) { obj.content_type = bl.c_str(); diff --git a/src/rgw/rgw_rest.h b/src/rgw/rgw_rest.h index 7e483a26f2445..4bc8b04a3cb47 100644 --- a/src/rgw/rgw_rest.h +++ b/src/rgw/rgw_rest.h @@ -120,7 +120,6 @@ extern void dump_owner(struct req_state *s, string& id, string& name); extern void dump_content_length(struct req_state *s, size_t len); extern void dump_etag(struct req_state *s, const char *etag); extern void dump_last_modified(struct req_state *s, time_t t); -extern void dump_bucket(struct req_state *s, RGWObjEnt& obj); extern void abort_early(struct req_state *s, int err); extern void dump_range(struct req_state *s, off_t ofs, off_t end); extern void dump_continue(struct req_state *s); diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 3d5f6e26bd3aa..5f4a82917e372 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -145,7 +145,7 @@ void RGWListBucket_REST_S3::send_response() s->formatter->dump_value_str("ETag", "\"%s\"", iter->etag); s->formatter->dump_value_int("Size", "%lld", iter->size); s->formatter->dump_value_str("StorageClass", "STANDARD"); - dump_owner(s, s->user.user_id, s->user.display_name); + dump_owner(s, iter->owner, iter->owner_display_name); s->formatter->close_section("Contents"); } if (common_prefixes.size() > 0) { -- 2.39.5