1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
4 #include "rgw_common.h"
9 #include "rgw_acl_s3.h"
10 #include "rgw_cache.h"
11 #include "rgw_meta_sync_status.h"
12 #include "rgw_data_sync.h"
13 #include "rgw_multi.h"
15 #include "common/Formatter.h"
17 static string shadow_ns
= RGW_OBJ_NS_SHADOW
;
19 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
)
25 b
->explicit_placement
.data_pool
= rgw_pool(dp
);
26 b
->explicit_placement
.index_pool
= rgw_pool(ip
);
29 void RGWObjManifestPart::generate_test_instances(std::list
<RGWObjManifestPart
*>& o
)
31 o
.push_back(new RGWObjManifestPart
);
33 RGWObjManifestPart
*p
= new RGWObjManifestPart
;
35 init_bucket(&b
, "tenant", "bucket", ".pool", ".index_pool", "marker_", "12");
37 p
->loc
= rgw_obj(b
, "object");
38 p
->loc_ofs
= 512 * 1024;
43 void RGWObjManifest::obj_iterator::seek(uint64_t o
)
46 if (manifest
->explicit_objs
) {
47 explicit_iter
= manifest
->objs
.upper_bound(ofs
);
48 if (explicit_iter
!= manifest
->objs
.begin()) {
51 if (ofs
< manifest
->obj_size
) {
52 update_explicit_pos();
54 ofs
= manifest
->obj_size
;
59 if (o
< manifest
->get_head_size()) {
60 rule_iter
= manifest
->rules
.begin();
62 stripe_size
= manifest
->get_head_size();
63 if (rule_iter
!= manifest
->rules
.end()) {
64 cur_part_id
= rule_iter
->second
.start_part_num
;
65 cur_override_prefix
= rule_iter
->second
.override_prefix
;
71 rule_iter
= manifest
->rules
.upper_bound(ofs
);
72 next_rule_iter
= rule_iter
;
73 if (rule_iter
!= manifest
->rules
.begin()) {
77 if (rule_iter
== manifest
->rules
.end()) {
82 RGWObjManifestRule
& rule
= rule_iter
->second
;
84 if (rule
.part_size
> 0) {
85 cur_part_id
= rule
.start_part_num
+ (ofs
- rule
.start_ofs
) / rule
.part_size
;
87 cur_part_id
= rule
.start_part_num
;
89 part_ofs
= rule
.start_ofs
+ (cur_part_id
- rule
.start_part_num
) * rule
.part_size
;
91 if (rule
.stripe_max_size
> 0) {
92 cur_stripe
= (ofs
- part_ofs
) / rule
.stripe_max_size
;
94 stripe_ofs
= part_ofs
+ cur_stripe
* rule
.stripe_max_size
;
95 if (!cur_part_id
&& manifest
->get_head_size() > 0) {
100 stripe_ofs
= part_ofs
;
103 if (!rule
.part_size
) {
104 stripe_size
= rule
.stripe_max_size
;
105 stripe_size
= std::min(manifest
->get_obj_size() - stripe_ofs
, stripe_size
);
107 uint64_t next
= std::min(stripe_ofs
+ rule
.stripe_max_size
, part_ofs
+ rule
.part_size
);
108 stripe_size
= next
- stripe_ofs
;
111 cur_override_prefix
= rule
.override_prefix
;
116 void RGWObjManifest::obj_iterator::update_location()
118 if (manifest
->explicit_objs
) {
119 if (manifest
->empty()) {
120 location
= rgw_obj_select
{};
122 location
= explicit_iter
->second
.loc
;
127 if (ofs
< manifest
->get_head_size()) {
128 location
= manifest
->get_obj();
129 location
.set_placement_rule(manifest
->get_head_placement_rule());
133 manifest
->get_implicit_location(cur_part_id
, cur_stripe
, ofs
, &cur_override_prefix
, &location
);
136 void RGWObjManifest::obj_iterator::update_explicit_pos()
138 ofs
= explicit_iter
->first
;
141 map
<uint64_t, RGWObjManifestPart
>::iterator next_iter
= explicit_iter
;
143 if (next_iter
!= manifest
->objs
.end()) {
144 stripe_size
= next_iter
->first
- ofs
;
146 stripe_size
= manifest
->obj_size
- ofs
;
150 void RGWObjManifest::generate_test_instances(std::list
<RGWObjManifest
*>& o
)
152 RGWObjManifest
*m
= new RGWObjManifest
;
153 map
<uint64_t, RGWObjManifestPart
> objs
;
154 uint64_t total_size
= 0;
155 for (int i
= 0; i
<10; i
++) {
156 RGWObjManifestPart p
;
158 init_bucket(&b
, "tenant", "bucket", ".pool", ".index_pool", "marker_", "12");
159 p
.loc
= rgw_obj(b
, "object");
162 total_size
+= p
.size
;
163 objs
[total_size
] = p
;
165 m
->set_explicit(total_size
, objs
);
167 o
.push_back(new RGWObjManifest
);
170 void RGWObjManifest::get_implicit_location(uint64_t cur_part_id
, uint64_t cur_stripe
, uint64_t ofs
, string
*override_prefix
, rgw_obj_select
*location
)
174 string
& oid
= loc
.key
.name
;
175 string
& ns
= loc
.key
.ns
;
177 if (!override_prefix
|| override_prefix
->empty()) {
180 oid
= *override_prefix
;
184 if (ofs
< max_head_size
) {
185 location
->set_placement_rule(head_placement_rule
);
190 snprintf(buf
, sizeof(buf
), "%d", (int)cur_stripe
);
196 if (cur_stripe
== 0) {
197 snprintf(buf
, sizeof(buf
), ".%d", (int)cur_part_id
);
199 ns
= RGW_OBJ_NS_MULTIPART
;
201 snprintf(buf
, sizeof(buf
), ".%d_%d", (int)cur_part_id
, (int)cur_stripe
);
207 if (!tail_placement
.bucket
.name
.empty()) {
208 loc
.bucket
= tail_placement
.bucket
;
210 loc
.bucket
= obj
.bucket
;
213 // Always overwrite instance with tail_instance
214 // to get the right shadow object location
215 loc
.key
.set_instance(tail_instance
);
217 location
->set_placement_rule(tail_placement
.placement_rule
);
223 void rgw_log_entry::generate_test_instances(list
<rgw_log_entry
*>& o
)
225 rgw_log_entry
*e
= new rgw_log_entry
;
226 e
->object_owner
= "object_owner";
227 e
->bucket_owner
= "bucket_owner";
228 e
->bucket
= "bucket";
229 e
->remote_addr
= "1.2.3.4";
231 e
->obj
= rgw_obj_key("obj");
232 e
->uri
= "http://uri/bucket/obj";
233 e
->http_status
= "200";
234 e
->error_code
= "error_code";
235 e
->bytes_sent
= 1024;
236 e
->bytes_received
= 512;
238 e
->user_agent
= "user_agent";
239 e
->referrer
= "referrer";
241 e
->trans_id
= "trans_id";
243 o
.push_back(new rgw_log_entry
);
246 void ACLPermission::generate_test_instances(list
<ACLPermission
*>& o
)
248 ACLPermission
*p
= new ACLPermission
;
249 p
->set_permissions(RGW_PERM_WRITE_ACP
);
251 o
.push_back(new ACLPermission
);
254 void ACLGranteeType::generate_test_instances(list
<ACLGranteeType
*>& o
)
256 ACLGranteeType
*t
= new ACLGranteeType
;
257 t
->set(ACL_TYPE_CANON_USER
);
259 o
.push_back(new ACLGranteeType
);
262 /* the following is copied here from rgw_acl_s3.cc, to avoid having to have excessive linking
263 with everything it needs */
265 #define RGW_URI_ALL_USERS "http://acs.amazonaws.com/groups/global/AllUsers"
266 #define RGW_URI_AUTH_USERS "http://acs.amazonaws.com/groups/global/AuthenticatedUsers"
268 static string rgw_uri_all_users
= RGW_URI_ALL_USERS
;
269 static string rgw_uri_auth_users
= RGW_URI_AUTH_USERS
;
271 ACLGroupTypeEnum
ACLGrant::uri_to_group(string
& uri
)
273 // this is required for backward compatibility
274 return ACLGrant_S3::uri_to_group(uri
);
277 ACLGroupTypeEnum
ACLGrant_S3::uri_to_group(string
& uri
)
279 if (uri
.compare(rgw_uri_all_users
) == 0)
280 return ACL_GROUP_ALL_USERS
;
281 else if (uri
.compare(rgw_uri_auth_users
) == 0)
282 return ACL_GROUP_AUTHENTICATED_USERS
;
284 return ACL_GROUP_NONE
;
287 void ACLGrant::generate_test_instances(list
<ACLGrant
*>& o
)
294 ACLGrant
*g1
= new ACLGrant
;
295 g1
->set_canon(id
, name
, RGW_PERM_READ
);
299 ACLGrant
*g2
= new ACLGrant
;
300 g1
->set_group(ACL_GROUP_AUTHENTICATED_USERS
, RGW_PERM_WRITE
);
303 o
.push_back(new ACLGrant
);
306 void RGWAccessControlList::generate_test_instances(list
<RGWAccessControlList
*>& o
)
308 RGWAccessControlList
*acl
= new RGWAccessControlList(NULL
);
310 list
<ACLGrant
*> glist
;
311 list
<ACLGrant
*>::iterator iter
;
313 ACLGrant::generate_test_instances(glist
);
314 for (iter
= glist
.begin(); iter
!= glist
.end(); ++iter
) {
315 ACLGrant
*grant
= *iter
;
316 acl
->add_grant(grant
);
321 o
.push_back(new RGWAccessControlList(NULL
));
324 void ACLOwner::generate_test_instances(list
<ACLOwner
*>& o
)
326 ACLOwner
*owner
= new ACLOwner
;
328 owner
->display_name
= "Mr. RGW";
330 o
.push_back(new ACLOwner
);
333 void RGWAccessControlPolicy::generate_test_instances(list
<RGWAccessControlPolicy
*>& o
)
335 list
<RGWAccessControlList
*> acl_list
;
336 list
<RGWAccessControlList
*>::iterator iter
;
337 for (iter
= acl_list
.begin(); iter
!= acl_list
.end(); ++iter
) {
338 RGWAccessControlList::generate_test_instances(acl_list
);
339 iter
= acl_list
.begin();
341 RGWAccessControlPolicy
*p
= new RGWAccessControlPolicy(NULL
);
342 RGWAccessControlList
*l
= *iter
;
345 string name
= "radosgw";
347 p
->owner
.set_name(name
);
355 o
.push_back(new RGWAccessControlPolicy(NULL
));
359 void ObjectMetaInfo::generate_test_instances(list
<ObjectMetaInfo
*>& o
)
361 ObjectMetaInfo
*m
= new ObjectMetaInfo
;
362 m
->size
= 1024 * 1024;
364 o
.push_back(new ObjectMetaInfo
);
367 void ObjectCacheInfo::generate_test_instances(list
<ObjectCacheInfo
*>& o
)
370 ObjectCacheInfo
*i
= new ObjectCacheInfo
;
372 i
->flags
= CACHE_FLAG_MODIFY_XATTRS
;
373 string s
= "this is a string";
374 string s2
= "this is a another string";
375 bufferlist data
, data2
;
379 i
->xattrs
["x1"] = data
;
380 i
->xattrs
["x2"] = data2
;
381 i
->rm_xattrs
["r2"] = data2
;
382 i
->rm_xattrs
["r3"] = data
;
383 i
->meta
.size
= 512 * 1024;
385 o
.push_back(new ObjectCacheInfo
);
388 void RGWCacheNotifyInfo::generate_test_instances(list
<RGWCacheNotifyInfo
*>& o
)
390 o
.push_back(new RGWCacheNotifyInfo
);
393 void RGWAccessKey::generate_test_instances(list
<RGWAccessKey
*>& o
)
395 RGWAccessKey
*k
= new RGWAccessKey
;
398 k
->subuser
= "subuser";
400 o
.push_back(new RGWAccessKey
);
403 void RGWSubUser::generate_test_instances(list
<RGWSubUser
*>& o
)
405 RGWSubUser
*u
= new RGWSubUser
;
409 o
.push_back(new RGWSubUser
);
412 void RGWUserInfo::generate_test_instances(list
<RGWUserInfo
*>& o
)
414 RGWUserInfo
*i
= new RGWUserInfo
;
415 i
->user_id
= "user_id";
416 i
->display_name
= "display_name";
417 i
->user_email
= "user@email";
422 k2
.subuser
= "subuser";
426 i
->access_keys
[k1
.id
] = k1
;
427 i
->swift_keys
[k2
.id
] = k2
;
428 i
->subusers
[u
.name
] = u
;
431 o
.push_back(new RGWUserInfo
);
434 void rgw_bucket::generate_test_instances(list
<rgw_bucket
*>& o
)
436 rgw_bucket
*b
= new rgw_bucket
;
437 init_bucket(b
, "tenant", "name", "pool", ".index_pool", "marker", "123");
439 o
.push_back(new rgw_bucket
);
442 void RGWBucketInfo::generate_test_instances(list
<RGWBucketInfo
*>& o
)
444 RGWBucketInfo
*i
= new RGWBucketInfo
;
445 init_bucket(&i
->bucket
, "tenant", "bucket", "pool", ".index_pool", "marker", "10");
447 i
->flags
= BUCKET_SUSPENDED
;
449 o
.push_back(new RGWBucketInfo
);
452 void RGWZoneGroup::generate_test_instances(list
<RGWZoneGroup
*>& o
)
454 RGWZoneGroup
*r
= new RGWZoneGroup
;
456 o
.push_back(new RGWZoneGroup
);
459 void RGWZone::generate_test_instances(list
<RGWZone
*> &o
)
461 RGWZone
*z
= new RGWZone
;
463 o
.push_back(new RGWZone
);
466 void RGWRealm::generate_test_instances(list
<RGWRealm
*> &o
)
468 RGWRealm
*z
= new RGWRealm
;
470 o
.push_back(new RGWRealm
);
473 void RGWPeriod::generate_test_instances(list
<RGWPeriod
*> &o
)
475 RGWPeriod
*z
= new RGWPeriod
;
477 o
.push_back(new RGWPeriod
);
480 void RGWPeriodLatestEpochInfo::generate_test_instances(list
<RGWPeriodLatestEpochInfo
*> &o
)
482 RGWPeriodLatestEpochInfo
*z
= new RGWPeriodLatestEpochInfo
;
484 o
.push_back(new RGWPeriodLatestEpochInfo
);
487 void RGWZoneParams::generate_test_instances(list
<RGWZoneParams
*> &o
)
489 o
.push_back(new RGWZoneParams
);
490 o
.push_back(new RGWZoneParams
);
493 void RGWOLHInfo::generate_test_instances(list
<RGWOLHInfo
*> &o
)
495 RGWOLHInfo
*olh
= new RGWOLHInfo
;
496 olh
->removed
= false;
498 o
.push_back(new RGWOLHInfo
);
501 void RGWBucketEnt::generate_test_instances(list
<RGWBucketEnt
*>& o
)
503 RGWBucketEnt
*e
= new RGWBucketEnt
;
504 init_bucket(&e
->bucket
, "tenant", "bucket", "pool", ".index_pool", "marker", "10");
506 e
->size_rounded
= 4096;
509 o
.push_back(new RGWBucketEnt
);
512 void RGWUploadPartInfo::generate_test_instances(list
<RGWUploadPartInfo
*>& o
)
514 RGWUploadPartInfo
*i
= new RGWUploadPartInfo
;
516 i
->size
= 10 * 1024 * 1024;
519 o
.push_back(new RGWUploadPartInfo
);
522 void rgw_obj::generate_test_instances(list
<rgw_obj
*>& o
)
525 init_bucket(&b
, "tenant", "bucket", "pool", ".index_pool", "marker", "10");
526 rgw_obj
*obj
= new rgw_obj(b
, "object");
528 o
.push_back(new rgw_obj
);
531 void rgw_meta_sync_info::generate_test_instances(list
<rgw_meta_sync_info
*>& o
)
533 auto info
= new rgw_meta_sync_info
;
534 info
->state
= rgw_meta_sync_info::StateBuildingFullSyncMaps
;
535 info
->period
= "periodid";
536 info
->realm_epoch
= 5;
538 o
.push_back(new rgw_meta_sync_info
);
541 void rgw_meta_sync_marker::generate_test_instances(list
<rgw_meta_sync_marker
*>& o
)
543 auto marker
= new rgw_meta_sync_marker
;
544 marker
->state
= rgw_meta_sync_marker::IncrementalSync
;
545 marker
->marker
= "01234";
546 marker
->realm_epoch
= 5;
548 o
.push_back(new rgw_meta_sync_marker
);
551 void rgw_meta_sync_status::generate_test_instances(list
<rgw_meta_sync_status
*>& o
)
553 o
.push_back(new rgw_meta_sync_status
);
556 void rgw_data_sync_info::generate_test_instances(list
<rgw_data_sync_info
*>& o
)
558 auto info
= new rgw_data_sync_info
;
559 info
->state
= rgw_data_sync_info::StateBuildingFullSyncMaps
;
560 info
->num_shards
= 8;
562 o
.push_back(new rgw_data_sync_info
);
565 void rgw_data_sync_marker::generate_test_instances(list
<rgw_data_sync_marker
*>& o
)
567 auto marker
= new rgw_data_sync_marker
;
568 marker
->state
= rgw_data_sync_marker::IncrementalSync
;
569 marker
->marker
= "01234";
572 o
.push_back(new rgw_data_sync_marker
);
575 void rgw_data_sync_status::generate_test_instances(list
<rgw_data_sync_status
*>& o
)
577 o
.push_back(new rgw_data_sync_status
);
580 void objexp_hint_entry::generate_test_instances(list
<objexp_hint_entry
*>& o
)
582 auto it
= new objexp_hint_entry
;
583 it
->tenant
= "tenant1";
584 it
->bucket_name
= "bucket1";
585 it
->bucket_id
= "1234";
586 it
->obj_key
= rgw_obj_key("obj");
588 o
.push_back(new objexp_hint_entry
);
591 void RGWBucketEntryPoint::generate_test_instances(list
<RGWBucketEntryPoint
*>& o
)
593 RGWBucketEntryPoint
*bp
= new RGWBucketEntryPoint();
594 init_bucket(&bp
->bucket
, "tenant", "bucket", "pool", ".index.pool", "marker", "10");
596 bp
->creation_time
= ceph::real_clock::from_ceph_timespec({init_le32(2), init_le32(3)});
599 o
.push_back(new RGWBucketEntryPoint
);
602 void rgw_user::generate_test_instances(list
<rgw_user
*>& o
)
604 rgw_user
*u
= new rgw_user("tenant", "user");
607 o
.push_back(new rgw_user
);
610 void obj_version::generate_test_instances(list
<obj_version
*>& o
)
612 obj_version
*v
= new obj_version
;
617 o
.push_back(new obj_version
);