]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_dencoder.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rgw / rgw_dencoder.cc
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#include "rgw_common.h"
5#include "rgw_rados.h"
11fdf7f2 6#include "rgw_zone.h"
7c673cae
FG
7#include "rgw_log.h"
8#include "rgw_acl.h"
9#include "rgw_acl_s3.h"
10#include "rgw_cache.h"
b32b8144
FG
11#include "rgw_meta_sync_status.h"
12#include "rgw_data_sync.h"
7c673cae
FG
13
14#include "common/Formatter.h"
15
16static string shadow_ns = RGW_OBJ_NS_SHADOW;
17
18static void init_bucket(rgw_bucket *b, const char *t, const char *n, const char *dp, const char *ip, const char *m, const char *id)
19{
20 b->tenant = t;
21 b->name = n;
22 b->marker = m;
23 b->bucket_id = id;
24 b->explicit_placement.data_pool = rgw_pool(dp);
25 b->explicit_placement.index_pool = rgw_pool(ip);
26}
27
28void RGWObjManifestPart::generate_test_instances(std::list<RGWObjManifestPart*>& o)
29{
30 o.push_back(new RGWObjManifestPart);
31
32 RGWObjManifestPart *p = new RGWObjManifestPart;
33 rgw_bucket b;
34 init_bucket(&b, "tenant", "bucket", ".pool", ".index_pool", "marker_", "12");
35
36 p->loc = rgw_obj(b, "object");
37 p->loc_ofs = 512 * 1024;
38 p->size = 128 * 1024;
39 o.push_back(p);
40}
41
42void RGWObjManifest::obj_iterator::seek(uint64_t o)
43{
44 ofs = o;
45 if (manifest->explicit_objs) {
46 explicit_iter = manifest->objs.upper_bound(ofs);
47 if (explicit_iter != manifest->objs.begin()) {
48 --explicit_iter;
49 }
50 if (ofs >= manifest->obj_size) {
51 ofs = manifest->obj_size;
52 return;
53 }
54 update_explicit_pos();
55 update_location();
56 return;
57 }
58 if (o < manifest->get_head_size()) {
59 rule_iter = manifest->rules.begin();
60 stripe_ofs = 0;
61 stripe_size = manifest->get_head_size();
62 if (rule_iter != manifest->rules.end()) {
63 cur_part_id = rule_iter->second.start_part_num;
64 cur_override_prefix = rule_iter->second.override_prefix;
65 }
66 update_location();
67 return;
68 }
69
70 rule_iter = manifest->rules.upper_bound(ofs);
71 next_rule_iter = rule_iter;
72 if (rule_iter != manifest->rules.begin()) {
73 --rule_iter;
74 }
75
76 if (rule_iter == manifest->rules.end()) {
77 update_location();
78 return;
79 }
80
81 RGWObjManifestRule& rule = rule_iter->second;
82
83 if (rule.part_size > 0) {
84 cur_part_id = rule.start_part_num + (ofs - rule.start_ofs) / rule.part_size;
85 } else {
86 cur_part_id = rule.start_part_num;
87 }
88 part_ofs = rule.start_ofs + (cur_part_id - rule.start_part_num) * rule.part_size;
89
90 if (rule.stripe_max_size > 0) {
91 cur_stripe = (ofs - part_ofs) / rule.stripe_max_size;
92
93 stripe_ofs = part_ofs + cur_stripe * rule.stripe_max_size;
94 if (!cur_part_id && manifest->get_head_size() > 0) {
95 cur_stripe++;
96 }
97 } else {
98 cur_stripe = 0;
99 stripe_ofs = part_ofs;
100 }
101
102 if (!rule.part_size) {
103 stripe_size = rule.stripe_max_size;
11fdf7f2 104 stripe_size = std::min(manifest->get_obj_size() - stripe_ofs, stripe_size);
7c673cae 105 } else {
11fdf7f2 106 uint64_t next = std::min(stripe_ofs + rule.stripe_max_size, part_ofs + rule.part_size);
7c673cae
FG
107 stripe_size = next - stripe_ofs;
108 }
109
110 cur_override_prefix = rule.override_prefix;
111
112 update_location();
113}
114
115void RGWObjManifest::obj_iterator::update_location()
116{
117 if (manifest->explicit_objs) {
118 location = explicit_iter->second.loc;
119 return;
120 }
121
122 if (ofs < manifest->get_head_size()) {
123 location = manifest->get_obj();
31f18b77 124 location.set_placement_rule(manifest->get_head_placement_rule());
7c673cae
FG
125 return;
126 }
127
128 manifest->get_implicit_location(cur_part_id, cur_stripe, ofs, &cur_override_prefix, &location);
129}
130
131void RGWObjManifest::obj_iterator::update_explicit_pos()
132{
133 ofs = explicit_iter->first;
134 stripe_ofs = ofs;
135
136 map<uint64_t, RGWObjManifestPart>::iterator next_iter = explicit_iter;
137 ++next_iter;
138 if (next_iter != manifest->objs.end()) {
139 stripe_size = next_iter->first - ofs;
140 } else {
141 stripe_size = manifest->obj_size - ofs;
142 }
143}
144
145void RGWObjManifest::generate_test_instances(std::list<RGWObjManifest*>& o)
146{
147 RGWObjManifest *m = new RGWObjManifest;
148 for (int i = 0; i<10; i++) {
149 RGWObjManifestPart p;
150 rgw_bucket b;
151 init_bucket(&b, "tenant", "bucket", ".pool", ".index_pool", "marker_", "12");
152 p.loc = rgw_obj(b, "object");
153 p.loc_ofs = 0;
154 p.size = 512 * 1024;
155 m->objs[(uint64_t)i * 512 * 1024] = p;
156 }
157 m->obj_size = 5 * 1024 * 1024;
158
159 o.push_back(m);
160
161 o.push_back(new RGWObjManifest);
162}
163
164void RGWObjManifest::get_implicit_location(uint64_t cur_part_id, uint64_t cur_stripe, uint64_t ofs, string *override_prefix, rgw_obj_select *location)
165{
166 rgw_obj loc;
167
168 string& oid = loc.key.name;
169 string& ns = loc.key.ns;
170
171 if (!override_prefix || override_prefix->empty()) {
172 oid = prefix;
173 } else {
174 oid = *override_prefix;
175 }
176
177 if (!cur_part_id) {
178 if (ofs < max_head_size) {
179 location->set_placement_rule(head_placement_rule);
180 *location = obj;
181 return;
182 } else {
183 char buf[16];
184 snprintf(buf, sizeof(buf), "%d", (int)cur_stripe);
185 oid += buf;
186 ns = shadow_ns;
187 }
188 } else {
189 char buf[32];
190 if (cur_stripe == 0) {
191 snprintf(buf, sizeof(buf), ".%d", (int)cur_part_id);
192 oid += buf;
193 ns= RGW_OBJ_NS_MULTIPART;
194 } else {
195 snprintf(buf, sizeof(buf), ".%d_%d", (int)cur_part_id, (int)cur_stripe);
196 oid += buf;
197 ns = shadow_ns;
198 }
199 }
200
201 if (!tail_placement.bucket.name.empty()) {
202 loc.bucket = tail_placement.bucket;
203 } else {
204 loc.bucket = obj.bucket;
205 }
206
207 // Always overwrite instance with tail_instance
208 // to get the right shadow object location
209 loc.key.set_instance(tail_instance);
210
211 location->set_placement_rule(tail_placement.placement_rule);
212 *location = loc;
213}
214
215
216
217void rgw_log_entry::generate_test_instances(list<rgw_log_entry*>& o)
218{
219 rgw_log_entry *e = new rgw_log_entry;
220 e->object_owner = "object_owner";
221 e->bucket_owner = "bucket_owner";
222 e->bucket = "bucket";
223 e->remote_addr = "1.2.3.4";
224 e->user = "user";
225 e->obj = rgw_obj_key("obj");
226 e->uri = "http://uri/bucket/obj";
227 e->http_status = "200";
228 e->error_code = "error_code";
229 e->bytes_sent = 1024;
230 e->bytes_received = 512;
231 e->obj_size = 2048;
232 e->user_agent = "user_agent";
233 e->referrer = "referrer";
234 e->bucket_id = "10";
235 o.push_back(e);
236 o.push_back(new rgw_log_entry);
237}
238
239void ACLPermission::generate_test_instances(list<ACLPermission*>& o)
240{
241 ACLPermission *p = new ACLPermission;
242 p->set_permissions(RGW_PERM_WRITE_ACP);
243 o.push_back(p);
244 o.push_back(new ACLPermission);
245}
246
247void ACLGranteeType::generate_test_instances(list<ACLGranteeType*>& o)
248{
249 ACLGranteeType *t = new ACLGranteeType;
250 t->set(ACL_TYPE_CANON_USER);
251 o.push_back(t);
252 o.push_back(new ACLGranteeType);
253}
254
255/* the following is copied here from rgw_acl_s3.cc, to avoid having to have excessive linking
256 with everything it needs */
257
258#define RGW_URI_ALL_USERS "http://acs.amazonaws.com/groups/global/AllUsers"
259#define RGW_URI_AUTH_USERS "http://acs.amazonaws.com/groups/global/AuthenticatedUsers"
260
261static string rgw_uri_all_users = RGW_URI_ALL_USERS;
262static string rgw_uri_auth_users = RGW_URI_AUTH_USERS;
263
264ACLGroupTypeEnum ACLGrant::uri_to_group(string& uri)
265{
266 // this is required for backward compatibility
267 return ACLGrant_S3::uri_to_group(uri);
268}
269
270ACLGroupTypeEnum ACLGrant_S3::uri_to_group(string& uri)
271{
272 if (uri.compare(rgw_uri_all_users) == 0)
273 return ACL_GROUP_ALL_USERS;
274 else if (uri.compare(rgw_uri_auth_users) == 0)
275 return ACL_GROUP_AUTHENTICATED_USERS;
276
277 return ACL_GROUP_NONE;
278}
279
280void ACLGrant::generate_test_instances(list<ACLGrant*>& o)
281{
282 rgw_user id("rgw");
283 string name, email;
284 name = "Mr. RGW";
285 email = "r@gw";
286
287 ACLGrant *g1 = new ACLGrant;
288 g1->set_canon(id, name, RGW_PERM_READ);
289 g1->email = email;
290 o.push_back(g1);
291
292 ACLGrant *g2 = new ACLGrant;
293 g1->set_group(ACL_GROUP_AUTHENTICATED_USERS, RGW_PERM_WRITE);
294 o.push_back(g2);
295
296 o.push_back(new ACLGrant);
297}
298
299void RGWAccessControlList::generate_test_instances(list<RGWAccessControlList*>& o)
300{
301 RGWAccessControlList *acl = new RGWAccessControlList(NULL);
302
303 list<ACLGrant *> glist;
304 list<ACLGrant *>::iterator iter;
305
306 ACLGrant::generate_test_instances(glist);
307 for (iter = glist.begin(); iter != glist.end(); ++iter) {
308 ACLGrant *grant = *iter;
309 acl->add_grant(grant);
310
311 delete grant;
312 }
313 o.push_back(acl);
314 o.push_back(new RGWAccessControlList(NULL));
315}
316
317void ACLOwner::generate_test_instances(list<ACLOwner*>& o)
318{
319 ACLOwner *owner = new ACLOwner;
320 owner->id = "rgw";
321 owner->display_name = "Mr. RGW";
322 o.push_back(owner);
323 o.push_back(new ACLOwner);
324}
325
326void RGWAccessControlPolicy::generate_test_instances(list<RGWAccessControlPolicy*>& o)
327{
328 list<RGWAccessControlList *> acl_list;
329 list<RGWAccessControlList *>::iterator iter;
330 for (iter = acl_list.begin(); iter != acl_list.end(); ++iter) {
331 RGWAccessControlList::generate_test_instances(acl_list);
332 iter = acl_list.begin();
333
334 RGWAccessControlPolicy *p = new RGWAccessControlPolicy(NULL);
335 RGWAccessControlList *l = *iter;
336 p->acl = *l;
337
338 string name = "radosgw";
339 rgw_user id("rgw");
340 p->owner.set_name(name);
341 p->owner.set_id(id);
342
343 o.push_back(p);
344
345 delete l;
346 }
347
348 o.push_back(new RGWAccessControlPolicy(NULL));
349}
350
351
352void ObjectMetaInfo::generate_test_instances(list<ObjectMetaInfo*>& o)
353{
354 ObjectMetaInfo *m = new ObjectMetaInfo;
355 m->size = 1024 * 1024;
356 o.push_back(m);
357 o.push_back(new ObjectMetaInfo);
358}
359
360void ObjectCacheInfo::generate_test_instances(list<ObjectCacheInfo*>& o)
361{
11fdf7f2 362 using ceph::encode;
7c673cae
FG
363 ObjectCacheInfo *i = new ObjectCacheInfo;
364 i->status = 0;
365 i->flags = CACHE_FLAG_MODIFY_XATTRS;
366 string s = "this is a string";
367 string s2 = "this is a another string";
368 bufferlist data, data2;
11fdf7f2
TL
369 encode(s, data);
370 encode(s2, data2);
7c673cae
FG
371 i->data = data;
372 i->xattrs["x1"] = data;
373 i->xattrs["x2"] = data2;
374 i->rm_xattrs["r2"] = data2;
375 i->rm_xattrs["r3"] = data;
376 i->meta.size = 512 * 1024;
377 o.push_back(i);
378 o.push_back(new ObjectCacheInfo);
379}
380
381void RGWCacheNotifyInfo::generate_test_instances(list<RGWCacheNotifyInfo*>& o)
382{
383 o.push_back(new RGWCacheNotifyInfo);
384}
385
386void RGWAccessKey::generate_test_instances(list<RGWAccessKey*>& o)
387{
388 RGWAccessKey *k = new RGWAccessKey;
389 k->id = "id";
390 k->key = "key";
391 k->subuser = "subuser";
392 o.push_back(k);
393 o.push_back(new RGWAccessKey);
394}
395
396void RGWSubUser::generate_test_instances(list<RGWSubUser*>& o)
397{
398 RGWSubUser *u = new RGWSubUser;
399 u->name = "name";
400 u->perm_mask = 0xf;
401 o.push_back(u);
402 o.push_back(new RGWSubUser);
403}
404
405void RGWUserInfo::generate_test_instances(list<RGWUserInfo*>& o)
406{
407 RGWUserInfo *i = new RGWUserInfo;
7c673cae
FG
408 i->user_id = "user_id";
409 i->display_name = "display_name";
410 i->user_email = "user@email";
411 RGWAccessKey k1, k2;
412 k1.id = "id1";
413 k1.key = "key1";
414 k2.id = "id2";
415 k2.subuser = "subuser";
416 RGWSubUser u;
417 u.name = "id2";
418 u.perm_mask = 0x1;
419 i->access_keys[k1.id] = k1;
420 i->swift_keys[k2.id] = k2;
421 i->subusers[u.name] = u;
422 o.push_back(i);
423
424 o.push_back(new RGWUserInfo);
425}
426
427void rgw_bucket::generate_test_instances(list<rgw_bucket*>& o)
428{
429 rgw_bucket *b = new rgw_bucket;
430 init_bucket(b, "tenant", "name", "pool", ".index_pool", "marker", "123");
431 o.push_back(b);
432 o.push_back(new rgw_bucket);
433}
434
435void RGWBucketInfo::generate_test_instances(list<RGWBucketInfo*>& o)
436{
437 RGWBucketInfo *i = new RGWBucketInfo;
438 init_bucket(&i->bucket, "tenant", "bucket", "pool", ".index_pool", "marker", "10");
439 i->owner = "owner";
440 i->flags = BUCKET_SUSPENDED;
441 o.push_back(i);
442 o.push_back(new RGWBucketInfo);
443}
444
445void RGWZoneGroup::generate_test_instances(list<RGWZoneGroup*>& o)
446{
447 RGWZoneGroup *r = new RGWZoneGroup;
448 o.push_back(r);
449 o.push_back(new RGWZoneGroup);
450}
451
452void RGWZone::generate_test_instances(list<RGWZone*> &o)
453{
454 RGWZone *z = new RGWZone;
455 o.push_back(z);
456 o.push_back(new RGWZone);
457}
458
11fdf7f2
TL
459void RGWRealm::generate_test_instances(list<RGWRealm*> &o)
460{
461 RGWRealm *z = new RGWRealm;
462 o.push_back(z);
463 o.push_back(new RGWRealm);
464}
465
466void RGWPeriod::generate_test_instances(list<RGWPeriod*> &o)
467{
468 RGWPeriod *z = new RGWPeriod;
469 o.push_back(z);
470 o.push_back(new RGWPeriod);
471}
472
7c673cae
FG
473void RGWZoneParams::generate_test_instances(list<RGWZoneParams*> &o)
474{
475 o.push_back(new RGWZoneParams);
476 o.push_back(new RGWZoneParams);
477}
478
479void RGWOLHInfo::generate_test_instances(list<RGWOLHInfo*> &o)
480{
481 RGWOLHInfo *olh = new RGWOLHInfo;
482 olh->removed = false;
483 o.push_back(olh);
484 o.push_back(new RGWOLHInfo);
485}
486
487void RGWBucketEnt::generate_test_instances(list<RGWBucketEnt*>& o)
488{
489 RGWBucketEnt *e = new RGWBucketEnt;
490 init_bucket(&e->bucket, "tenant", "bucket", "pool", ".index_pool", "marker", "10");
491 e->size = 1024;
492 e->size_rounded = 4096;
493 e->count = 1;
494 o.push_back(e);
495 o.push_back(new RGWBucketEnt);
496}
497
498void RGWUploadPartInfo::generate_test_instances(list<RGWUploadPartInfo*>& o)
499{
500 RGWUploadPartInfo *i = new RGWUploadPartInfo;
501 i->num = 1;
502 i->size = 10 * 1024 * 1024;
503 i->etag = "etag";
504 o.push_back(i);
505 o.push_back(new RGWUploadPartInfo);
506}
507
508void rgw_obj::generate_test_instances(list<rgw_obj*>& o)
509{
510 rgw_bucket b;
511 init_bucket(&b, "tenant", "bucket", "pool", ".index_pool", "marker", "10");
512 rgw_obj *obj = new rgw_obj(b, "object");
513 o.push_back(obj);
514 o.push_back(new rgw_obj);
515}
516
b32b8144
FG
517void rgw_meta_sync_info::generate_test_instances(list<rgw_meta_sync_info*>& o)
518{
519 auto info = new rgw_meta_sync_info;
520 info->state = rgw_meta_sync_info::StateBuildingFullSyncMaps;
521 info->period = "periodid";
522 info->realm_epoch = 5;
523 o.push_back(info);
524 o.push_back(new rgw_meta_sync_info);
525}
526
527void rgw_meta_sync_marker::generate_test_instances(list<rgw_meta_sync_marker*>& o)
528{
529 auto marker = new rgw_meta_sync_marker;
530 marker->state = rgw_meta_sync_marker::IncrementalSync;
531 marker->marker = "01234";
532 marker->realm_epoch = 5;
533 o.push_back(marker);
534 o.push_back(new rgw_meta_sync_marker);
535}
536
537void rgw_meta_sync_status::generate_test_instances(list<rgw_meta_sync_status*>& o)
538{
539 o.push_back(new rgw_meta_sync_status);
540}
541
542void rgw_data_sync_info::generate_test_instances(list<rgw_data_sync_info*>& o)
543{
544 auto info = new rgw_data_sync_info;
545 info->state = rgw_data_sync_info::StateBuildingFullSyncMaps;
546 info->num_shards = 8;
547 o.push_back(info);
548 o.push_back(new rgw_data_sync_info);
549}
550
551void rgw_data_sync_marker::generate_test_instances(list<rgw_data_sync_marker*>& o)
552{
553 auto marker = new rgw_data_sync_marker;
554 marker->state = rgw_data_sync_marker::IncrementalSync;
555 marker->marker = "01234";
556 marker->pos = 5;
557 o.push_back(marker);
558 o.push_back(new rgw_data_sync_marker);
559}
560
561void rgw_data_sync_status::generate_test_instances(list<rgw_data_sync_status*>& o)
562{
563 o.push_back(new rgw_data_sync_status);
564}