1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "rgw_common.h"
8 #include "rgw_acl_s3.h"
11 #include "common/Formatter.h"
13 static string shadow_ns = RGW_OBJ_NS_SHADOW;
15 static void init_bucket(rgw_bucket *b, const char *t, const char *n, const char *dp, const char *ip, const char *m, const char *id)
21 b->explicit_placement.data_pool = rgw_pool(dp);
22 b->explicit_placement.index_pool = rgw_pool(ip);
25 void RGWObjManifestPart::generate_test_instances(std::list<RGWObjManifestPart*>& o)
27 o.push_back(new RGWObjManifestPart);
29 RGWObjManifestPart *p = new RGWObjManifestPart;
31 init_bucket(&b, "tenant", "bucket", ".pool", ".index_pool", "marker_", "12");
33 p->loc = rgw_obj(b, "object");
34 p->loc_ofs = 512 * 1024;
39 void RGWObjManifest::obj_iterator::seek(uint64_t o)
42 if (manifest->explicit_objs) {
43 explicit_iter = manifest->objs.upper_bound(ofs);
44 if (explicit_iter != manifest->objs.begin()) {
47 if (ofs >= manifest->obj_size) {
48 ofs = manifest->obj_size;
51 update_explicit_pos();
55 if (o < manifest->get_head_size()) {
56 rule_iter = manifest->rules.begin();
58 stripe_size = manifest->get_head_size();
59 if (rule_iter != manifest->rules.end()) {
60 cur_part_id = rule_iter->second.start_part_num;
61 cur_override_prefix = rule_iter->second.override_prefix;
67 rule_iter = manifest->rules.upper_bound(ofs);
68 next_rule_iter = rule_iter;
69 if (rule_iter != manifest->rules.begin()) {
73 if (rule_iter == manifest->rules.end()) {
78 RGWObjManifestRule& rule = rule_iter->second;
80 if (rule.part_size > 0) {
81 cur_part_id = rule.start_part_num + (ofs - rule.start_ofs) / rule.part_size;
83 cur_part_id = rule.start_part_num;
85 part_ofs = rule.start_ofs + (cur_part_id - rule.start_part_num) * rule.part_size;
87 if (rule.stripe_max_size > 0) {
88 cur_stripe = (ofs - part_ofs) / rule.stripe_max_size;
90 stripe_ofs = part_ofs + cur_stripe * rule.stripe_max_size;
91 if (!cur_part_id && manifest->get_head_size() > 0) {
96 stripe_ofs = part_ofs;
99 if (!rule.part_size) {
100 stripe_size = rule.stripe_max_size;
101 stripe_size = MIN(manifest->get_obj_size() - stripe_ofs, stripe_size);
103 uint64_t next = MIN(stripe_ofs + rule.stripe_max_size, part_ofs + rule.part_size);
104 stripe_size = next - stripe_ofs;
107 cur_override_prefix = rule.override_prefix;
112 void RGWObjManifest::obj_iterator::update_location()
114 if (manifest->explicit_objs) {
115 location = explicit_iter->second.loc;
119 if (ofs < manifest->get_head_size()) {
120 location = manifest->get_obj();
121 location.set_placement_rule(manifest->get_head_placement_rule());
125 manifest->get_implicit_location(cur_part_id, cur_stripe, ofs, &cur_override_prefix, &location);
128 void RGWObjManifest::obj_iterator::update_explicit_pos()
130 ofs = explicit_iter->first;
133 map<uint64_t, RGWObjManifestPart>::iterator next_iter = explicit_iter;
135 if (next_iter != manifest->objs.end()) {
136 stripe_size = next_iter->first - ofs;
138 stripe_size = manifest->obj_size - ofs;
142 void RGWObjManifest::generate_test_instances(std::list<RGWObjManifest*>& o)
144 RGWObjManifest *m = new RGWObjManifest;
145 for (int i = 0; i<10; i++) {
146 RGWObjManifestPart p;
148 init_bucket(&b, "tenant", "bucket", ".pool", ".index_pool", "marker_", "12");
149 p.loc = rgw_obj(b, "object");
152 m->objs[(uint64_t)i * 512 * 1024] = p;
154 m->obj_size = 5 * 1024 * 1024;
158 o.push_back(new RGWObjManifest);
161 void RGWObjManifest::get_implicit_location(uint64_t cur_part_id, uint64_t cur_stripe, uint64_t ofs, string *override_prefix, rgw_obj_select *location)
165 string& oid = loc.key.name;
166 string& ns = loc.key.ns;
168 if (!override_prefix || override_prefix->empty()) {
171 oid = *override_prefix;
175 if (ofs < max_head_size) {
176 location->set_placement_rule(head_placement_rule);
181 snprintf(buf, sizeof(buf), "%d", (int)cur_stripe);
187 if (cur_stripe == 0) {
188 snprintf(buf, sizeof(buf), ".%d", (int)cur_part_id);
190 ns= RGW_OBJ_NS_MULTIPART;
192 snprintf(buf, sizeof(buf), ".%d_%d", (int)cur_part_id, (int)cur_stripe);
198 if (!tail_placement.bucket.name.empty()) {
199 loc.bucket = tail_placement.bucket;
201 loc.bucket = obj.bucket;
204 // Always overwrite instance with tail_instance
205 // to get the right shadow object location
206 loc.key.set_instance(tail_instance);
208 location->set_placement_rule(tail_placement.placement_rule);
214 void rgw_log_entry::generate_test_instances(list<rgw_log_entry*>& o)
216 rgw_log_entry *e = new rgw_log_entry;
217 e->object_owner = "object_owner";
218 e->bucket_owner = "bucket_owner";
219 e->bucket = "bucket";
220 e->remote_addr = "1.2.3.4";
222 e->obj = rgw_obj_key("obj");
223 e->uri = "http://uri/bucket/obj";
224 e->http_status = "200";
225 e->error_code = "error_code";
226 e->bytes_sent = 1024;
227 e->bytes_received = 512;
229 e->user_agent = "user_agent";
230 e->referrer = "referrer";
233 o.push_back(new rgw_log_entry);
236 void ACLPermission::generate_test_instances(list<ACLPermission*>& o)
238 ACLPermission *p = new ACLPermission;
239 p->set_permissions(RGW_PERM_WRITE_ACP);
241 o.push_back(new ACLPermission);
244 void ACLGranteeType::generate_test_instances(list<ACLGranteeType*>& o)
246 ACLGranteeType *t = new ACLGranteeType;
247 t->set(ACL_TYPE_CANON_USER);
249 o.push_back(new ACLGranteeType);
252 /* the following is copied here from rgw_acl_s3.cc, to avoid having to have excessive linking
253 with everything it needs */
255 #define RGW_URI_ALL_USERS "http://acs.amazonaws.com/groups/global/AllUsers"
256 #define RGW_URI_AUTH_USERS "http://acs.amazonaws.com/groups/global/AuthenticatedUsers"
258 static string rgw_uri_all_users = RGW_URI_ALL_USERS;
259 static string rgw_uri_auth_users = RGW_URI_AUTH_USERS;
261 ACLGroupTypeEnum ACLGrant::uri_to_group(string& uri)
263 // this is required for backward compatibility
264 return ACLGrant_S3::uri_to_group(uri);
267 ACLGroupTypeEnum ACLGrant_S3::uri_to_group(string& uri)
269 if (uri.compare(rgw_uri_all_users) == 0)
270 return ACL_GROUP_ALL_USERS;
271 else if (uri.compare(rgw_uri_auth_users) == 0)
272 return ACL_GROUP_AUTHENTICATED_USERS;
274 return ACL_GROUP_NONE;
277 void ACLGrant::generate_test_instances(list<ACLGrant*>& o)
284 ACLGrant *g1 = new ACLGrant;
285 g1->set_canon(id, name, RGW_PERM_READ);
289 ACLGrant *g2 = new ACLGrant;
290 g1->set_group(ACL_GROUP_AUTHENTICATED_USERS, RGW_PERM_WRITE);
293 o.push_back(new ACLGrant);
296 void RGWAccessControlList::generate_test_instances(list<RGWAccessControlList*>& o)
298 RGWAccessControlList *acl = new RGWAccessControlList(NULL);
300 list<ACLGrant *> glist;
301 list<ACLGrant *>::iterator iter;
303 ACLGrant::generate_test_instances(glist);
304 for (iter = glist.begin(); iter != glist.end(); ++iter) {
305 ACLGrant *grant = *iter;
306 acl->add_grant(grant);
311 o.push_back(new RGWAccessControlList(NULL));
314 void ACLOwner::generate_test_instances(list<ACLOwner*>& o)
316 ACLOwner *owner = new ACLOwner;
318 owner->display_name = "Mr. RGW";
320 o.push_back(new ACLOwner);
323 void RGWAccessControlPolicy::generate_test_instances(list<RGWAccessControlPolicy*>& o)
325 list<RGWAccessControlList *> acl_list;
326 list<RGWAccessControlList *>::iterator iter;
327 for (iter = acl_list.begin(); iter != acl_list.end(); ++iter) {
328 RGWAccessControlList::generate_test_instances(acl_list);
329 iter = acl_list.begin();
331 RGWAccessControlPolicy *p = new RGWAccessControlPolicy(NULL);
332 RGWAccessControlList *l = *iter;
335 string name = "radosgw";
337 p->owner.set_name(name);
345 o.push_back(new RGWAccessControlPolicy(NULL));
349 void ObjectMetaInfo::generate_test_instances(list<ObjectMetaInfo*>& o)
351 ObjectMetaInfo *m = new ObjectMetaInfo;
352 m->size = 1024 * 1024;
354 o.push_back(new ObjectMetaInfo);
357 void ObjectCacheInfo::generate_test_instances(list<ObjectCacheInfo*>& o)
359 ObjectCacheInfo *i = new ObjectCacheInfo;
361 i->flags = CACHE_FLAG_MODIFY_XATTRS;
362 string s = "this is a string";
363 string s2 = "this is a another string";
364 bufferlist data, data2;
368 i->xattrs["x1"] = data;
369 i->xattrs["x2"] = data2;
370 i->rm_xattrs["r2"] = data2;
371 i->rm_xattrs["r3"] = data;
372 i->meta.size = 512 * 1024;
374 o.push_back(new ObjectCacheInfo);
377 void RGWCacheNotifyInfo::generate_test_instances(list<RGWCacheNotifyInfo*>& o)
379 o.push_back(new RGWCacheNotifyInfo);
382 void RGWAccessKey::generate_test_instances(list<RGWAccessKey*>& o)
384 RGWAccessKey *k = new RGWAccessKey;
387 k->subuser = "subuser";
389 o.push_back(new RGWAccessKey);
392 void RGWSubUser::generate_test_instances(list<RGWSubUser*>& o)
394 RGWSubUser *u = new RGWSubUser;
398 o.push_back(new RGWSubUser);
401 void RGWUserInfo::generate_test_instances(list<RGWUserInfo*>& o)
403 RGWUserInfo *i = new RGWUserInfo;
405 i->user_id = "user_id";
406 i->display_name = "display_name";
407 i->user_email = "user@email";
412 k2.subuser = "subuser";
416 i->access_keys[k1.id] = k1;
417 i->swift_keys[k2.id] = k2;
418 i->subusers[u.name] = u;
421 o.push_back(new RGWUserInfo);
424 void rgw_bucket::generate_test_instances(list<rgw_bucket*>& o)
426 rgw_bucket *b = new rgw_bucket;
427 init_bucket(b, "tenant", "name", "pool", ".index_pool", "marker", "123");
429 o.push_back(new rgw_bucket);
432 void RGWBucketInfo::generate_test_instances(list<RGWBucketInfo*>& o)
434 RGWBucketInfo *i = new RGWBucketInfo;
435 init_bucket(&i->bucket, "tenant", "bucket", "pool", ".index_pool", "marker", "10");
437 i->flags = BUCKET_SUSPENDED;
439 o.push_back(new RGWBucketInfo);
442 void RGWZoneGroup::generate_test_instances(list<RGWZoneGroup*>& o)
444 RGWZoneGroup *r = new RGWZoneGroup;
446 o.push_back(new RGWZoneGroup);
449 void RGWZone::generate_test_instances(list<RGWZone*> &o)
451 RGWZone *z = new RGWZone;
453 o.push_back(new RGWZone);
456 void RGWZoneParams::generate_test_instances(list<RGWZoneParams*> &o)
458 o.push_back(new RGWZoneParams);
459 o.push_back(new RGWZoneParams);
462 void RGWOLHInfo::generate_test_instances(list<RGWOLHInfo*> &o)
464 RGWOLHInfo *olh = new RGWOLHInfo;
465 olh->removed = false;
467 o.push_back(new RGWOLHInfo);
470 void RGWBucketEnt::generate_test_instances(list<RGWBucketEnt*>& o)
472 RGWBucketEnt *e = new RGWBucketEnt;
473 init_bucket(&e->bucket, "tenant", "bucket", "pool", ".index_pool", "marker", "10");
475 e->size_rounded = 4096;
478 o.push_back(new RGWBucketEnt);
481 void RGWUploadPartInfo::generate_test_instances(list<RGWUploadPartInfo*>& o)
483 RGWUploadPartInfo *i = new RGWUploadPartInfo;
485 i->size = 10 * 1024 * 1024;
488 o.push_back(new RGWUploadPartInfo);
491 void rgw_obj::generate_test_instances(list<rgw_obj*>& o)
494 init_bucket(&b, "tenant", "bucket", "pool", ".index_pool", "marker", "10");
495 rgw_obj *obj = new rgw_obj(b, "object");
497 o.push_back(new rgw_obj);