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"
10 #include "rgw_meta_sync_status.h"
11 #include "rgw_data_sync.h"
13 #include "common/Formatter.h"
15 static string shadow_ns
= RGW_OBJ_NS_SHADOW
;
17 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
)
23 b
->explicit_placement
.data_pool
= rgw_pool(dp
);
24 b
->explicit_placement
.index_pool
= rgw_pool(ip
);
27 void RGWObjManifestPart::generate_test_instances(std::list
<RGWObjManifestPart
*>& o
)
29 o
.push_back(new RGWObjManifestPart
);
31 RGWObjManifestPart
*p
= new RGWObjManifestPart
;
33 init_bucket(&b
, "tenant", "bucket", ".pool", ".index_pool", "marker_", "12");
35 p
->loc
= rgw_obj(b
, "object");
36 p
->loc_ofs
= 512 * 1024;
41 void RGWObjManifest::obj_iterator::seek(uint64_t o
)
44 if (manifest
->explicit_objs
) {
45 explicit_iter
= manifest
->objs
.upper_bound(ofs
);
46 if (explicit_iter
!= manifest
->objs
.begin()) {
49 if (ofs
>= manifest
->obj_size
) {
50 ofs
= manifest
->obj_size
;
53 update_explicit_pos();
57 if (o
< manifest
->get_head_size()) {
58 rule_iter
= manifest
->rules
.begin();
60 stripe_size
= manifest
->get_head_size();
61 if (rule_iter
!= manifest
->rules
.end()) {
62 cur_part_id
= rule_iter
->second
.start_part_num
;
63 cur_override_prefix
= rule_iter
->second
.override_prefix
;
69 rule_iter
= manifest
->rules
.upper_bound(ofs
);
70 next_rule_iter
= rule_iter
;
71 if (rule_iter
!= manifest
->rules
.begin()) {
75 if (rule_iter
== manifest
->rules
.end()) {
80 RGWObjManifestRule
& rule
= rule_iter
->second
;
82 if (rule
.part_size
> 0) {
83 cur_part_id
= rule
.start_part_num
+ (ofs
- rule
.start_ofs
) / rule
.part_size
;
85 cur_part_id
= rule
.start_part_num
;
87 part_ofs
= rule
.start_ofs
+ (cur_part_id
- rule
.start_part_num
) * rule
.part_size
;
89 if (rule
.stripe_max_size
> 0) {
90 cur_stripe
= (ofs
- part_ofs
) / rule
.stripe_max_size
;
92 stripe_ofs
= part_ofs
+ cur_stripe
* rule
.stripe_max_size
;
93 if (!cur_part_id
&& manifest
->get_head_size() > 0) {
98 stripe_ofs
= part_ofs
;
101 if (!rule
.part_size
) {
102 stripe_size
= rule
.stripe_max_size
;
103 stripe_size
= MIN(manifest
->get_obj_size() - stripe_ofs
, stripe_size
);
105 uint64_t next
= MIN(stripe_ofs
+ rule
.stripe_max_size
, part_ofs
+ rule
.part_size
);
106 stripe_size
= next
- stripe_ofs
;
109 cur_override_prefix
= rule
.override_prefix
;
114 void RGWObjManifest::obj_iterator::update_location()
116 if (manifest
->explicit_objs
) {
117 location
= explicit_iter
->second
.loc
;
121 if (ofs
< manifest
->get_head_size()) {
122 location
= manifest
->get_obj();
123 location
.set_placement_rule(manifest
->get_head_placement_rule());
127 manifest
->get_implicit_location(cur_part_id
, cur_stripe
, ofs
, &cur_override_prefix
, &location
);
130 void RGWObjManifest::obj_iterator::update_explicit_pos()
132 ofs
= explicit_iter
->first
;
135 map
<uint64_t, RGWObjManifestPart
>::iterator next_iter
= explicit_iter
;
137 if (next_iter
!= manifest
->objs
.end()) {
138 stripe_size
= next_iter
->first
- ofs
;
140 stripe_size
= manifest
->obj_size
- ofs
;
144 void RGWObjManifest::generate_test_instances(std::list
<RGWObjManifest
*>& o
)
146 RGWObjManifest
*m
= new RGWObjManifest
;
147 for (int i
= 0; i
<10; i
++) {
148 RGWObjManifestPart p
;
150 init_bucket(&b
, "tenant", "bucket", ".pool", ".index_pool", "marker_", "12");
151 p
.loc
= rgw_obj(b
, "object");
154 m
->objs
[(uint64_t)i
* 512 * 1024] = p
;
156 m
->obj_size
= 5 * 1024 * 1024;
160 o
.push_back(new RGWObjManifest
);
163 void RGWObjManifest::get_implicit_location(uint64_t cur_part_id
, uint64_t cur_stripe
, uint64_t ofs
, string
*override_prefix
, rgw_obj_select
*location
)
167 string
& oid
= loc
.key
.name
;
168 string
& ns
= loc
.key
.ns
;
170 if (!override_prefix
|| override_prefix
->empty()) {
173 oid
= *override_prefix
;
177 if (ofs
< max_head_size
) {
178 location
->set_placement_rule(head_placement_rule
);
183 snprintf(buf
, sizeof(buf
), "%d", (int)cur_stripe
);
189 if (cur_stripe
== 0) {
190 snprintf(buf
, sizeof(buf
), ".%d", (int)cur_part_id
);
192 ns
= RGW_OBJ_NS_MULTIPART
;
194 snprintf(buf
, sizeof(buf
), ".%d_%d", (int)cur_part_id
, (int)cur_stripe
);
200 if (!tail_placement
.bucket
.name
.empty()) {
201 loc
.bucket
= tail_placement
.bucket
;
203 loc
.bucket
= obj
.bucket
;
206 // Always overwrite instance with tail_instance
207 // to get the right shadow object location
208 loc
.key
.set_instance(tail_instance
);
210 location
->set_placement_rule(tail_placement
.placement_rule
);
216 void rgw_log_entry::generate_test_instances(list
<rgw_log_entry
*>& o
)
218 rgw_log_entry
*e
= new rgw_log_entry
;
219 e
->object_owner
= "object_owner";
220 e
->bucket_owner
= "bucket_owner";
221 e
->bucket
= "bucket";
222 e
->remote_addr
= "1.2.3.4";
224 e
->obj
= rgw_obj_key("obj");
225 e
->uri
= "http://uri/bucket/obj";
226 e
->http_status
= "200";
227 e
->error_code
= "error_code";
228 e
->bytes_sent
= 1024;
229 e
->bytes_received
= 512;
231 e
->user_agent
= "user_agent";
232 e
->referrer
= "referrer";
235 o
.push_back(new rgw_log_entry
);
238 void ACLPermission::generate_test_instances(list
<ACLPermission
*>& o
)
240 ACLPermission
*p
= new ACLPermission
;
241 p
->set_permissions(RGW_PERM_WRITE_ACP
);
243 o
.push_back(new ACLPermission
);
246 void ACLGranteeType::generate_test_instances(list
<ACLGranteeType
*>& o
)
248 ACLGranteeType
*t
= new ACLGranteeType
;
249 t
->set(ACL_TYPE_CANON_USER
);
251 o
.push_back(new ACLGranteeType
);
254 /* the following is copied here from rgw_acl_s3.cc, to avoid having to have excessive linking
255 with everything it needs */
257 #define RGW_URI_ALL_USERS "http://acs.amazonaws.com/groups/global/AllUsers"
258 #define RGW_URI_AUTH_USERS "http://acs.amazonaws.com/groups/global/AuthenticatedUsers"
260 static string rgw_uri_all_users
= RGW_URI_ALL_USERS
;
261 static string rgw_uri_auth_users
= RGW_URI_AUTH_USERS
;
263 ACLGroupTypeEnum
ACLGrant::uri_to_group(string
& uri
)
265 // this is required for backward compatibility
266 return ACLGrant_S3::uri_to_group(uri
);
269 ACLGroupTypeEnum
ACLGrant_S3::uri_to_group(string
& uri
)
271 if (uri
.compare(rgw_uri_all_users
) == 0)
272 return ACL_GROUP_ALL_USERS
;
273 else if (uri
.compare(rgw_uri_auth_users
) == 0)
274 return ACL_GROUP_AUTHENTICATED_USERS
;
276 return ACL_GROUP_NONE
;
279 void ACLGrant::generate_test_instances(list
<ACLGrant
*>& o
)
286 ACLGrant
*g1
= new ACLGrant
;
287 g1
->set_canon(id
, name
, RGW_PERM_READ
);
291 ACLGrant
*g2
= new ACLGrant
;
292 g1
->set_group(ACL_GROUP_AUTHENTICATED_USERS
, RGW_PERM_WRITE
);
295 o
.push_back(new ACLGrant
);
298 void RGWAccessControlList::generate_test_instances(list
<RGWAccessControlList
*>& o
)
300 RGWAccessControlList
*acl
= new RGWAccessControlList(NULL
);
302 list
<ACLGrant
*> glist
;
303 list
<ACLGrant
*>::iterator iter
;
305 ACLGrant::generate_test_instances(glist
);
306 for (iter
= glist
.begin(); iter
!= glist
.end(); ++iter
) {
307 ACLGrant
*grant
= *iter
;
308 acl
->add_grant(grant
);
313 o
.push_back(new RGWAccessControlList(NULL
));
316 void ACLOwner::generate_test_instances(list
<ACLOwner
*>& o
)
318 ACLOwner
*owner
= new ACLOwner
;
320 owner
->display_name
= "Mr. RGW";
322 o
.push_back(new ACLOwner
);
325 void RGWAccessControlPolicy::generate_test_instances(list
<RGWAccessControlPolicy
*>& o
)
327 list
<RGWAccessControlList
*> acl_list
;
328 list
<RGWAccessControlList
*>::iterator iter
;
329 for (iter
= acl_list
.begin(); iter
!= acl_list
.end(); ++iter
) {
330 RGWAccessControlList::generate_test_instances(acl_list
);
331 iter
= acl_list
.begin();
333 RGWAccessControlPolicy
*p
= new RGWAccessControlPolicy(NULL
);
334 RGWAccessControlList
*l
= *iter
;
337 string name
= "radosgw";
339 p
->owner
.set_name(name
);
347 o
.push_back(new RGWAccessControlPolicy(NULL
));
351 void ObjectMetaInfo::generate_test_instances(list
<ObjectMetaInfo
*>& o
)
353 ObjectMetaInfo
*m
= new ObjectMetaInfo
;
354 m
->size
= 1024 * 1024;
356 o
.push_back(new ObjectMetaInfo
);
359 void ObjectCacheInfo::generate_test_instances(list
<ObjectCacheInfo
*>& o
)
361 ObjectCacheInfo
*i
= new ObjectCacheInfo
;
363 i
->flags
= CACHE_FLAG_MODIFY_XATTRS
;
364 string s
= "this is a string";
365 string s2
= "this is a another string";
366 bufferlist data
, data2
;
370 i
->xattrs
["x1"] = data
;
371 i
->xattrs
["x2"] = data2
;
372 i
->rm_xattrs
["r2"] = data2
;
373 i
->rm_xattrs
["r3"] = data
;
374 i
->meta
.size
= 512 * 1024;
376 o
.push_back(new ObjectCacheInfo
);
379 void RGWCacheNotifyInfo::generate_test_instances(list
<RGWCacheNotifyInfo
*>& o
)
381 o
.push_back(new RGWCacheNotifyInfo
);
384 void RGWAccessKey::generate_test_instances(list
<RGWAccessKey
*>& o
)
386 RGWAccessKey
*k
= new RGWAccessKey
;
389 k
->subuser
= "subuser";
391 o
.push_back(new RGWAccessKey
);
394 void RGWSubUser::generate_test_instances(list
<RGWSubUser
*>& o
)
396 RGWSubUser
*u
= new RGWSubUser
;
400 o
.push_back(new RGWSubUser
);
403 void RGWUserInfo::generate_test_instances(list
<RGWUserInfo
*>& o
)
405 RGWUserInfo
*i
= new RGWUserInfo
;
407 i
->user_id
= "user_id";
408 i
->display_name
= "display_name";
409 i
->user_email
= "user@email";
414 k2
.subuser
= "subuser";
418 i
->access_keys
[k1
.id
] = k1
;
419 i
->swift_keys
[k2
.id
] = k2
;
420 i
->subusers
[u
.name
] = u
;
423 o
.push_back(new RGWUserInfo
);
426 void rgw_bucket::generate_test_instances(list
<rgw_bucket
*>& o
)
428 rgw_bucket
*b
= new rgw_bucket
;
429 init_bucket(b
, "tenant", "name", "pool", ".index_pool", "marker", "123");
431 o
.push_back(new rgw_bucket
);
434 void RGWBucketInfo::generate_test_instances(list
<RGWBucketInfo
*>& o
)
436 RGWBucketInfo
*i
= new RGWBucketInfo
;
437 init_bucket(&i
->bucket
, "tenant", "bucket", "pool", ".index_pool", "marker", "10");
439 i
->flags
= BUCKET_SUSPENDED
;
441 o
.push_back(new RGWBucketInfo
);
444 void RGWZoneGroup::generate_test_instances(list
<RGWZoneGroup
*>& o
)
446 RGWZoneGroup
*r
= new RGWZoneGroup
;
448 o
.push_back(new RGWZoneGroup
);
451 void RGWZone::generate_test_instances(list
<RGWZone
*> &o
)
453 RGWZone
*z
= new RGWZone
;
455 o
.push_back(new RGWZone
);
458 void RGWZoneParams::generate_test_instances(list
<RGWZoneParams
*> &o
)
460 o
.push_back(new RGWZoneParams
);
461 o
.push_back(new RGWZoneParams
);
464 void RGWOLHInfo::generate_test_instances(list
<RGWOLHInfo
*> &o
)
466 RGWOLHInfo
*olh
= new RGWOLHInfo
;
467 olh
->removed
= false;
469 o
.push_back(new RGWOLHInfo
);
472 void RGWBucketEnt::generate_test_instances(list
<RGWBucketEnt
*>& o
)
474 RGWBucketEnt
*e
= new RGWBucketEnt
;
475 init_bucket(&e
->bucket
, "tenant", "bucket", "pool", ".index_pool", "marker", "10");
477 e
->size_rounded
= 4096;
480 o
.push_back(new RGWBucketEnt
);
483 void RGWUploadPartInfo::generate_test_instances(list
<RGWUploadPartInfo
*>& o
)
485 RGWUploadPartInfo
*i
= new RGWUploadPartInfo
;
487 i
->size
= 10 * 1024 * 1024;
490 o
.push_back(new RGWUploadPartInfo
);
493 void rgw_obj::generate_test_instances(list
<rgw_obj
*>& o
)
496 init_bucket(&b
, "tenant", "bucket", "pool", ".index_pool", "marker", "10");
497 rgw_obj
*obj
= new rgw_obj(b
, "object");
499 o
.push_back(new rgw_obj
);
502 void rgw_meta_sync_info::generate_test_instances(list
<rgw_meta_sync_info
*>& o
)
504 auto info
= new rgw_meta_sync_info
;
505 info
->state
= rgw_meta_sync_info::StateBuildingFullSyncMaps
;
506 info
->period
= "periodid";
507 info
->realm_epoch
= 5;
509 o
.push_back(new rgw_meta_sync_info
);
512 void rgw_meta_sync_marker::generate_test_instances(list
<rgw_meta_sync_marker
*>& o
)
514 auto marker
= new rgw_meta_sync_marker
;
515 marker
->state
= rgw_meta_sync_marker::IncrementalSync
;
516 marker
->marker
= "01234";
517 marker
->realm_epoch
= 5;
519 o
.push_back(new rgw_meta_sync_marker
);
522 void rgw_meta_sync_status::generate_test_instances(list
<rgw_meta_sync_status
*>& o
)
524 o
.push_back(new rgw_meta_sync_status
);
527 void rgw_data_sync_info::generate_test_instances(list
<rgw_data_sync_info
*>& o
)
529 auto info
= new rgw_data_sync_info
;
530 info
->state
= rgw_data_sync_info::StateBuildingFullSyncMaps
;
531 info
->num_shards
= 8;
533 o
.push_back(new rgw_data_sync_info
);
536 void rgw_data_sync_marker::generate_test_instances(list
<rgw_data_sync_marker
*>& o
)
538 auto marker
= new rgw_data_sync_marker
;
539 marker
->state
= rgw_data_sync_marker::IncrementalSync
;
540 marker
->marker
= "01234";
543 o
.push_back(new rgw_data_sync_marker
);
546 void rgw_data_sync_status::generate_test_instances(list
<rgw_data_sync_status
*>& o
)
548 o
.push_back(new rgw_data_sync_status
);